From 60fdb813c02f266c8c5ecaf20bfaee711372a982 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 1 Oct 2020 00:34:23 +0800 Subject: Show a warning if nsfw is disabled and the subreddit is nsfw. --- .../Activity/ViewSubredditDetailActivity.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'app/src/main/java') 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 f1799f06..a5c7b9a7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -35,6 +35,7 @@ import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.bottomappbar.BottomAppBar; import com.google.android.material.chip.Chip; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.tabs.TabLayout; @@ -167,6 +168,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Named("sort_type") SharedPreferences mSortTypeSharedPreferences; @Inject + @Named("nsfw_and_spoiler") + SharedPreferences mNsfwAndSpoilerSharedPreferences; + @Inject @Named("post_layout") SharedPreferences mPostLayoutSharedPreferences; @Inject @@ -207,6 +211,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp private int unsubscribedColor; private int subscribedColor; private SlidrInterface mSlidrInterface; + private MaterialAlertDialogBuilder nsfwWarningBuilder; @Override protected void onCreate(Bundle savedInstanceState) { @@ -416,6 +421,21 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp descriptionTextView.setVisibility(View.VISIBLE); descriptionTextView.setText(subredditData.getDescription()); } + + if (subredditData.isNSFW()) { + if (nsfwWarningBuilder == null + && mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false)) { + nsfwWarningBuilder = new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.warning) + .setMessage(R.string.this_is_a_nsfw_subreddit) + .setPositiveButton(R.string.leave, (dialogInterface, i) + -> { + finish(); + }) + .setNegativeButton(R.string.dismiss, null); + nsfwWarningBuilder.show(); + } + } } }); } -- cgit v1.2.3