diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-09-13 14:10:43 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-09-13 14:10:43 +0000 |
commit | aa673436ab4fb13a810b6cdc4624f830c529d704 (patch) | |
tree | 7f5f944e670ce0d1d2a0a1bb023517eda5ea84cb /app/src | |
parent | 05e3889fe7eb9c01bd050da1da9d9e7f24f0945e (diff) | |
download | infinity-for-reddit-aa673436ab4fb13a810b6cdc4624f830c529d704.tar infinity-for-reddit-aa673436ab4fb13a810b6cdc4624f830c529d704.tar.gz infinity-for-reddit-aa673436ab4fb13a810b6cdc4624f830c529d704.tar.bz2 infinity-for-reddit-aa673436ab4fb13a810b6cdc4624f830c529d704.tar.lz infinity-for-reddit-aa673436ab4fb13a810b6cdc4624f830c529d704.tar.xz infinity-for-reddit-aa673436ab4fb13a810b6cdc4624f830c529d704.tar.zst infinity-for-reddit-aa673436ab4fb13a810b6cdc4624f830c529d704.zip |
Gfycat and Redgifs videos autoplay in CommentAndPostRecyclerViewAdapter is available. Show an error icon when loading gfycats and redgifs videos failed in PostRecyclerViewAdapter and CommentAndPostRecyclerViewAdapter.
Diffstat (limited to 'app/src')
6 files changed, 88 insertions, 7 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index d317800c..9b34f58f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -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() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index b93f3375..0faf9c78 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -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); - ((PostDetailVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(mPost.getVideoUrl())); + + 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 diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index db81a51f..869442b8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -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) diff --git a/app/src/main/res/drawable/ic_error_white_36dp.xml b/app/src/main/res/drawable/ic_error_white_36dp.xml new file mode 100644 index 00000000..c4705c5d --- /dev/null +++ b/app/src/main/res/drawable/ic_error_white_36dp.xml @@ -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> diff --git a/app/src/main/res/layout/item_post_detail_video_autoplay.xml b/app/src/main/res/layout/item_post_detail_video_autoplay.xml index 6f3183b7..79e32dd7 100644 --- a/app/src/main/res/layout/item_post_detail_video_autoplay.xml +++ b/app/src/main/res/layout/item_post_detail_video_autoplay.xml @@ -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 diff --git a/app/src/main/res/layout/item_post_video_type_autoplay.xml b/app/src/main/res/layout/item_post_video_type_autoplay.xml index dd404645..b68c9231 100644 --- a/app/src/main/res/layout/item_post_video_type_autoplay.xml +++ b/app/src/main/res/layout/item_post_video_type_autoplay.xml @@ -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 |