aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorDocile-Alligator <chineseperson5@gmail.com>2022-04-02 08:09:16 +0000
committerDocile-Alligator <chineseperson5@gmail.com>2022-04-02 08:09:16 +0000
commit840216b3d9b0999abfce490d3d5ffdfda685ccb2 (patch)
treebed60ee248dd96fe83a2c06e3b1352c202e2e7eb /app/src/main/java
parent95d792779e98b8a4180ed50f3d945865b406b127 (diff)
downloadinfinity-for-reddit-840216b3d9b0999abfce490d3d5ffdfda685ccb2.tar
infinity-for-reddit-840216b3d9b0999abfce490d3d5ffdfda685ccb2.tar.gz
infinity-for-reddit-840216b3d9b0999abfce490d3d5ffdfda685ccb2.tar.bz2
infinity-for-reddit-840216b3d9b0999abfce490d3d5ffdfda685ccb2.tar.lz
infinity-for-reddit-840216b3d9b0999abfce490d3d5ffdfda685ccb2.tar.xz
infinity-for-reddit-840216b3d9b0999abfce490d3d5ffdfda685ccb2.tar.zst
infinity-for-reddit-840216b3d9b0999abfce490d3d5ffdfda685ccb2.zip
Render full markdown in CommentsListingRecyclerViewAdapter.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java141
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java2
4 files changed, 101 insertions, 50 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java
index 32896b06..ea973995 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java
@@ -248,13 +248,13 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
}
}
- private void lockSwipeRightToGoBack() {
+ public void lockSwipeRightToGoBack() {
if (mSlidrInterface != null) {
mSlidrInterface.lock();
}
}
- private void unlockSwipeRightToGoBack() {
+ public void unlockSwipeRightToGoBack() {
if (mSlidrInterface != null) {
mSlidrInterface.unlock();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
index 78625af4..48f43088 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
@@ -1755,13 +1755,13 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
}
}
- private void lockSwipeRightToGoBack() {
+ public void lockSwipeRightToGoBack() {
if (mSlidrInterface != null) {
mSlidrInterface.lock();
}
}
- private void unlockSwipeRightToGoBack() {
+ public void unlockSwipeRightToGoBack() {
if (mSlidrInterface != null) {
mSlidrInterface.unlock();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java
index 7ebfb52e..aecd9581 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java
@@ -3,9 +3,11 @@ package ml.docilealligator.infinityforreddit.adapters;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
+import android.graphics.Color;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
+import android.text.Spanned;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
@@ -26,6 +28,8 @@ import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
+import org.commonmark.ext.gfm.tables.TableBlock;
+
import java.util.Locale;
import butterknife.BindView;
@@ -42,20 +46,28 @@ import io.noties.markwon.inlineparser.BangInlineProcessor;
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.table.TableEntry;
+import io.noties.markwon.recycler.table.TableEntryPlugin;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SaveThing;
import ml.docilealligator.infinityforreddit.VoteThing;
+import ml.docilealligator.infinityforreddit.activities.AccountSavedThingActivity;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity;
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
+import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.CommentMoreBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.comment.Comment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView;
+import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
+import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager;
import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView;
import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin;
import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor;
@@ -83,6 +95,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
private Retrofit mOauthRetrofit;
private Locale mLocale;
private Markwon mMarkwon;
+ private RecyclerView.RecycledViewPool recycledViewPool;
private String mAccessToken;
private String mAccountName;
private int mColorPrimaryLightTheme;
@@ -115,6 +128,29 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
mOauthRetrofit = oauthRetrofit;
mCommentColor = customThemeWrapper.getCommentColor();
int commentSpoilerBackgroundColor = mCommentColor | 0xFF000000;
+ mLocale = locale;
+ mAccessToken = accessToken;
+ mAccountName = accountName;
+ mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
+ mShowCommentDivider = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
+ mShowAbsoluteNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
+ mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
+ mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE);
+ mRetryLoadingMoreCallback = retryLoadingMoreCallback;
+ mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme();
+ mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
+ mCommentBackgroundColor = customThemeWrapper.getCommentBackgroundColor();
+ mCommentColor = customThemeWrapper.getCommentColor();
+ mDividerColor = customThemeWrapper.getDividerColor();
+ mSubredditColor = customThemeWrapper.getSubreddit();
+ mUsernameColor = customThemeWrapper.getUsername();
+ mAuthorFlairColor = customThemeWrapper.getAuthorFlairTextColor();
+ mUpvotedColor = customThemeWrapper.getUpvoted();
+ mDownvotedColor = customThemeWrapper.getDownvoted();
+ mButtonTextColor = customThemeWrapper.getButtonTextColor();
+ mColorAccent = customThemeWrapper.getColorAccent();
+ mCommentIconAndInfoColor = customThemeWrapper.getCommentIconAndInfoColor();
+ int linkColor = customThemeWrapper.getLinkColor();
mMarkwon = Markwon.builder(mActivity)
.usePlugin(MarkwonInlineParserPlugin.create(plugin -> {
plugin.excludeInlineProcessor(AutolinkInlineProcessor.class);
@@ -133,8 +169,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}
@Override
- public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
- builder.linkColor(customThemeWrapper.getLinkColor());
+ public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
+ if (mActivity.contentTypeface != null) {
+ textView.setTypeface(mActivity.contentTypeface);
+ }
+ textView.setTextColor(mCommentColor);
+ textView.setHighlightColor(Color.TRANSPARENT);
}
@Override
@@ -145,35 +185,29 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
intent.setData(uri);
mActivity.startActivity(intent);
});
+ }
+ @Override
+ public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
+ builder.linkColor(linkColor);
}
})
.usePlugin(SpoilerParserPlugin.create(mCommentColor, commentSpoilerBackgroundColor))
- .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(StrikethroughPlugin.create())
+ .usePlugin(MovementMethodPlugin.create(BetterLinkMovementMethod.linkify(Linkify.WEB_URLS).setOnLinkLongClickListener((textView, url) -> {
+ if (!activity.isDestroyed() && !activity.isFinishing()) {
+ UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment();
+ Bundle bundle = new Bundle();
+ bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url);
+ urlMenuBottomSheetFragment.setArguments(bundle);
+ urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag());
+ }
+ return true;
+ })))
+ .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
+ .usePlugin(TableEntryPlugin.create(mActivity))
.build();
- mLocale = locale;
- mAccessToken = accessToken;
- mAccountName = accountName;
- mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
- mShowCommentDivider = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
- mShowAbsoluteNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
- mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
- mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE);
- mRetryLoadingMoreCallback = retryLoadingMoreCallback;
- mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme();
- mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
- mCommentBackgroundColor = customThemeWrapper.getCommentBackgroundColor();
- mCommentColor = customThemeWrapper.getCommentColor();
- mDividerColor = customThemeWrapper.getDividerColor();
- mSubredditColor = customThemeWrapper.getSubreddit();
- mUsernameColor = customThemeWrapper.getUsername();
- mAuthorFlairColor = customThemeWrapper.getAuthorFlairTextColor();
- mUpvotedColor = customThemeWrapper.getUpvoted();
- mDownvotedColor = customThemeWrapper.getDownvoted();
- mButtonTextColor = customThemeWrapper.getButtonTextColor();
- mColorAccent = customThemeWrapper.getColorAccent();
- mCommentIconAndInfoColor = customThemeWrapper.getCommentIconAndInfoColor();
+ recycledViewPool = new RecyclerView.RecycledViewPool();
}
@NonNull
@@ -217,7 +251,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).awardsTextView, comment.getAwards(), true);
}
- mMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown());
+ ((CommentViewHolder) holder).markwonAdapter.setMarkdown(mMarkwon, comment.getCommentMarkdown());
+ ((CommentViewHolder) holder).markwonAdapter.notifyDataSetChanged();
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
@@ -353,7 +388,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@BindView(R.id.awards_text_view_item_comment)
TextView awardsTextView;
@BindView(R.id.comment_markdown_view_item_post_comment)
- SpoilerOnClickTextView commentMarkdownView;
+ RecyclerView commentMarkdownView;
@BindView(R.id.bottom_constraint_layout_item_post_comment)
ConstraintLayout bottomConstraintLayout;
@BindView(R.id.up_vote_button_item_post_comment)
@@ -374,6 +409,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
ImageView replyButton;
@BindView(R.id.divider_item_comment)
View commentDivider;
+ CustomMarkwonAdapter markwonAdapter;
CommentViewHolder(View itemView) {
super(itemView);
@@ -435,15 +471,11 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
awardsTextView.setTypeface(mActivity.typeface);
scoreTextView.setTypeface(mActivity.typeface);
}
- if (mActivity.contentTypeface != null) {
- commentMarkdownView.setTypeface(mActivity.typeface);
- }
itemView.setBackgroundColor(mCommentBackgroundColor);
authorTextView.setTextColor(mUsernameColor);
authorFlairTextView.setTextColor(mAuthorFlairColor);
commentTimeTextView.setTextColor(mSecondaryTextColor);
awardsTextView.setTextColor(mSecondaryTextColor);
- commentMarkdownView.setTextColor(mCommentColor);
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
@@ -500,24 +532,43 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}
});
- commentMarkdownView.setOnClickListener(view -> {
- if (commentMarkdownView.isSpoilerOnClick()) {
- commentMarkdownView.setSpoilerOnClick(false);
- return;
+ commentMarkdownView.setRecycledViewPool(recycledViewPool);
+ LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
+ @Override
+ public void onScrolledLeft() {
+ if (mActivity instanceof AccountSavedThingActivity) {
+ ((AccountSavedThingActivity) mActivity).lockSwipeRightToGoBack();
+ } else {
+ ((ViewUserDetailActivity) mActivity).lockSwipeRightToGoBack();
+ }
+ }
+
+ @Override
+ public void onScrolledRight() {
+ if (mActivity instanceof AccountSavedThingActivity) {
+ ((AccountSavedThingActivity) mActivity).unlockSwipeRightToGoBack();
+ } else {
+ ((ViewUserDetailActivity) mActivity).unlockSwipeRightToGoBack();
+ }
+ }
+ });
+ commentMarkdownView.setLayoutManager(linearLayoutManager);
+ markwonAdapter = CustomMarkwonAdapter.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)))
+ .build();
+ markwonAdapter.setOnClickListener(view -> {
+ if (view instanceof SpoilerOnClickTextView) {
+ if (((SpoilerOnClickTextView) view).isSpoilerOnClick()) {
+ ((SpoilerOnClickTextView) view).setSpoilerOnClick(false);
+ return;
+ }
}
itemView.callOnClick();
});
+ commentMarkdownView.setAdapter(markwonAdapter);
- commentMarkdownView.setMovementMethod(BetterLinkMovementMethod.newInstance().setOnLinkLongClickListener((textView, url) -> {
- if (mActivity != null && !mActivity.isDestroyed() && !mActivity.isFinishing()) {
- UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment();
- Bundle bundle = new Bundle();
- bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url);
- urlMenuBottomSheetFragment.setArguments(bundle);
- urlMenuBottomSheetFragment.show(mActivity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag());
- }
- return true;
- }));
upvoteButton.setOnClickListener(view -> {
if (mAccessToken == null) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java
index d1dde6f2..6f0280e7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java
@@ -35,7 +35,7 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin {
this.backgroundColor = backgroundColor;
}
- public static SpoilerParserPlugin create(@NonNull int textColor, @NonNull int backgroundColor) {
+ public static SpoilerParserPlugin create(int textColor, int backgroundColor) {
return new SpoilerParserPlugin(textColor, backgroundColor);
}