diff options
11 files changed, 147 insertions, 95 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index b45992fd..2272e448 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -173,8 +173,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb private SectionsPagerAdapter sectionsPagerAdapter; private AppBarLayout.LayoutParams params; private PostTypeBottomSheetFragment postTypeBottomSheetFragment; - private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment; - private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment; + private SortTypeBottomSheetFragment sortTypeBottomSheetFragment; private SortTimeBottomSheetFragment sortTimeBottomSheetFragment; private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment; private NavigationDrawerRecyclerViewAdapter adapter; @@ -234,17 +233,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } postTypeBottomSheetFragment = new PostTypeBottomSheetFragment(); - - bestSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); - Bundle bestBundle = new Bundle(); - bestBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, false); - bestSortTypeBottomSheetFragment.setArguments(bestBundle); - - popularAndAllSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); - Bundle popularBundle = new Bundle(); - popularBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); - popularAndAllSortTypeBottomSheetFragment.setArguments(popularBundle); - + sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment(); postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); @@ -727,11 +716,16 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb public boolean onOptionsItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.action_sort_main_activity: - if (viewPager.getCurrentItem() == 1 || viewPager.getCurrentItem() == 2) { - popularAndAllSortTypeBottomSheetFragment.show(getSupportFragmentManager(), popularAndAllSortTypeBottomSheetFragment.getTag()); + int currentPostType = sectionsPagerAdapter.getCurrentPostType(); + Bundle bundle = new Bundle(); + if (currentPostType != PostDataSource.TYPE_FRONT_PAGE) { + bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true); } else { - bestSortTypeBottomSheetFragment.show(getSupportFragmentManager(), bestSortTypeBottomSheetFragment.getTag()); + bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, false); } + bundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_RANDOM_TYPE, true); + sortTypeBottomSheetFragment.setArguments(bundle); + sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag()); return true; case R.id.action_search_main_activity: Intent intent = new Intent(this, SearchActivity.class); @@ -1240,6 +1234,25 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } } + int getCurrentPostType() { + if (mAccessToken == null) { + if (viewPager.getCurrentItem() == 0) { + return tab2.getPostType(); + } else { + return tab3.getPostType(); + } + } else { + switch (viewPager.getCurrentItem()) { + case 1: + return tab2.getPostType(); + case 2: + return tab3.getPostType(); + default: + return tab1.getPostType(); + } + } + } + void changeSortType(SortType sortType) { if (mAccessToken == null) { if (viewPager.getCurrentItem() == 0) { @@ -1250,27 +1263,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } else { switch (viewPager.getCurrentItem()) { case 0: - 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(); - } - tab1.changeSortType(sortType); break; case 1: - mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, sortType.getType().name()).apply(); - if (sortType.getTime() != null) { - mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, sortType.getTime().name()).apply(); - } - tab2.changeSortType(sortType); break; case 2: - mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, sortType.getType().name()).apply(); - if (sortType.getTime() != null) { - mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_ALL_POST, sortType.getTime().name()).apply(); - } - tab3.changeSortType(sortType); } } @@ -1373,6 +1371,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb tab3.goBackToTop(); } } + void displaySortTypeInToolbar() { switch (viewPager.getCurrentItem()) { case 0: diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java index c905cdfc..fa5f14fc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java @@ -419,11 +419,6 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect } void changeSortType(SortType sortType) { - 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(); - } - postFragment.changeSortType(sortType); displaySortTypeInToolbar(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java index 990b9388..91c7512a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java @@ -305,13 +305,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Override public void sortTypeSelected(SortType sortType) { - mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiPath, - sortType.getType().name()).apply(); - if (sortType.getTime() != null) { - mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiPath, - sortType.getTime().name()).apply(); - } - ((PostFragment) mFragment).changeSortType(sortType); displaySortType(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java index cdcf72a2..2230f81f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -989,11 +989,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp public void changeSortType(SortType sortType) { if (postFragment != null) { - 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(); - } - postFragment.changeSortType(sortType); displaySortTypeInToolbar(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java index 2b777851..e2099faa 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -908,11 +908,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele public void changeSortType(SortType sortType) { if (viewPager.getCurrentItem() == 0) { if (postFragment != null) { - 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(); - } - postFragment.changeSortType(sortType); } } else { 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 153e0899..d763f64d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSortTypesAsyncTask.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSortTypesAsyncTask.java @@ -31,16 +31,16 @@ public class DeleteAllSortTypesAsyncTask extends AsyncTask<Void, Void, Void> { for(Map.Entry<String,?> entry : keys.entrySet()){ String key = entry.getKey(); - if (key.startsWith(SharedPreferencesUtils.SORT_TYPE_BEST_POST) || key.startsWith(SharedPreferencesUtils.SORT_TIME_BEST_POST) - || key.startsWith(SharedPreferencesUtils.SORT_TYPE_ALL_POST) || key.startsWith(SharedPreferencesUtils.SORT_TIME_ALL_POST) - || key.startsWith(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST) || key.startsWith(SharedPreferencesUtils.SORT_TIME_POPULAR_POST) - || key.startsWith(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST) || key.startsWith(SharedPreferencesUtils.SORT_TIME_SEARCH_POST) - || key.startsWith(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE) || key.startsWith(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE) - || key.startsWith(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE) || key.startsWith(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE) - || key.startsWith(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE) || key.startsWith(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE) - || key.startsWith(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT) || key.startsWith(SharedPreferencesUtils.SORT_TIME_USER_COMMENT) - || key.startsWith(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT) || key.startsWith(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER) - || key.startsWith(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT)) { + 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_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) + || key.contains(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE) || key.contains(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE) + || key.contains(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT) || key.contains(SharedPreferencesUtils.SORT_TIME_USER_COMMENT) + || key.contains(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT) || key.contains(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER) + || key.contains(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT)) { editor.remove(key); } } 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 fc6bfd61..997984bc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -376,8 +376,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { subredditName = getArguments().getString(EXTRA_NAME); String query = getArguments().getString(EXTRA_QUERY); - 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()); + 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()); sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime)); postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout); @@ -415,26 +415,18 @@ 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()); + 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()); + } boolean displaySubredditName = subredditName != null && (subredditName.equals("popular") || subredditName.equals("all")); if(displaySubredditName) { if(subredditName.equals("popular")) { - sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, SortType.Type.HOT.name()); - if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) { - sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, SortType.Time.ALL.name()); - } postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, defaultPostLayout); } else { - sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, SortType.Type.HOT.name()); - if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) { - sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_ALL_POST, SortType.Time.ALL.name()); - } postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, defaultPostLayout); } } else { - 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(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, SortType.Time.ALL.name()); - } postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout); } @@ -477,10 +469,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator { String sort; String sortTime = null; - sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath, + sort = mSortTypeSharedPreferences.getString((accountName == null ? "" : accountName) + 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(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, + sortTime = mSortTypeSharedPreferences.getString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Time.ALL.name()); } postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, @@ -568,9 +560,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(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name()); + String sort = mSortTypeSharedPreferences.getString(accountName + 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(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name()); + String sortTime = mSortTypeSharedPreferences.getString(accountName + 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)); @@ -654,6 +646,40 @@ 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(); + if (sortType.getTime() != null) { + mSortTypeSharedPreferences.edit().putString(accountName + 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(); + if (sortType.getTime() != null) { + mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + 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(); + if(sortType.getTime() != null) { + mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + 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(); + if(sortType.getTime() != null) { + mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + 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, + sortType.getType().name()).apply(); + if (sortType.getTime() != null) { + mSortTypeSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, + sortType.getTime().name()).apply(); + } + break; + } if (mFetchPostInfoLinearLayout.getVisibility() != View.GONE) { mFetchPostInfoLinearLayout.setVisibility(View.GONE); mGlide.clear(mFetchPostInfoImageView); @@ -1048,6 +1074,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator { return sortType; } + public int getPostType() { + return postType; + } + @Override public void onPause() { super.onPause(); 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 4268b28f..5656a9f1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java @@ -72,6 +72,7 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { Preference deletePostLaoutPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_POST_LAYOUT_DATA_IN_DATABASE); Preference deleteAllThemesPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_THEMES_IN_DATABASE); Preference deletePostFeedScrolledPositionsPreference = findPreference(SharedPreferencesUtils.DELETE_FRONT_PAGE_SCROLLED_POSITIONS_IN_DATABASE); + Preference deleteAllLegacySettingsPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_LEGACY_SETTINGS); Preference resetAllSettingsPreference = findPreference(SharedPreferencesUtils.RESET_ALL_SETTINGS); if (deleteSubredditsPreference != null) { @@ -161,6 +162,31 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { }); } + if (deleteAllLegacySettingsPreference != null) { + deleteAllLegacySettingsPreference.setOnPreferenceClickListener(preference -> { + new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.are_you_sure) + .setPositiveButton(R.string.yes, (dialogInterface, i) + -> { + SharedPreferences.Editor editor = mSharedPreferences.edit(); + editor.remove(SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE_LEGACY); + editor.remove(SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE_LEGACY); + editor.remove(SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE_LEGACY); + editor.remove(SharedPreferencesUtils.MAIN_PAGE_TAB_1_POST_TYPE_LEGACY); + editor.remove(SharedPreferencesUtils.MAIN_PAGE_TAB_2_POST_TYPE_LEGACY); + editor.remove(SharedPreferencesUtils.MAIN_PAGE_TAB_3_POST_TYPE_LEGACY); + 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); + editor.apply(); + Toast.makeText(activity, R.string.delete_all_legacy_settings_success, Toast.LENGTH_SHORT).show(); + }) + .setNegativeButton(R.string.no, null) + .show(); + return true; + }); + } + if (resetAllSettingsPreference != null) { resetAllSettingsPreference.setOnPreferenceClickListener(preference -> { new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) 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 b3ce6be5..b6b5cd7f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -42,20 +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_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_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"; @@ -117,6 +113,7 @@ public class SharedPreferencesUtils { public static final String DELETE_ALL_POST_LAYOUT_DATA_IN_DATABASE = "delete_all_post_layout_data_in_database"; public static final String DELETE_ALL_THEMES_IN_DATABASE = "delete_all_themes_in_database"; public static final String DELETE_FRONT_PAGE_SCROLLED_POSITIONS_IN_DATABASE = "delete_front_page_scrolled_positions_in_database"; + public static final String DELETE_ALL_LEGACY_SETTINGS = "delete_all_legacy_settings"; public static final String RESET_ALL_SETTINGS = "reset_all_settings"; public static final String MAIN_PAGE_TAB_1_TITLE = "main_page_tab_1_title"; public static final String MAIN_PAGE_TAB_2_TITLE = "main_page_tab_2_title"; @@ -138,4 +135,20 @@ public class SharedPreferencesUtils { public static final String MUTE_NSFW_VIDEO = "mute_nsfw_video"; public static final String VIDEO_PLAYER_IGNORE_NAV_BAR = "video_player_ignore_nav_bar"; public static final String SAVE_FRONT_PAGE_SCROLLED_POSITION = "save_front_page_scrolled_position"; + + //Legacy Settings + public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title"; + public static final String MAIN_PAGE_TAB_2_TITLE_LEGACY = "main_page_tab_2_title"; + public static final String MAIN_PAGE_TAB_3_TITLE_LEGACY = "main_page_tab_3_title"; + public static final String MAIN_PAGE_TAB_1_POST_TYPE_LEGACY = "main_page_tab_1_post_type"; + public static final String MAIN_PAGE_TAB_2_POST_TYPE_LEGACY = "main_page_tab_2_post_type"; + public static final String MAIN_PAGE_TAB_3_POST_TYPE_LEGACY = "main_page_tab_3_post_type"; + public static final String MAIN_PAGE_TAB_1_NAME_LEGACY = "main_page_tab_1_name"; + 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"; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f79108a6..b909ab32 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -455,6 +455,7 @@ <string name="settings_delete_all_post_layout_data_in_database_title">Delete All Post Layouts in Database</string> <string name="settings_delete_all_themes_in_database_title">Delete All Themes in Database</string> <string name="settings_delete_front_page_scrolled_positions_in_database_title">Delete All Front Page Scrolled Positions in Database</string> + <string name="settings_delete_all_legacy_settings_title">Delete All Legacy Settings</string> <string name="settings_reset_all_settings_title">Reset All Settings</string> <string name="settings_advanced_settings_summary">Clean the database and shared preferences</string> <string name="settings_tab_info">Restart the app to see the changes</string> @@ -776,6 +777,7 @@ <string name="delete_all_post_layouts_success">Delete all post layouts successful</string> <string name="delete_all_themes_success">Delete all themes successful</string> <string name="delete_all_front_page_scrolled_positions_success">Delete all scrolled positions in front page successful</string> + <string name="delete_all_legacy_settings_success">Delete all legacy settings successful</string> <string name="reset_all_settings_success">Reset all settings successful</string> <string name="theme_preview">Theme Preview</string> diff --git a/app/src/main/res/xml/advanced_preferences.xml b/app/src/main/res/xml/advanced_preferences.xml index d890159f..0d6c02e5 100644 --- a/app/src/main/res/xml/advanced_preferences.xml +++ b/app/src/main/res/xml/advanced_preferences.xml @@ -27,6 +27,10 @@ app:title="@string/settings_delete_front_page_scrolled_positions_in_database_title" /> <Preference + app:key="delete_all_legacy_settings" + app:title="@string/settings_delete_all_legacy_settings_title" /> + + <Preference app:key="reset_all_settings" app:title="@string/settings_reset_all_settings_title" /> |