Docile-Alligator 2023-05-04 13:06:27 +08:00
parent b0f2e89c7b
commit 304fa86400
3 changed files with 22 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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;
}
});

View File

@ -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;
}