diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-02-27 04:29:43 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-02-27 04:29:43 +0000 |
commit | f0e5bcb477029a095fd0794e9e25ea0169f4af29 (patch) | |
tree | cc274afeeafa83b6c83c33a52f7498327e90eae3 /app/src/main/java | |
parent | 378b65b84f6d32f3a9335913b26165303765e1ec (diff) | |
download | infinity-for-reddit-f0e5bcb477029a095fd0794e9e25ea0169f4af29.tar infinity-for-reddit-f0e5bcb477029a095fd0794e9e25ea0169f4af29.tar.gz infinity-for-reddit-f0e5bcb477029a095fd0794e9e25ea0169f4af29.tar.bz2 infinity-for-reddit-f0e5bcb477029a095fd0794e9e25ea0169f4af29.tar.lz infinity-for-reddit-f0e5bcb477029a095fd0794e9e25ea0169f4af29.tar.xz infinity-for-reddit-f0e5bcb477029a095fd0794e9e25ea0169f4af29.tar.zst infinity-for-reddit-f0e5bcb477029a095fd0794e9e25ea0169f4af29.zip |
Loading fallback video in PostRecyclerViewAdapter
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java | 46 |
1 files changed, 42 insertions, 4 deletions
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 efe7b6df..e869b021 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -1022,7 +1022,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie @Override public void failed(int errorCode) { if (position == holder.getBindingAdapterPosition()) { - ((PostCard2BaseVideoAutoplayViewHolder) holder).errorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + ((PostCard2BaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } } }); @@ -1046,7 +1046,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie @Override public void failed() { if (position == holder.getBindingAdapterPosition()) { - ((PostCard2BaseVideoAutoplayViewHolder) holder).errorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + ((PostCard2BaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } } }); @@ -1884,7 +1884,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie @Override public void failed(int errorCode) { if (position == holder.getBindingAdapterPosition()) { - ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).errorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } } }); @@ -1908,7 +1908,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie @Override public void failed() { if (position == holder.getBindingAdapterPosition()) { - ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).errorLoadingRedgifsImageView.setVisibility(View.VISIBLE); + ((PostMaterial3CardBaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo(); } } }); @@ -5199,6 +5199,16 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie 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() { @@ -5252,6 +5262,15 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie 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); @@ -6210,6 +6229,16 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie 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() { @@ -6263,6 +6292,15 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie 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); |