diff options
4 files changed, 134 insertions, 9 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java index 39d79d39..8c538e47 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java @@ -44,6 +44,7 @@ import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; +import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.Tracks; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.DefaultTimeBar; @@ -793,7 +794,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy @Override public void failed(int errorCode) { if (position == holder.getBindingAdapterPosition()) { - ((PostBaseVideoAutoplayViewHolder) holder).errorLoadingVideoImageView.setVisibility(View.VISIBLE); + ((PostBaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } } }); @@ -817,7 +818,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy @Override public void failed() { if (position == holder.getBindingAdapterPosition()) { - ((PostBaseVideoAutoplayViewHolder) holder).errorLoadingVideoImageView.setVisibility(View.VISIBLE); + ((PostBaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } } }); @@ -974,7 +975,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy @Override public void failed(int errorCode) { if (position == holder.getBindingAdapterPosition()) { - ((PostCard2BaseVideoAutoplayViewHolder) holder).errorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + ((PostCard2BaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } } }); @@ -998,7 +999,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy @Override public void failed() { if (position == holder.getBindingAdapterPosition()) { - ((PostCard2BaseVideoAutoplayViewHolder) holder).errorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + ((PostCard2BaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } } }); @@ -1797,7 +1798,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy @Override public void failed(int errorCode) { if (position == holder.getBindingAdapterPosition()) { - ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).errorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } } }); @@ -1821,7 +1822,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy @Override public void failed() { if (position == holder.getBindingAdapterPosition()) { - ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).errorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } } }); @@ -2475,9 +2476,17 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } else if (post.isRedgifs()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); intent.putExtra(ViewVideoActivity.EXTRA_REDGIFS_ID, post.getRedgifsId()); + if (post.isLoadRedgifsOrStreamableVideoSuccess()) { + 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()); + if (post.isLoadRedgifsOrStreamableVideoSuccess()) { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); + } } else { intent.setData(Uri.parse(post.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName()); @@ -3238,6 +3247,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } else if (post.isStreamable()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE); intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode()); + if (post.isLoadRedgifsOrStreamableVideoSuccess()) { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); + } } else { intent.setData(Uri.parse(post.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); @@ -3309,6 +3322,16 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy if (container != null) container.savePlaybackInfo(order, playbackInfo); } + void loadFallbackDirectVideo() { + mediaUri = Uri.parse(post.getVideoFallBackDirectUrl()); + post.setVideoDownloadUrl(post.getVideoFallBackDirectUrl()); + post.setVideoUrl(post.getVideoFallBackDirectUrl()); + post.setLoadRedgifsOrStreamableVideoSuccess(true); + if (container != null) { + container.onScrollStateChanged(RecyclerView.SCROLL_STATE_IDLE); + } + } + @NonNull @Override public View getPlayerView() { @@ -3362,6 +3385,15 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy mGlide.clear(previewImageView); previewImageView.setVisibility(View.GONE); } + + @Override + public void onPlayerError(@NonNull PlaybackException error) { + if (post.getVideoFallBackDirectUrl() == null || post.getVideoFallBackDirectUrl().equals(mediaUri.toString())) { + errorLoadingVideoImageView.setVisibility(View.VISIBLE); + } else { + loadFallbackDirectVideo(); + } + } }); } helper.initialize(container, playbackInfo); @@ -4901,6 +4933,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } else if (post.isStreamable()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE); intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode()); + if (post.isLoadRedgifsOrStreamableVideoSuccess()) { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); + } } else { intent.setData(Uri.parse(post.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); @@ -4941,6 +4977,16 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy if (container != null) container.savePlaybackInfo(order, playbackInfo); } + void loadFallbackDirectVideo() { + mediaUri = Uri.parse(post.getVideoFallBackDirectUrl()); + post.setVideoDownloadUrl(post.getVideoFallBackDirectUrl()); + post.setVideoUrl(post.getVideoFallBackDirectUrl()); + post.setLoadRedgifsOrStreamableVideoSuccess(true); + if (container != null) { + container.onScrollStateChanged(RecyclerView.SCROLL_STATE_IDLE); + } + } + @NonNull @Override public View getPlayerView() { @@ -4994,6 +5040,15 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy mGlide.clear(previewImageView); previewImageView.setVisibility(View.GONE); } + + @Override + public void onPlayerError(@NonNull PlaybackException error) { + if (post.getVideoFallBackDirectUrl() == null || post.getVideoFallBackDirectUrl().equals(mediaUri.toString())) { + errorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + } else { + loadFallbackDirectVideo(); + } + } }); } helper.initialize(container, playbackInfo); @@ -5872,6 +5927,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } else if (post.isStreamable()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE); intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode()); + if (post.isLoadRedgifsOrStreamableVideoSuccess()) { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); + } } else { intent.setData(Uri.parse(post.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); @@ -5912,6 +5971,16 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy if (container != null) container.savePlaybackInfo(order, playbackInfo); } + void loadFallbackDirectVideo() { + mediaUri = Uri.parse(post.getVideoFallBackDirectUrl()); + post.setVideoDownloadUrl(post.getVideoFallBackDirectUrl()); + post.setVideoUrl(post.getVideoFallBackDirectUrl()); + post.setLoadRedgifsOrStreamableVideoSuccess(true); + if (container != null) { + container.onScrollStateChanged(RecyclerView.SCROLL_STATE_IDLE); + } + } + @NonNull @Override public View getPlayerView() { @@ -5965,6 +6034,15 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy mGlide.clear(previewImageView); previewImageView.setVisibility(View.GONE); } + + @Override + public void onPlayerError(@NonNull PlaybackException error) { + if (post.getVideoFallBackDirectUrl() == null || post.getVideoFallBackDirectUrl().equals(mediaUri.toString())) { + errorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + } else { + loadFallbackDirectVideo(); + } + } }); } helper.initialize(container, playbackInfo); 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 45b5dd5b..7e08d604 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -38,6 +38,7 @@ import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; +import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.Tracks; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.DefaultTimeBar; @@ -722,7 +723,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler @Override public void failed(int errorCode) { - ((PostDetailBaseVideoAutoplayViewHolder) holder).mErrorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + ((PostDetailBaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } }); } else if(mPost.isStreamable() && !mPost.isLoadRedgifsOrStreamableVideoSuccess()) { @@ -742,7 +743,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler @Override public void failed() { - ((PostDetailBaseVideoAutoplayViewHolder) holder).mErrorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + ((PostDetailBaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } }); } else { @@ -1710,6 +1711,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler } else if (mPost.isStreamable()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE); intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, mPost.getStreamableShortCode()); + if (mPost.isLoadRedgifsOrStreamableVideoSuccess()) { + intent.setData(Uri.parse(mPost.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); + } } else { intent.setData(Uri.parse(mPost.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); @@ -1779,6 +1784,16 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler if (container != null) container.savePlaybackInfo(order, playbackInfo); } + void loadFallbackDirectVideo() { + mediaUri = Uri.parse(mPost.getVideoFallBackDirectUrl()); + mPost.setVideoDownloadUrl(mPost.getVideoFallBackDirectUrl()); + mPost.setVideoUrl(mPost.getVideoFallBackDirectUrl()); + mPost.setLoadRedgifsOrStreamableVideoSuccess(true); + if (container != null) { + container.onScrollStateChanged(RecyclerView.SCROLL_STATE_IDLE); + } + } + @NonNull @Override public View getPlayerView() { @@ -1829,6 +1844,15 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler mGlide.clear(previewImageView); previewImageView.setVisibility(View.GONE); } + + @Override + public void onPlayerError(@NonNull PlaybackException error) { + if (mPost.getVideoFallBackDirectUrl() == null || mPost.getVideoFallBackDirectUrl().equals(mediaUri.toString())) { + mErrorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + } else { + loadFallbackDirectVideo(); + } + } }); } helper.initialize(container, playbackInfo); @@ -1996,9 +2020,17 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler } else if (mPost.isRedgifs()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); intent.putExtra(ViewVideoActivity.EXTRA_REDGIFS_ID, mPost.getRedgifsId()); + if (mPost.isLoadRedgifsOrStreamableVideoSuccess()) { + 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()); + if (mPost.isLoadRedgifsOrStreamableVideoSuccess()) { + intent.setData(Uri.parse(mPost.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); + } } else { intent.setData(Uri.parse(mPost.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName()); @@ -2192,9 +2224,17 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler if (mPost.isRedgifs()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); intent.putExtra(ViewVideoActivity.EXTRA_REDGIFS_ID, mPost.getRedgifsId()); + if (mPost.isLoadRedgifsOrStreamableVideoSuccess()) { + 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()); + if (mPost.isLoadRedgifsOrStreamableVideoSuccess()) { + intent.setData(Uri.parse(mPost.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); + } } else { intent.setData(Uri.parse(mPost.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName()); 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 e869b021..a1cb9447 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -2602,9 +2602,17 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } else if (post.isRedgifs()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); intent.putExtra(ViewVideoActivity.EXTRA_REDGIFS_ID, post.getRedgifsId()); + if (post.isLoadRedgifsOrStreamableVideoSuccess()) { + 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()); + if (post.isLoadRedgifsOrStreamableVideoSuccess()) { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); + } } else { intent.setData(Uri.parse(post.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/widget/Container.java b/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/widget/Container.java index 1ac271db..9eb04c41 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/widget/Container.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/widget/Container.java @@ -279,7 +279,6 @@ public class Container extends RecyclerView { } @CallSuper @Override public void onScrollStateChanged(int state) { - super.onScrollStateChanged(state); // Need to handle the dead playback even when the Container is still scrolling/flinging. List<ToroPlayer> players = playerManager.getPlayers(); // 1. Find players those are managed but not qualified to play anymore. |