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,39 +1133,41 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public void changeSortType(SortType sortType) { public void changeSortType(SortType sortType) {
if (mPostViewModel != null) { if (mPostViewModel != null) {
switch (postType) { if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) {
case PostDataSource.TYPE_FRONT_PAGE: switch (postType) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply(); case PostDataSource.TYPE_FRONT_PAGE:
if (sortType.getTime() != null) { mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply(); if (sortType.getTime() != null) {
} mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
break; }
case PostDataSource.TYPE_SUBREDDIT: break;
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply(); case PostDataSource.TYPE_SUBREDDIT:
if (sortType.getTime() != null) { mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply(); if (sortType.getTime() != null) {
} mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
break; }
case PostDataSource.TYPE_USER: break;
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply(); case PostDataSource.TYPE_USER:
if (sortType.getTime() != null) { mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply(); if (sortType.getTime() != null) {
} mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
break; }
case PostDataSource.TYPE_SEARCH: break;
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply(); case PostDataSource.TYPE_SEARCH:
if (sortType.getTime() != null) { mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply(); if (sortType.getTime() != null) {
} mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
break; }
case PostDataSource.TYPE_MULTI_REDDIT: break;
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath, case PostDataSource.TYPE_MULTI_REDDIT:
sortType.getType().name()).apply(); mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
if (sortType.getTime() != null) { sortType.getType().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, if (sortType.getTime() != null) {
sortType.getTime().name()).apply(); mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
} sortType.getTime().name()).apply();
break; }
break;
}
} }
if (mFetchPostInfoLinearLayout.getVisibility() != View.GONE) { if (mFetchPostInfoLinearLayout.getVisibility() != View.GONE) {
mFetchPostInfoLinearLayout.setVisibility(View.GONE); mFetchPostInfoLinearLayout.setVisibility(View.GONE);

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);