mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-14 12:17:11 +01:00
Rename confidence sort to best (#1177)
* Rename CONFIDENCE comments sort type to BEST and remove old BEST type The Reddit API supports only CONFIDENCE sort type for comments but displays it as BEST. I renamed CONFIDENCE name to Best and added a migration step for loading correct sort type. * Clean up sortType usages in ViewPostDetailFragment Removed unnecessary null checks, object creations and most case conversions
This commit is contained in:
parent
78496e080f
commit
72c66e7e4e
@ -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");
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
@ -27,22 +27,6 @@
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/confidence_type_text_view_post_comment_sort_type_bottom_sheet_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:paddingStart="32dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingEnd="32dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:text="@string/sort_confidence"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/top_type_text_view_post_comment_sort_type_bottom_sheet_fragment"
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
Reference in New Issue
Block a user