mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Gfycat and Redgifs videos autoplay in CommentAndPostRecyclerViewAdapter is available. Show an error icon when loading gfycats and redgifs videos failed in PostRecyclerViewAdapter and CommentAndPostRecyclerViewAdapter.
This commit is contained in:
parent
05e3889fe7
commit
aa673436ab
@ -172,6 +172,12 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Inject
|
||||
@Named("gfycat")
|
||||
Retrofit mGfycatRetrofit;
|
||||
@Inject
|
||||
@Named("redgifs")
|
||||
Retrofit mRedgifsRetrofit;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
@Named("default")
|
||||
@ -489,7 +495,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
|
||||
setupMenu();
|
||||
|
||||
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this,
|
||||
mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
|
||||
mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit,
|
||||
mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide,
|
||||
mWindowWidth, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
|
||||
isSingleCommentThreadMode, mSharedPreferences, mExoCreator,
|
||||
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
||||
@ -651,7 +658,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
|
||||
setupMenu();
|
||||
|
||||
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this,
|
||||
mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
|
||||
mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit,
|
||||
mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide,
|
||||
mWindowWidth, mAccessToken, mAccountName, mPost, mLocale,
|
||||
mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences, mExoCreator,
|
||||
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
||||
|
@ -105,6 +105,7 @@ import ml.docilealligator.infinityforreddit.Comment.FetchComment;
|
||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||
import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView;
|
||||
import ml.docilealligator.infinityforreddit.CustomView.MarkwonLinearLayoutManager;
|
||||
import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks;
|
||||
import ml.docilealligator.infinityforreddit.Post.Post;
|
||||
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
@ -141,6 +142,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
private AppCompatActivity mActivity;
|
||||
private Retrofit mRetrofit;
|
||||
private Retrofit mOauthRetrofit;
|
||||
private Retrofit mGfycatRetrofit;
|
||||
private Retrofit mRedgifsRetrofit;
|
||||
private RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
private RequestManager mGlide;
|
||||
private Markwon mPostDetailMarkwon;
|
||||
@ -172,6 +175,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
private boolean mFullyCollapseComment;
|
||||
private double mStartAutoplayVisibleAreaOffset;
|
||||
private boolean mMuteNSFWVideo;
|
||||
private boolean mAutomaticallyTryRedgifs;
|
||||
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
|
||||
private boolean isInitiallyLoading;
|
||||
private boolean isInitiallyLoadingFailed;
|
||||
@ -229,7 +233,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
private ExoCreator mExoCreator;
|
||||
|
||||
public CommentAndPostRecyclerViewAdapter(AppCompatActivity activity, CustomThemeWrapper customThemeWrapper,
|
||||
Retrofit retrofit, Retrofit oauthRetrofit,
|
||||
Retrofit retrofit, Retrofit oauthRetrofit, Retrofit gfycatRetrofit,
|
||||
Retrofit redgifsRetrofit,
|
||||
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
|
||||
int imageViewWidth, String accessToken, String accountName,
|
||||
Post post, Locale locale, String singleCommentId,
|
||||
@ -239,6 +244,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
mActivity = activity;
|
||||
mRetrofit = retrofit;
|
||||
mOauthRetrofit = oauthRetrofit;
|
||||
mGfycatRetrofit = gfycatRetrofit;
|
||||
mRedgifsRetrofit = redgifsRetrofit;
|
||||
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||
mGlide = glide;
|
||||
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
||||
@ -467,6 +474,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
sharedPreferences.getInt(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE, 50) / 100.0;
|
||||
|
||||
mMuteNSFWVideo = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_NSFW_VIDEO, false);
|
||||
mAutomaticallyTryRedgifs = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOMATICALLY_TRY_REDGIFS, true);
|
||||
|
||||
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
|
||||
isInitiallyLoading = true;
|
||||
@ -826,7 +834,30 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
mGlide.load(mPost.getPreviewUrl()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
|
||||
}
|
||||
((PostDetailVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (mPost.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
|
||||
|
||||
if (mPost.isGfycat() || mPost.isRedgifs() && !mPost.isLoadGfyOrRedgifsVideoSuccess()) {
|
||||
((PostDetailVideoAutoplayViewHolder) holder).mTypeTextView.setText("GFYCAT");
|
||||
((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks = new FetchGfycatOrRedgifsVideoLinks(new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
|
||||
@Override
|
||||
public void success(String webm, String mp4) {
|
||||
mPost.setVideoDownloadUrl(mp4);
|
||||
mPost.setVideoUrl(webm);
|
||||
mPost.setLoadGfyOrRedgifsVideoSuccess(true);
|
||||
((PostDetailVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(mPost.getVideoUrl()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(int errorCode) {
|
||||
((PostDetailVideoAutoplayViewHolder) holder).mErrorLoadingGfycatImageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks
|
||||
.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mGfycatRetrofit, mRedgifsRetrofit,
|
||||
mPost.getGfycatId(), mPost.isGfycat(), mAutomaticallyTryRedgifs);
|
||||
} else {
|
||||
((PostDetailVideoAutoplayViewHolder) holder).mTypeTextView.setText("VIDEO");
|
||||
((PostDetailVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(mPost.getVideoUrl()));
|
||||
}
|
||||
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
|
||||
if (mPost.getPostType() == Post.GIF_TYPE) {
|
||||
((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.gif));
|
||||
@ -1781,6 +1812,10 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
((PostDetailBaseViewHolder) holder).mNSFWTextView.setVisibility(View.GONE);
|
||||
|
||||
if (holder instanceof PostDetailVideoAutoplayViewHolder) {
|
||||
if (((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks != null) {
|
||||
((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks.cancel();
|
||||
}
|
||||
((PostDetailVideoAutoplayViewHolder) holder).mErrorLoadingGfycatImageView.setVisibility(View.GONE);
|
||||
((PostDetailVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE);
|
||||
((PostDetailVideoAutoplayViewHolder) holder).resetVolume();
|
||||
mGlide.clear(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
|
||||
@ -2286,6 +2321,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
PlayerView playerView;
|
||||
@BindView(R.id.preview_image_view_item_post_detail_video_autoplay)
|
||||
GifImageView previewImageView;
|
||||
@BindView(R.id.error_loading_gfycat_image_view_item_post_detail_video_autoplay)
|
||||
ImageView mErrorLoadingGfycatImageView;
|
||||
@BindView(R.id.mute_exo_playback_control_view)
|
||||
ImageView muteButton;
|
||||
@BindView(R.id.fullscreen_exo_playback_control_view)
|
||||
@ -2309,6 +2346,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
ExoPlayerViewHelper helper;
|
||||
private Uri mediaUri;
|
||||
private float volume;
|
||||
public FetchGfycatOrRedgifsVideoLinks fetchGfycatOrRedgifsVideoLinks;
|
||||
|
||||
public PostDetailVideoAutoplayViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
@ -2400,11 +2438,14 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
@NonNull
|
||||
@Override
|
||||
public PlaybackInfo getCurrentPlaybackInfo() {
|
||||
return helper != null ? helper.getLatestPlaybackInfo() : new PlaybackInfo();
|
||||
return helper != null && mediaUri != null ? helper.getLatestPlaybackInfo() : new PlaybackInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(@NonNull Container container, @NonNull PlaybackInfo playbackInfo) {
|
||||
if (mediaUri == null) {
|
||||
return;
|
||||
}
|
||||
if (helper == null) {
|
||||
helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator);
|
||||
helper.addEventListener(new Playable.EventListener() {
|
||||
@ -2451,7 +2492,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
|
||||
@Override
|
||||
public void play() {
|
||||
if (helper != null) helper.play();
|
||||
if (helper != null && mediaUri != null) helper.play();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -577,7 +577,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
|
||||
@Override
|
||||
public void failed(int errorCode) {
|
||||
Toast.makeText(mActivity, "asdfasdfadf", Toast.LENGTH_SHORT).show();
|
||||
((PostVideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks
|
||||
@ -1193,6 +1193,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
if (((PostVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks != null) {
|
||||
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks.cancel();
|
||||
}
|
||||
((PostVideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.GONE);
|
||||
((PostVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE);
|
||||
((PostVideoAutoplayViewHolder) holder).resetVolume();
|
||||
mGlide.clear(((PostVideoAutoplayViewHolder) holder).previewImageView);
|
||||
@ -1791,6 +1792,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
AspectRatioFrameLayout aspectRatioFrameLayout;
|
||||
@BindView(R.id.preview_image_view_item_post_video_type_autoplay)
|
||||
GifImageView previewImageView;
|
||||
@BindView(R.id.error_loading_gfycat_image_view_item_post_video_type_autoplay)
|
||||
ImageView errorLoadingGfycatImageView;
|
||||
@BindView(R.id.player_view_item_post_video_type_autoplay)
|
||||
PlayerView videoPlayer;
|
||||
@BindView(R.id.mute_exo_playback_control_view)
|
||||
|
9
app/src/main/res/drawable/ic_error_white_36dp.xml
Normal file
9
app/src/main/res/drawable/ic_error_white_36dp.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="36dp"
|
||||
android:height="36dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"
|
||||
android:fillColor="#FFFFFF"/>
|
||||
</vector>
|
@ -214,6 +214,16 @@
|
||||
android:scaleType="fitStart"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/error_loading_gfycat_image_view_item_post_detail_video_autoplay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/play_button_round_background"
|
||||
android:src="@drawable/ic_error_white_36dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
@ -217,6 +217,16 @@
|
||||
android:scaleType="fitStart"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/error_loading_gfycat_image_view_item_post_video_type_autoplay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/play_button_round_background"
|
||||
android:src="@drawable/ic_error_white_36dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
Loading…
Reference in New Issue
Block a user