Disable saving sort type for different users.

This commit is contained in:
Alex Ning 2020-08-25 11:48:39 +08:00
parent 087ca72fc7
commit b17d0a65d1
4 changed files with 42 additions and 34 deletions

View File

@ -32,8 +32,8 @@ public class DeleteAllSortTypesAsyncTask extends AsyncTask<Void, Void, Void> {
for(Map.Entry<String,?> entry : keys.entrySet()){
String key = entry.getKey();
if (key.contains(SharedPreferencesUtils.SORT_TYPE_BEST_POST) || key.contains(SharedPreferencesUtils.SORT_TIME_BEST_POST)
|| key.contains(SharedPreferencesUtils.SORT_TYPE_ALL_POST) || key.contains(SharedPreferencesUtils.SORT_TIME_ALL_POST)
|| key.contains(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST) || key.contains(SharedPreferencesUtils.SORT_TIME_POPULAR_POST)
|| key.contains(SharedPreferencesUtils.SORT_TYPE_ALL_POST_LEGACY) || key.contains(SharedPreferencesUtils.SORT_TIME_ALL_POST_LEGACY)
|| key.contains(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST_LEGACY) || key.contains(SharedPreferencesUtils.SORT_TIME_POPULAR_POST_LEGACY)
|| key.contains(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST) || key.contains(SharedPreferencesUtils.SORT_TIME_SEARCH_POST)
|| key.contains(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE) || key.contains(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE)
|| key.contains(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE) || key.contains(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE)

View File

@ -383,8 +383,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
subredditName = getArguments().getString(EXTRA_NAME);
String query = getArguments().getString(EXTRA_QUERY);
String sort = mSortTypeSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, SortType.Type.RELEVANCE.name());
String sortTime = mSortTypeSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TIME_SEARCH_POST, SortType.Time.ALL.name());
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, SortType.Type.RELEVANCE.name());
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, SortType.Time.ALL.name());
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
@ -422,9 +422,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String sort;
String sortTime = null;
sort = mSortTypeSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, SortType.Type.HOT.name());
sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, SortType.Type.HOT.name());
if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
sortTime = mSortTypeSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, SortType.Time.ALL.name());
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, SortType.Time.ALL.name());
}
boolean displaySubredditName = subredditName != null && (subredditName.equals("popular") || subredditName.equals("all"));
if(displaySubredditName) {
@ -476,10 +476,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String sort;
String sortTime = null;
sort = mSortTypeSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
SortType.Type.HOT.name());
if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
sortTime = mSortTypeSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
SortType.Time.ALL.name());
}
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath,
@ -567,9 +567,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
accountName, getResources().getConfiguration().locale, mSharedPreferences,
postFeedScrolledPositionSharedPreferences, username, postType, sortType, where, filter, nsfw)).get(PostViewModel.class);
} else {
String sort = mSortTypeSharedPreferences.getString(accountName + SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name());
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name());
if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
String sortTime = mSortTypeSharedPreferences.getString(accountName + SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
} else {
sortType = new SortType(SortType.Type.valueOf(sort));
@ -655,34 +655,34 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public void changeSortType(SortType sortType) {
switch (postType) {
case PostDataSource.TYPE_FRONT_PAGE:
mSortTypeSharedPreferences.edit().putString(accountName + SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(accountName + SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
}
break;
case PostDataSource.TYPE_SUBREDDIT:
mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply();
if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
}
break;
case PostDataSource.TYPE_USER:
mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply();
if(sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
}
break;
case PostDataSource.TYPE_SEARCH:
mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
if(sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
}
break;
case PostDataSource.TYPE_MULTI_REDDIT:
mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
sortType.getType().name()).apply();
if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
sortType.getTime().name()).apply();
}
break;

View File

