diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-06-04 08:43:46 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-06-04 08:43:46 +0000 |
commit | ca957e890443452d2c543f567b53e94495dbf8e5 (patch) | |
tree | 95ac359b92880a0fb65c3e63c40ebc9c3ea1bfff /app | |
parent | d9de2938b495b4972ba706bfc383ee2800073e45 (diff) | |
download | infinity-for-reddit-ca957e890443452d2c543f567b53e94495dbf8e5.tar infinity-for-reddit-ca957e890443452d2c543f567b53e94495dbf8e5.tar.gz infinity-for-reddit-ca957e890443452d2c543f567b53e94495dbf8e5.tar.bz2 infinity-for-reddit-ca957e890443452d2c543f567b53e94495dbf8e5.tar.lz infinity-for-reddit-ca957e890443452d2c543f567b53e94495dbf8e5.tar.xz infinity-for-reddit-ca957e890443452d2c543f567b53e94495dbf8e5.tar.zst infinity-for-reddit-ca957e890443452d2c543f567b53e94495dbf8e5.zip |
Support REdgifs and Gfycat videos in post lists and links.
Diffstat (limited to '')
9 files changed, 216 insertions, 98 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/API/GfycatAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/API/GfycatAPI.java index 56eafa4d..161659b7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/API/GfycatAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/API/GfycatAPI.java @@ -6,5 +6,5 @@ import retrofit2.http.Path; public interface GfycatAPI { @GET("{gfyid}") - Call<String> getSubredditData(@Path("gfyid") String gfyId); + Call<String> getGfycatData(@Path("gfyid") String gfyId); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index 1a042e65..f987a2a3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -39,6 +39,7 @@ public class LinkResolverActivity extends AppCompatActivity { private static final String MULTIREDDIT_PATTERN_2 = "/[rR]/(\\w+\\+?)+/?"; private static final String REDD_IT_POST_PATTERN = "/\\w+/?"; private static final String GFYCAT_PATTERN = "/[\\w-]+$"; + private static final String REDGIFS_PATTERN = "/watch/[\\w-]+$"; private static final String IMGUR_GALLERY_PATTERN = "/gallery/\\w+/?"; private static final String IMGUR_ALBUM_PATTERN = "/(album|a)/\\w+/?"; private static final String IMGUR_IMAGE_PATTERN = "/\\w+/?"; @@ -76,119 +77,151 @@ public class LinkResolverActivity extends AppCompatActivity { path = path.substring(0, path.length() - 1); } - String messageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME); - String newAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); + if (path.endsWith("jpg") || path.endsWith("png")) { + Intent intent = new Intent(this, ViewImageActivity.class); + String url = uri.toString(); + String fileName = url.substring(url.lastIndexOf('/') + 1); + intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, url); + intent.putExtra(ViewImageActivity.FILE_NAME_KEY, fileName); + intent.putExtra(ViewImageActivity.POST_TITLE_KEY, fileName); + startActivity(intent); + } else if (path.endsWith("gif")) { + Intent intent = new Intent(this, ViewGIFActivity.class); + String url = uri.toString(); + String fileName = url.substring(url.lastIndexOf('/') + 1); + intent.putExtra(ViewGIFActivity.GIF_URL_KEY, url); + intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, fileName); + intent.putExtra(ViewGIFActivity.POST_TITLE_KEY, fileName); + startActivity(intent); + } else if (path.endsWith("mp4")) { + Intent intent = new Intent(this, ViewVideoActivity.class); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT); + intent.setData(uri); + startActivity(intent); + } else { + String messageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME); + String newAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME); - String authority = uri.getAuthority(); - List<String> segments = uri.getPathSegments(); + String authority = uri.getAuthority(); + List<String> segments = uri.getPathSegments(); - if (authority != null) { - if (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app")) { - if (authority.equals("reddit.app.link") && path.isEmpty()) { - String redirect = uri.getQueryParameter("$og_redirect"); - handleUri(Uri.parse(redirect)); - } else if (path.isEmpty()) { - Intent intent = new Intent(this, MainActivity.class); - startActivity(intent); - } else if (path.matches(POST_PATTERN)) { - int commentsIndex = segments.lastIndexOf("comments"); - if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + if (authority != null) { + if (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app")) { + if (authority.equals("reddit.app.link") && path.isEmpty()) { + String redirect = uri.getQueryParameter("$og_redirect"); + handleUri(Uri.parse(redirect)); + } else if (path.isEmpty()) { + Intent intent = new Intent(this, MainActivity.class); + startActivity(intent); + } else if (path.matches(POST_PATTERN)) { + int commentsIndex = segments.lastIndexOf("comments"); + if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + Intent intent = new Intent(this, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + deepLinkError(uri); + } + } else if (path.matches(COMMENT_PATTERN)) { + int commentsIndex = segments.lastIndexOf("comments"); + if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + Intent intent = new Intent(this, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, segments.get(segments.size() - 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + deepLinkError(uri); + } + } else if (path.matches(SUBREDDIT_PATTERN)) { + String subredditName = path.substring(3); + if (subredditName.equals("popular") || subredditName.equals("all")) { + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_POST_TYPE, subredditName); + intent.putExtra(MainActivity.EXTRA_MESSSAGE_FULLNAME, messageFullname); + intent.putExtra(MainActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + Intent intent = new Intent(this, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3)); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } + } else if (path.matches(USER_PATTERN)) { + Intent intent = new Intent(this, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); + intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else if (path.matches(SIDEBAR_PATTERN)) { + Intent intent = new Intent(this, ViewSidebarActivity.class); + intent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, path.substring(3, path.length() - 14)); + startActivity(intent); + } else if (path.matches(MULTIREDDIT_PATTERN)) { + Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class); + intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path); + startActivity(intent); + } else if (path.matches(MULTIREDDIT_PATTERN_2)) { + String subredditName = path.substring(3); + Intent intent = new Intent(this, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else if (authority.equals("redd.it") && path.matches(REDD_IT_POST_PATTERN)) { Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1)); startActivity(intent); } else { deepLinkError(uri); } - } else if (path.matches(COMMENT_PATTERN)) { - int commentsIndex = segments.lastIndexOf("comments"); - if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { - Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, segments.get(segments.size() - 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + } else if (authority.contains("gfycat.com")) { + if (path.matches(GFYCAT_PATTERN)) { + Intent intent = new Intent(this, ViewVideoActivity.class); + intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, path.substring(1)); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); startActivity(intent); } else { deepLinkError(uri); } - } else if (path.matches(SUBREDDIT_PATTERN)) { - String subredditName = path.substring(3); - if (subredditName.equals("popular") || subredditName.equals("all")) { - Intent intent = new Intent(this, MainActivity.class); - intent.putExtra(MainActivity.EXTRA_POST_TYPE, subredditName); - intent.putExtra(MainActivity.EXTRA_MESSSAGE_FULLNAME, messageFullname); - intent.putExtra(MainActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + } else if (authority.contains("redgifs.com")) { + if (path.matches(REDGIFS_PATTERN)) { + Intent intent = new Intent(this, ViewVideoActivity.class); + intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, path.substring(7)); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); startActivity(intent); } else { - Intent intent = new Intent(this, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3)); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + deepLinkError(uri); + } + } else if (authority.contains("imgur.com")) { + if (path.matches(IMGUR_GALLERY_PATTERN)) { + Intent intent = new Intent(this, ViewImgurMediaActivity.class); + intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_TYPE, ViewImgurMediaActivity.IMGUR_TYPE_GALLERY); + intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_ID, segments.get(1)); + startActivity(intent); + } else if (path.matches(IMGUR_ALBUM_PATTERN)) { + Intent intent = new Intent(this, ViewImgurMediaActivity.class); + intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_TYPE, ViewImgurMediaActivity.IMGUR_TYPE_ALBUM); + intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_ID, segments.get(1)); startActivity(intent); + } else if (path.matches(IMGUR_IMAGE_PATTERN)) { + Intent intent = new Intent(this, ViewImgurMediaActivity.class); + intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_TYPE, ViewImgurMediaActivity.IMGUR_TYPE_IMAGE); + intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_ID, path.substring(1)); + startActivity(intent); + } else { + deepLinkError(uri); } - } else if (path.matches(USER_PATTERN)) { - Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); - intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else if (path.matches(SIDEBAR_PATTERN)) { - Intent intent = new Intent(this, ViewSidebarActivity.class); - intent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, path.substring(3, path.length() - 14)); - startActivity(intent); - } else if (path.matches(MULTIREDDIT_PATTERN)) { - Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class); - intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path); - startActivity(intent); - } else if (path.matches(MULTIREDDIT_PATTERN_2)) { - String subredditName = path.substring(3); - Intent intent = new Intent(this, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else if (authority.equals("redd.it") && path.matches(REDD_IT_POST_PATTERN)) { - Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1)); - startActivity(intent); - } else { - deepLinkError(uri); - } - } else if (authority.contains("gfycat.com")) { - if (path.matches(GFYCAT_PATTERN)) { - Intent intent = new Intent(this, ViewVideoActivity.class); - intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, path.substring(1)); - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); - startActivity(intent); - } else { - deepLinkError(uri); - } - } else if (authority.contains("imgur.com")) { - if (path.matches(IMGUR_GALLERY_PATTERN)) { - Intent intent = new Intent(this, ViewImgurMediaActivity.class); - intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_TYPE, ViewImgurMediaActivity.IMGUR_TYPE_GALLERY); - intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_ID, segments.get(1)); - startActivity(intent); - } else if (path.matches(IMGUR_ALBUM_PATTERN)) { - Intent intent = new Intent(this, ViewImgurMediaActivity.class); - intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_TYPE, ViewImgurMediaActivity.IMGUR_TYPE_ALBUM); - intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_ID, segments.get(1)); - startActivity(intent); - } else if (path.matches(IMGUR_IMAGE_PATTERN)) { - Intent intent = new Intent(this, ViewImgurMediaActivity.class); - intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_TYPE, ViewImgurMediaActivity.IMGUR_TYPE_IMAGE); - intent.putExtra(ViewImgurMediaActivity.EXTRA_IMGUR_ID, path.substring(1)); - startActivity(intent); } else { deepLinkError(uri); } } else { deepLinkError(uri); } - } else { - deepLinkError(uri); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java index 20941e54..fdf5c7d2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java @@ -78,6 +78,8 @@ public class ViewVideoActivity extends AppCompatActivity { public static final String EXTRA_PROGRESS_SECONDS = "EPS"; public static final String EXTRA_VIDEO_TYPE = "EVT"; public static final String EXTRA_GFYCAT_ID = "EGI"; + public static final int VIDEO_TYPE_DIRECT = 3; + public static final int VIDEO_TYPE_REDGIFS = 2; public static final int VIDEO_TYPE_GFYCAT = 1; private static final int VIDEO_TYPE_NORMAL = 0; private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0; @@ -115,6 +117,10 @@ public class ViewVideoActivity extends AppCompatActivity { Retrofit gfycatRetrofit; @Inject + @Named("redgifs") + Retrofit redgifsRetrofit; + + @Inject @Named("default") SharedPreferences mSharedPreferences; @@ -335,7 +341,8 @@ public class ViewVideoActivity extends AppCompatActivity { TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); videoPlayerView.setPlayer(player); - if (getIntent().getIntExtra(EXTRA_VIDEO_TYPE, VIDEO_TYPE_NORMAL) == VIDEO_TYPE_GFYCAT) { + int videoType = getIntent().getIntExtra(EXTRA_VIDEO_TYPE, VIDEO_TYPE_NORMAL); + if (videoType == VIDEO_TYPE_GFYCAT || videoType == VIDEO_TYPE_REDGIFS) { if (savedInstanceState != null) { String videoUrl = savedInstanceState.getString(VIDEO_URI_STATE); if (videoUrl != null) { @@ -350,8 +357,15 @@ public class ViewVideoActivity extends AppCompatActivity { if (gfycatId != null && gfycatId.contains("-")) { gfycatId = gfycatId.substring(0, gfycatId.indexOf('-')); } - videoFileName = "Gfycat-" + gfycatId + ".mp4"; - FetchGfycatVideoLinks.fetchGfycatVideoLinks(gfycatRetrofit, gfycatId, + Retrofit retrofit; + if (videoType == VIDEO_TYPE_GFYCAT) { + retrofit = gfycatRetrofit; + videoFileName = "Gfycat-" + gfycatId + ".mp4"; + } else { + retrofit = redgifsRetrofit; + videoFileName = "Redgifs-" + gfycatId + ".mp4"; + } + FetchGfycatVideoLinks.fetchGfycatVideoLinks(retrofit, gfycatId, new FetchGfycatVideoLinks.FetchGfycatVideoLinksListener() { @Override public void success(String webm, String mp4) { @@ -367,7 +381,11 @@ public class ViewVideoActivity extends AppCompatActivity { @Override public void failed() { progressBar.setVisibility(View.GONE); - Toast.makeText(ViewVideoActivity.this, R.string.fetch_gfycat_video_failed, Toast.LENGTH_SHORT).show(); + if (videoType == VIDEO_TYPE_GFYCAT) { + Toast.makeText(ViewVideoActivity.this, R.string.fetch_gfycat_video_failed, Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(ViewVideoActivity.this, R.string.fetch_redgifs_video_failed, Toast.LENGTH_SHORT).show(); + } } }); } else { @@ -376,6 +394,15 @@ public class ViewVideoActivity extends AppCompatActivity { player.prepare(new DashMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); preparePlayer(savedInstanceState); } + } if (videoType == VIDEO_TYPE_REDGIFS) { + + } else if (videoType == VIDEO_TYPE_DIRECT) { + videoDownloadUrl = mVideoUri.toString(); + videoFileName = videoDownloadUrl.substring(videoDownloadUrl.lastIndexOf('/') + 1); + // Produces DataSource instances through which media data is loaded. + dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "Infinity")); + // Prepare the player with the source. + player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); } else { videoDownloadUrl = intent.getStringExtra(EXTRA_VIDEO_DOWNLOAD_URL); videoFileName = intent.getStringExtra(EXTRA_SUBREDDIT) + "-" + intent.getStringExtra(EXTRA_ID) + ".mp4"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java index bf64a37a..8fe1e28d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java @@ -101,6 +101,16 @@ class AppModule { } @Provides + @Named("redgifs") + @Singleton + Retrofit provideRedgifsRetrofit() { + return new Retrofit.Builder() + .baseUrl(APIUtils.REDGIFS_API_BASE_URI) + .addConverterFactory(ScalarsConverterFactory.create()) + .build(); + } + + @Provides @Named("imgur") @Singleton Retrofit provideImgurRetrofit() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatVideoLinks.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatVideoLinks.java index 730c050b..b9799484 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatVideoLinks.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatVideoLinks.java @@ -22,7 +22,7 @@ public class FetchGfycatVideoLinks { public static void fetchGfycatVideoLinks(Retrofit gfycatRetrofit, String gfycatId, FetchGfycatVideoLinksListener fetchGfycatVideoLinksListener) { - gfycatRetrofit.create(GfycatAPI.class).getSubredditData(gfycatId).enqueue(new Callback<String>() { + gfycatRetrofit.create(GfycatAPI.class).getGfycatData(gfycatId).enqueue(new Callback<String>() { @Override public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { if (response.isSuccessful()) { 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 ba59f855..dac601f7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/ParsePost.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.Post; +import android.net.Uri; import android.os.AsyncTask; import android.text.Html; @@ -277,6 +278,19 @@ public class ParsePost { post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); post.setVideoUrl(url); + } else if (url.endsWith("mp4")) { + //Video post + int postType = Post.VIDEO_TYPE; + + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title, + previewUrl, thumbnailPreviewUrl, url, permalink, score, postType, + voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, + archived, locked, saved, isCrosspost); + post.setPreviewWidth(previewWidth); + post.setPreviewHeight(previewHeight); + post.setVideoUrl(url); + post.setVideoDownloadUrl(url); } else { if (url.contains(permalink)) { //Text post but with a preview @@ -339,6 +353,19 @@ public class ParsePost { archived, locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); + } else if (url.endsWith("mp4")) { + //Video post + int postType = Post.VIDEO_TYPE; + + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title, + previewUrl, thumbnailPreviewUrl, url, permalink, score, postType, + voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, + archived, locked, saved, isCrosspost); + post.setPreviewWidth(previewWidth); + post.setPreviewHeight(previewHeight); + post.setVideoUrl(url); + post.setVideoDownloadUrl(url); } else { //CP No Preview Link post int postType = Post.NO_PREVIEW_LINK_TYPE; @@ -352,6 +379,17 @@ public class ParsePost { } } + if (post.getPostType() == Post.VIDEO_TYPE) { + try { + Uri uri = Uri.parse(url); + String authority = uri.getAuthority(); + if (authority != null && (authority.contains("gfycat.com") || authority.contains("redgifs.com"))) { + post.setPostType(Post.LINK_TYPE); + post.setUrl(url); + } + } catch (IllegalArgumentException ignore) { } + } + return post; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java index 9b5417b9..a05a97f2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java @@ -324,6 +324,10 @@ public class Post implements Parcelable { return url; } + public void setUrl(String url) { + this.url = url; + } + public String getVideoUrl() { return videoUrl; } @@ -372,6 +376,10 @@ public class Post implements Parcelable { return postType; } + public void setPostType(int postType) { + this.postType = postType; + } + public int getVoteType() { return voteType; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java index a87ce406..c080bdd4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java @@ -19,6 +19,7 @@ public class APIUtils { public static final String API_UPLOAD_MEDIA_URI = "https://reddit-uploaded-media.s3-accelerate.amazonaws.com"; public static final String API_UPLOAD_VIDEO_URI = "https://reddit-uploaded-video.s3-accelerate.amazonaws.com"; public static final String GFYCAT_API_BASE_URI = "https://api.gfycat.com/v1/gfycats/"; + public static final String REDGIFS_API_BASE_URI = "https://api.redgifs.com/v1/gfycats/"; public static final String IMGUR_API_BASE_URI = "https://api.imgur.com/3/"; public static final String CLIENT_ID_KEY = "client_id"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7194dcf4..5ffef9a6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -734,6 +734,7 @@ <string name="popular">Popular</string> <string name="fetch_gfycat_video_failed">Fetch Gfycat video failed</string> + <string name="fetch_redgifs_video_failed">Fetch Redgifs video failed</string> <string name="fetching_video_info_please_wait">Fetching video info. Please wait.</string> <string name="error_fetching_imgur_media">Cannot load images</string> |