diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-01-19 15:04:51 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-01-19 15:04:51 +0000 |
commit | 569283ea93dba6816df092e702b97f6d5c956ebf (patch) | |
tree | 9da508188fa72dd1fa43bbf137a66080cb78e911 /app/src/main/java/ml | |
parent | b0bf06e0c09763726c3225f7f08076cda552aaa5 (diff) | |
download | infinity-for-reddit-569283ea93dba6816df092e702b97f6d5c956ebf.tar infinity-for-reddit-569283ea93dba6816df092e702b97f6d5c956ebf.tar.gz infinity-for-reddit-569283ea93dba6816df092e702b97f6d5c956ebf.tar.bz2 infinity-for-reddit-569283ea93dba6816df092e702b97f6d5c956ebf.tar.lz infinity-for-reddit-569283ea93dba6816df092e702b97f6d5c956ebf.tar.xz infinity-for-reddit-569283ea93dba6816df092e702b97f6d5c956ebf.tar.zst infinity-for-reddit-569283ea93dba6816df092e702b97f6d5c956ebf.zip |
Setting default sort for subreddits and users is available.
Diffstat (limited to 'app/src/main/java/ml')
3 files changed, 29 insertions, 5 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 5f64e1e1..0f1ee2d8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -68,8 +68,8 @@ import ml.docilealligator.infinityforreddit.FetchPostFilterAndReadPosts; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.NetworkState; -import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.activities.BaseActivity; @@ -488,9 +488,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { String sort; String sortTime = null; - sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, SortType.Type.HOT.name()); + sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, + mSharedPreferences.getString(SharedPreferencesUtils.SUBREDDIT_DEFAULT_SORT_TYPE, 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()); + sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, + mSharedPreferences.getString(SharedPreferencesUtils.SUBREDDIT_DEFAULT_SORT_TIME, SortType.Time.ALL.name())); } boolean displaySubredditName = subredditName != null && (subredditName.equals("popular") || subredditName.equals("all")); postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout); @@ -618,9 +620,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mFetchPostInfoLinearLayout.setLayoutParams(params); } - String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, SortType.Type.NEW.name()); + String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, + mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TYPE, SortType.Type.NEW.name())); if (sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) { - String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, SortType.Time.ALL.name()); + String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, + mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TIME, SortType.Time.ALL.name())); sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime)); } else { sortType = new SortType(SortType.Type.valueOf(sort)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SortTypePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SortTypePreferenceFragment.java new file mode 100644 index 00000000..78d32b46 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SortTypePreferenceFragment.java @@ -0,0 +1,15 @@ +package ml.docilealligator.infinityforreddit.settings; + +import android.os.Bundle; + +import androidx.preference.PreferenceFragmentCompat; + +import ml.docilealligator.infinityforreddit.R; + +public class SortTypePreferenceFragment extends PreferenceFragmentCompat { + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.sort_type_preferences, rootKey); + } +}
\ No newline at end of file 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 85be7c4e..b0e2d901 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -151,6 +151,11 @@ public class SharedPreferencesUtils { public static final String ENABLE_SEARCH_HISTORY = "enable_search_history"; public static final String POST_FILTER = "post_filter"; public static final String ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS = "only_disable_preview_in_video_and_gif_posts"; + public static final String SAVE_SORT_TYPE = "save_sort_type"; + public static final String SUBREDDIT_DEFAULT_SORT_TYPE = "subreddit_default_sort_type"; + public static final String SUBREDDIT_DEFAULT_SORT_TIME = "subreddit_default_sort_time"; + public static final String USER_DEFAULT_SORT_TYPE = "user_default_sort_type"; + public static final String USER_DEFAULT_SORT_TIME = "user_default_sort_time"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count"; |