@ -178,7 +178,15 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat {
editor.remove(SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME_LEGACY);
editor.remove(SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME_LEGACY);
editor.remove(SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME_LEGACY);
SharedPreferences.Editor sortTypeEditor = mSortTypeSharedPreferences.edit();
sortTypeEditor.remove(SharedPreferencesUtils.SORT_TYPE_ALL_POST_LEGACY);
sortTypeEditor.remove(SharedPreferencesUtils.SORT_TIME_ALL_POST_LEGACY);
sortTypeEditor.remove(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST_LEGACY);
sortTypeEditor.remove(SharedPreferencesUtils.SORT_TIME_POPULAR_POST_LEGACY);
editor.apply();
sortTypeEditor.apply();
Toast.makeText(activity, R.string.delete_all_legacy_settings_success, Toast.LENGTH_SHORT).show();
})
.setNegativeButton(R.string.no, null)

View File

@ -42,16 +42,16 @@ public class SharedPreferencesUtils {
public static final String VOTE_BUTTONS_ON_THE_RIGHT_KEY = "vote_buttons_on_the_right";
public static final String SORT_TYPE_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.sort_type";
public static final String SORT_TYPE_BEST_POST = "_sort_type_best_post";
public static final String SORT_TIME_BEST_POST = "_sort_time_best_post";
public static final String SORT_TYPE_SEARCH_POST = "_sort_type_search_post";
public static final String SORT_TIME_SEARCH_POST = "_sort_time_search_post";
public static final String SORT_TYPE_SUBREDDIT_POST_BASE = "_sort_type_subreddit_post_";
public static final String SORT_TIME_SUBREDDIT_POST_BASE = "_sort_time_subreddit_post_";
public static final String SORT_TYPE_MULTI_REDDIT_POST_BASE = "_sort_type_multi_reddit_post_";
public static final String SORT_TIME_MULTI_REDDIT_POST_BASE = "_sort_time_multi_reddit_post_";
public static final String SORT_TYPE_USER_POST_BASE = "_sort_type_user_post_";
public static final String SORT_TIME_USER_POST_BASE = "_sort_time_user_post_";
public static final String SORT_TYPE_BEST_POST = "sort_type_best_post";
public static final String SORT_TIME_BEST_POST = "sort_time_best_post";
public static final String SORT_TYPE_SEARCH_POST = "sort_type_search_post";
public static final String SORT_TIME_SEARCH_POST = "sort_time_search_post";
public static final String SORT_TYPE_SUBREDDIT_POST_BASE = "sort_type_subreddit_post_";
public static final String SORT_TIME_SUBREDDIT_POST_BASE = "sort_time_subreddit_post_";
public static final String SORT_TYPE_MULTI_REDDIT_POST_BASE = "sort_type_multi_reddit_post_";
public static final String SORT_TIME_MULTI_REDDIT_POST_BASE = "sort_time_multi_reddit_post_";
public static final String SORT_TYPE_USER_POST_BASE = "sort_type_user_post_";
public static final String SORT_TIME_USER_POST_BASE = "sort_time_user_post_";
public static final String SORT_TYPE_USER_COMMENT = "sort_type_user_comment";
public static final String SORT_TIME_USER_COMMENT = "sort_time_user_comment";
public static final String SORT_TYPE_SEARCH_SUBREDDIT = "sort_type_search_subreddit";
@ -152,8 +152,8 @@ public class SharedPreferencesUtils {
public static final String MAIN_PAGE_TAB_2_NAME_LEGACY = "main_page_tab_2_name";
public static final String MAIN_PAGE_TAB_3_NAME_LEGACY = "main_page_tab_3_name";
public static final String SORT_TYPE_ALL_POST = "sort_type_all_post";
public static final String SORT_TIME_ALL_POST = "sort_time_all_post";
public static final String SORT_TYPE_POPULAR_POST = "sort_type_popular_post";
public static final String SORT_TIME_POPULAR_POST = "sort_time_popular_post";
public static final String SORT_TYPE_ALL_POST_LEGACY = "sort_type_all_post";
public static final String SORT_TIME_ALL_POST_LEGACY = "sort_time_all_post";
public static final String SORT_TYPE_POPULAR_POST_LEGACY = "sort_type_popular_post";
public static final String SORT_TIME_POPULAR_POST_LEGACY = "sort_time_popular_post";
}