aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-02-20 15:26:42 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-02-20 15:26:42 +0000
commitdb2c4d6c8d4200649a5003b7a45e54ec66237aaf (patch)
tree3a9d4a9411dc9dc0865cad4207280c6d67177a41 /app/src/main/java
parent70709596872612306dc9f32e20135182c087b7b2 (diff)
downloadinfinity-for-reddit-db2c4d6c8d4200649a5003b7a45e54ec66237aaf.tar
infinity-for-reddit-db2c4d6c8d4200649a5003b7a45e54ec66237aaf.tar.gz
infinity-for-reddit-db2c4d6c8d4200649a5003b7a45e54ec66237aaf.tar.bz2
infinity-for-reddit-db2c4d6c8d4200649a5003b7a45e54ec66237aaf.tar.lz
infinity-for-reddit-db2c4d6c8d4200649a5003b7a45e54ec66237aaf.tar.xz
infinity-for-reddit-db2c4d6c8d4200649a5003b7a45e54ec66237aaf.tar.zst
infinity-for-reddit-db2c4d6c8d4200649a5003b7a45e54ec66237aaf.zip
Long click gallery layout.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java205
1 files changed, 70 insertions, 135 deletions
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 b1e0bea1..c791e2d8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -1737,6 +1737,54 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mActivity.startActivity(intent);
}
+ private void openMedia(Post post) {
+ if (post.getPostType() == Post.VIDEO_TYPE) {
+ Intent intent = new Intent(mActivity, ViewVideoActivity.class);
+ if (post.isGfycat()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
+ intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
+ } else if (post.isRedgifs()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
+ intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
+ } else {
+ intent.setData(Uri.parse(post.getVideoUrl()));
+ intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
+ intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
+ }
+ intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
+ intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
+ mActivity.startActivity(intent);
+ } else if (post.getPostType() == Post.IMAGE_TYPE) {
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, post.getUrl());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
+ + "-" + post.getId() + ".jpg");
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
+ 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());
+ 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());
+ intent.setData(uri);
+ intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, post.isNSFW());
+ mActivity.startActivity(intent);
+ } else if (post.getPostType() == Post.GALLERY_TYPE) {
+ Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
+ intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
+ intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
+ mActivity.startActivity(intent);
+ }
+ }
+
public class PostBaseViewHolder extends RecyclerView.ViewHolder {
MaterialCardView cardView;
AspectRatioGifImageView iconGifImageView;
@@ -2600,51 +2648,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
Post post = getItem(position);
if (post != null) {
markPostRead(post, true);
- if (post.getPostType() == Post.VIDEO_TYPE) {
- Intent intent = new Intent(mActivity, ViewVideoActivity.class);
- if (post.isGfycat()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
- } else if (post.isRedgifs()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
- } else {
- intent.setData(Uri.parse(post.getVideoUrl()));
- intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
- intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
- }
- intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
- intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
- mActivity.startActivity(intent);
- } else if (post.getPostType() == Post.IMAGE_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
- intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, post.getUrl());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
- + "-" + post.getId() + ".jpg");
- intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
- 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());
- 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());
- intent.setData(uri);
- intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, post.isNSFW());
- mActivity.startActivity(intent);
- } else if (post.getPostType() == Post.GALLERY_TYPE) {
- Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
- intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
- intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
- mActivity.startActivity(intent);
- }
+ openMedia(post);
}
});
@@ -2965,51 +2969,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
Post post = getItem(position);
if (post != null) {
markPostRead(post, true);
- if (post.getPostType() == Post.VIDEO_TYPE) {
- Intent intent = new Intent(mActivity, ViewVideoActivity.class);
- if (post.isGfycat()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
- } else if (post.isRedgifs()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
- } else {
- intent.setData(Uri.parse(post.getVideoUrl()));
- intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
- intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
- }
- intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
- intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
- mActivity.startActivity(intent);
- } else if (post.getPostType() == Post.IMAGE_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
- intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, post.getUrl());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
- + "-" + post.getId() + ".jpg");
- intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
- 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());
- 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());
- intent.setData(uri);
- intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, post.isNSFW());
- mActivity.startActivity(intent);
- } else if (post.getPostType() == Post.GALLERY_TYPE) {
- Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
- intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
- intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
- mActivity.startActivity(intent);
- }
+ openMedia(post);
}
});
@@ -3478,54 +3438,29 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
if (post.getPostType() == Post.TEXT_TYPE || !mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) {
openViewPostDetailActivity(post, getBindingAdapterPosition());
} else {
- if (post.getPostType() == Post.VIDEO_TYPE) {
- Intent intent = new Intent(mActivity, ViewVideoActivity.class);
- if (post.isGfycat()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
- } else if (post.isRedgifs()) {
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
- intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
- } else {
- intent.setData(Uri.parse(post.getVideoUrl()));
- intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
- intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
- intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
- }
- intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
- intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
- mActivity.startActivity(intent);
- } else if (post.getPostType() == Post.IMAGE_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
- intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, post.getUrl());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName()
- + "-" + post.getId() + ".jpg");
- intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle());
- intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName());
- 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());
- 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());
- intent.setData(uri);
- intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, post.isNSFW());
- mActivity.startActivity(intent);
- } else if (post.getPostType() == Post.GALLERY_TYPE) {
- Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
- intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
- intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
- mActivity.startActivity(intent);
- }
+ openMedia(post);
+ }
+ }
+ }
+ });
+
+ itemView.setOnLongClickListener(view -> {
+ int position = getBindingAdapterPosition();
+ if (position >= 0 && canStartActivity) {
+ Post post = getItem(position);
+ if (post != null) {
+ markPostRead(post, true);
+ canStartActivity = false;
+
+ if (post.getPostType() == Post.TEXT_TYPE || mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) {
+ openViewPostDetailActivity(post, getBindingAdapterPosition());
+ } else {
+ openMedia(post);
}
}
}
+
+ return true;
});
noPreviewImageView.setOnClickListener(view -> {