From 113db92ce712c59475c8adfe01431f9ac845a8e8 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 13 Jun 2022 18:34:31 +0200 Subject: [PATCH] Some fixes --- .../app/fedilab/android/BaseMainActivity.java | 16 +++--- .../android/client/entities/app/Account.java | 2 +- .../android/helper/MastodonHelper.java | 50 ++++++++++--------- .../android/helper/PinnedTimelineHelper.java | 9 ++-- .../fedilab/android/helper/PushHelper.java | 4 +- .../android/services/PostMessageService.java | 4 +- .../ui/pageadapter/FedilabPageAdapter.java | 5 -- 7 files changed, 48 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 57efd908..ec5a73e9 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -729,10 +729,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt private void manageFilters(int position) { View view = binding.bottomNavView.findViewById(R.id.nav_home); - if (position == 1) { + boolean showExtendedFilter = true; + if (position == BottomMenu.getPosition(bottomMenu, R.id.nav_local)) { view = binding.bottomNavView.findViewById(R.id.nav_local); - } else if (position == 2) { + showExtendedFilter = false; + } else if (position == BottomMenu.getPosition(bottomMenu, R.id.nav_public)) { view = binding.bottomNavView.findViewById(R.id.nav_public); + showExtendedFilter = false; } PopupMenu popup = new PopupMenu(new ContextThemeWrapper(BaseMainActivity.this, Helper.popupStyle()), view, Gravity.TOP); popup.getMenuInflater() @@ -741,7 +744,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt final MenuItem itemShowBoosts = menu.findItem(R.id.action_show_boosts); final MenuItem itemShowReplies = menu.findItem(R.id.action_show_replies); final MenuItem itemFilter = menu.findItem(R.id.action_filter); - if (position > 0) { + if (!showExtendedFilter) { itemShowBoosts.setVisible(false); itemShowReplies.setVisible(false); } else { @@ -751,13 +754,14 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this); String show_filtered = null; - if (position == 0) { + if (position == BottomMenu.getPosition(bottomMenu, R.id.nav_home)) { show_filtered = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_HOME) + currentUserID + currentInstance, null); - } else if (position == 1) { + } else if (position == BottomMenu.getPosition(bottomMenu, R.id.nav_local)) { show_filtered = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_LOCAL) + currentUserID + currentInstance, null); - } else if (position == 2) { + } else if (position == BottomMenu.getPosition(bottomMenu, R.id.nav_public)) { show_filtered = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_PUBLIC) + currentUserID + currentInstance, null); } + itemShowBoosts.setChecked(show_boosts); itemShowReplies.setChecked(show_replies); if (show_filtered != null && show_filtered.length() > 0) { diff --git a/app/src/main/java/app/fedilab/android/client/entities/app/Account.java b/app/src/main/java/app/fedilab/android/client/entities/app/Account.java index ca6f1e68..5157e26a 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/app/Account.java +++ b/app/src/main/java/app/fedilab/android/client/entities/app/Account.java @@ -118,7 +118,7 @@ public class Account implements Serializable { public List getPushNotificationAccounts() { try { - Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, "(" + Sqlite.COL_API + " = 'MASTODON' OR " + Sqlite.COL_API + " = 'PLEROMA') AND " + Sqlite.COL_TOKEN + " IS NOT NULL", null, null, null, Sqlite.COL_INSTANCE + " ASC", null); + Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, "(" + Sqlite.COL_API + " = 'MASTODON' OR " + Sqlite.COL_API + " = 'PLEROMA' OR " + Sqlite.COL_API + " = 'FRIENDICA') AND " + Sqlite.COL_TOKEN + " IS NOT NULL", null, null, null, Sqlite.COL_INSTANCE + " ASC", null); return cursorToListUserWithOwner(c); } catch (Exception e) { return null; diff --git a/app/src/main/java/app/fedilab/android/helper/MastodonHelper.java b/app/src/main/java/app/fedilab/android/helper/MastodonHelper.java index b7f33b53..28347348 100644 --- a/app/src/main/java/app/fedilab/android/helper/MastodonHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/MastodonHelper.java @@ -202,30 +202,32 @@ public class MastodonHelper { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean disableGif = sharedpreferences.getBoolean(context.getString(R.string.SET_DISABLE_GIF), false); @DrawableRes int placeholder = type == MediaAccountType.AVATAR ? R.drawable.ic_person : R.drawable.default_banner; - if (account == null) { - Glide.with(view.getContext()) - .asDrawable() - .load(placeholder) - .thumbnail(0.1f) - .placeholder(placeholder) - .into(view); - return; - } - String targetedUrl = disableGif ? (type == MediaAccountType.AVATAR ? account.avatar_static : account.header_static) : (type == MediaAccountType.AVATAR ? account.avatar : account.header); - if (disableGif || (!targetedUrl.endsWith(".gif"))) { - Glide.with(view.getContext()) - .asDrawable() - .load(targetedUrl) - .thumbnail(0.1f) - .placeholder(placeholder) - .into(view); - } else { - Glide.with(view.getContext()) - .asGif() - .load(targetedUrl) - .thumbnail(0.1f) - .placeholder(placeholder) - .into(view); + if (Helper.isValidContextForGlide(view.getContext())) { + if (account == null) { + Glide.with(view.getContext()) + .asDrawable() + .load(placeholder) + .thumbnail(0.1f) + .placeholder(placeholder) + .into(view); + return; + } + String targetedUrl = disableGif ? (type == MediaAccountType.AVATAR ? account.avatar_static : account.header_static) : (type == MediaAccountType.AVATAR ? account.avatar : account.header); + if (disableGif || (!targetedUrl.endsWith(".gif"))) { + Glide.with(view.getContext()) + .asDrawable() + .load(targetedUrl) + .thumbnail(0.1f) + .placeholder(placeholder) + .into(view); + } else { + Glide.with(view.getContext()) + .asGif() + .load(targetedUrl) + .thumbnail(0.1f) + .placeholder(placeholder) + .into(view); + } } } diff --git a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java index 8b5397b8..4f5f0a86 100644 --- a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java @@ -187,7 +187,7 @@ public class PinnedTimelineHelper { int finalI = i; Pinned finalPinned = pinned; tabStrip.getChildAt(i).setOnLongClickListener(v -> { - switch (pinnedTimelineVisibleList.get(finalI - BOTTOM_TIMELINE_COUNT).type) { + switch (pinnedTimelineVisibleList.get(finalI - (BOTTOM_TIMELINE_COUNT - toRemove)).type) { case LIST: break; @@ -288,9 +288,9 @@ public class PinnedTimelineHelper { * @param position - int position of the tab */ public static void tagClick(Context context, Pinned pinned, View view, ActivityMainBinding activityMainBinding, int position) { - + int toRemove = itemToRemoveInBottomMenu(context); PopupMenu popup = new PopupMenu(new ContextThemeWrapper(context, Helper.popupStyle()), view); - int offSetPosition = position - BOTTOM_TIMELINE_COUNT; + int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove); String tag; TagTimeline tagTimeline = pinned.pinnedTimelines.get(offSetPosition).tagTimeline; if (tagTimeline == null) @@ -503,7 +503,8 @@ public class PinnedTimelineHelper { public static void instanceClick(Context context, Pinned pinned, View view, ActivityMainBinding activityMainBinding, int position) { PopupMenu popup = new PopupMenu(new ContextThemeWrapper(context, Helper.popupStyle()), view); - int offSetPosition = position - BOTTOM_TIMELINE_COUNT; + int toRemove = itemToRemoveInBottomMenu(context); + int offSetPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove); RemoteInstance remoteInstance = pinned.pinnedTimelines.get(offSetPosition).remoteInstance; if (remoteInstance == null) return; diff --git a/app/src/main/java/app/fedilab/android/helper/PushHelper.java b/app/src/main/java/app/fedilab/android/helper/PushHelper.java index 87a20402..4a2cce81 100644 --- a/app/src/main/java/app/fedilab/android/helper/PushHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/PushHelper.java @@ -111,7 +111,9 @@ public class PushHelper { private static void registerAppWithDialog(Context context, List accounts) { - + if (accounts == null) { + return; + } List distributors = UnifiedPush.getDistributors(context, new ArrayList<>()); if (distributors.size() == 1 || !UnifiedPush.getDistributor(context).isEmpty()) { if (distributors.size() == 1) { diff --git a/app/src/main/java/app/fedilab/android/services/PostMessageService.java b/app/src/main/java/app/fedilab/android/services/PostMessageService.java index 0ce01194..17cafba8 100644 --- a/app/src/main/java/app/fedilab/android/services/PostMessageService.java +++ b/app/src/main/java/app/fedilab/android/services/PostMessageService.java @@ -199,12 +199,14 @@ public class PostMessageService extends IntentService { poll_hide_totals = false; } Call statusCall; + if (error) { + return; + } if (dataPost.scheduledDate == null) { statusCall = mastodonStatusesService.createStatus(null, dataPost.token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in, poll_multiple, poll_hide_totals, in_reply_to_status, statuses.get(i).sensitive, statuses.get(i).spoiler_text, statuses.get(i).visibility.toLowerCase(), statuses.get(i).language); try { Response statusResponse = statusCall.execute(); - if (statusResponse.isSuccessful()) { Status statusReply = statusResponse.body(); if (statusReply != null) { diff --git a/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabPageAdapter.java b/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabPageAdapter.java index a929a8c3..84ecc32e 100644 --- a/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabPageAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabPageAdapter.java @@ -16,7 +16,6 @@ package app.fedilab.android.ui.pageadapter; import android.content.Context; import android.os.Bundle; -import android.util.Log; import android.view.ViewGroup; import androidx.annotation.NonNull; @@ -75,11 +74,9 @@ public class FedilabPageAdapter extends FragmentStatePagerAdapter { FragmentMastodonTimeline fragment = new FragmentMastodonTimeline(); Bundle bundle = new Bundle(); //Position 3 is for notifications - Log.v(Helper.TAG, "position: " + position + " -> " + (BOTTOM_TIMELINE_COUNT - toRemove)); if (position < (BOTTOM_TIMELINE_COUNT - toRemove)) { if (bottomMenu != null) { BottomMenu.ItemMenuType type = BottomMenu.getType(bottomMenu, position); - Log.v(Helper.TAG, "type: " + type); if (type == null) { return fragment; } @@ -101,10 +98,8 @@ public class FedilabPageAdapter extends FragmentStatePagerAdapter { } else { int pinnedPosition = position - (BOTTOM_TIMELINE_COUNT - toRemove); //Real position has an offset. - Log.v(Helper.TAG, "pinnedPosition: " + pinnedPosition); PinnedTimeline pinnedTimeline = pinned.pinnedTimelines.get(pinnedPosition); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, pinnedTimeline.type); - Log.v(Helper.TAG, " pinnedTimeline.type: " + pinnedTimeline.type); if (pinnedTimeline.type == Timeline.TimeLineEnum.LIST) { bundle.putString(Helper.ARG_LIST_ID, pinnedTimeline.mastodonList.id); } else if (pinnedTimeline.type == Timeline.TimeLineEnum.TAG) {