diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-11-19 16:34:58 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-11-19 16:34:58 +0000 |
commit | c5e1c5ddd000b071342f905ebf61d9bdcaa9ed47 (patch) | |
tree | f6a815aaa97a7e79677ffac2f44ebe6949d0ac17 /app/src | |
parent | 9b20b783d22fcbf363a6cfbe1f87691e8ff22d81 (diff) | |
download | infinity-for-reddit-c5e1c5ddd000b071342f905ebf61d9bdcaa9ed47.tar infinity-for-reddit-c5e1c5ddd000b071342f905ebf61d9bdcaa9ed47.tar.gz infinity-for-reddit-c5e1c5ddd000b071342f905ebf61d9bdcaa9ed47.tar.bz2 infinity-for-reddit-c5e1c5ddd000b071342f905ebf61d9bdcaa9ed47.tar.lz infinity-for-reddit-c5e1c5ddd000b071342f905ebf61d9bdcaa9ed47.tar.xz infinity-for-reddit-c5e1c5ddd000b071342f905ebf61d9bdcaa9ed47.tar.zst infinity-for-reddit-c5e1c5ddd000b071342f905ebf61d9bdcaa9ed47.zip |
Fix crashes related to gilded posts.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java | 8 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java | 4 |
2 files changed, 8 insertions, 4 deletions
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 <T> int fixIndexOutOfBounds(T[] array, int index) { return index >= array.length ? array.length - 1 : index; } + + public static <T> int fixIndexOutOfBoundsUsingPredetermined(T[] array, int index, int predeterminedIndex) { + return index >= array.length ? predeterminedIndex : index; + } } |