From 304fa86400d473a514f18f4f0334ef1cbe26d8eb Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Thu, 4 May 2023 13:06:27 +0800 Subject: [PATCH] Fix https://github.com/Docile-Alligator/Infinity-For-Reddit/issues/1301 --- .../activities/FilteredPostsActivity.java | 17 +++++++++++++++++ .../activities/ViewVideoActivity.java | 6 +++--- .../fragments/PostFragment.java | 2 ++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java index 8f93faa9..1305733b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java @@ -14,6 +14,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.lifecycle.ViewModelProvider; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; @@ -52,6 +53,7 @@ import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostPagingSource; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.readpost.InsertReadPost; +import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class FilteredPostsActivity extends BaseActivity implements SortTypeSelectionCallback, @@ -98,6 +100,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; + public SubredditViewModel mSubredditViewModel; private String mAccessToken; private String mAccountName; private String name; @@ -105,6 +108,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec private int postType; private PostFragment mFragment; private Menu mMenu; + private boolean isNsfwSubreddit = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -276,6 +280,15 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec } else { String subredditNamePrefixed = "r/" + name; getSupportActionBar().setTitle(subredditNamePrefixed); + + mSubredditViewModel = new ViewModelProvider(this, + new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, name)) + .get(SubredditViewModel.class); + mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> { + if (subredditData != null) { + isNsfwSubreddit = subredditData.isNSFW(); + } + }); } break; case PostPagingSource.TYPE_MULTI_REDDIT: @@ -484,4 +497,8 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec public void contentScrollDown() { fab.hide(); } + + public boolean isNsfwSubreddit() { + return isNsfwSubreddit; + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index ed8a6cd8..59cb5fd4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -354,10 +354,10 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe @NonNull @Override public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) { - Insets systemBar = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + Insets navigationBars = insets.getInsets(WindowInsetsCompat.Type.navigationBars()); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams(); - params.bottomMargin = systemBar.bottom; - params.rightMargin = systemBar.right; + params.bottomMargin = navigationBars.bottom; + params.rightMargin = navigationBars.right; return WindowInsetsCompat.CONSUMED; } }); 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 766eadf1..06eef725 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -1723,6 +1723,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { public boolean getIsNsfwSubreddit() { if (activity instanceof ViewSubredditDetailActivity) { return ((ViewSubredditDetailActivity) activity).isNsfwSubreddit(); + } else if (activity instanceof FilteredPostsActivity) { + return ((FilteredPostsActivity) activity).isNsfwSubreddit(); } else { return false; }