diff options
Diffstat (limited to 'app/src/main/java')
14 files changed, 141 insertions, 66 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java index 29b49d24..6ff51607 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java @@ -64,6 +64,9 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("post_layout") + SharedPreferences mPostLayoutSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; private boolean isInLazyMode = false; private boolean mNullAccessToken = false; @@ -281,7 +284,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect @Override public void postLayoutSelected(int postLayout) { if (mFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + mAccountName, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + mAccountName, postLayout).apply(); ((FragmentCommunicator) mFragment).changePostLayout(postLayout); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java index 545bce1d..cd39817c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java @@ -72,6 +72,9 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("post_layout") + SharedPreferences mPostLayoutSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; private boolean isInLazyMode = false; private boolean mNullAccessToken = false; @@ -399,16 +402,16 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec if (mFragment != null) { switch (postType) { case PostDataSource.TYPE_FRONT_PAGE: - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply(); break; case PostDataSource.TYPE_SUBREDDIT: - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + name, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + name, postLayout).apply(); break; case PostDataSource.TYPE_USER: - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + name, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + name, postLayout).apply(); break; case PostDataSource.TYPE_SEARCH: - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply(); } ((FragmentCommunicator) mFragment).changePostLayout(postLayout); } 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 1a38677a..3cc64c30 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -161,6 +161,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("sort_type") + SharedPreferences mSortTypeSharedPreferences; + @Inject + @Named("post_layout") + SharedPreferences mPostLayoutSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; private SectionsPagerAdapter sectionsPagerAdapter; private AppBarLayout.LayoutParams params; @@ -1188,25 +1194,25 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } else { switch (viewPager.getCurrentItem()) { case 0: - mSharedPreferences.edit().putString(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) { - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply(); } frontPagePostFragment.changeSortType(sortType); break; case 1: - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, sortType.getType().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, sortType.getType().name()).apply(); if (sortType.getTime() != null) { - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, sortType.getTime().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, sortType.getTime().name()).apply(); } popularPostFragment.changeSortType(sortType); break; case 2: - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, sortType.getType().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, sortType.getType().name()).apply(); if (sortType.getTime() != null) { - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_ALL_POST, sortType.getTime().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_ALL_POST, sortType.getTime().name()).apply(); } allPostFragment.changeSortType(sortType); @@ -1261,12 +1267,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (mAccessToken == null) { if (viewPager.getCurrentItem() == 0) { if (popularPostFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply(); popularPostFragment.changePostLayout(postLayout); } } else { if (allPostFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply(); allPostFragment.changePostLayout(postLayout); } } @@ -1274,19 +1280,19 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb switch (viewPager.getCurrentItem()) { case 0: if (frontPagePostFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply(); frontPagePostFragment.changePostLayout(postLayout); } break; case 1: if (popularPostFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply(); popularPostFragment.changePostLayout(postLayout); } break; case 2: if (allPostFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply(); allPostFragment.changePostLayout(postLayout); } } 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 359d408b..7c8f25a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java @@ -74,6 +74,12 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("sort_type") + SharedPreferences mSortTypeSharedPreferences; + @Inject + @Named("post_layout") + SharedPreferences mPostLayoutSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; private boolean mNullAccessToken = false; private String mAccessToken; @@ -375,9 +381,9 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect } void changeSortType(SortType sortType) { - mSharedPreferences.edit().putString(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) { - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply(); } postFragment.changeSortType(sortType); @@ -386,11 +392,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect void changeSortType(SortType sortType, int fragmentPosition) { switch (fragmentPosition) { case 1: - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, sortType.getType().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, sortType.getType().name()).apply(); subredditListingFragment.changeSortType(sortType); break; case 2: - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, sortType.getType().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, sortType.getType().name()).apply(); userListingFragment.changeSortType(sortType); } } @@ -417,7 +423,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect void changePostLayout(int postLayout) { if (postFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply(); ((FragmentCommunicator) postFragment).changePostLayout(postLayout); } } 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 3cdd25ba..0fb5b439 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java @@ -74,6 +74,12 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("sort_type") + SharedPreferences mSortTypeSharedPreferences; + @Inject + @Named("post_layout") + SharedPreferences mPostLayoutSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; private boolean mNullAccessToken = false; private String mAccessToken; @@ -284,10 +290,10 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Override public void sortTypeSelected(SortType sortType) { - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiPath, + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiPath, sortType.getType().name()).apply(); if(sortType.getTime() != null) { - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE+ multiPath, + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE+ multiPath, sortType.getTime().name()).apply(); } @@ -305,7 +311,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Override public void postLayoutSelected(int postLayout) { if (mFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiPath, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiPath, postLayout).apply(); ((FragmentCommunicator) mFragment).changePostLayout(postLayout); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index 152b71ad..b08bacd2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -159,6 +159,9 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("sort_type") + SharedPreferences mSortTypeSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; private RequestManager mGlide; private Locale mLocale; @@ -558,7 +561,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mSwipeRefreshLayout.setRefreshing(true); mGlide.clear(mFetchPostInfoImageView); - String sortType = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value).toLowerCase(); + String sortType = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value).toLowerCase(); Call<String> postAndComments; @@ -836,7 +839,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS } private void fetchComments(boolean changeRefreshState) { - String sortType = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, + String sortType = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value).toLowerCase(); fetchComments(changeRefreshState, true, sortType); } @@ -1582,7 +1585,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS children.clear(); } fetchComments(false, false, sortType.getType().value); - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply(); } public void lockSwipeRightToGoBack() { 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 daddd979..474a5912 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -147,6 +147,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("sort_type") + SharedPreferences mSortTypeSharedPreferences; + @Inject + @Named("post_layout") + SharedPreferences mPostLayoutSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; public SubredditViewModel mSubredditViewModel; private SectionsPagerAdapter sectionsPagerAdapter; @@ -774,7 +780,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Override public void postLayoutSelected(int postLayout) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply(); sectionsPagerAdapter.changePostLayout(postLayout); } @@ -914,9 +920,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp public void changeSortType(SortType sortType) { if (postFragment != null) { - mSharedPreferences.edit().putString(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) { - mSharedPreferences.edit().putString(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(); } postFragment.changeSortType(sortType); @@ -931,7 +937,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp void changePostLayout(int postLayout) { if (postFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply(); ((FragmentCommunicator) postFragment).changePostLayout(postLayout); } } 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 95ce79e1..96adba7b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -125,6 +125,12 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("sort_type") + SharedPreferences mSortTypeSharedPreferences; + @Inject + @Named("post_layout") + SharedPreferences mPostLayoutSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; public UserViewModel userViewModel; private SectionsPagerAdapter sectionsPagerAdapter; @@ -811,18 +817,18 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele public void changeSortType(SortType sortType) { if (viewPager.getCurrentItem() == 0) { if (postFragment != null) { - mSharedPreferences.edit().putString(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) { - mSharedPreferences.edit().putString(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(); } postFragment.changeSortType(sortType); } } else { if (commentsListingFragment != null) { - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, sortType.getType().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, sortType.getType().name()).apply(); if(sortType.getTime() != null) { - mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, sortType.getTime().name()).apply(); + mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, sortType.getTime().name()).apply(); } commentsListingFragment.changeSortType(sortType); @@ -838,7 +844,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele void changePostLayout(int postLayout) { if (postFragment != null) { - mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, postLayout).apply(); + mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, postLayout).apply(); ((FragmentCommunicator) postFragment).changePostLayout(postLayout); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java index 70567266..fe483c3c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java @@ -16,6 +16,7 @@ import dagger.Provides; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.RedditUtils; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import okhttp3.ConnectionPool; import okhttp3.OkHttpClient; import retrofit2.Retrofit; @@ -128,6 +129,18 @@ class AppModule { } @Provides + @Named("sort_type") + SharedPreferences provideSortTypeSharedPreferences() { + return mApplication.getSharedPreferences(SharedPreferencesUtils.SORT_TYPE_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE); + } + + @Provides + @Named("post_layout") + SharedPreferences providePostLayoutSharedPreferences() { + return mApplication.getSharedPreferences(SharedPreferencesUtils.POST_LAYOUT_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE); + } + + @Provides @Singleton CustomThemeWrapper provideCustomThemeWrapper(@Named("light_theme") SharedPreferences lightThemeSharedPreferences, @Named("dark_theme") SharedPreferences darkThemeSharedPreferences, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java index 5b1b8359..caf3a5cf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java @@ -84,6 +84,12 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("sort_type") + SharedPreferences mSortTypeSharedPreferences; + @Inject + @Named("post_layout") + SharedPreferences mPostLayoutSharedPreferences; + @Inject CustomThemeWrapper customThemeWrapper; private boolean mNullAccessToken = false; private String mAccessToken; @@ -165,10 +171,10 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni () -> mCommentViewModel.retryLoadingMore()); String username = getArguments().getString(EXTRA_USERNAME); - String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value); + String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value); SortType sortType; if(sort.equals(SortType.Type.CONTROVERSIAL.value) || sort.equals(SortType.Type.TOP.value)) { - String sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, SortType.Time.ALL.value); + String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, SortType.Time.ALL.value); sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()), SortType.Time.valueOf(sortTime.toUpperCase())); } else { sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase())); 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 25a850bc..4b464944 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -114,6 +114,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("sort_type") + SharedPreferences mSortTypeSharedPreferences; + @Inject + @Named("post_layout") + SharedPreferences mPostLayoutSharedPreferences; + @Inject CustomThemeWrapper customThemeWrapper; private RequestManager mGlide; private AppCompatActivity activity; @@ -329,10 +335,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator { String subredditName = getArguments().getString(EXTRA_NAME); String query = getArguments().getString(EXTRA_QUERY); - String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, SortType.Type.RELEVANCE.name()); - String sortTime = mSharedPreferences.getString(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 sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime)); - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout); + postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout); mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, customThemeWrapper, accessToken, postType, postLayout, true, @@ -373,24 +379,24 @@ public class PostFragment extends Fragment implements FragmentCommunicator { boolean displaySubredditName = subredditName != null && (subredditName.equals("popular") || subredditName.equals("all")); if(displaySubredditName) { if(subredditName.equals("popular")) { - sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, SortType.Type.HOT.name()); + 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 = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, SortType.Time.ALL.name()); + sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, SortType.Time.ALL.name()); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, defaultPostLayout); + postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, defaultPostLayout); } else { - sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, SortType.Type.HOT.name()); + 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 = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_ALL_POST, SortType.Time.ALL.name()); + sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_ALL_POST, SortType.Time.ALL.name()); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, defaultPostLayout); + postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, defaultPostLayout); } } else { - sort = mSharedPreferences.getString(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 = mSharedPreferences.getString(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()); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout); + postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout); } if(sortTime != null) { @@ -434,13 +440,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator { String sortTime = null; SortType sortType; - sort = mSharedPreferences.getString(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 = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, + sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Time.ALL.name()); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, + postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, defaultPostLayout); if(sortTime != null) { @@ -487,15 +493,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mFetchPostInfoLinearLayout.setLayoutParams(params); } - String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, SortType.Type.NEW.name()); + String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, SortType.Type.NEW.name()); SortType sortType; if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) { - String sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, SortType.Time.ALL.name()); + String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, SortType.Time.ALL.name()); sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime)); } else { sortType = new SortType(SortType.Type.valueOf(sort)); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout); + postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout); mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, customThemeWrapper, accessToken, postType, postLayout, true, @@ -528,15 +534,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator { filter, nsfw)).get(PostViewModel.class); } } else { - String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name()); + String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name()); SortType sortType; if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) { - String sortTime = mSharedPreferences.getString(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)); } - postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout); + postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout); mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, customThemeWrapper, accessToken, postType, postLayout, true, @@ -804,27 +810,27 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (bundle != null) { switch (postType) { case PostDataSource.TYPE_SUBREDDIT: - if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) { + if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) { changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout); } break; case PostDataSource.TYPE_USER: - if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + bundle.getString(EXTRA_USER_NAME))) { + if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + bundle.getString(EXTRA_USER_NAME))) { changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout); } break; case PostDataSource.TYPE_MULTI_REDDIT: - if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) { + if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) { changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout); } break; case PostDataSource.TYPE_SEARCH: - if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST)) { + if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST)) { changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout); } break; case PostDataSource.TYPE_FRONT_PAGE: - if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST)) { + if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST)) { changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout); } break; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java index 1b0f3401..2625d1bb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java @@ -82,6 +82,9 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("sort_type") + SharedPreferences mSortTypeSharedPreferences; + @Inject CustomThemeWrapper customThemeWrapper; private LinearLayoutManager mLinearLayoutManager; private SubredditListingRecyclerViewAdapter mAdapter; @@ -124,7 +127,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); - String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, SortType.Type.RELEVANCE.value); + String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, SortType.Type.RELEVANCE.value); SortType sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase())); mAdapter = new SubredditListingRecyclerViewAdapter(mActivity, mOauthRetrofit, mRetrofit, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java index 07430235..0cf3ea71 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java @@ -78,6 +78,9 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato @Named("default") SharedPreferences mSharedPreferences; @Inject + @Named("sort_type") + SharedPreferences mSortTypeSharedPreferences; + @Inject CustomThemeWrapper customThemeWrapper; private LinearLayoutManager mLinearLayoutManager; private String mQuery; @@ -119,7 +122,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato mQuery = getArguments().getString(EXTRA_QUERY); String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); - String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, SortType.Type.RELEVANCE.value); + String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, SortType.Type.RELEVANCE.value); SortType sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase())); mAdapter = new UserListingRecyclerViewAdapter(getActivity(), mOauthRetrofit, mRetrofit, 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 c10b83fc..e3d3d699 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -33,6 +33,8 @@ public class SharedPreferencesUtils { public static final String IMMERSIVE_INTERFACE_KEY = "immersive_interface"; public static final String BOTTOM_APP_BAR_KEY = "bottom_app_bar"; 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"; @@ -52,6 +54,8 @@ public class SharedPreferencesUtils { public static final String SORT_TYPE_SEARCH_SUBREDDIT = "sort_type_search_subreddit"; public static final String SORT_TYPE_SEARCH_USER = "sort_type_search_user"; public static final String SORT_TYPE_POST_COMMENT = "sort_type_post_comment"; + + public static final String POST_LAYOUT_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.post_layout"; public static final String POST_LAYOUT_FRONT_PAGE_POST = "post_layout_best_post"; public static final String POST_LAYOUT_POPULAR_POST = "post_layout_popular_post"; public static final String POST_LAYOUT_ALL_POST = "post_layout_all_post"; @@ -61,6 +65,7 @@ public class SharedPreferencesUtils { public static final String POST_LAYOUT_SEARCH_POST = "post_layout_search_post"; public static final int POST_LAYOUT_CARD = 0; public static final int POST_LAYOUT_COMPACT = 1; + public static final String PULL_NOTIFICATION_TIME = "pull_notification_time"; public static final String SHOW_ELAPSED_TIME_KEY = "show_elapsed_time"; public static final String DEFAULT_POST_LAYOUT_KEY = "default_post_layout"; |