From c5e1c5ddd000b071342f905ebf61d9bdcaa9ed47 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 19 Nov 2023 11:34:58 -0500 Subject: Fix crashes related to gilded posts. --- .../infinityforreddit/settings/CustomizeMainPageTabsFragment.java | 8 ++++---- .../java/ml/docilealligator/infinityforreddit/utils/Utils.java | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java index fb8a5df7..af471538 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java @@ -226,7 +226,7 @@ public class CustomizeMainPageTabsFragment extends Fragment { tab1CurrentTitle = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home)); tab1CurrentPostType = mainActivityTabsSharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_HOME); if (accountName != null) { - tab1CurrentPostType = Utils.fixIndexOutOfBounds(typeValues, tab1CurrentPostType); + tab1CurrentPostType = Utils.fixIndexOutOfBoundsUsingPredetermined(typeValues, tab1CurrentPostType, 1); } tab1CurrentName = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, ""); tab1TypeSummaryTextView.setText(typeValues[tab1CurrentPostType]); @@ -318,7 +318,7 @@ public class CustomizeMainPageTabsFragment extends Fragment { tab2CurrentTitle = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular)); tab2CurrentPostType = mainActivityTabsSharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_POPULAR); if (accountName != null) { - tab2CurrentPostType = Utils.fixIndexOutOfBounds(typeValues, tab2CurrentPostType); + tab2CurrentPostType = Utils.fixIndexOutOfBoundsUsingPredetermined(typeValues, tab2CurrentPostType, 1); } tab2CurrentName = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, ""); tab2TypeSummaryTextView.setText(typeValues[tab2CurrentPostType]); @@ -406,8 +406,8 @@ public class CustomizeMainPageTabsFragment extends Fragment { tab3CurrentTitle = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all)); tab3CurrentPostType = mainActivityTabsSharedPreferences.getInt((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE, SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL); - if (accountName == null) { - tab3CurrentPostType = Utils.fixIndexOutOfBounds(typeValues, tab3CurrentPostType); + if (accountName != null) { + tab3CurrentPostType = Utils.fixIndexOutOfBoundsUsingPredetermined(typeValues, tab3CurrentPostType, 1); } tab3CurrentName = mainActivityTabsSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, ""); tab3TypeSummaryTextView.setText(typeValues[tab3CurrentPostType]); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index 67925743..f5f3b163 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -486,4 +486,8 @@ public final class Utils { public static int fixIndexOutOfBounds(T[] array, int index) { return index >= array.length ? array.length - 1 : index; } + + public static int fixIndexOutOfBoundsUsingPredetermined(T[] array, int index, int predeterminedIndex) { + return index >= array.length ? predeterminedIndex : index; + } } -- cgit v1.2.3