aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java162
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java76
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomToroContainer.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java16
5 files changed, 178 insertions, 107 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
index 47330304..0c9b0ca3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
@@ -14,6 +14,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.Spanned;
+import android.text.TextUtils;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
@@ -206,6 +207,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private Drawable mCommentIcon;
private float mScale;
private ExoCreator mExoCreator;
+ private boolean canStartActivity = true;
+ private boolean canPlayVideo = true;
public PostDetailRecyclerViewAdapter(AppCompatActivity activity, ViewPostDetailFragment fragment,
Executor executor, CustomThemeWrapper customThemeWrapper,
@@ -392,6 +395,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mExoCreator = exoCreator;
}
+ public void setCanStartActivity(boolean canStartActivity) {
+ this.canStartActivity = canStartActivity;
+ }
+
@Override
public int getItemViewType(int position) {
switch (mPost.getPostType()) {
@@ -827,8 +834,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
if (holder instanceof PostDetailGalleryViewHolder) {
String previewCaption = preview.getPreviewCaption();
String previewCaptionUrl = preview.getPreviewCaptionUrl();
- boolean previewCaptionIsEmpty = android.text.TextUtils.isEmpty(previewCaption);
- boolean previewCaptionUrlIsEmpty = android.text.TextUtils.isEmpty(previewCaptionUrl);
+ boolean previewCaptionIsEmpty = TextUtils.isEmpty(previewCaption);
+ boolean previewCaptionUrlIsEmpty = TextUtils.isEmpty(previewCaptionUrl);
if (!previewCaptionIsEmpty || !previewCaptionUrlIsEmpty) {
((PostDetailGalleryViewHolder) holder).mCaptionConstraintLayout.setBackgroundColor(mCardViewColor & 0x0D000000); // Make 10% darker than CardViewColor
((PostDetailGalleryViewHolder) holder).mCaptionConstraintLayout.setVisibility(View.VISIBLE);
@@ -1083,6 +1090,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
return 0;
}
+ public void setCanPlayVideo(boolean canPlayVideo) {
+ this.canPlayVideo = canPlayVideo;
+ }
+
public interface PostDetailRecyclerViewAdapterCallback {
void updatePost(Post post);
}
@@ -1643,36 +1654,39 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
});
fullscreenButton.setOnClickListener(view -> {
- Intent intent = new Intent(mActivity, ViewVideoActivity.class);
- if (mPost.isGfycat()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
- if (mPost.isLoadGfycatOrStreamableVideoSuccess()) {
+ if (canStartActivity) {
+ canStartActivity = false;
+ Intent intent = new Intent(mActivity, ViewVideoActivity.class);
+ if (mPost.isGfycat()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
+ intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
+ if (mPost.isLoadGfycatOrStreamableVideoSuccess()) {
+ intent.setData(Uri.parse(mPost.getVideoUrl()));
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
+ }
+ } else if (mPost.isRedgifs()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
+ intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
+ if (mPost.isLoadGfycatOrStreamableVideoSuccess()) {
+ intent.setData(Uri.parse(mPost.getVideoUrl()));
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
+ }
+ } else if (mPost.isStreamable()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
+ intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, mPost.getStreamableShortCode());
+ } else {
intent.setData(Uri.parse(mPost.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
+ intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
+ intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
}
- } else if (mPost.isRedgifs()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
- if (mPost.isLoadGfycatOrStreamableVideoSuccess()) {
- intent.setData(Uri.parse(mPost.getVideoUrl()));
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
+ intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle());
+ if (helper != null) {
+ intent.putExtra(ViewVideoActivity.EXTRA_PROGRESS_SECONDS, helper.getLatestPlaybackInfo().getResumePosition());
}
- } else if (mPost.isStreamable()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
- intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, mPost.getStreamableShortCode());
- } else {
- intent.setData(Uri.parse(mPost.getVideoUrl()));
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
- intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
- intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
- }
- intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle());
- if (helper != null) {
- intent.putExtra(ViewVideoActivity.EXTRA_PROGRESS_SECONDS, helper.getLatestPlaybackInfo().getResumePosition());
+ intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, mPost.isNSFW());
+ mActivity.startActivity(intent);
}
- intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, mPost.isNSFW());
- mActivity.startActivity(intent);
});
previewImageView.setOnLongClickListener(view -> fullscreenButton.performClick());
@@ -1767,7 +1781,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
@Override
public boolean wantsToPlay() {
- return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
+ return canPlayVideo && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
}
@Override
@@ -1864,34 +1878,37 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mLoadImageErrorTextView.setTextColor(mPrimaryTextColor);
mImageView.setOnClickListener(view -> {
- if (mPost.getPostType() == Post.VIDEO_TYPE) {
- Intent intent = new Intent(mActivity, ViewVideoActivity.class);
- if (mPost.isGfycat()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
- } else if (mPost.isRedgifs()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
- } else if (mPost.isStreamable()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
- intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, mPost.getStreamableShortCode());
- } else {
- intent.setData(Uri.parse(mPost.getVideoUrl()));
- intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
- intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
+ if (canStartActivity) {
+ canStartActivity = false;
+ if (mPost.getPostType() == Post.VIDEO_TYPE) {
+ Intent intent = new Intent(mActivity, ViewVideoActivity.class);
+ if (mPost.isGfycat()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
+ intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
+ } else if (mPost.isRedgifs()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
+ intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
+ } else if (mPost.isStreamable()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
+ intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, mPost.getStreamableShortCode());
+ } else {
+ intent.setData(Uri.parse(mPost.getVideoUrl()));
+ intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
+ intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
+ }
+ intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle());
+ intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, mPost.isNSFW());
+ mActivity.startActivity(intent);
+ } else if (mPost.getPostType() == Post.GIF_TYPE) {
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
+ + "-" + mPost.getId() + ".gif");
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mPost.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
+ mActivity.startActivity(intent);
}
- intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle());
- intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, mPost.isNSFW());
- mActivity.startActivity(intent);
- } else if (mPost.getPostType() == Post.GIF_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
- intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
- + "-" + mPost.getId() + ".gif");
- intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mPost.getVideoUrl());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
- mActivity.startActivity(intent);
}
});
}
@@ -1983,22 +2000,25 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mLoadImageErrorTextView.setTextColor(mPrimaryTextColor);
mImageView.setOnClickListener(view -> {
- if (mPost.getPostType() == Post.IMAGE_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
- intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mPost.getUrl());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditNamePrefixed().substring(2)
- + "-" + mPost.getId().substring(3) + ".jpg");
- intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
- mActivity.startActivity(intent);
- } else if (mPost.getPostType() == Post.GIF_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
- intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
- + "-" + mPost.getId() + ".gif");
- intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mPost.getVideoUrl());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
- mActivity.startActivity(intent);
+ if (canStartActivity) {
+ canStartActivity = false;
+ if (mPost.getPostType() == Post.IMAGE_TYPE) {
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mPost.getUrl());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditNamePrefixed().substring(2)
+ + "-" + mPost.getId().substring(3) + ".jpg");
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
+ mActivity.startActivity(intent);
+ } else if (mPost.getPostType() == Post.GIF_TYPE) {
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
+ + "-" + mPost.getId() + ".gif");
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mPost.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
+ mActivity.startActivity(intent);
+ }
}
});
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
index 852f8c93..edd0ee82 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -209,6 +209,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private Drawable mCommentIcon;
private ExoCreator mExoCreator;
private Callback mCallback;
+ private boolean canPlayVideo = true;
public PostRecyclerViewAdapter(AppCompatActivity activity, PostFragment fragment, Executor executor, Retrofit oauthRetrofit,
Retrofit gfycatRetrofit, Retrofit redgifsRetrofit, Retrofit streambleRetrofit,
@@ -1991,6 +1992,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
}
+ public void setCanPlayVideo(boolean canPlayVideo) {
+ this.canPlayVideo = canPlayVideo;
+ }
+
public class PostBaseViewHolder extends RecyclerView.ViewHolder {
AspectRatioGifImageView iconGifImageView;
TextView subredditTextView;
@@ -2665,43 +2670,46 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
});
fullscreenButton.setOnClickListener(view -> {
- int position = getBindingAdapterPosition();
- if (position < 0) {
- return;
- }
- Post post = getItem(position);
- if (post != null) {
- markPostRead(post, true);
- Intent intent = new Intent(mActivity, ViewVideoActivity.class);
- if (post.isGfycat()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
- if (post.isLoadGfycatOrStreamableVideoSuccess()) {
+ if (canStartActivity) {
+ canStartActivity = false;
+ int position = getBindingAdapterPosition();
+ if (position < 0) {
+ return;
+ }
+ Post post = getItem(position);
+ if (post != null) {
+ markPostRead(post, true);
+ Intent intent = new Intent(mActivity, ViewVideoActivity.class);
+ if (post.isGfycat()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
+ intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
+ if (post.isLoadGfycatOrStreamableVideoSuccess()) {
+ intent.setData(Uri.parse(post.getVideoUrl()));
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
+ }
+ } else if (post.isRedgifs()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
+ intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
+ if (post.isLoadGfycatOrStreamableVideoSuccess()) {
+ intent.setData(Uri.parse(post.getVideoUrl()));
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
+ }
+ } else if (post.isStreamable()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
+ intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode());
+ } else {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
+ intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
+ intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
}
- } else if (post.isRedgifs()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
- if (post.isLoadGfycatOrStreamableVideoSuccess()) {
- intent.setData(Uri.parse(post.getVideoUrl()));
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
+ intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
+ if (helper != null) {
+ intent.putExtra(ViewVideoActivity.EXTRA_PROGRESS_SECONDS, helper.getLatestPlaybackInfo().getResumePosition());
}
- } else if (post.isStreamable()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
- intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode());
- } else {
- intent.setData(Uri.parse(post.getVideoUrl()));
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
- intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
- intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
- }
- intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
- if (helper != null) {
- intent.putExtra(ViewVideoActivity.EXTRA_PROGRESS_SECONDS, helper.getLatestPlaybackInfo().getResumePosition());
+ intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
+ mActivity.startActivity(intent);
}
- intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
- mActivity.startActivity(intent);
}
});
@@ -2801,7 +2809,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
@Override
public boolean wantsToPlay() {
- return mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
+ return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
}
@Override
@@ -4085,7 +4093,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
@Override
public boolean wantsToPlay() {
- return mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
+ return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomToroContainer.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomToroContainer.java
index 3df8b083..8d925ae6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomToroContainer.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomToroContainer.java
@@ -8,6 +8,8 @@ import androidx.annotation.Nullable;
import im.ene.toro.widget.Container;
public class CustomToroContainer extends Container {
+ private OnWindowFocusChangedListener listener;
+
public CustomToroContainer(Context context) {
super(context);
}
@@ -24,4 +26,20 @@ public class CustomToroContainer extends Container {
public void onWindowVisibilityChanged(int visibility) {
super.onWindowVisibilityChanged(visibility);
}
+
+ @Override
+ public void onWindowFocusChanged(boolean hasWindowFocus) {
+ super.onWindowFocusChanged(hasWindowFocus);
+ if (listener != null) {
+ listener.onWindowFocusChanged(hasWindowFocus);
+ }
+ }
+
+ public void addOnWindowFocusChangedListener(OnWindowFocusChangedListener onWindowFocusChangedListener) {
+ this.listener = onWindowFocusChangedListener;
+ }
+
+ public interface OnWindowFocusChangedListener {
+ void onWindowFocusChanged(boolean hasWindowsFocus);
+ }
}
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 1b83d8a8..9bd9bff8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -315,6 +315,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
applyTheme();
+ mPostRecyclerView.addOnWindowFocusChangedListener(this::onWindowFocusChanged);
+
lazyModeHandler = new Handler();
lazyModeInterval = Float.parseFloat(mSharedPreferences.getString(SharedPreferencesUtils.LAZY_MODE_INTERVAL_KEY, "2.5"));
@@ -2115,9 +2117,18 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void onDestroy() {
EventBus.getDefault().unregister(this);
+ if (mPostRecyclerView != null) {
+ mPostRecyclerView.addOnWindowFocusChangedListener(null);
+ }
super.onDestroy();
}
+ private void onWindowFocusChanged(boolean hasWindowsFocus) {
+ if (mAdapter != null) {
+ mAdapter.setCanPlayVideo(hasWindowsFocus);
+ }
+ }
+
private static abstract class LazyModeRunnable implements Runnable {
private int currentPosition = -1;
@@ -2184,4 +2195,4 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public interface LoadIconListener {
void loadIconSuccess(String subredditOrUserName, String iconUrl);
}
-} \ No newline at end of file
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
index eb94b01e..7f51721d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
@@ -263,6 +263,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
applyTheme();
+ mRecyclerView.addOnWindowFocusChangedListener(this::onWindowFocusChanged);
+
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
@@ -1101,6 +1103,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public void onResume() {
super.onResume();
+ if (mPostAdapter != null) {
+ mPostAdapter.setCanStartActivity(true);
+ }
if (mRecyclerView != null) {
mRecyclerView.onWindowVisibilityChanged(View.VISIBLE);
}
@@ -1131,6 +1136,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public void onDestroy() {
EventBus.getDefault().unregister(this);
+ if (mRecyclerView != null) {
+ mRecyclerView.addOnWindowFocusChangedListener(null);
+ }
super.onDestroy();
}
@@ -1899,4 +1907,10 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
mFetchPostInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor());
}
-} \ No newline at end of file
+
+ private void onWindowFocusChanged(boolean hasWindowsFocus) {
+ if (mPostAdapter != null) {
+ mPostAdapter.setCanPlayVideo(hasWindowsFocus);
+ }
+ }
+}