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) {
if (mPostViewModel != null) {
switch (postType) {
case PostDataSource.TYPE_FRONT_PAGE:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
}
break;
case PostDataSource.TYPE_SUBREDDIT:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().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:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().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:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
}
break;
case PostDataSource.TYPE_MULTI_REDDIT:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
sortType.getType().name()).apply();
if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
sortType.getTime().name()).apply();
}
break;
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) {
switch (postType) {
case PostDataSource.TYPE_FRONT_PAGE:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
}
break;
case PostDataSource.TYPE_SUBREDDIT:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().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:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().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:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
}
break;
case PostDataSource.TYPE_MULTI_REDDIT:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
sortType.getType().name()).apply();
if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
sortType.getTime().name()).apply();
}
break;
}
}
if (mFetchPostInfoLinearLayout.getVisibility() != View.GONE) {
mFetchPostInfoLinearLayout.setVisibility(View.GONE);

View File

@ -717,7 +717,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
children.clear();
}
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();
}
fetchCommentsRespectRecommendedSort(false, false, sortType.getType().value);