From 23611df3feffbe128e904f4143010c5128893c05 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Fri, 2 Apr 2021 12:01:29 -0400 Subject: [PATCH] make isNavRootInCurrentTabs consistent, show/hide explore --- .../instagrabber/activities/MainActivity.java | 6 +++--- .../fragments/main/ProfileFragment.java | 2 +- .../settings/MorePreferencesFragment.java | 17 +++++++++++++++-- .../java/awais/instagrabber/utils/Utils.java | 8 +++++++- app/src/main/res/navigation/more_nav_graph.xml | 1 + 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/activities/MainActivity.java b/app/src/main/java/awais/instagrabber/activities/MainActivity.java index fa6b65f2..b03a3696 100644 --- a/app/src/main/java/awais/instagrabber/activities/MainActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/MainActivity.java @@ -906,9 +906,9 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage return currentTabs; } - public boolean isNavRootInCurrentTabs(@IdRes final int navRootId) { - return showBottomViewDestinations.stream().anyMatch(id -> id == navRootId); - } +// public boolean isNavRootInCurrentTabs(@IdRes final int navRootId) { +// return showBottomViewDestinations.stream().anyMatch(id -> id == navRootId); +// } private void setNavBarDMUnreadCountBadge(final int unseenCount) { final BadgeDrawable badge = binding.bottomNavView.getOrCreateBadge(R.id.direct_messages_nav_graph); diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 2cb002ff..cc2ce13a 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -580,7 +580,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe } private void init() { - disableDm = !fragmentActivity.isNavRootInCurrentTabs(R.id.directMessagesInboxFragment); + disableDm = !Utils.isNavRootInCurrentTabs("direct_messages_nav_graph"); if (getArguments() != null) { final ProfileFragmentArgs fragmentArgs = ProfileFragmentArgs.fromBundle(getArguments()); username = fragmentArgs.getUsername(); diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java index 947996a2..ecfcff77 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java @@ -39,6 +39,7 @@ import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.FlavorTown; import awais.instagrabber.utils.TextUtils; +import awais.instagrabber.utils.Utils; import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.UserService; @@ -59,6 +60,7 @@ public class MorePreferencesFragment extends BasePreferencesFragment { final MainActivity activity = (MainActivity) getActivity(); // screen.addPreference(new MoreHeaderPreference(getContext())); final Context context = getContext(); + final Resources resources = context.getResources(); if (context == null) return; accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(context)); final PreferenceCategory accountCategory = new PreferenceCategory(context); @@ -138,8 +140,10 @@ public class MorePreferencesFragment extends BasePreferencesFragment { final NavController navController = NavHostFragment.findNavController(this); if (isLoggedIn) { boolean showActivity = true; + boolean showExplore = false; if (activity != null) { - showActivity = !activity.isNavRootInCurrentTabs(R.id.notificationsViewer); + showActivity = !Utils.isNavRootInCurrentTabs("notification_viewer_nav_graph"); + showExplore = !Utils.isNavRootInCurrentTabs("discover_nav_graph"); } if (showActivity) { screen.addPreference(getPreference(R.string.action_notif, R.drawable.ic_not_liked, preference -> { @@ -150,6 +154,15 @@ public class MorePreferencesFragment extends BasePreferencesFragment { return true; })); } + if (showExplore) { + screen.addPreference(getPreference(R.string.title_discover, R.drawable.ic_explore_24, preference -> { + if (isSafeToNavigate(navController)) { + navController.navigate(R.id.discover_nav_graph); + } + return true; + })); + } + screen.addPreference(getPreference(R.string.action_ayml, R.drawable.ic_suggested_users, preference -> { if (isSafeToNavigate(navController)) { final NavDirections navDirections = MorePreferencesFragmentDirections.actionGlobalNotificationsViewerFragment("ayml"); @@ -169,7 +182,7 @@ public class MorePreferencesFragment extends BasePreferencesFragment { // Check if favorites has been added as a tab. And if so, do not add in this list boolean showFavorites = true; if (activity != null) { - showFavorites = !activity.isNavRootInCurrentTabs(R.id.favoritesFragment); + showFavorites = !Utils.isNavRootInCurrentTabs("favorites_nav_graph"); } if (showFavorites) { screen.addPreference(getPreference(R.string.title_favorites, R.drawable.ic_star_24, preference -> { diff --git a/app/src/main/java/awais/instagrabber/utils/Utils.java b/app/src/main/java/awais/instagrabber/utils/Utils.java index 7d0afd2b..6f966c33 100644 --- a/app/src/main/java/awais/instagrabber/utils/Utils.java +++ b/app/src/main/java/awais/instagrabber/utils/Utils.java @@ -31,6 +31,7 @@ import android.webkit.MimeTypeMap; import android.widget.Toast; import androidx.annotation.DrawableRes; +import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; @@ -80,6 +81,7 @@ public final class Utils { private static int actionBarHeight; public static Handler applicationHandler; public static String cacheDir; + public static String tabOrderString; private static int defaultStatusBarColor; public static int convertDpToPx(final float dp) { @@ -468,7 +470,7 @@ public final class Utils { @NonNull private static List getCurrentOrderOfGraphNamesFromPref(@NonNull final String[] navGraphNames) { - final String tabOrderString = settingsHelper.getString(PreferenceKeys.PREF_TAB_ORDER); + tabOrderString = settingsHelper.getString(PreferenceKeys.PREF_TAB_ORDER); final List navGraphNameList = Arrays.asList(navGraphNames); if (TextUtils.isEmpty(tabOrderString)) { // Use top 5 entries for default list @@ -485,4 +487,8 @@ public final class Utils { } return orderGraphNames; } + + public static boolean isNavRootInCurrentTabs(final String navRootString) { + return tabOrderString.contains(navRootString); + } } diff --git a/app/src/main/res/navigation/more_nav_graph.xml b/app/src/main/res/navigation/more_nav_graph.xml index 84ae9423..0274390e 100644 --- a/app/src/main/res/navigation/more_nav_graph.xml +++ b/app/src/main/res/navigation/more_nav_graph.xml @@ -11,6 +11,7 @@ +