From 522144298896f172250859687ff9c8708f8158dc Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Mon, 12 Jul 2021 20:19:05 -0400 Subject: [PATCH] put setToolbar() on onResume() fix problem with ActionBar duplicating --- .../java/awais/instagrabber/fragments/HashTagFragment.java | 2 +- .../awais/instagrabber/fragments/LocationFragment.java | 2 +- .../awais/instagrabber/fragments/main/FeedFragment.java | 7 ++++++- .../awais/instagrabber/fragments/main/ProfileFragment.kt | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java index bb6ae483..0e5ba714 100644 --- a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java @@ -305,7 +305,6 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe @Override public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { - fragmentActivity.setToolbar(binding.toolbar, this); if (!shouldRefresh) return; binding.swipeRefreshLayout.setOnRefreshListener(this); init(); @@ -321,6 +320,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe @Override public void onResume() { super.onResume(); + fragmentActivity.setToolbar(binding.toolbar, this); setTitle(); } diff --git a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java index 4d59428a..ab862a91 100644 --- a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java @@ -300,7 +300,6 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR @Override public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { - fragmentActivity.setToolbar(binding.toolbar, this); if (!shouldRefresh) return; binding.swipeRefreshLayout.setOnRefreshListener(this); init(); @@ -315,6 +314,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR @Override public void onResume() { super.onResume(); + fragmentActivity.setToolbar(binding.toolbar, this); setTitle(); } diff --git a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java index 6fdc1130..e1dbc584 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java @@ -280,7 +280,6 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre @Override public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { - fragmentActivity.setToolbar(binding.toolbar, this); if (!shouldRefresh) return; binding.feedSwipeRefreshLayout.setOnRefreshListener(this); /* @@ -335,6 +334,12 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre fetchStories(); } + @Override + public void onResume() { + super.onResume(); + fragmentActivity.setToolbar(binding.toolbar, this); + } + @Override public void onStop() { super.onStop(); diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt index 40ce6632..e5c165a6 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.kt @@ -380,12 +380,14 @@ class ProfileFragment : Fragment(), OnRefreshListener, ConfirmDialogFragmentCall override fun onResume() { super.onResume() + mainActivity.setToolbar(binding.toolbar, this) try { val backStackEntry = NavHostFragment.findNavController(this).currentBackStackEntry if (backStackEntry != null) { backStackSavedStateResultLiveData = backStackEntry.savedStateHandle.getLiveData("result") backStackSavedStateResultLiveData?.observe(viewLifecycleOwner, backStackSavedStateObserver) } + mainActivity.supportActionBar?.title = viewModel.username.value } catch (e: Exception) { Log.e(TAG, "onResume: ", e) } @@ -439,7 +441,6 @@ class ProfileFragment : Fragment(), OnRefreshListener, ConfirmDialogFragmentCall } private fun init() { - mainActivity.setToolbar(binding.toolbar, this) binding.swipeRefreshLayout.setOnRefreshListener(this) disableDm = !isNavRootInCurrentTabs("direct_messages_nav_graph") setupHighlights()