diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-02-20 13:44:50 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-02-20 13:44:50 +0000 |
commit | 70709596872612306dc9f32e20135182c087b7b2 (patch) | |
tree | 36780d175161e7e3ca0aa9a0645c95709fd0267b /app/src | |
parent | 800b3c63a599f3a7b50c43e344b6fc3cd4ce3aff (diff) | |
download | infinity-for-reddit-70709596872612306dc9f32e20135182c087b7b2.tar infinity-for-reddit-70709596872612306dc9f32e20135182c087b7b2.tar.gz infinity-for-reddit-70709596872612306dc9f32e20135182c087b7b2.tar.bz2 infinity-for-reddit-70709596872612306dc9f32e20135182c087b7b2.tar.lz infinity-for-reddit-70709596872612306dc9f32e20135182c087b7b2.tar.xz infinity-for-reddit-70709596872612306dc9f32e20135182c087b7b2.tar.zst infinity-for-reddit-70709596872612306dc9f32e20135182c087b7b2.zip |
New option: Click to show media in gallery layout.
Diffstat (limited to 'app/src')
4 files changed, 65 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"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 57b528e7..94a18a9d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -534,6 +534,7 @@ <string name="settings_subreddit_default_sort_time_title">Subreddit Default Sort Time</string> <string name="settings_user_default_sort_type_title">User Default Sort Type</string> <string name="settings_user_default_sort_time_title">User Default Sort Time</string> + <string name="settings_click_to_show_media_in_gallery_layout">Click to Show Media in Gallery Layout</string> <string name="no_link_available">Cannot get the link</string> diff --git a/app/src/main/res/xml/post_preferences.xml b/app/src/main/res/xml/post_preferences.xml index 4c4b50aa..6dfbff12 100644 --- a/app/src/main/res/xml/post_preferences.xml +++ b/app/src/main/res/xml/post_preferences.xml @@ -33,5 +33,13 @@ <Preference app:title="@string/settings_number_of_columns_in_post_feed_title" app:fragment="ml.docilealligator.infinityforreddit.settings.NumberOfColumnsInPostFeedPreferenceFragment" /> + + <PreferenceCategory + app:title="@string/post_layout_gallery" /> + + <SwitchPreference + android:defaultValue="false" + app:key="click_to_show_media_in_gallery_layout" + app:title="@string/settings_click_to_show_media_in_gallery_layout" /> </PreferenceScreen>
\ No newline at end of file |