diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-09-23 11:20:41 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-09-23 11:20:41 +0000 |
commit | 396501e350b23667bb70728fbd60b715beffe489 (patch) | |
tree | c73a48d81c06bb383546ed02cd3e31cb298a6902 /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | d730b719b8811eca930e5a0e88faba0737098a55 (diff) | |
download | infinity-for-reddit-396501e350b23667bb70728fbd60b715beffe489.tar infinity-for-reddit-396501e350b23667bb70728fbd60b715beffe489.tar.gz infinity-for-reddit-396501e350b23667bb70728fbd60b715beffe489.tar.bz2 infinity-for-reddit-396501e350b23667bb70728fbd60b715beffe489.tar.lz infinity-for-reddit-396501e350b23667bb70728fbd60b715beffe489.tar.xz infinity-for-reddit-396501e350b23667bb70728fbd60b715beffe489.tar.zst infinity-for-reddit-396501e350b23667bb70728fbd60b715beffe489.zip |
Set NSFW, NSFW blurring and spoiler blurring on a per-user basis. Only close the account section in the navigation drawer after dismissing if the account section is open.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
14 files changed, 206 insertions, 84 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 6d78ad7b..1d05e6d6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -176,6 +176,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Named("main_activity_tabs") SharedPreferences mMainActivityTabsSharedPreferences; @Inject + @Named("nsfw_and_spoiler") + SharedPreferences mNsfwAndSpoilerSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; private FragmentManager fragmentManager; private SectionsPagerAdapter sectionsPagerAdapter; @@ -264,8 +267,9 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Override public void onDrawerClosed(View drawerView) { if (adapter != null) { - adapter.closeAccountSectionWithoutChangeIconResource(); - adapter.notifyItemChanged(0); + if (adapter.closeAccountSectionWithoutChangeIconResource(true)) { + adapter.notifyItemChanged(0); + } } } }); @@ -480,7 +484,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } adapter = new NavigationDrawerRecyclerViewAdapter(this, mSharedPreferences, - mCustomThemeWrapper, mAccountName, + mNsfwAndSpoilerSharedPreferences, mCustomThemeWrapper, mAccountName, mProfileImageUrl, mBannerImageUrl, mKarma, new NavigationDrawerRecyclerViewAdapter.ItemClickListener() { @Override @@ -536,13 +540,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb break; case R.string.enable_nsfw: if (sectionsPagerAdapter != null) { - mSharedPreferences.edit().putBoolean(SharedPreferencesUtils.NSFW_KEY, true).apply(); + mNsfwAndSpoilerSharedPreferences.edit().putBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, true).apply(); sectionsPagerAdapter.changeNSFW(true); } break; case R.string.disable_nsfw: if (sectionsPagerAdapter != null) { - mSharedPreferences.edit().putBoolean(SharedPreferencesUtils.NSFW_KEY, false).apply(); + mNsfwAndSpoilerSharedPreferences.edit().putBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false).apply(); sectionsPagerAdapter.changeNSFW(false); } break; 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 78f39e19..a246bae1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java @@ -238,7 +238,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect tab.setText(R.string.posts); break; case 1: - tab.setText(R.string.comments); + tab.setText(R.string.subreddits); break; case 2: tab.setText(R.string.users); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java index 07abf2d5..f1c296e3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java @@ -33,6 +33,7 @@ import ml.docilealligator.infinityforreddit.Settings.FontPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.GesturesAndButtonsPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.InterfacePreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment; +import ml.docilealligator.infinityforreddit.Settings.NsfwAndBlurringFragment; public class SettingsActivity extends BaseActivity implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback { @@ -159,6 +160,8 @@ public class SettingsActivity extends BaseActivity implements pref.getFragment()); if (fragment instanceof CustomizeMainPageTabsFragment) { args.putString(CustomizeMainPageTabsFragment.EXTRA_ACCOUNT_NAME, mAccountName); + } else if (fragment instanceof NsfwAndBlurringFragment) { + args.putString(NsfwAndBlurringFragment.EXTRA_ACCOUNT_NAME, mAccountName); } fragment.setArguments(args); fragment.setTargetFragment(caller, 0); 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 475d0001..cc047de9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -195,6 +195,9 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS @Named("sort_type") SharedPreferences mSortTypeSharedPreferences; @Inject + @Named("nsfw_and_spoiler") + SharedPreferences mNsfwAndSpoilerSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; @Inject ExoCreator mExoCreator; @@ -623,7 +626,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide, mWindowWidth, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, - isSingleCommentThreadMode, mSharedPreferences, mExoCreator, + isSingleCommentThreadMode, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mExoCreator, new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void updatePost(Post post) { @@ -786,7 +789,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide, mWindowWidth, mAccessToken, mAccountName, mPost, mLocale, - mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences, mExoCreator, + mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences, + mNsfwAndSpoilerSharedPreferences, mExoCreator, new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void updatePost(Post post) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index 4874dd31..bc476b67 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -240,7 +240,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy int imageViewWidth, String accessToken, String accountName, Post post, Locale locale, String singleCommentId, boolean isSingleCommentThreadMode, - SharedPreferences sharedPreferences, ExoCreator exoCreator, + SharedPreferences sharedPreferences, + SharedPreferences nsfwAndSpoilerSharedPreferences, ExoCreator exoCreator, CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) { mActivity = activity; mRetrofit = retrofit; @@ -449,8 +450,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mSingleCommentId = singleCommentId; mIsSingleCommentThreadMode = isSingleCommentThreadMode; - mNeedBlurNsfw = sharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true); - mNeedBlurSpoiler = sharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false); + mNeedBlurNsfw = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true); + mNeedBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false); mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java index fc330b00..088a576c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java @@ -74,6 +74,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re private int primaryIconColor; public NavigationDrawerRecyclerViewAdapter(AppCompatActivity appCompatActivity, SharedPreferences sharedPreferences, + SharedPreferences nsfwAndSpoilerSharedPreferences, CustomThemeWrapper customThemeWrapper, String accountName, String userIconUrl, String userBannerUrl, int karma, @@ -85,7 +86,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re this.userIconUrl = userIconUrl; this.userBannerUrl = userBannerUrl; this.karma = karma; - isNSFWEnabled = sharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false); + isNSFWEnabled = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); requireAuthToAccountSection = sharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false); isLoggedIn = accountName != null; this.itemClickListener = itemClickListener; @@ -223,7 +224,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re } } else { ((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_arrow_drop_down_24px, null)); - closeAccountSectionWithoutChangeIconResource(); + closeAccountSectionWithoutChangeIconResource(false); } }); } else if (holder instanceof MenuGroupTitleViewHolder) { @@ -413,18 +414,24 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re } } - public void closeAccountSectionWithoutChangeIconResource() { - notifyItemRangeRemoved(1, getItemCount() - 1); - if (isLoggedIn) { - if (subscribedSubreddits != null) { - notifyItemRangeInserted(1, subscribedSubreddits.size() + CURRENT_MENU_ITEMS - 1); + public boolean closeAccountSectionWithoutChangeIconResource(boolean checkIsInMainPage) { + if (!(checkIsInMainPage && isInMainPage)) { + notifyItemRangeRemoved(1, getItemCount() - 1); + if (isLoggedIn) { + if (subscribedSubreddits != null) { + notifyItemRangeInserted(1, subscribedSubreddits.size() + CURRENT_MENU_ITEMS - 1); + } else { + notifyItemRangeInserted(1, CURRENT_MENU_ITEMS - 1); + } } else { - notifyItemRangeInserted(1, CURRENT_MENU_ITEMS - 1); + notifyItemRangeInserted(1, 2); } - } else { - notifyItemRangeInserted(1, 2); + isInMainPage = true; + + return true; } - isInMainPage = true; + + return false; } private void openAccountSection(ImageView dropIconImageView) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 74ac57cc..772040b6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -194,8 +194,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView Retrofit gfycatRetrofit, Retrofit redgifsRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, CustomThemeWrapper customThemeWrapper, Locale locale, int imageViewWidth, - String accessToken, int postType, int postLayout, boolean displaySubredditName, - SharedPreferences sharedPreferences, ExoCreator exoCreator, Callback callback) { + String accessToken, String accountName, int postType, int postLayout, boolean displaySubredditName, + SharedPreferences sharedPreferences, SharedPreferences nsfwAndSpoilerSharedPreferences, + ExoCreator exoCreator, Callback callback) { super(DIFF_CALLBACK); if (activity != null) { mActivity = activity; @@ -207,8 +208,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mAccessToken = accessToken; mPostType = postType; mDisplaySubredditName = displaySubredditName; - mNeedBlurNSFW = sharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true); - mNeedBlurSpoiler = sharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false); + mNeedBlurNSFW = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true); + mNeedBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false); mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 8a8905a8..461f263c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -66,6 +66,7 @@ import ml.docilealligator.infinityforreddit.Settings.DownloadLocationPreferenceF import ml.docilealligator.infinityforreddit.Settings.GesturesAndButtonsPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragment; +import ml.docilealligator.infinityforreddit.Settings.NsfwAndBlurringFragment; import ml.docilealligator.infinityforreddit.Settings.SecurityPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.ThemePreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.VideoPreferenceFragment; @@ -206,4 +207,6 @@ public interface AppComponent { void inject(SelectUserFlairActivity selectUserFlairActivity); void inject(SecurityPreferenceFragment securityPreferenceFragment); + + void inject(NsfwAndBlurringFragment nsfwAndBlurringFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java index a1dd3517..069540ef 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java @@ -149,7 +149,6 @@ class AppModule { .readTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) .connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS)); - //.addInterceptor(new Okhttp3DebugInterceptor(mApplication)); return okHttpClientBuilder.build(); } @@ -212,6 +211,12 @@ class AppModule { } @Provides + @Named("nsfw_and_spoiler") + SharedPreferences provideNsfwAndSpoilerSharedPreferences() { + return mApplication.getSharedPreferences(SharedPreferencesUtils.NSFW_AND_SPOILER_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/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index c8d58e11..5918ddb1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -159,6 +159,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Named("post_layout") SharedPreferences mPostLayoutSharedPreferences; @Inject + @Named("nsfw_and_spoiler") + SharedPreferences mNsfwAndSpoilerSharedPreferences; + @Inject CustomThemeWrapper customThemeWrapper; @Inject ExoCreator exoCreator; @@ -396,7 +399,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { int filter = getArguments().getInt(EXTRA_FILTER); String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); - boolean nsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false); + boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0")); savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false); vibrateWhenActionTriggered = mSharedPreferences.getBoolean(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED, true); @@ -414,8 +417,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale, - windowWidth, accessToken, postType, postLayout, true, - mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() { + windowWidth, accessToken, accountName, postType, postLayout, true, + mSharedPreferences, mNsfwAndSpoilerSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -462,8 +465,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale, - windowWidth, accessToken, postType, postLayout, displaySubredditName, - mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() { + windowWidth, accessToken, accountName, postType, postLayout, displaySubredditName, + mSharedPreferences, mNsfwAndSpoilerSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -511,8 +514,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale, - windowWidth, accessToken, postType, postLayout, true, - mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() { + windowWidth, accessToken, accountName, postType, postLayout, true, + mSharedPreferences, mNsfwAndSpoilerSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -558,8 +561,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale, - windowWidth, accessToken, postType, postLayout, true, - mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() { + windowWidth, accessToken, accountName, postType, postLayout, true, + mSharedPreferences, mNsfwAndSpoilerSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -598,8 +601,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale, - windowWidth, accessToken, postType, postLayout, true, - mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() { + windowWidth, accessToken, accountName, postType, postLayout, true, + mSharedPreferences, mNsfwAndSpoilerSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); 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 46a39de2..ff794aa5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java @@ -58,6 +58,12 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { @Inject @Named("amoled_theme") SharedPreferences amoledThemeSharedPreferences; + @Inject + @Named("main_activity_tabs") + SharedPreferences mainActivityTabsSharedPreferences; + @Inject + @Named("nsfw_and_spoiler") + SharedPreferences nsfwAndBlurringSharedPreferences; private Activity activity; @Override @@ -178,6 +184,9 @@ 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); + editor.remove(SharedPreferencesUtils.NSFW_KEY_LEGACY); + editor.remove(SharedPreferencesUtils.BLUR_NSFW_KEY_LEGACY); + editor.remove(SharedPreferencesUtils.BLUR_SPOILER_KEY_LEGACY); SharedPreferences.Editor sortTypeEditor = mSortTypeSharedPreferences.edit(); sortTypeEditor.remove(SharedPreferencesUtils.SORT_TYPE_ALL_POST_LEGACY); @@ -207,6 +216,9 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { .setPositiveButton(R.string.yes, (dialogInterface, i) -> { mSharedPreferences.edit().clear().apply(); + mainActivityTabsSharedPreferences.edit().clear().apply(); + nsfwAndBlurringSharedPreferences.edit().clear().apply(); + Toast.makeText(activity, R.string.reset_all_settings_success, Toast.LENGTH_SHORT).show(); EventBus.getDefault().post(new RecreateActivityEvent()); }) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java index ce601cf7..9ab5a099 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java @@ -17,10 +17,7 @@ import org.greenrobot.eventbus.EventBus; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; -import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSavePostFeedScrolledPositionEvent; -import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; @@ -47,9 +44,6 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { Preference securityPreference = findPreference(SharedPreferencesUtils.SECURITY); SwitchPreference savePostFeedScrolledPositionSwitch = findPreference(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION); SwitchPreference confirmToExitSwitch = findPreference(SharedPreferencesUtils.CONFIRM_TO_EXIT); - SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY); - SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY); - SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY); if (savePostFeedScrolledPositionSwitch != null) { savePostFeedScrolledPositionSwitch.setOnPreferenceChangeListener((preference, newValue) -> { @@ -68,38 +62,6 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { }); } - if (nsfwSwitch != null) { - nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue)); - if (blurNSFWSwitch != null) { - blurNSFWSwitch.setVisible((Boolean) newValue); - } - return true; - }); - } - - if (blurNSFWSwitch != null) { - boolean nsfwEnabled = sharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false); - - if (nsfwEnabled) { - blurNSFWSwitch.setVisible(true); - } else { - blurNSFWSwitch.setVisible(false); - } - - blurNSFWSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new ChangeNSFWBlurEvent((Boolean) newValue)); - return true; - }); - } - - if (blurSpoilerSwitch != null) { - blurSpoilerSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new ChangeSpoilerBlurEvent((Boolean) newValue)); - return true; - }); - } - BiometricManager biometricManager = BiometricManager.from(activity); if (biometricManager.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) != BiometricManager.BIOMETRIC_SUCCESS) { if (securityPreference != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/NsfwAndBlurringFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/NsfwAndBlurringFragment.java new file mode 100644 index 00000000..470d10d5 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/NsfwAndBlurringFragment.java @@ -0,0 +1,112 @@ +package ml.docilealligator.infinityforreddit.Settings; + +import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; + +import com.google.android.material.switchmaterial.SwitchMaterial; + +import org.greenrobot.eventbus.EventBus; + +import javax.inject.Inject; +import javax.inject.Named; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; + +public class NsfwAndBlurringFragment extends Fragment { + + public static final String EXTRA_ACCOUNT_NAME = "EAN"; + + @BindView(R.id.enable_nsfw_linear_layout_nsfw_and_spoiler_fragment) + LinearLayout enableNsfwLinearLayout; + @BindView(R.id.enable_nsfw_switch_nsfw_and_spoiler_fragment) + SwitchMaterial enableNsfwSwitchMaterial; + @BindView(R.id.blur_nsfw_linear_layout_nsfw_and_spoiler_fragment) + LinearLayout blurNsfwLinearLayout; + @BindView(R.id.blur_nsfw_switch_nsfw_and_spoiler_fragment) + SwitchMaterial blurNsfwSwitchMaterial; + @BindView(R.id.blur_spoiler_linear_layout_nsfw_and_spoiler_fragment) + LinearLayout blurSpoilerLinearLayout; + @BindView(R.id.blur_spoiler_switch_nsfw_and_spoiler_fragment) + SwitchMaterial blurSpoilerSwitchMaterial; + @Inject + @Named("nsfw_and_spoiler") + SharedPreferences nsfwAndBlurringSharedPreferences; + + private Activity activity; + + public NsfwAndBlurringFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View rootView = inflater.inflate(R.layout.fragment_nsfw_and_spoiler, container, false); + + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + + ButterKnife.bind(this, rootView); + + String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); + + boolean enableNsfw = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); + boolean blurNsfw = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true); + boolean blurSpoiler = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false); + + if (enableNsfw) { + blurNsfwLinearLayout.setVisibility(View.VISIBLE); + } + + enableNsfwSwitchMaterial.setChecked(enableNsfw); + blurNsfwSwitchMaterial.setChecked(blurNsfw); + blurSpoilerSwitchMaterial.setChecked(blurSpoiler); + + enableNsfwLinearLayout.setOnClickListener(view -> enableNsfwSwitchMaterial.performClick()); + enableNsfwSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> { + nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, b).apply(); + if (b) { + blurNsfwLinearLayout.setVisibility(View.VISIBLE); + } else { + blurNsfwLinearLayout.setVisibility(View.GONE); + } + EventBus.getDefault().post(new ChangeNSFWEvent(b)); + }); + + blurNsfwLinearLayout.setOnClickListener(view -> blurNsfwSwitchMaterial.performClick()); + blurNsfwSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> { + nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, b).apply(); + EventBus.getDefault().post(new ChangeNSFWBlurEvent(b)); + }); + + blurSpoilerLinearLayout.setOnClickListener(view -> blurSpoilerSwitchMaterial.performClick()); + blurSpoilerSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> { + nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, b).apply(); + EventBus.getDefault().post(new ChangeSpoilerBlurEvent(b)); + }); + return rootView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + this.activity = (AppCompatActivity) context; + } +}
\ 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 351088c3..598c3d98 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -8,9 +8,6 @@ public class SharedPreferencesUtils { public static final String ENABLE_NOTIFICATION_KEY = "enable_notification"; public static final String NOTIFICATION_INTERVAL_KEY = "notificaiton_interval"; public static final String LAZY_MODE_INTERVAL_KEY = "lazy_mode_interval"; - public static final String NSFW_KEY = "nsfw"; - public static final String BLUR_NSFW_KEY = "blur_nsfw"; - public static final String BLUR_SPOILER_KEY = "blur_spoiler"; public static final String THEME_KEY = "theme"; public static final String ICON_FOREGROUND_KEY = "icon_foreground"; public static final String ICON_BACKGROUND_KEY = "icon_background"; @@ -127,6 +124,11 @@ public class SharedPreferencesUtils { public static final String LONG_PRESS_TO_HIDE_TOOLBAR_IN_COMPACT_LAYOUT = "long_press_to_hide_toolbar_in_compact_layout"; public static final String POST_COMPACT_LAYOUT_TOOLBAR_HIDDEN_BY_DEFAULT = "post_compact_layout_toolbar_hidden_by_default"; public static final String SECURITY = "security"; + public static final String START_AUTOPLAY_VISIBLE_AREA_OFFSET_PORTRAIT = "start_autoplay_visible_area_offset_portrait"; + public static final String START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE = "start_autoplay_visible_area_offset_landscape"; + 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"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; public static final String MAIN_PAGE_TAB_1_TITLE = "_main_page_tab_1_title"; @@ -145,11 +147,10 @@ public class SharedPreferencesUtils { public static final int MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT = 4; public static final int MAIN_PAGE_TAB_POST_TYPE_USER = 5; - public static final String START_AUTOPLAY_VISIBLE_AREA_OFFSET_PORTRAIT = "start_autoplay_visible_area_offset_portrait"; - public static final String START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE = "start_autoplay_visible_area_offset_landscape"; - 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"; + public static final String NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.nsfw_and_spoiler"; + public static final String NSFW_BASE = "_nsfw"; + public static final String BLUR_NSFW_BASE = "_blur_nsfw"; + public static final String BLUR_SPOILER_BASE = "_blur_spoiler"; //Legacy Settings public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title"; @@ -169,4 +170,8 @@ public class SharedPreferencesUtils { public static final String POST_LAYOUT_POPULAR_POST_LEGACY = "post_layout_popular_post"; public static final String POST_LAYOUT_ALL_POST_LEGACY = "post_layout_all_post"; + + public static final String NSFW_KEY_LEGACY = "nsfw"; + public static final String BLUR_NSFW_KEY_LEGACY = "blur_nsfw"; + public static final String BLUR_SPOILER_KEY_LEGACY = "blur_spoiler"; } |