aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-08-25 03:48:39 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-08-25 03:48:39 +0000
commitb17d0a65d1d899596fe4803f794fcd22a1dda2da (patch)
tree09918b3219cdbcf50a7df68398822bad8ab06e84
parent087ca72fc75708184fa7154afb69e2907538c66e (diff)
downloadinfinity-for-reddit-b17d0a65d1d899596fe4803f794fcd22a1dda2da.tar
infinity-for-reddit-b17d0a65d1d899596fe4803f794fcd22a1dda2da.tar.gz
infinity-for-reddit-b17d0a65d1d899596fe4803f794fcd22a1dda2da.tar.bz2
infinity-for-reddit-b17d0a65d1d899596fe4803f794fcd22a1dda2da.tar.lz
infinity-for-reddit-b17d0a65d1d899596fe4803f794fcd22a1dda2da.tar.xz
infinity-for-reddit-b17d0a65d1d899596fe4803f794fcd22a1dda2da.tar.zst
infinity-for-reddit-b17d0a65d1d899596fe4803f794fcd22a1dda2da.zip
Disable saving sort type for different users.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSortTypesAsyncTask.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java36
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java28
4 files changed, 42 insertions, 34 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSortTypesAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSortTypesAsyncTask.java
index d763f64d..2e76b6c3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSortTypesAsyncTask.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSortTypesAsyncTask.java
@@ -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)
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
index c481cd05..a2097c3b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -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;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java
index 5656a9f1..b9ce33fd 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java
@@ -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)
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
index 81222569..fab9bdd4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -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";
}