aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-01-10 16:02:42 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-01-10 16:02:42 +0000
commitaf6b92ffa3e28ef56ececa23fa30aef21aa41e98 (patch)
tree7f8d93e8d9c16dd89ae40199baaf792abd26b534 /app/src
parent48624cc34aa6c57bfb809cca873e3ec0eb68380a (diff)
downloadinfinity-for-reddit-af6b92ffa3e28ef56ececa23fa30aef21aa41e98.tar
infinity-for-reddit-af6b92ffa3e28ef56ececa23fa30aef21aa41e98.tar.gz
infinity-for-reddit-af6b92ffa3e28ef56ececa23fa30aef21aa41e98.tar.bz2
infinity-for-reddit-af6b92ffa3e28ef56ececa23fa30aef21aa41e98.tar.lz
infinity-for-reddit-af6b92ffa3e28ef56ececa23fa30aef21aa41e98.tar.xz
infinity-for-reddit-af6b92ffa3e28ef56ececa23fa30aef21aa41e98.tar.zst
infinity-for-reddit-af6b92ffa3e28ef56ececa23fa30aef21aa41e98.zip
Show gifs in ViewVideoActivity if possible.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java28
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java78
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java28
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java1
6 files changed, 119 insertions, 37 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
index da1078b2..781f59e1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
@@ -2503,14 +2503,26 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW());
mActivity.startActivity(intent);
} else if (post.getPostType() == Post.GIF_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
- intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
- + "-" + post.getId() + ".gif");
- intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, post.getVideoUrl());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW());
- mActivity.startActivity(intent);
+ if (post.getMp4Variant() != null) {
+ Intent intent = new Intent(mActivity, ViewVideoActivity.class);
+ intent.setData(Uri.parse(post.getMp4Variant()));
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT);
+ intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
+ intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getMp4Variant());
+ intent.putExtra(ViewVideoActivity.EXTRA_POST, post);
+ intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
+ mActivity.startActivity(intent);
+ } else {
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
+ + "-" + post.getId() + ".gif");
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, post.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW());
+ mActivity.startActivity(intent);
+ }
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
Uri uri = Uri.parse(post.getUrl());
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
index 39ac232a..d2d3d002 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
@@ -2015,13 +2015,25 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, mPost.isNSFW());
mActivity.startActivity(intent);
} else if (mPost.getPostType() == Post.GIF_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
- intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
- + "-" + mPost.getId() + ".gif");
- intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mPost.getVideoUrl());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
- mActivity.startActivity(intent);
+ if (mPost.getMp4Variant() != null) {
+ Intent intent = new Intent(mActivity, ViewVideoActivity.class);
+ intent.setData(Uri.parse(mPost.getMp4Variant()));
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT);
+ intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
+ intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getMp4Variant());
+ intent.putExtra(ViewVideoActivity.EXTRA_POST, mPost);
+ intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, mPost.isNSFW());
+ mActivity.startActivity(intent);
+ } else {
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
+ + "-" + mPost.getId() + ".gif");
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mPost.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
+ mActivity.startActivity(intent);
+ }
}
}
});
@@ -2072,13 +2084,25 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
mActivity.startActivity(intent);
} else if (mPost.getPostType() == Post.GIF_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
- intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
- + "-" + mPost.getId() + ".gif");
- intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mPost.getVideoUrl());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
- mActivity.startActivity(intent);
+ if (mPost.getMp4Variant() != null) {
+ Intent intent = new Intent(mActivity, ViewVideoActivity.class);
+ intent.setData(Uri.parse(mPost.getMp4Variant()));
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT);
+ intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
+ intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getMp4Variant());
+ intent.putExtra(ViewVideoActivity.EXTRA_POST, mPost);
+ intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, mPost.isNSFW());
+ mActivity.startActivity(intent);
+ } else {
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
+ + "-" + mPost.getId() + ".gif");
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mPost.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
+ mActivity.startActivity(intent);
+ }
}
}
});
@@ -2195,13 +2219,25 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
mActivity.startActivity(intent);
} else if (mPost.getPostType() == Post.GIF_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
- intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
- + "-" + mPost.getId() + ".gif");
- intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mPost.getVideoUrl());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
- mActivity.startActivity(intent);
+ if (mPost.getMp4Variant() != null) {
+ Intent intent = new Intent(mActivity, ViewVideoActivity.class);
+ intent.setData(Uri.parse(mPost.getMp4Variant()));
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT);
+ intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
+ intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getMp4Variant());
+ intent.putExtra(ViewVideoActivity.EXTRA_POST, mPost);
+ intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, mPost.isNSFW());
+ mActivity.startActivity(intent);
+ } else {
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mPost.getSubredditName()
+ + "-" + mPost.getId() + ".gif");
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mPost.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, mPost.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mPost.getSubredditName());
+ mActivity.startActivity(intent);
+ }
} else if (mPost.getPostType() == Post.LINK_TYPE || mPost.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
Uri uri = Uri.parse(mPost.getUrl());
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 5f8ff0d5..d2260407 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -2630,14 +2630,26 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW());
mActivity.startActivity(intent);
} else if (post.getPostType() == Post.GIF_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
- intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
- + "-" + post.getId() + ".gif");
- intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, post.getVideoUrl());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW());
- mActivity.startActivity(intent);
+ if (post.getMp4Variant() != null) {
+ Intent intent = new Intent(mActivity, ViewVideoActivity.class);
+ intent.setData(Uri.parse(post.getMp4Variant()));
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT);
+ intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
+ intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getMp4Variant());
+ intent.putExtra(ViewVideoActivity.EXTRA_POST, post);
+ intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
+ mActivity.startActivity(intent);
+ } else {
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
+ + "-" + post.getId() + ".gif");
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, post.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW());
+ mActivity.startActivity(intent);
+ }
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
Uri uri = Uri.parse(post.getUrl());
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 9389c87e..70fc3632 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
@@ -432,6 +432,16 @@ public class ParsePost {
post.setPreviews(previews);
post.setVideoUrl(url);
+
+ try {
+ String mp4Variant = data.getJSONObject(JSONUtils.PREVIEW_KEY)
+ .getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0)
+ .getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.MP4_KEY)
+ .getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
+ if (!mp4Variant.isEmpty()) {
+ post.setMp4Variant(mp4Variant);
+ }
+ } catch (Exception ignore) {}
} else if (uri.getAuthority().contains("imgur.com") && (path.endsWith(".gifv") || path.endsWith(".mp4"))) {
// Imgur gifv/mp4
int postType = Post.VIDEO_TYPE;
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 f03a666c..ba7b4beb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java
@@ -69,6 +69,7 @@ public class Post implements Parcelable {
private String crosspostParentId;
private final String distinguished;
private final String suggestedSort;
+ private String mp4Variant;
private ArrayList<Preview> previews = new ArrayList<>();
@Nullable
private Map<String, MediaMetadata> mediaMetadataMap;
@@ -192,6 +193,7 @@ public class Post implements Parcelable {
crosspostParentId = in.readString();
distinguished = in.readString();
suggestedSort = in.readString();
+ mp4Variant = in.readString();
previews = in.createTypedArrayList(Preview.CREATOR);
mediaMetadataMap = (Map<String, MediaMetadata>) in.readValue(getClass().getClassLoader());
gallery = in.createTypedArrayList(Gallery.CREATOR);
@@ -512,6 +514,7 @@ public class Post implements Parcelable {
dest.writeString(crosspostParentId);
dest.writeString(distinguished);
dest.writeString(suggestedSort);
+ dest.writeString(mp4Variant);
dest.writeTypedList(previews);
dest.writeValue(mediaMetadataMap);
dest.writeTypedList(gallery);
@@ -581,6 +584,14 @@ public class Post implements Parcelable {
this.gallery = gallery;
}
+ public String getMp4Variant() {
+ return mp4Variant;
+ }
+
+ public void setMp4Variant(String mp4Variant) {
+ this.mp4Variant = mp4Variant;
+ }
+
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Post)) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java
index 6ddf5493..800e6d45 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java
@@ -194,6 +194,7 @@ public class JSONUtils {
public static final String HD_KEY = "hd";
public static final String SUGGESTED_SORT_KEY = "suggested_sort";
public static final String P_KEY = "p";
+ public static final String VARIANTS_KEY = "variants";
@Nullable
public static Map<String, MediaMetadata> parseMediaMetadata(JSONObject data) {