diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-11-26 22:39:06 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-11-26 22:39:06 +0000 |
commit | fbfd0a3fb24bfd5d2066640b241b1fd3cd33b747 (patch) | |
tree | a3da82582e3bb38842dbf4e883120e852f471ee3 /app/src/main/java | |
parent | e7b4b8aa8100327d83e99f2f0b3362a318e2c0eb (diff) | |
download | infinity-for-reddit-fbfd0a3fb24bfd5d2066640b241b1fd3cd33b747.tar infinity-for-reddit-fbfd0a3fb24bfd5d2066640b241b1fd3cd33b747.tar.gz infinity-for-reddit-fbfd0a3fb24bfd5d2066640b241b1fd3cd33b747.tar.bz2 infinity-for-reddit-fbfd0a3fb24bfd5d2066640b241b1fd3cd33b747.tar.lz infinity-for-reddit-fbfd0a3fb24bfd5d2066640b241b1fd3cd33b747.tar.xz infinity-for-reddit-fbfd0a3fb24bfd5d2066640b241b1fd3cd33b747.tar.zst infinity-for-reddit-fbfd0a3fb24bfd5d2066640b241b1fd3cd33b747.zip |
Implement ImageAndGifEntry.OnItemClickListener in other places.
Diffstat (limited to '')
12 files changed, 155 insertions, 151 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java index 8ec61c8a..9ff5cf9c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -45,11 +45,9 @@ import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; -import io.noties.markwon.recycler.MarkwonAdapter; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.AnyAccountAccessTokenAuthenticator; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MediaMetadata; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.UploadImageEnabledActivity; @@ -62,6 +60,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesB import ml.docilealligator.infinityforreddit.comment.Comment; import ml.docilealligator.infinityforreddit.comment.SendComment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.databinding.ActivityCommentBinding; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; @@ -83,6 +82,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA public static final String EXTRA_PARENT_FULLNAME_KEY = "EPFK"; public static final String EXTRA_PARENT_DEPTH_KEY = "EPDK"; public static final String EXTRA_PARENT_POSITION_KEY = "EPPK"; + public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESNK"; public static final String EXTRA_IS_REPLYING_KEY = "EIRK"; public static final String RETURN_EXTRA_COMMENT_DATA_KEY = "RECDK"; public static final int WRITE_COMMENT_REQUEST_CODE = 1; @@ -189,9 +189,11 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA } textView.setTextColor(parentTextColor); textView.setOnLongClickListener(view -> { - Utils.hideKeyboard(CommentActivity.this); - CopyTextBottomSheetFragment.show(getSupportFragmentManager(), - parentBody, parentBodyMarkdown); + if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) { + Utils.hideKeyboard(CommentActivity.this); + CopyTextBottomSheetFragment.show(getSupportFragmentManager(), + parentBody, parentBodyMarkdown); + } return true; }); } @@ -216,12 +218,22 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this, miscPlugin, emoteCloseBracketInlineProcessor, imageAndGifPlugin, parentTextColor, parentSpoilerBackgroundColor, null); - MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(this, mGlide, new ImageAndGifEntry.OnItemClickListener() { - @Override - public void onItemClick(MediaMetadata mediaMetadata) { - + CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(this, mGlide, mediaMetadata -> { + Intent imageIntent = new Intent(this, ViewImageOrGifActivity.class); + if (mediaMetadata.isGIF) { + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); + } else { + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); } + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, intent.getStringExtra(EXTRA_SUBREDDIT_NAME_KEY)); + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); })); + markwonAdapter.setOnLongClickListener(view -> { + Utils.hideKeyboard(CommentActivity.this); + CopyTextBottomSheetFragment.show(getSupportFragmentManager(), + parentBody, parentBodyMarkdown); + return true; + }); binding.commentContentMarkdownView.setLayoutManager(new LinearLayoutManagerBugFixed(this)); binding.commentContentMarkdownView.setAdapter(markwonAdapter); markwonAdapter.setMarkdown(postBodyMarkwon, parentBodyMarkdown); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java index 07de032d..3897323b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -35,11 +35,10 @@ import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; -import io.noties.markwon.recycler.MarkwonAdapter; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MediaMetadata; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; @@ -149,13 +148,17 @@ public class FullMarkdownActivity extends BaseActivity { miscPlugin, emoteCloseBracketInlineProcessor, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, null); - MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(this, - Glide.with(this), new ImageAndGifEntry.OnItemClickListener() { - @Override - public void onItemClick(MediaMetadata mediaMetadata) { - - } - })); + CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(this, + Glide.with(this), mediaMetadata -> { + Intent intent = new Intent(this, ViewImageOrGifActivity.class); + if (mediaMetadata.isGIF) { + intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); + } else { + intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); + } + intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, isNsfw); + intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); + })); LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() { @Override public void lockSwipe() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java index 7ffa36a5..8644704f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java @@ -131,7 +131,7 @@ public class RulesActivity extends BaseActivity { mSubredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); - mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper, sliderPanel); + mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper, sliderPanel, mSubredditName); recyclerView.setAdapter(mAdapter); FetchRules.fetchRules(mExecutor, new Handler(), mAccessToken == null ? mRetrofit : mOauthRetrofit, mAccessToken, mSubredditName, new FetchRules.FetchRulesListener() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index 10cbb519..5d31f2f0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -43,7 +43,6 @@ import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.recycler.MarkwonAdapter; import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MediaMetadata; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; @@ -99,6 +98,7 @@ public class WikiActivity extends BaseActivity { @Inject CustomThemeWrapper mCustomThemeWrapper; private String wikiMarkdown; + private String mSubredditName; private EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor; private ImageAndGifPlugin imageAndGifPlugin; private Markwon markwon; @@ -146,6 +146,8 @@ public class WikiActivity extends BaseActivity { mGlide = Glide.with(this); + mSubredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); + swipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true)); swipeRefreshLayout.setOnRefreshListener(this::loadWiki); @@ -186,13 +188,17 @@ public class WikiActivity extends BaseActivity { markwon = MarkdownUtils.createFullRedditMarkwon(this, miscPlugin, emoteCloseBracketInlineProcessor, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener); - markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(this, - mGlide, new ImageAndGifEntry.OnItemClickListener() { - @Override - public void onItemClick(MediaMetadata mediaMetadata) { - - } - })); + markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(this, + mGlide, mediaMetadata -> { + Intent intent = new Intent(this, ViewImageOrGifActivity.class); + if (mediaMetadata.isGIF) { + intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); + } else { + intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); + } + intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mSubredditName); + intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); + })); LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() { @Override public void lockSwipe() { @@ -235,7 +241,7 @@ public class WikiActivity extends BaseActivity { Glide.with(this).clear(mFetchWikiInfoImageView); mFetchWikiInfoLinearLayout.setVisibility(View.GONE); - retrofit.create(RedditAPI.class).getWikiPage(getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME), getIntent().getStringExtra(EXTRA_WIKI_PATH)).enqueue(new Callback<String>() { + retrofit.create(RedditAPI.class).getWikiPage(mSubredditName, getIntent().getStringExtra(EXTRA_WIKI_PATH)).enqueue(new Callback<String>() { @Override public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { if (response.isSuccessful()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index aaafde55..85e03845 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -45,7 +45,6 @@ import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import me.saket.bettermovementmethod.BetterLinkMovementMethod; -import ml.docilealligator.infinityforreddit.MediaMetadata; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SortType; @@ -168,6 +167,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi Post post, Locale locale, String singleCommentId, boolean isSingleCommentThreadMode, SharedPreferences sharedPreferences, + SharedPreferences nsfwAndSpoilerSharedPreferences, CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) { mActivity = activity; mFragment = fragment; @@ -217,24 +217,27 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi mCommentMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity, miscPlugin, mEmoteCloseBracketInlineProcessor, mImageAndGifPlugin, mCommentTextColor, commentSpoilerBackgroundColor, onLinkLongClickListener); - mImageAndGifEntry = new ImageAndGifEntry(activity, mGlide, new ImageAndGifEntry.OnItemClickListener() { - @Override - public void onItemClick(MediaMetadata mediaMetadata) { - Intent intent = new Intent(activity, ViewImageOrGifActivity.class); - if (mediaMetadata.isGIF) { - intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); - } else { - intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); - } - intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW()); - intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName()); - intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); - if (canStartActivity) { - canStartActivity = false; - activity.startActivity(intent); - } - } - }); + + boolean needBlurNsfw = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true); + boolean doNotBlurNsfwInNsfwSubreddits = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.DO_NOT_BLUR_NSFW_IN_NSFW_SUBREDDITS, false); + boolean needBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false); + boolean blurImage = (post.isNSFW() && needBlurNsfw && !(doNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && needBlurSpoiler); + mImageAndGifEntry = new ImageAndGifEntry(activity, mGlide, blurImage, + mediaMetadata -> { + Intent intent = new Intent(activity, ViewImageOrGifActivity.class); + if (mediaMetadata.isGIF) { + intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); + } else { + intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); + } + intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW()); + intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName()); + intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); + if (canStartActivity) { + canStartActivity = false; + activity.startActivity(intent); + } + }); recycledViewPool = new RecyclerView.RecycledViewPool(); mAccessToken = accessToken; mAccountName = accountName; @@ -1409,6 +1412,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY, comment.getCommentMarkdown()); intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, comment.getCommentRawText()); intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, comment.getFullName()); + intent.putExtra(CommentActivity.EXTRA_SUBREDDIT_NAME_KEY, mPost.getSubredditName()); intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, true); int parentPosition = mIsSingleCommentThreadMode ? getBindingAdapterPosition() - 1 : getBindingAdapterPosition(); 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 f50c62c3..8a43d74f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -59,7 +59,6 @@ import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; -import io.noties.markwon.recycler.MarkwonAdapter; import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import me.saket.bettermovementmethod.BetterLinkMovementMethod; @@ -91,6 +90,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottom import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; +import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; @@ -149,7 +149,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler private ImageAndGifPlugin mImageAndGifPlugin; private Markwon mPostDetailMarkwon; private ImageAndGifEntry mImageAndGifEntry; - private final MarkwonAdapter mMarkwonAdapter; + private final CustomMarkwonAdapter mMarkwonAdapter; private String mAccessToken; private String mAccountName; private Post mPost; @@ -395,7 +395,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (mPost.isSpoiler() && mNeedBlurSpoiler), mediaMetadata -> { Intent intent = new Intent(activity, ViewImageOrGifActivity.class); - intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); + if (mediaMetadata.isGIF) { + intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); + } else { + intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); + } intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, post.isNSFW()); intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName()); intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); @@ -404,7 +408,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler activity.startActivity(intent); } }); - mMarkwonAdapter = MarkdownUtils.createTablesAdapter(mImageAndGifEntry); + mMarkwonAdapter = MarkdownUtils.createCustomTablesAdapter(mImageAndGifEntry); } public void setCanStartActivity(boolean canStartActivity) { @@ -1207,6 +1211,14 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler } })); + mMarkwonAdapter.setOnLongClickListener(v -> { + CopyTextBottomSheetFragment.show( + mActivity.getSupportFragmentManager(), + mPost.getSelfTextPlain(), mPost.getSelfText() + ); + return true; + }); + upvoteButton.setOnClickListener(view -> { if (mPost.isArchived()) { Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); @@ -1413,6 +1425,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TITLE_KEY, mPost.getTitle()); intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY, mPost.getSelfText()); intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfTextPlain()); + intent.putExtra(CommentActivity.EXTRA_SUBREDDIT_NAME_KEY, mPost.getSubredditName()); intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false); intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0); mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java index 40c4e19f..ed55fe62 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -25,11 +25,11 @@ import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.recycler.MarkwonAdapter; import me.saket.bettermovementmethod.BetterLinkMovementMethod; -import ml.docilealligator.infinityforreddit.MediaMetadata; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Rule; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; +import ml.docilealligator.infinityforreddit.activities.ViewImageOrGifActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; @@ -47,14 +47,16 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler private Markwon markwon; @Nullable private final SliderPanel sliderPanel; + private String subredditName; private ArrayList<Rule> rules; private int mPrimaryTextColor; public RulesRecyclerViewAdapter(@NonNull BaseActivity activity, @NonNull CustomThemeWrapper customThemeWrapper, - @Nullable SliderPanel sliderPanel) { + @Nullable SliderPanel sliderPanel, String subredditName) { this.activity = activity; this.sliderPanel = sliderPanel; + this.subredditName = subredditName; mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor(); int spoilerBackgroundColor = mPrimaryTextColor | 0xFF000000; MarkwonPlugin miscPlugin = new AbstractMarkwonPlugin() { @@ -147,13 +149,17 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler if (activity.typeface != null) { shortNameTextView.setTypeface(activity.typeface); } - markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(activity, + markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(activity, Glide.with(activity), - new ImageAndGifEntry.OnItemClickListener() { - @Override - public void onItemClick(MediaMetadata mediaMetadata) { - + mediaMetadata -> { + Intent imageIntent = new Intent(activity, ViewImageOrGifActivity.class); + if (mediaMetadata.isGIF) { + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); + } else { + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); } + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, subredditName); + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); })); SwipeLockLinearLayoutManager swipeLockLinearLayoutManager = new SwipeLockLinearLayoutManager(activity, new SwipeLockInterface() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomMarkwonAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomMarkwonAdapter.java index 48432ff8..10ed5719 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomMarkwonAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomMarkwonAdapter.java @@ -130,8 +130,18 @@ public class CustomMarkwonAdapter extends MarkwonAdapter { TableRow tableRow = ((TableRow) tableLayout.getChildAt(i)); for (int j = 0; j < tableRow.getChildCount(); j++) { if (tableRow.getChildAt(j) instanceof TextView) { - tableRow.getChildAt(j).setOnClickListener(onClickListener); - tableRow.getChildAt(j).setOnLongClickListener(onLongClickListener); + TextView textView = (TextView) tableRow.getChildAt(j); + tableRow.getChildAt(j).setOnClickListener(view -> { + if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) { + onClickListener.onClick(view); + } + }); + tableRow.getChildAt(j).setOnLongClickListener(view -> { + if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) { + onLongClickListener.onLongClick(view); + } + return true; + }); } } } @@ -139,8 +149,11 @@ public class CustomMarkwonAdapter extends MarkwonAdapter { } } - if (node instanceof ImageAndGifBlock && !holder.itemView.hasOnClickListeners()) { - holder.itemView.setOnClickListener(onClickListener); + if (node instanceof ImageAndGifBlock) { + if (!holder.itemView.hasOnClickListeners()) { + holder.itemView.setOnClickListener(onClickListener); + } + holder.itemView.setOnLongClickListener(onLongClickListener); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java index 821e6926..84d3bf5d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -32,18 +32,19 @@ import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; -import io.noties.markwon.recycler.MarkwonAdapter; import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.MediaMetadata; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; +import ml.docilealligator.infinityforreddit.activities.ViewImageOrGifActivity; import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditData; import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor; import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry; @@ -152,15 +153,28 @@ public class SidebarFragment extends Fragment { Markwon markwon = MarkdownUtils.createFullRedditMarkwon(activity, miscPlugin, emoteCloseBracketInlineProcessor, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener); - MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter(new ImageAndGifEntry(activity, + CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(activity, Glide.with(this), - new ImageAndGifEntry.OnItemClickListener() { - @Override - public void onItemClick(MediaMetadata mediaMetadata) { - + mediaMetadata -> { + Intent imageIntent = new Intent(activity, ViewImageOrGifActivity.class); + if (mediaMetadata.isGIF) { + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); + } else { + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); } + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, subredditName); + imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); })); - + markwonAdapter.setOnLongClickListener(view -> { + if (sidebarDescription != null && !sidebarDescription.equals("")) { + Bundle bundle = new Bundle(); + bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, sidebarDescription); + CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment(); + copyTextBottomSheetFragment.setArguments(bundle); + copyTextBottomSheetFragment.show(getChildFragmentManager(), copyTextBottomSheetFragment.getTag()); + } + return true; + }); linearLayoutManager = new LinearLayoutManagerBugFixed(activity); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setAdapter(markwonAdapter); @@ -168,9 +182,9 @@ public class SidebarFragment extends Fragment { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { if (dy > 0) { - ((ViewSubredditDetailActivity) activity).contentScrollDown(); + activity.contentScrollDown(); } else if (dy < 0) { - ((ViewSubredditDetailActivity) activity).contentScrollUp(); + activity.contentScrollUp(); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 1e1c32db..91113d84 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -607,7 +607,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mCommentsAdapter = new CommentsRecyclerViewAdapter(activity, this, mCustomThemeWrapper, mExecutor, mRetrofit, mOauthRetrofit, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, - isSingleCommentThreadMode, mSharedPreferences, + isSingleCommentThreadMode, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void retryFetchingComments() { @@ -969,6 +969,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfTextPlain()); intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName()); intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0); + intent.putExtra(CommentActivity.EXTRA_SUBREDDIT_NAME_KEY, mPost.getSubredditName()); intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false); startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE); } @@ -1315,6 +1316,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic ViewPostDetailFragment.this, mCustomThemeWrapper, mExecutor, mRetrofit, mOauthRetrofit, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences, + mNsfwAndSpoilerSharedPreferences, new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void retryFetchingComments() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java index 9611a5dc..4f42acc1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java @@ -55,6 +55,7 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima colorAccent = baseActivity.getCustomThemeWrapper().getColorAccent(); primaryTextColor = baseActivity.getCustomThemeWrapper().getPrimaryTextColor(); postContentColor = baseActivity.getCustomThemeWrapper().getPostContentColor(); + String dataSavingModeString = sharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF); if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ALWAYS)) { dataSavingMode = true; @@ -63,16 +64,22 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima } } + public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, boolean blurImage, + OnItemClickListener onItemClickListener) { + this(baseActivity, glide, onItemClickListener); + this.blurImage = blurImage; + } + public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide, boolean dataSavingMode, boolean blurImage, OnItemClickListener onItemClickListener) { this.baseActivity = baseActivity; this.glide = glide; + this.dataSavingMode = dataSavingMode; + this.blurImage = blurImage; SharedPreferences sharedPreferences = baseActivity.getDefaultSharedPreferences(); this.saveMemoryCenterInsideDownsampleStrategy = new SaveMemoryCenterInisdeDownsampleStrategy( Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.POST_FEED_MAX_RESOLUTION, "5000000"))); this.onItemClickListener = onItemClickListener; - this.dataSavingMode = dataSavingMode; - this.blurImage = blurImage; colorAccent = baseActivity.getCustomThemeWrapper().getColorAccent(); primaryTextColor = baseActivity.getCustomThemeWrapper().getPrimaryTextColor(); postContentColor = baseActivity.getCustomThemeWrapper().getPostContentColor(); @@ -192,68 +199,6 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima } }); } - - /*void bindImage(ImageMetadata image) { - binding.gifLink.setVisibility(View.GONE); - binding.iv.setVisibility(View.VISIBLE); - binding.progressBar.setVisibility(View.VISIBLE); - binding.giphyWatermark.setVisibility(View.GONE); - - ViewGroup.LayoutParams params = binding.iv.getLayoutParams(); - if (image.x > image.y) { - params.height = dpToPx(160); - params.width = params.height * image.x / image.y; - } else { - params.width = dpToPx(160); - params.height = params.width * image.y / image.x; - } - binding.iv.setLayoutParams(params); - - // todo: check if waitForLayout is necessary here since we explicitly set width/height in LP - Target<Drawable> target = new DrawableImageViewTarget(binding.iv) - .waitForLayout(); - glide.load(image.getUrl()) - .addListener(requestListener) - .error(R.drawable.ic_error_outline_black_24dp) - .into(target); - } - - void bindGif(GiphyGifMetadata gif) { - if (!canLoadGif()) { - // video autoplay is disabled, don't load gif - binding.gifLink.setVisibility(View.VISIBLE); - binding.iv.setVisibility(View.GONE); - binding.progressBar.setVisibility(View.GONE); - binding.giphyWatermark.setVisibility(View.GONE); - - binding.gifLink.setOnClickListener(v -> { - onClickListener.accept(Uri.parse(gif.getGifUrl())); - }); - return; - } - binding.gifLink.setVisibility(View.GONE); - binding.iv.setVisibility(View.VISIBLE); - binding.progressBar.setVisibility(View.VISIBLE); - binding.giphyWatermark.setVisibility(View.VISIBLE); - - ViewGroup.LayoutParams params = binding.iv.getLayoutParams(); - if (gif.x > gif.y) { - params.height = dpToPx(160); - params.width = params.height * gif.x / gif.y; - } else { - params.width = dpToPx(160); - params.height = params.width * gif.y / gif.x; - } - binding.iv.setLayoutParams(params); - - // todo: check if waitForLayout is necessary here since we explicitly set width/height in LP - Target<Drawable> target = new DrawableImageViewTarget(binding.iv) - .waitForLayout(); - glide.load(gif.getGifUrl()) - .addListener(requestListener) - .error(R.drawable.ic_error_outline_black_24dp) - .into(target); - }*/ } public interface OnItemClickListener { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java index 1b4e92b0..da867443 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java @@ -17,7 +17,6 @@ import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; -import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.table.TableEntry; import io.noties.markwon.recycler.table.TableEntryPlugin; import me.saket.bettermovementmethod.BetterLinkMovementMethod; @@ -98,20 +97,7 @@ public class MarkdownUtils { } /** - * Creates a MarkwonAdapter configured with support for tables. - */ - @NonNull - public static MarkwonAdapter createTablesAdapter(ImageAndGifEntry imageAndGifEntry) { - return MarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text) - .include(TableBlock.class, TableEntry.create(builder -> builder - .tableLayout(R.layout.adapter_table_block, R.id.table_layout) - .textLayoutIsRoot(R.layout.view_table_entry_cell))) - .include(ImageAndGifBlock.class, imageAndGifEntry) - .build(); - } - - /** - * Creates a CustomMarkwonAdapter configured with support for tables. + * Creates a CustomMarkwonAdapter configured with support for tables and images. */ @NonNull public static CustomMarkwonAdapter createCustomTablesAdapter(ImageAndGifEntry imageAndGifEntry) { |