aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java43
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java2
2 files changed, 38 insertions, 7 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 b0c2d618..efe7b6df 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -25,7 +25,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.appcompat.content.res.AppCompatResources;
import androidx.constraintlayout.widget.Barrier;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
@@ -44,6 +43,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;
@@ -838,7 +838,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
@Override
public void failed(int errorCode) {
if (position == holder.getBindingAdapterPosition()) {
- ((PostBaseVideoAutoplayViewHolder) holder).errorLoadingRedgifsImageView.setVisibility(View.VISIBLE);
+ ((PostBaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo();
}
}
});
@@ -862,7 +862,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
@Override
public void failed() {
if (position == holder.getBindingAdapterPosition()) {
- ((PostBaseVideoAutoplayViewHolder) holder).errorLoadingRedgifsImageView.setVisibility(View.VISIBLE);
+ ((PostBaseVideoAutoplayViewHolder) holder).loadFallbackDirectVideo();
}
}
});
@@ -3401,6 +3401,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
} 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());
@@ -3472,6 +3476,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() {
@@ -3486,12 +3500,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
@Override
public void initialize(@NonNull Container container, @NonNull PlaybackInfo playbackInfo) {
- if (mediaUri == null) {
- return;
- }
if (this.container == null) {
this.container = container;
}
+ if (mediaUri == null) {
+ return;
+ }
if (helper == null) {
helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator);
helper.addEventListener(new Playable.DefaultEventListener() {
@@ -3525,6 +3539,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);
@@ -5102,6 +5125,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
} 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());
@@ -6108,6 +6135,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
} 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());
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
index 6c786189..f0dc2138 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
@@ -384,7 +384,7 @@ public class ParsePost {
post.setVideoDownloadUrl(url);
post.setIsImgur(true);
} else {
- //Gif video post (HLS)
+ //Gif video post (HLS) and maybe Redgifs
String videoUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY)
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.HLS_URL_KEY)).toString();