diff options
Diffstat (limited to 'app/src/main/java')
3 files changed, 31 insertions, 33 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java index 83d45f57..be4b1b89 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java @@ -33,7 +33,7 @@ public class SortType { RELEVANCE("relevance", "Relevance"), COMMENTS("comments", "Comments"), ACTIVITY("activity", "Activity"), - CONFIDENCE("confidence", "Confidence"), + CONFIDENCE("confidence", "Best"), OLD("old", "Old"), QA("qa", "QA"), LIVE("live", "Live"); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java index 20871a1f..66dfe02c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java @@ -31,8 +31,6 @@ public class PostCommentSortTypeBottomSheetFragment extends LandscapeExpandedRou public static final String EXTRA_CURRENT_SORT_TYPE = "ECST"; @BindView(R.id.best_type_text_view_post_comment_sort_type_bottom_sheet_fragment) - TextView bestTypeTextView; - @BindView(R.id.confidence_type_text_view_post_comment_sort_type_bottom_sheet_fragment) TextView confidenceTypeTextView; @BindView(R.id.top_type_text_view_post_comment_sort_type_bottom_sheet_fragment) TextView topTypeTextView; @@ -71,9 +69,7 @@ public class PostCommentSortTypeBottomSheetFragment extends LandscapeExpandedRou ButterKnife.bind(this, rootView); String currentSortType = getArguments().getString(EXTRA_CURRENT_SORT_TYPE); - if (currentSortType.equals(SortType.Type.BEST.value)) { - bestTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(bestTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); - } else if (currentSortType.equals(SortType.Type.CONFIDENCE.value)) { + if (currentSortType.equals(SortType.Type.BEST.value) || currentSortType.equals(SortType.Type.CONFIDENCE.value)) { confidenceTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(confidenceTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); } else if (currentSortType.equals(SortType.Type.TOP.value)) { topTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(topTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null); @@ -96,11 +92,6 @@ public class PostCommentSortTypeBottomSheetFragment extends LandscapeExpandedRou rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); } - bestTypeTextView.setOnClickListener(view -> { - ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.BEST)); - dismiss(); - }); - confidenceTypeTextView.setOnClickListener(view -> { ((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.CONFIDENCE)); dismiss(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 4475e8f8..baaf1261 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -546,15 +546,13 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mMessageFullname = getArguments().getString(EXTRA_MESSAGE_FULLNAME); if (!mRespectSubredditRecommendedSortType || isSingleCommentThreadMode) { - sortType = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value.toUpperCase()); - if (sortType != null) { - activity.setTitle(new SortType(SortType.Type.valueOf(sortType)).getType().fullName); - sortType = sortType.toLowerCase(); - } + SortType.Type sortTypeType = loadSortType(); + activity.setTitle(sortTypeType.fullName); + sortType = sortTypeType.value; } } else { if (sortType != null) { - activity.setTitle(new SortType(SortType.Type.valueOf(sortType.toUpperCase())).getType().fullName); + activity.setTitle(SortType.Type.valueOf(sortType.toUpperCase()).fullName); } } @@ -815,6 +813,20 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic fetchCommentsRespectRecommendedSort(false, false, sortType.getType().value); } + @NonNull + private SortType.Type loadSortType() { + String sortTypeName = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.CONFIDENCE.name()); + if (SortType.Type.BEST.name().equals(sortTypeName)) { + // migrate from BEST to CONFIDENCE + // key guaranteed to exist because got non-default value + mSharedPreferences.edit() + .putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.CONFIDENCE.name()) + .apply(); + return SortType.Type.CONFIDENCE; + } + return SortType.Type.valueOf(sortTypeName); + } + public void goToTop() { ((LinearLayoutManagerBugFixed) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(0, 0); if (mCommentsRecyclerView != null) { @@ -1408,30 +1420,25 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic new FetchSubredditData.FetchSubredditDataListener() { @Override public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { - if (subredditData.getSuggestedCommentSort() == null || subredditData.getSuggestedCommentSort().equals("null") || subredditData.getSuggestedCommentSort().equals("")) { + String suggestedCommentSort = subredditData.getSuggestedCommentSort(); + SortType.Type sortTypeType; + if (suggestedCommentSort == null || suggestedCommentSort.equals("null") || suggestedCommentSort.equals("")) { mRespectSubredditRecommendedSortType = false; - ViewPostDetailFragment.this.sortType = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value.toUpperCase()); - if (ViewPostDetailFragment.this.sortType != null) { - activity.setTitle(new SortType(SortType.Type.valueOf(ViewPostDetailFragment.this.sortType)).getType().fullName); - ViewPostDetailFragment.this.sortType = ViewPostDetailFragment.this.sortType.toLowerCase(); - } - fetchComments(changeRefreshState, checkSortState, ViewPostDetailFragment.this.sortType); + sortTypeType = loadSortType(); } else { - ViewPostDetailFragment.this.sortType = subredditData.getSuggestedCommentSort(); - String sortTypeTemp = ViewPostDetailFragment.this.sortType.toLowerCase().substring(0, 1).toUpperCase() + ViewPostDetailFragment.this.sortType.substring(1); - activity.setTitle(sortTypeTemp); - fetchComments(changeRefreshState, checkSortState, subredditData.getSuggestedCommentSort()); + sortTypeType = SortType.Type.valueOf(suggestedCommentSort.toUpperCase(Locale.US)); } + activity.setTitle(sortTypeType.fullName); + ViewPostDetailFragment.this.sortType = sortTypeType.value; + fetchComments(changeRefreshState, checkSortState, ViewPostDetailFragment.this.sortType); } @Override public void onFetchSubredditDataFail(boolean isQuarantined) { mRespectSubredditRecommendedSortType = false; - ViewPostDetailFragment.this.sortType = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value.toUpperCase()); - if (ViewPostDetailFragment.this.sortType != null) { - activity.setTitle(new SortType(SortType.Type.valueOf(ViewPostDetailFragment.this.sortType)).getType().fullName); - ViewPostDetailFragment.this.sortType = ViewPostDetailFragment.this.sortType.toLowerCase(); - } + SortType.Type sortTypeType = loadSortType(); + activity.setTitle(sortTypeType.fullName); + ViewPostDetailFragment.this.sortType = sortTypeType.value; } }); } else { |