Implement save sort type.

This commit is contained in:
Alex Ning 2021-03-07 19:41:49 +08:00
parent 22a7ad1eb5
commit 916143fd46
2 changed files with 37 additions and 34 deletions

View File

@ -1133,6 +1133,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public void changeSortType(SortType sortType) { public void changeSortType(SortType sortType) {
if (mPostViewModel != null) { if (mPostViewModel != null) {
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) {
switch (postType) { switch (postType) {
case PostDataSource.TYPE_FRONT_PAGE: case PostDataSource.TYPE_FRONT_PAGE:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply(); mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
@ -1167,6 +1168,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} }
break; break;
} }
}
if (mFetchPostInfoLinearLayout.getVisibility() != View.GONE) { if (mFetchPostInfoLinearLayout.getVisibility() != View.GONE) {
mFetchPostInfoLinearLayout.setVisibility(View.GONE); mFetchPostInfoLinearLayout.setVisibility(View.GONE);
mGlide.clear(mFetchPostInfoImageView); mGlide.clear(mFetchPostInfoImageView);

View File

@ -717,7 +717,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
children.clear(); children.clear();
} }
this.sortType = sortType.getType().value; this.sortType = sortType.getType().value;
if (!mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false)) { if (!mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false)
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply(); mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply();
} }
fetchCommentsRespectRecommendedSort(false, false, sortType.getType().value); fetchCommentsRespectRecommendedSort(false, false, sortType.getType().value);