mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-30 21:07:11 +01:00
Barebone gfycat and redgifs video autoplay in PostRecyclerViewAdapter.
This commit is contained in:
parent
24261df3db
commit
fc1b1ae585
@ -81,6 +81,7 @@ import ml.docilealligator.infinityforreddit.BottomSheetFragment.ShareLinkBottomS
|
|||||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView;
|
import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView;
|
||||||
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivity;
|
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivity;
|
||||||
|
import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks;
|
||||||
import ml.docilealligator.infinityforreddit.NetworkState;
|
import ml.docilealligator.infinityforreddit.NetworkState;
|
||||||
import ml.docilealligator.infinityforreddit.Post.Post;
|
import ml.docilealligator.infinityforreddit.Post.Post;
|
||||||
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
|
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
|
||||||
@ -124,6 +125,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
private AppCompatActivity mActivity;
|
private AppCompatActivity mActivity;
|
||||||
private Retrofit mOauthRetrofit;
|
private Retrofit mOauthRetrofit;
|
||||||
private Retrofit mRetrofit;
|
private Retrofit mRetrofit;
|
||||||
|
private Retrofit mGfycatRetrofit;
|
||||||
|
private Retrofit mRedgifsRetrofit;
|
||||||
private int mImageViewWidth;
|
private int mImageViewWidth;
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private RequestManager mGlide;
|
private RequestManager mGlide;
|
||||||
@ -178,6 +181,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
private boolean mShowThumbnailOnTheRightInCompactLayout;
|
private boolean mShowThumbnailOnTheRightInCompactLayout;
|
||||||
private double mStartAutoplayVisibleAreaOffset;
|
private double mStartAutoplayVisibleAreaOffset;
|
||||||
private boolean mMuteNSFWVideo;
|
private boolean mMuteNSFWVideo;
|
||||||
|
private boolean mAutomaticallyTryRedgifs;
|
||||||
private Drawable mCommentIcon;
|
private Drawable mCommentIcon;
|
||||||
private NetworkState networkState;
|
private NetworkState networkState;
|
||||||
private ExoCreator mExoCreator;
|
private ExoCreator mExoCreator;
|
||||||
@ -185,6 +189,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment;
|
private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment;
|
||||||
|
|
||||||
public PostRecyclerViewAdapter(AppCompatActivity activity, Retrofit oauthRetrofit, Retrofit retrofit,
|
public PostRecyclerViewAdapter(AppCompatActivity activity, Retrofit oauthRetrofit, Retrofit retrofit,
|
||||||
|
Retrofit gfycatRetrofit, Retrofit redgifsRetrofit,
|
||||||
RedditDataRoomDatabase redditDataRoomDatabase,
|
RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
CustomThemeWrapper customThemeWrapper, Locale locale, int imageViewWidth,
|
CustomThemeWrapper customThemeWrapper, Locale locale, int imageViewWidth,
|
||||||
String accessToken, int postType, int postLayout, boolean displaySubredditName,
|
String accessToken, int postType, int postLayout, boolean displaySubredditName,
|
||||||
@ -194,6 +199,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mOauthRetrofit = oauthRetrofit;
|
mOauthRetrofit = oauthRetrofit;
|
||||||
mRetrofit = retrofit;
|
mRetrofit = retrofit;
|
||||||
|
mGfycatRetrofit = gfycatRetrofit;
|
||||||
|
mRedgifsRetrofit = redgifsRetrofit;
|
||||||
mImageViewWidth = imageViewWidth;
|
mImageViewWidth = imageViewWidth;
|
||||||
mAccessToken = accessToken;
|
mAccessToken = accessToken;
|
||||||
mPostType = postType;
|
mPostType = postType;
|
||||||
@ -222,6 +229,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
sharedPreferences.getInt(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE, 50) / 100.0;
|
sharedPreferences.getInt(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE, 50) / 100.0;
|
||||||
|
|
||||||
mMuteNSFWVideo = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_NSFW_VIDEO, false);
|
mMuteNSFWVideo = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_NSFW_VIDEO, false);
|
||||||
|
mAutomaticallyTryRedgifs = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOMATICALLY_TRY_REDGIFS, true);
|
||||||
|
|
||||||
mPostLayout = postLayout;
|
mPostLayout = postLayout;
|
||||||
|
|
||||||
@ -555,7 +563,30 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
mGlide.load(post.getPreviewUrl()).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
|
mGlide.load(post.getPreviewUrl()).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
|
||||||
}
|
}
|
||||||
((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
|
((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
|
||||||
((PostVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl()));
|
|
||||||
|
if (post.isGfycat() || post.isRedgifs() && !post.isLoadGfyOrRedgifsVideoSuccess()) {
|
||||||
|
((PostVideoAutoplayViewHolder) holder).typeTextView.setText("GFYCAT");
|
||||||
|
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks = new FetchGfycatOrRedgifsVideoLinks(new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
|
||||||
|
@Override
|
||||||
|
public void success(String webm, String mp4) {
|
||||||
|
post.setVideoDownloadUrl(mp4);
|
||||||
|
post.setVideoUrl(webm);
|
||||||
|
post.setLoadGfyOrRedgifsVideoSuccess(true);
|
||||||
|
((PostVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void failed(int errorCode) {
|
||||||
|
Toast.makeText(mActivity, "asdfasdfadf", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks
|
||||||
|
.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mGfycatRetrofit, mRedgifsRetrofit,
|
||||||
|
post.getGfycatId(), post.isGfycat(), mAutomaticallyTryRedgifs);
|
||||||
|
} else {
|
||||||
|
((PostVideoAutoplayViewHolder) holder).typeTextView.setText("VIDEO");
|
||||||
|
((PostVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl()));
|
||||||
|
}
|
||||||
} else if (holder instanceof PostVideoAndGifPreviewViewHolder) {
|
} else if (holder instanceof PostVideoAndGifPreviewViewHolder) {
|
||||||
if (post.getPostType() == Post.VIDEO_TYPE) {
|
if (post.getPostType() == Post.VIDEO_TYPE) {
|
||||||
((PostVideoAndGifPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.video));
|
((PostVideoAndGifPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.video));
|
||||||
@ -1158,6 +1189,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
super.onViewRecycled(holder);
|
super.onViewRecycled(holder);
|
||||||
if (holder instanceof PostBaseViewHolder) {
|
if (holder instanceof PostBaseViewHolder) {
|
||||||
if (holder instanceof PostVideoAutoplayViewHolder) {
|
if (holder instanceof PostVideoAutoplayViewHolder) {
|
||||||
|
((PostVideoAutoplayViewHolder) holder).mediaUri = null;
|
||||||
|
if (((PostVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks != null) {
|
||||||
|
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks.cancel();
|
||||||
|
}
|
||||||
((PostVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE);
|
((PostVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE);
|
||||||
((PostVideoAutoplayViewHolder) holder).resetVolume();
|
((PostVideoAutoplayViewHolder) holder).resetVolume();
|
||||||
mGlide.clear(((PostVideoAutoplayViewHolder) holder).previewImageView);
|
mGlide.clear(((PostVideoAutoplayViewHolder) holder).previewImageView);
|
||||||
@ -1781,6 +1816,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
ExoPlayerViewHelper helper;
|
ExoPlayerViewHelper helper;
|
||||||
private Uri mediaUri;
|
private Uri mediaUri;
|
||||||
private float volume;
|
private float volume;
|
||||||
|
public FetchGfycatOrRedgifsVideoLinks fetchGfycatOrRedgifsVideoLinks;
|
||||||
|
|
||||||
PostVideoAutoplayViewHolder(View itemView) {
|
PostVideoAutoplayViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
@ -1865,11 +1901,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public PlaybackInfo getCurrentPlaybackInfo() {
|
public PlaybackInfo getCurrentPlaybackInfo() {
|
||||||
return helper != null ? helper.getLatestPlaybackInfo() : new PlaybackInfo();
|
return helper != null && mediaUri != null ? helper.getLatestPlaybackInfo() : new PlaybackInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(@NonNull Container container, @NonNull PlaybackInfo playbackInfo) {
|
public void initialize(@NonNull Container container, @NonNull PlaybackInfo playbackInfo) {
|
||||||
|
if (mediaUri == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (helper == null) {
|
if (helper == null) {
|
||||||
helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator);
|
helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator);
|
||||||
helper.addEventListener(new Playable.EventListener() {
|
helper.addEventListener(new Playable.EventListener() {
|
||||||
@ -1916,7 +1955,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void play() {
|
public void play() {
|
||||||
if (helper != null) helper.play();
|
if (helper != null && mediaUri != null) {
|
||||||
|
helper.play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1939,7 +1980,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean wantsToPlay() {
|
public boolean wantsToPlay() {
|
||||||
return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
|
return mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,11 +15,20 @@ import retrofit2.Response;
|
|||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
public class FetchGfycatOrRedgifsVideoLinks {
|
public class FetchGfycatOrRedgifsVideoLinks {
|
||||||
|
private FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener;
|
||||||
|
private ParseGfycatVideoLinksAsyncTask parseGfycatVideoLinksAsyncTask;
|
||||||
|
Retrofit gfycatRetrofit;
|
||||||
|
Call<String> gfycatCall;
|
||||||
|
|
||||||
public interface FetchGfycatOrRedgifsVideoLinksListener {
|
public interface FetchGfycatOrRedgifsVideoLinksListener {
|
||||||
void success(String webm, String mp4);
|
void success(String webm, String mp4);
|
||||||
void failed(int errorCode);
|
void failed(int errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FetchGfycatOrRedgifsVideoLinks(FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
|
||||||
|
this.fetchGfycatOrRedgifsVideoLinksListener = fetchGfycatOrRedgifsVideoLinksListener;
|
||||||
|
}
|
||||||
|
|
||||||
public static void fetchGfycatOrRedgifsVideoLinks(Retrofit gfycatRetrofit, String gfycatId,
|
public static void fetchGfycatOrRedgifsVideoLinks(Retrofit gfycatRetrofit, String gfycatId,
|
||||||
FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
|
FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
|
||||||
gfycatRetrofit.create(GfycatAPI.class).getGfycatData(gfycatId).enqueue(new Callback<String>() {
|
gfycatRetrofit.create(GfycatAPI.class).getGfycatData(gfycatId).enqueue(new Callback<String>() {
|
||||||
@ -39,6 +48,41 @@ public class FetchGfycatOrRedgifsVideoLinks {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(Retrofit gfycatRetrofit, Retrofit redgifsRetrofit,
|
||||||
|
String gfycatId, boolean isGfycatVideo,
|
||||||
|
boolean automaticallyTryRedgifs) {
|
||||||
|
gfycatCall = (isGfycatVideo ? gfycatRetrofit : redgifsRetrofit).create(GfycatAPI.class).getGfycatData(gfycatId);
|
||||||
|
gfycatCall.enqueue(new Callback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
parseGfycatVideoLinksAsyncTask = new ParseGfycatVideoLinksAsyncTask(response.body(), fetchGfycatOrRedgifsVideoLinksListener);
|
||||||
|
parseGfycatVideoLinksAsyncTask.execute();
|
||||||
|
} else {
|
||||||
|
if (response.code() == 404 && isGfycatVideo && automaticallyTryRedgifs) {
|
||||||
|
fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(gfycatRetrofit, redgifsRetrofit, gfycatId, false, false);
|
||||||
|
} else {
|
||||||
|
fetchGfycatOrRedgifsVideoLinksListener.failed(response.code());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
|
fetchGfycatOrRedgifsVideoLinksListener.failed(-1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel() {
|
||||||
|
if (gfycatCall != null && !gfycatCall.isCanceled()) {
|
||||||
|
gfycatCall.cancel();
|
||||||
|
}
|
||||||
|
if (parseGfycatVideoLinksAsyncTask != null && !parseGfycatVideoLinksAsyncTask.isCancelled()) {
|
||||||
|
parseGfycatVideoLinksAsyncTask.cancel(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class ParseGfycatVideoLinksAsyncTask extends AsyncTask<Void, Void, Void> {
|
private static class ParseGfycatVideoLinksAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
private String response;
|
private String response;
|
||||||
|
@ -138,6 +138,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
@Named("oauth")
|
@Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("gfycat")
|
||||||
|
Retrofit mGfycatRetrofit;
|
||||||
|
@Inject
|
||||||
|
@Named("redgifs")
|
||||||
|
Retrofit mRedgifsRetrofit;
|
||||||
|
@Inject
|
||||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("default")
|
@Named("default")
|
||||||
@ -401,8 +407,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
|
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
||||||
customThemeWrapper, locale, windowWidth, accessToken, postType, postLayout, true,
|
mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale,
|
||||||
|
windowWidth, accessToken, postType, postLayout, true,
|
||||||
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
|
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
@ -456,8 +463,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
sortType = new SortType(SortType.Type.valueOf(sort));
|
sortType = new SortType(SortType.Type.valueOf(sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
||||||
customThemeWrapper, locale, windowWidth, accessToken, postType, postLayout, displaySubredditName,
|
mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale,
|
||||||
|
windowWidth, accessToken, postType, postLayout, displaySubredditName,
|
||||||
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
|
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
@ -504,8 +512,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
sortType = new SortType(SortType.Type.valueOf(sort));
|
sortType = new SortType(SortType.Type.valueOf(sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
||||||
customThemeWrapper, locale, windowWidth, accessToken, postType, postLayout, true,
|
mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale,
|
||||||
|
windowWidth, accessToken, postType, postLayout, true,
|
||||||
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
|
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
@ -550,8 +559,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
||||||
customThemeWrapper, locale, windowWidth, accessToken, postType, postLayout, true,
|
mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale,
|
||||||
|
windowWidth, accessToken, postType, postLayout, true,
|
||||||
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
|
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
@ -589,8 +599,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
|
||||||
customThemeWrapper, locale, windowWidth, accessToken, postType, postLayout, true,
|
mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale,
|
||||||
|
windowWidth, accessToken, postType, postLayout, true,
|
||||||
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
|
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
|
@ -384,9 +384,14 @@ public class ParsePost {
|
|||||||
try {
|
try {
|
||||||
Uri uri = Uri.parse(url);
|
Uri uri = Uri.parse(url);
|
||||||
String authority = uri.getAuthority();
|
String authority = uri.getAuthority();
|
||||||
if (authority != null && (authority.contains("gfycat.com") || authority.contains("redgifs.com"))) {
|
if (authority != null && (authority.contains("gfycat.com"))) {
|
||||||
post.setPostType(Post.LINK_TYPE);
|
post.setIsGfycat(true);
|
||||||
post.setUrl(url);
|
post.setVideoUrl(url);
|
||||||
|
post.setGfycatId(url.substring(url.lastIndexOf("/") + 1));
|
||||||
|
} else if (authority != null && authority.contains("redgifs.com")) {
|
||||||
|
post.setIsRedgifs(true);
|
||||||
|
post.setVideoUrl(url);
|
||||||
|
post.setGfycatId(url.substring(url.lastIndexOf("/") + 1));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignore) { }
|
} catch (IllegalArgumentException ignore) { }
|
||||||
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
|
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
|
||||||
@ -422,6 +427,20 @@ public class ParsePost {
|
|||||||
post.setPostType(Post.GALLERY_TYPE);
|
post.setPostType(Post.GALLERY_TYPE);
|
||||||
post.setGallery(gallery);
|
post.setGallery(gallery);
|
||||||
}
|
}
|
||||||
|
} else if (post.getPostType() == Post.LINK_TYPE) {
|
||||||
|
Uri uri = Uri.parse(url);
|
||||||
|
String authority = uri.getAuthority();
|
||||||
|
if (authority != null && (authority.contains("gfycat.com"))) {
|
||||||
|
post.setPostType(Post.VIDEO_TYPE);
|
||||||
|
post.setIsGfycat(true);
|
||||||
|
post.setVideoUrl(url);
|
||||||
|
post.setGfycatId(url.substring(url.lastIndexOf("/") + 1));
|
||||||
|
} else if (authority != null && authority.contains("redgifs.com")) {
|
||||||
|
post.setPostType(Post.VIDEO_TYPE);
|
||||||
|
post.setIsRedgifs(true);
|
||||||
|
post.setVideoUrl(url);
|
||||||
|
post.setGfycatId(url.substring(url.lastIndexOf("/") + 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,10 @@ public class Post implements Parcelable {
|
|||||||
private String url;
|
private String url;
|
||||||
private String videoUrl;
|
private String videoUrl;
|
||||||
private String videoDownloadUrl;
|
private String videoDownloadUrl;
|
||||||
|
private String gfycatId;
|
||||||
|
private boolean isGfycat;
|
||||||
|
private boolean isRedgifs;
|
||||||
|
private boolean loadGfyOrRedgifsVideoSuccess;
|
||||||
private String permalink;
|
private String permalink;
|
||||||
private String flair;
|
private String flair;
|
||||||
private String awards;
|
private String awards;
|
||||||
@ -202,6 +206,10 @@ public class Post implements Parcelable {
|
|||||||
url = in.readString();
|
url = in.readString();
|
||||||
videoUrl = in.readString();
|
videoUrl = in.readString();
|
||||||
videoDownloadUrl = in.readString();
|
videoDownloadUrl = in.readString();
|
||||||
|
gfycatId = in.readString();
|
||||||
|
isGfycat = in.readByte() != 0;
|
||||||
|
isRedgifs = in.readByte() != 0;
|
||||||
|
loadGfyOrRedgifsVideoSuccess = in.readByte() != 0;
|
||||||
permalink = in.readString();
|
permalink = in.readString();
|
||||||
flair = in.readString();
|
flair = in.readString();
|
||||||
awards = in.readString();
|
awards = in.readString();
|
||||||
@ -353,6 +361,38 @@ public class Post implements Parcelable {
|
|||||||
this.videoDownloadUrl = videoDownloadUrl;
|
this.videoDownloadUrl = videoDownloadUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getGfycatId() {
|
||||||
|
return gfycatId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGfycatId(String gfycatId) {
|
||||||
|
this.gfycatId = gfycatId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGfycat() {
|
||||||
|
return isGfycat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsGfycat(boolean isGfycat) {
|
||||||
|
this.isGfycat = isGfycat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRedgifs() {
|
||||||
|
return isRedgifs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsRedgifs(boolean isRedgifs) {
|
||||||
|
this.isRedgifs = isRedgifs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLoadGfyOrRedgifsVideoSuccess() {
|
||||||
|
return loadGfyOrRedgifsVideoSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoadGfyOrRedgifsVideoSuccess(boolean loadGfyOrRedgifsVideoSuccess) {
|
||||||
|
this.loadGfyOrRedgifsVideoSuccess = loadGfyOrRedgifsVideoSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPermalink() {
|
public String getPermalink() {
|
||||||
return permalink;
|
return permalink;
|
||||||
}
|
}
|
||||||
@ -512,6 +552,10 @@ public class Post implements Parcelable {
|
|||||||
parcel.writeString(url);
|
parcel.writeString(url);
|
||||||
parcel.writeString(videoUrl);
|
parcel.writeString(videoUrl);
|
||||||
parcel.writeString(videoDownloadUrl);
|
parcel.writeString(videoDownloadUrl);
|
||||||
|
parcel.writeString(gfycatId);
|
||||||
|
parcel.writeByte((byte) (isGfycat ? 1 : 0));
|
||||||
|
parcel.writeByte((byte) (isRedgifs ? 1 : 0));
|
||||||
|
parcel.writeByte((byte) (loadGfyOrRedgifsVideoSuccess ? 1 : 0));
|
||||||
parcel.writeString(permalink);
|
parcel.writeString(permalink);
|
||||||
parcel.writeString(flair);
|
parcel.writeString(flair);
|
||||||
parcel.writeString(awards);
|
parcel.writeString(awards);
|
||||||
|
Loading…
Reference in New Issue
Block a user