diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-03-07 11:41:49 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-03-07 11:41:49 +0000 |
commit | 916143fd4627bdfdbc3c379e98989196ba1adeb6 (patch) | |
tree | 04f1fb89617ce1898ff9ef603a69ad4b6d4cf65e /app/src/main/java | |
parent | 22a7ad1eb5231bd89838621f4de488f1c9aaa686 (diff) | |
download | infinity-for-reddit-916143fd4627bdfdbc3c379e98989196ba1adeb6.tar infinity-for-reddit-916143fd4627bdfdbc3c379e98989196ba1adeb6.tar.gz infinity-for-reddit-916143fd4627bdfdbc3c379e98989196ba1adeb6.tar.bz2 infinity-for-reddit-916143fd4627bdfdbc3c379e98989196ba1adeb6.tar.lz infinity-for-reddit-916143fd4627bdfdbc3c379e98989196ba1adeb6.tar.xz infinity-for-reddit-916143fd4627bdfdbc3c379e98989196ba1adeb6.tar.zst infinity-for-reddit-916143fd4627bdfdbc3c379e98989196ba1adeb6.zip |
Implement save sort type.
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java | 68 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java | 3 |
2 files changed, 37 insertions, 34 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index e4fe58c0..2a1eabbc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -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); 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 b41a7ec0..744f0d04 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -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); |