New option: Click to show media in gallery layout.

This commit is contained in:
Alex Ning 2021-02-20 21:44:50 +08:00
parent 800b3c63a5
commit 7070959687
4 changed files with 65 additions and 4 deletions

View File

@ -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) {

View File

@ -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";

View File

@ -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>

View File

@ -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>