From bde319ecd46ca4f56e03845a036c33b6c40d0e78 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 3 Apr 2021 20:23:03 +0900 Subject: [PATCH 1/8] 1. Fix NavDirection compile issue. 2. Fix null pointer if tab order pref is null. 3. Set initial tab order in pref if empty. --- .../NotificationsViewerFragment.java | 7 ++-- .../java/awais/instagrabber/utils/Utils.java | 7 +++- .../notification_viewer_nav_graph.xml | 38 +++++++++---------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java index 77157ab6..60c4a7be 100644 --- a/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java @@ -79,7 +79,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe binding.swipeRefreshLayout.setRefreshing(false); Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show(); } - catch(Throwable e) {} + catch(Throwable ignored) {} } }; @@ -92,7 +92,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe @Override public void onPreviewClick(final Notification model) { final NotificationImage notificationImage = model.getArgs().getMedia().get(0); - final long mediaId = Long.valueOf(notificationImage.getId().split("_")[0]); + final long mediaId = Long.parseLong(notificationImage.getId().split("_")[0]); if (model.getType() == NotificationType.RESPONDED_STORY) { final NavDirections action = NotificationsViewerFragmentDirections .actionNotificationsViewerFragmentToStoryViewerFragment( @@ -277,8 +277,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe } private void openProfile(final String username) { - final NavDirections action = NotificationsViewerFragmentDirections - .actionGlobalProfileFragment("@" + username); + final NavDirections action = NotificationsViewerFragmentDirections.actionGlobalProfileFragment("@" + username); NavHostFragment.findNavController(this).navigate(action); } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/utils/Utils.java b/app/src/main/java/awais/instagrabber/utils/Utils.java index 6f966c33..e6824d84 100644 --- a/app/src/main/java/awais/instagrabber/utils/Utils.java +++ b/app/src/main/java/awais/instagrabber/utils/Utils.java @@ -31,7 +31,6 @@ 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; @@ -474,7 +473,10 @@ public final class Utils { final List navGraphNameList = Arrays.asList(navGraphNames); if (TextUtils.isEmpty(tabOrderString)) { // Use top 5 entries for default list - return navGraphNameList.subList(0, 5); + final List top5navGraphNames = navGraphNameList.subList(0, 5); + final String newOrderString = android.text.TextUtils.join(",", top5navGraphNames); + Utils.settingsHelper.putString(PreferenceKeys.PREF_TAB_ORDER, newOrderString); + return top5navGraphNames; } // Make sure that the list from preference does not contain any invalid values final List orderGraphNames = Arrays.stream(tabOrderString.split(",")) @@ -489,6 +491,7 @@ public final class Utils { } public static boolean isNavRootInCurrentTabs(final String navRootString) { + if (navRootString == null || tabOrderString == null) return false; return tabOrderString.contains(navRootString); } } diff --git a/app/src/main/res/navigation/notification_viewer_nav_graph.xml b/app/src/main/res/navigation/notification_viewer_nav_graph.xml index 8f80b18e..8f838474 100644 --- a/app/src/main/res/navigation/notification_viewer_nav_graph.xml +++ b/app/src/main/res/navigation/notification_viewer_nav_graph.xml @@ -5,25 +5,6 @@ android:id="@+id/notification_viewer_nav_graph" app:startDestination="@id/notificationsViewer"> - - - - - - + + + + + + \ No newline at end of file From b1dd0e6e3c37cbdfa7737fd6a90f1cdc57393f6d Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 3 Apr 2021 20:41:35 +0900 Subject: [PATCH 2/8] Get tabOrderString always from settings, so that it's not stale if preferences were updated --- app/src/main/java/awais/instagrabber/utils/Utils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/utils/Utils.java b/app/src/main/java/awais/instagrabber/utils/Utils.java index e6824d84..ff79f67f 100644 --- a/app/src/main/java/awais/instagrabber/utils/Utils.java +++ b/app/src/main/java/awais/instagrabber/utils/Utils.java @@ -80,7 +80,6 @@ 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) { @@ -469,7 +468,7 @@ public final class Utils { @NonNull private static List getCurrentOrderOfGraphNamesFromPref(@NonNull final String[] navGraphNames) { - tabOrderString = settingsHelper.getString(PreferenceKeys.PREF_TAB_ORDER); + final String tabOrderString = settingsHelper.getString(PreferenceKeys.PREF_TAB_ORDER); final List navGraphNameList = Arrays.asList(navGraphNames); if (TextUtils.isEmpty(tabOrderString)) { // Use top 5 entries for default list @@ -491,6 +490,7 @@ public final class Utils { } public static boolean isNavRootInCurrentTabs(final String navRootString) { + final String tabOrderString = settingsHelper.getString(PreferenceKeys.PREF_TAB_ORDER); if (navRootString == null || tabOrderString == null) return false; return tabOrderString.contains(navRootString); } From e2c15e76b8d051e36b647777b12eb6c279e05158 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 3 Apr 2021 20:41:35 +0900 Subject: [PATCH 3/8] Revert "Get tabOrderString always from settings, so that it's not stale if preferences were updated" This reverts commit b1dd0e6e3c37cbdfa7737fd6a90f1cdc57393f6d. --- app/src/main/java/awais/instagrabber/utils/Utils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/utils/Utils.java b/app/src/main/java/awais/instagrabber/utils/Utils.java index ff79f67f..e6824d84 100644 --- a/app/src/main/java/awais/instagrabber/utils/Utils.java +++ b/app/src/main/java/awais/instagrabber/utils/Utils.java @@ -80,6 +80,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 +469,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 @@ -490,7 +491,6 @@ public final class Utils { } public static boolean isNavRootInCurrentTabs(final String navRootString) { - final String tabOrderString = settingsHelper.getString(PreferenceKeys.PREF_TAB_ORDER); if (navRootString == null || tabOrderString == null) return false; return tabOrderString.contains(navRootString); } From c5786a684304a505779b61e6a80c44e930ea3136 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 3 Apr 2021 20:48:21 +0900 Subject: [PATCH 4/8] Set tabOrderString value with default graph names when its empty --- app/src/main/java/awais/instagrabber/utils/Utils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/awais/instagrabber/utils/Utils.java b/app/src/main/java/awais/instagrabber/utils/Utils.java index e6824d84..6f711a45 100644 --- a/app/src/main/java/awais/instagrabber/utils/Utils.java +++ b/app/src/main/java/awais/instagrabber/utils/Utils.java @@ -476,6 +476,7 @@ public final class Utils { final List top5navGraphNames = navGraphNameList.subList(0, 5); final String newOrderString = android.text.TextUtils.join(",", top5navGraphNames); Utils.settingsHelper.putString(PreferenceKeys.PREF_TAB_ORDER, newOrderString); + tabOrderString = newOrderString; return top5navGraphNames; } // Make sure that the list from preference does not contain any invalid values From 3038a06dca803d37b6071480c36b4b4c972f358f Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 3 Apr 2021 22:07:58 +0900 Subject: [PATCH 5/8] Long name causing compile issues on windows? --- .../instagrabber/fragments/NotificationsViewerFragment.java | 5 ++--- .../main/res/navigation/notification_viewer_nav_graph.xml | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java index 60c4a7be..15d5306d 100644 --- a/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java @@ -78,8 +78,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe try { binding.swipeRefreshLayout.setRefreshing(false); Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show(); - } - catch(Throwable ignored) {} + } catch (Throwable ignored) {} } }; @@ -95,7 +94,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe final long mediaId = Long.parseLong(notificationImage.getId().split("_")[0]); if (model.getType() == NotificationType.RESPONDED_STORY) { final NavDirections action = NotificationsViewerFragmentDirections - .actionNotificationsViewerFragmentToStoryViewerFragment( + .actionNotificationsToStory( StoryViewerOptions.forStory( mediaId, model.getArgs().getUsername())); diff --git a/app/src/main/res/navigation/notification_viewer_nav_graph.xml b/app/src/main/res/navigation/notification_viewer_nav_graph.xml index 8f838474..50e2fbdf 100644 --- a/app/src/main/res/navigation/notification_viewer_nav_graph.xml +++ b/app/src/main/res/navigation/notification_viewer_nav_graph.xml @@ -97,7 +97,7 @@ android:defaultValue="0L" app:argType="long" /> \ No newline at end of file From 043b0d50eb7aeb091f9026222e27729b390b2623 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 3 Apr 2021 23:08:37 +0900 Subject: [PATCH 6/8] Remove unused files --- app/src/main/resources/feed_response.json | 1 - app/src/main/resources/stories_response.json | 1 - 2 files changed, 2 deletions(-) delete mode 100644 app/src/main/resources/feed_response.json delete mode 100644 app/src/main/resources/stories_response.json diff --git a/app/src/main/resources/feed_response.json b/app/src/main/resources/feed_response.json deleted file mode 100644 index 9e26dfee..00000000 --- a/app/src/main/resources/feed_response.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/app/src/main/resources/stories_response.json b/app/src/main/resources/stories_response.json deleted file mode 100644 index 9e26dfee..00000000 --- a/app/src/main/resources/stories_response.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file From 70055271500c9ae72a070fa98a8fc8de09679c03 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 3 Apr 2021 23:44:46 +0900 Subject: [PATCH 7/8] Check navigation. Fixes https://github.com/austinhuang0131/barinsta/issues/380 --- .../instagrabber/fragments/main/FeedFragment.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 f4b8d47e..bfc1dee3 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java @@ -83,9 +83,12 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre new FeedStoriesAdapter.OnFeedStoryClickListener() { @Override public void onFeedStoryClick(FeedStoryModel model, int position) { - final NavDirections action = FeedFragmentDirections - .actionFeedFragmentToStoryViewerFragment(StoryViewerOptions.forFeedStoryPosition(position)); - NavHostFragment.findNavController(FeedFragment.this).navigate(action); + final NavController navController = NavHostFragment.findNavController(FeedFragment.this); + if (isSafeToNavigate(navController)) { + final NavDirections action = FeedFragmentDirections + .actionFeedFragmentToStoryViewerFragment(StoryViewerOptions.forFeedStoryPosition(position)); + navController.navigate(action); + } } @Override @@ -437,4 +440,9 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre binding.feedRecyclerView.smoothScrollToPosition(0); // binding.storiesContainer.setExpanded(true); } + + private boolean isSafeToNavigate(final NavController navController) { + return navController.getCurrentDestination() != null + && navController.getCurrentDestination().getId() == R.id.feedFragment; + } } From 122f9b23818f6fd5de6841850dac47bf85494acf Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sat, 3 Apr 2021 23:49:54 +0900 Subject: [PATCH 8/8] Fix highlights overlapping counts --- app/src/main/res/layout/layout_profile_details.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/layout_profile_details.xml b/app/src/main/res/layout/layout_profile_details.xml index 035a04b0..ea4df164 100644 --- a/app/src/main/res/layout/layout_profile_details.xml +++ b/app/src/main/res/layout/layout_profile_details.xml @@ -326,6 +326,7 @@