diff options
Diffstat (limited to 'app/src/main/java')
2 files changed, 56 insertions, 4 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 6ea507df..b1e0bea1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -95,7 +95,6 @@ import ml.docilealligator.infinityforreddit.events.PostUpdateEventToDetailActivi import ml.docilealligator.infinityforreddit.fragments.PostFragment; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostDataSource; -import ml.docilealligator.infinityforreddit.user.UserDao; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -133,6 +132,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView private AppCompatActivity mActivity; private PostFragment mFragment; + private SharedPreferences mSharedPreferences; private Executor mExecutor; private Retrofit mOauthRetrofit; private Retrofit mRetrofit; @@ -143,7 +143,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView private RequestManager mGlide; private RedditDataRoomDatabase mRedditDataRoomDatabase; private Locale mLocale; - private UserDao mUserDao; private boolean canStartActivity = true; private int mPostType; private int mPostLayout; @@ -224,6 +223,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView if (activity != null) { mActivity = activity; mFragment = fragment; + mSharedPreferences = sharedPreferences; mExecutor = executor; mOauthRetrofit = oauthRetrofit; mRetrofit = retrofit; @@ -323,7 +323,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mGlide = Glide.with(mActivity); mRedditDataRoomDatabase = redditDataRoomDatabase; mLocale = locale; - mUserDao = redditDataRoomDatabase.userDao(); mExoCreator = exoCreator; mCallback = callback; } @@ -3476,10 +3475,62 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView markPostRead(post, true); canStartActivity = false; - openViewPostDetailActivity(post, getBindingAdapterPosition()); + 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); + } + } } } }); + + noPreviewImageView.setOnClickListener(view -> { + itemView.performClick(); + }); } void markPostRead(Post post, boolean changePostItemColor) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index 26c64308..d19f905d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -161,6 +161,7 @@ public class SharedPreferencesUtils { public static final String SUBREDDIT_DEFAULT_SORT_TIME = "subreddit_default_sort_time"; public static final String USER_DEFAULT_SORT_TYPE = "user_default_sort_type"; public static final String USER_DEFAULT_SORT_TIME = "user_default_sort_time"; + public static final String CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT = "click_to_show_media_in_gallery_layout"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count"; |