Disable video autoplay when separating post and comments in post detail page is enabled.

This commit is contained in:
Alex Ning 2021-08-11 23:44:43 +08:00
parent dc248735c7
commit c1862f334e
5 changed files with 27 additions and 17 deletions

View File

@ -166,6 +166,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private boolean mHideSubredditAndUserPrefix;
private boolean mHideTheNumberOfVotes;
private boolean mHideTheNumberOfComments;
private boolean mSeparatePostAndComments;
private PostDetailRecyclerViewAdapterCallback mPostDetailRecyclerViewAdapterCallback;
private int mColorAccent;
@ -203,7 +204,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
Executor executor, CustomThemeWrapper customThemeWrapper,
Retrofit retrofit, Retrofit oauthRetrofit, Retrofit gfycatRetrofit,
Retrofit redgifsRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
RequestManager glide, int imageViewWidth, String accessToken,
RequestManager glide, int imageViewWidth,
boolean separatePostAndComments, String accessToken,
String accountName, Post post, Locale locale,
SharedPreferences sharedPreferences,
SharedPreferences nsfwAndSpoilerSharedPreferences,
@ -335,6 +337,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
.build();
mImageViewWidth = imageViewWidth;
mSeparatePostAndComments = separatePostAndComments;
mAccessToken = accessToken;
mAccountName = accountName;
mPost = post;
@ -424,7 +427,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
public int getItemViewType(int position) {
switch (mPost.getPostType()) {
case Post.VIDEO_TYPE:
if (mAutoplay) {
if (mAutoplay && !mSeparatePostAndComments) {
if (!mAutoplayNsfwVideos && mPost.isNSFW()) {
return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
}

View File

@ -1,5 +1,10 @@
package ml.docilealligator.infinityforreddit.fragments;
import static im.ene.toro.media.PlaybackInfo.INDEX_UNSET;
import static im.ene.toro.media.PlaybackInfo.TIME_UNSET;
import static ml.docilealligator.infinityforreddit.activities.CommentActivity.RETURN_EXTRA_COMMENT_DATA_KEY;
import static ml.docilealligator.infinityforreddit.activities.CommentActivity.WRITE_COMMENT_REQUEST_CODE;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
@ -111,11 +116,6 @@ import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import static im.ene.toro.media.PlaybackInfo.INDEX_UNSET;
import static im.ene.toro.media.PlaybackInfo.TIME_UNSET;
import static ml.docilealligator.infinityforreddit.activities.CommentActivity.RETURN_EXTRA_COMMENT_DATA_KEY;
import static ml.docilealligator.infinityforreddit.activities.CommentActivity.WRITE_COMMENT_REQUEST_CODE;
public class ViewPostDetailFragment extends Fragment implements FragmentCommunicator {
public static final String EXTRA_POST_DATA = "EPD";
@ -218,6 +218,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
private boolean mLockFab;
private boolean mSwipeUpToHideFab;
private boolean mExpandChildren;
private boolean mSeparatePostAndComments = false;
private int mWindowWidth;
private ConcatAdapter mConcatAdapter;
private PostDetailRecyclerViewAdapter mPostAdapter;
@ -272,6 +273,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mCommentsRecyclerView.setVisibility(View.GONE);
mCommentsRecyclerView = null;
}
} else {
mSeparatePostAndComments = true;
}
if (activity != null && activity.isImmersiveInterface()) {
@ -541,7 +544,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide,
mWindowWidth, mAccessToken, mAccountName, mPost, mLocale,
mWindowWidth, mSeparatePostAndComments, mAccessToken, mAccountName, mPost, mLocale,
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences,
mExoCreator, post -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
mCommentsAdapter = new CommentsRecyclerViewAdapter(activity,
@ -1176,8 +1179,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper,
mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit,
mRedditDataRoomDatabase, mGlide, mWindowWidth, mAccessToken,
mAccountName, mPost, mLocale, mSharedPreferences,
mRedditDataRoomDatabase, mGlide, mWindowWidth, mSeparatePostAndComments,
mAccessToken, mAccountName, mPost, mLocale, mSharedPreferences,
mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences,
mExoCreator,
post1 -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
@ -1725,7 +1728,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null ? nextParentPosition + 1 : nextParentPosition);
mIsSmoothScrolling = true;
((LinearLayoutManager) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).startSmoothScroll(mSmoothScroller);
(mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().startSmoothScroll(mSmoothScroller);
}
}
@ -1738,7 +1741,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null ? previousParentPosition + 1 : previousParentPosition);
mIsSmoothScrolling = true;
((LinearLayoutManager) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).startSmoothScroll(mSmoothScroller);
(mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().startSmoothScroll(mSmoothScroller);
}
}

View File

@ -590,8 +590,9 @@
<string name="settings_video_player_automatic_landscape_orientation">Switch to Landscape Orientation in Video Player Automatically</string>
<string name="settings_remember_muting_option_in_post_feed">Remember Muting Option in Post Feed</string>
<string name="settings_post_details_title">Post Details</string>
<string name="settings_separate_post_and_comments_in_portrait_mode">Separate Post And Comments in Portrait Mode</string>
<string name="settings_separate_post_and_comments_in_landscape_mode">Separate Post And Comments in Landscape Mode</string>
<string name="settings_separate_post_and_comments_in_portrait_mode_title">Separate Post And Comments in Portrait Mode</string>
<string name="settings_separate_post_and_comments_in_landscape_mode_title">Separate Post And Comments in Landscape Mode</string>
<string name="settings_separate_post_and_comments_summary">Video autoplay will be disabled in the post detail page</string>
<string name="settings_use_bottom_toolbar_in_media_viewer_title">Use Bottom Toolbar in Media Viewer</string>
<string name="settings_secure_mode_title">Secure Mode</string>
<string name="settings_secure_mode_summary">Screenshot and video recording are not allowed. No preview in recent app screen.</string>

View File

@ -5,12 +5,14 @@
<SwitchPreference
app:defaultValue="true"
app:key="separate_post_and_comments_in_portrait_mode"
app:title="@string/settings_separate_post_and_comments_in_portrait_mode" />
app:title="@string/settings_separate_post_and_comments_in_portrait_mode_title"
app:summary="@string/settings_separate_post_and_comments_summary" />
<SwitchPreference
app:defaultValue="true"
app:key="separate_post_and_comments_in_landscape_mode"
app:title="@string/settings_separate_post_and_comments_in_landscape_mode" />
app:title="@string/settings_separate_post_and_comments_in_landscape_mode_title"
app:summary="@string/settings_separate_post_and_comments_summary" />
<SwitchPreference
app:defaultValue="false"

View File

@ -5,7 +5,8 @@
<SwitchPreference
app:defaultValue="true"
app:key="separate_post_and_comments_in_landscape_mode"
app:title="@string/settings_separate_post_and_comments_in_landscape_mode" />
app:title="@string/settings_separate_post_and_comments_in_landscape_mode_title"
app:summary="@string/settings_separate_post_and_comments_summary" />
<SwitchPreference
app:defaultValue="false"