From a05c917b2c81aa4d1803891687b49cc856fe580f Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 21 Nov 2023 21:46:41 +0300 Subject: [PATCH] Assorted crash fixes --- .../android/fragments/BaseStatusListFragment.java | 2 ++ .../fragments/NotificationsListFragment.java | 2 ++ .../fragments/settings/SettingsMainFragment.java | 2 +- .../android/ui/AccountSwitcherSheet.java | 13 +++++++++++++ .../ToolbarDropdownMenuController.java | 2 ++ .../android/ui/views/ReorderableLinearLayout.java | 1 + 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 5d5724f0..0b23e2e8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -248,6 +248,7 @@ public abstract class BaseStatusListFragment exten @Override public void photoViewerDismissed(){ currentPhotoViewer=null; + gridHolder.itemView.setHasTransientState(false); } @Override @@ -259,6 +260,7 @@ public abstract class BaseStatusListFragment exten return gridHolder.getViewController(index); } }); + gridHolder.itemView.setHasTransientState(true); } @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java index ffa2a1ae..f51dc684 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java @@ -314,6 +314,8 @@ public class NotificationsListFragment extends BaseStatusListFragment0){ new SaveMarkers(null, id).exec(accountID); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java index 1c819d69..79980bcc 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java @@ -153,7 +153,7 @@ public class SettingsMainFragment extends BaseSettingsFragment{ } private void onManageAccountsClick(ListItem item){ - new AccountSwitcherSheet(getActivity(), null).show(); + new AccountSwitcherSheet(getActivity(), null).setOnLoggedOutCallback(()->loggedOut=true).show(); } private void onLogOutClick(ListItem item_){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java b/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java index 540c1c90..561deed6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java @@ -60,6 +60,7 @@ public class AccountSwitcherSheet extends BottomSheet{ private UsableRecyclerView list; private List accounts; private ListImageLoaderWrapper imgLoader; + private Runnable onLoggedOutCallback; public AccountSwitcherSheet(@NonNull Activity activity, @Nullable HomeFragment fragment){ super(activity); @@ -95,6 +96,11 @@ public class AccountSwitcherSheet extends BottomSheet{ UiUtils.getThemeColor(activity, R.attr.colorM3Primary), 0.05f)), !UiUtils.isDarkTheme()); } + public AccountSwitcherSheet setOnLoggedOutCallback(Runnable onLoggedOutCallback){ + this.onLoggedOutCallback=onLoggedOutCallback; + return this; + } + private void confirmLogOut(String accountID){ AccountSession session=AccountSessionManager.getInstance().getAccount(accountID); new M3AlertDialogBuilder(activity) @@ -113,7 +119,10 @@ public class AccountSwitcherSheet extends BottomSheet{ } private void logOut(String accountID){ + String activeAccount=AccountSessionManager.getInstance().getLastActiveAccountID(); AccountSessionManager.get(accountID).logOut(activity, ()->{ + if(accountID.equals(activeAccount) && onLoggedOutCallback!=null) + onLoggedOutCallback.run(); dismiss(); ((MainActivity)activity).restartHomeFragment(); }); @@ -133,6 +142,8 @@ public class AccountSwitcherSheet extends BottomSheet{ AccountSessionManager.getInstance().removeAccount(session.getID()); sessions.remove(session); if(sessions.isEmpty()){ + if(onLoggedOutCallback!=null) + onLoggedOutCallback.run(); progress.dismiss(); Nav.goClearingStack(activity, SplashFragment.class, null); dismiss(); @@ -144,6 +155,8 @@ public class AccountSwitcherSheet extends BottomSheet{ AccountSessionManager.getInstance().removeAccount(session.getID()); sessions.remove(session); if(sessions.isEmpty()){ + if(onLoggedOutCallback!=null) + onLoggedOutCallback.run(); progress.dismiss(); Nav.goClearingStack(activity, SplashFragment.class, null); dismiss(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ToolbarDropdownMenuController.java b/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ToolbarDropdownMenuController.java index a40eca8c..520ef51e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ToolbarDropdownMenuController.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/viewcontrollers/ToolbarDropdownMenuController.java @@ -181,6 +181,8 @@ public class ToolbarDropdownMenuController{ public void resizeOnNextFrame(){ if(currentTransition!=null) currentTransition.cancel(); + if(windowView==null) + return; int origBottom=menuContainer.getBottom(); menuContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){ @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/views/ReorderableLinearLayout.java b/mastodon/src/main/java/org/joinmastodon/android/ui/views/ReorderableLinearLayout.java index 3285848f..4c071f60 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/views/ReorderableLinearLayout.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/views/ReorderableLinearLayout.java @@ -173,6 +173,7 @@ public class ReorderableLinearLayout extends LinearLayout implements CustomViewH else bottomSibling=null; dragListener.onSwapItems(prevIndex, index); + final View draggedView=this.draggedView; draggedView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){ @Override public boolean onPreDraw(){