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"; diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 79819832..52191982 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -349,4 +349,52 @@ tr-rTR + + Hot + New + Rising + Top + Controversial + + + + HOT + NEW + RISING + TOP + CONTROVERSIAL + + + + New + Hot + Top + Controversial + + + + NEW + HOT + TOP + CONTROVERSIAL + + + + Hour + Day + Week + Month + Year + All Time + + + + HOUR + DAY + WEEK + MONTH + YEAR + ALL + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f5410e92..50eab52f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -528,6 +528,12 @@ Mark Posts as Read After Voting Mark Posts as Read on Scroll Hide Read Posts Automatically + Sort Type + Save Sort Type + Subreddit Default Sort Type + Subreddit Default Sort Time + User Default Sort Type + User Default Sort Time Cannot get the link @@ -1010,5 +1016,7 @@ Unable to add %1$s to multireddit %2$s Choose a user + + Hello blank fragment diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml index e2dac88d..82a4689e 100644 --- a/app/src/main/res/xml/main_preferences.xml +++ b/app/src/main/res/xml/main_preferences.xml @@ -67,10 +67,15 @@ app:icon="@drawable/ic_filter_24dp" app:title="@string/settings_post_filter_title" /> + + + app:fragment="ml.docilealligator.infinityforreddit.settings.MiscellaneousPreferenceFragment" /> - - + + + + + + + + + + + + + + + \ No newline at end of file