mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-04 07:17:12 +01:00
Fix spoiler background color that cannot hide spoiler. Support spoiler in MessageRecyclerViewAdapter.
This commit is contained in:
parent
acaece6e3e
commit
4870d2bee6
@ -114,6 +114,7 @@ public class CommentFullMarkdownActivity extends BaseActivity {
|
|||||||
String commentMarkdown = getIntent().getStringExtra(EXTRA_COMMENT_MARKDOWN);
|
String commentMarkdown = getIntent().getStringExtra(EXTRA_COMMENT_MARKDOWN);
|
||||||
boolean isNsfw = getIntent().getBooleanExtra(EXTRA_IS_NSFW, false);
|
boolean isNsfw = getIntent().getBooleanExtra(EXTRA_IS_NSFW, false);
|
||||||
int markdownColor = mCustomThemeWrapper.getCommentColor();
|
int markdownColor = mCustomThemeWrapper.getCommentColor();
|
||||||
|
int spoilerBackgroundColor = markdownColor | 0xFF000000;
|
||||||
int linkColor = mCustomThemeWrapper.getLinkColor();
|
int linkColor = mCustomThemeWrapper.getLinkColor();
|
||||||
Markwon markwon = Markwon.builder(this)
|
Markwon markwon = Markwon.builder(this)
|
||||||
.usePlugin(new AbstractMarkwonPlugin() {
|
.usePlugin(new AbstractMarkwonPlugin() {
|
||||||
@ -149,7 +150,7 @@ public class CommentFullMarkdownActivity extends BaseActivity {
|
|||||||
super.updateDrawState(ds);
|
super.updateDrawState(ds);
|
||||||
ds.setColor(markdownColor);
|
ds.setColor(markdownColor);
|
||||||
} else {
|
} else {
|
||||||
ds.bgColor = markdownColor;
|
ds.bgColor = spoilerBackgroundColor;
|
||||||
ds.setColor(markdownColor);
|
ds.setColor(markdownColor);
|
||||||
}
|
}
|
||||||
ds.setUnderlineText(false);
|
ds.setUnderlineText(false);
|
||||||
|
@ -250,7 +250,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
mGlide = glide;
|
mGlide = glide;
|
||||||
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
||||||
mCommentTextColor = customThemeWrapper.getCommentColor();
|
mCommentTextColor = customThemeWrapper.getCommentColor();
|
||||||
|
int commentSpoilerBackgroundColor = mCommentTextColor | 0xFF000000;
|
||||||
int markdownColor = customThemeWrapper.getPostContentColor();
|
int markdownColor = customThemeWrapper.getPostContentColor();
|
||||||
|
int postSpoilerBackgroundColor = markdownColor | 0xFF000000;
|
||||||
int linkColor = customThemeWrapper.getLinkColor();
|
int linkColor = customThemeWrapper.getLinkColor();
|
||||||
mPostDetailMarkwon = Markwon.builder(mActivity)
|
mPostDetailMarkwon = Markwon.builder(mActivity)
|
||||||
.usePlugin(new AbstractMarkwonPlugin() {
|
.usePlugin(new AbstractMarkwonPlugin() {
|
||||||
@ -286,7 +288,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
super.updateDrawState(ds);
|
super.updateDrawState(ds);
|
||||||
ds.setColor(markdownColor);
|
ds.setColor(markdownColor);
|
||||||
} else {
|
} else {
|
||||||
ds.bgColor = markdownColor;
|
ds.bgColor = postSpoilerBackgroundColor;
|
||||||
ds.setColor(markdownColor);
|
ds.setColor(markdownColor);
|
||||||
}
|
}
|
||||||
ds.setUnderlineText(false);
|
ds.setUnderlineText(false);
|
||||||
@ -382,7 +384,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
super.updateDrawState(ds);
|
super.updateDrawState(ds);
|
||||||
ds.setColor(mCommentTextColor);
|
ds.setColor(mCommentTextColor);
|
||||||
} else {
|
} else {
|
||||||
ds.bgColor = mCommentTextColor;
|
ds.bgColor = commentSpoilerBackgroundColor;
|
||||||
ds.setColor(mCommentTextColor);
|
ds.setColor(mCommentTextColor);
|
||||||
}
|
}
|
||||||
ds.setUnderlineText(false);
|
ds.setUnderlineText(false);
|
||||||
@ -3657,7 +3659,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
((ViewPostDetailActivity) mActivity).changeToSingleThreadMode();
|
((ViewPostDetailActivity) mActivity).changeToSingleThreadMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
itemView.setBackgroundColor(mCommentBackgroundColor);
|
itemView.setBackgroundColor(mColorAccent);
|
||||||
((TextView) itemView).setTextColor(mColorAccent);
|
((TextView) itemView).setTextColor(mColorAccent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mOauthRetrofit = oauthRetrofit;
|
mOauthRetrofit = oauthRetrofit;
|
||||||
mCommentColor = customThemeWrapper.getCommentColor();
|
mCommentColor = customThemeWrapper.getCommentColor();
|
||||||
|
int commentSpoilerBackgroundColor = mCommentColor | 0xFF000000;
|
||||||
mMarkwon = Markwon.builder(mContext)
|
mMarkwon = Markwon.builder(mContext)
|
||||||
.usePlugin(new AbstractMarkwonPlugin() {
|
.usePlugin(new AbstractMarkwonPlugin() {
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -147,7 +148,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
super.updateDrawState(ds);
|
super.updateDrawState(ds);
|
||||||
ds.setColor(mCommentColor);
|
ds.setColor(mCommentColor);
|
||||||
} else {
|
} else {
|
||||||
ds.bgColor = mCommentColor;
|
ds.bgColor = commentSpoilerBackgroundColor;
|
||||||
ds.setColor(mCommentColor);
|
ds.setColor(mCommentColor);
|
||||||
}
|
}
|
||||||
ds.setUnderlineText(false);
|
ds.setUnderlineText(false);
|
||||||
|
@ -3,7 +3,13 @@ package ml.docilealligator.infinityforreddit.Adapter;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.Spanned;
|
||||||
|
import android.text.TextPaint;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.text.style.ClickableSpan;
|
||||||
import android.text.style.SuperscriptSpan;
|
import android.text.style.SuperscriptSpan;
|
||||||
import android.text.util.Linkify;
|
import android.text.util.Linkify;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -19,6 +25,8 @@ import androidx.recyclerview.widget.DiffUtil;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -79,8 +87,73 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mOauthRetrofit = oauthRetrofit;
|
mOauthRetrofit = oauthRetrofit;
|
||||||
mRetryLoadingMoreCallback = retryLoadingMoreCallback;
|
mRetryLoadingMoreCallback = retryLoadingMoreCallback;
|
||||||
|
|
||||||
|
mColorAccent = customThemeWrapper.getColorAccent();
|
||||||
|
mMessageBackgroundColor = customThemeWrapper.getCardViewBackgroundColor();
|
||||||
|
mUsernameColor = customThemeWrapper.getUsername();
|
||||||
|
mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor();
|
||||||
|
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
||||||
|
int spoilerBackgroundColor = mSecondaryTextColor | 0xFF000000;
|
||||||
|
mUnreadMessageBackgroundColor = customThemeWrapper.getUnreadMessageBackgroundColor();
|
||||||
|
mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme();
|
||||||
|
mButtonTextColor = customThemeWrapper.getButtonTextColor();
|
||||||
|
|
||||||
mMarkwon = Markwon.builder(mContext)
|
mMarkwon = Markwon.builder(mContext)
|
||||||
.usePlugin(new AbstractMarkwonPlugin() {
|
.usePlugin(new AbstractMarkwonPlugin() {
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public String processMarkdown(@NonNull String markdown) {
|
||||||
|
StringBuilder markdownStringBuilder = new StringBuilder(markdown);
|
||||||
|
Pattern spoilerPattern = Pattern.compile(">![\\S\\s]*?!<");
|
||||||
|
Matcher matcher = spoilerPattern.matcher(markdownStringBuilder);
|
||||||
|
while (matcher.find()) {
|
||||||
|
markdownStringBuilder.replace(matcher.start(), matcher.start() + 1, ">");
|
||||||
|
}
|
||||||
|
return super.processMarkdown(markdownStringBuilder.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterSetText(@NonNull TextView textView) {
|
||||||
|
textView.setHighlightColor(Color.TRANSPARENT);
|
||||||
|
SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText().toString());
|
||||||
|
Pattern spoilerPattern = Pattern.compile(">![\\S\\s]*?!<");
|
||||||
|
Matcher matcher = spoilerPattern.matcher(markdownStringBuilder);
|
||||||
|
int start = 0;
|
||||||
|
boolean find = false;
|
||||||
|
while (matcher.find(start)) {
|
||||||
|
find = true;
|
||||||
|
markdownStringBuilder.delete(matcher.end() - 2, matcher.end());
|
||||||
|
markdownStringBuilder.delete(matcher.start(), matcher.start() + 2);
|
||||||
|
int matcherStart = matcher.start();
|
||||||
|
int matcherEnd = matcher.end();
|
||||||
|
ClickableSpan clickableSpan = new ClickableSpan() {
|
||||||
|
private boolean isShowing = false;
|
||||||
|
@Override
|
||||||
|
public void updateDrawState(@NonNull TextPaint ds) {
|
||||||
|
if (isShowing) {
|
||||||
|
super.updateDrawState(ds);
|
||||||
|
ds.setColor(mSecondaryTextColor);
|
||||||
|
} else {
|
||||||
|
ds.bgColor = spoilerBackgroundColor;
|
||||||
|
ds.setColor(mSecondaryTextColor);
|
||||||
|
}
|
||||||
|
ds.setUnderlineText(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(@NonNull View view) {
|
||||||
|
isShowing = !isShowing;
|
||||||
|
view.invalidate();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
markdownStringBuilder.setSpan(clickableSpan, matcherStart, matcherEnd - 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
start = matcherEnd - 4;
|
||||||
|
}
|
||||||
|
if (find) {
|
||||||
|
textView.setText(markdownStringBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
|
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
|
||||||
builder.linkResolver((view, link) -> {
|
builder.linkResolver((view, link) -> {
|
||||||
@ -115,15 +188,6 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
|||||||
} else {
|
} else {
|
||||||
mMessageType = FetchMessage.MESSAGE_TYPE_INBOX;
|
mMessageType = FetchMessage.MESSAGE_TYPE_INBOX;
|
||||||
}
|
}
|
||||||
|
|
||||||
mColorAccent = customThemeWrapper.getColorAccent();
|
|
||||||
mMessageBackgroundColor = customThemeWrapper.getCardViewBackgroundColor();
|
|
||||||
mUsernameColor = customThemeWrapper.getUsername();
|
|
||||||
mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor();
|
|
||||||
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
|
||||||
mUnreadMessageBackgroundColor = customThemeWrapper.getUnreadMessageBackgroundColor();
|
|
||||||
mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme();
|
|
||||||
mButtonTextColor = customThemeWrapper.getButtonTextColor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -205,7 +269,11 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
|||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
});
|
});
|
||||||
|
|
||||||
((DataViewHolder) holder).contentCustomMarkwonView.setOnClickListener(view -> ((DataViewHolder) holder).itemView.performClick());
|
((DataViewHolder) holder).contentCustomMarkwonView.setOnClickListener(view -> {
|
||||||
|
if (((DataViewHolder) holder).contentCustomMarkwonView.getSelectionStart() == -1 && ((DataViewHolder) holder).contentCustomMarkwonView.getSelectionEnd() == -1) {
|
||||||
|
((DataViewHolder) holder).itemView.performClick();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,6 +361,8 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
|||||||
subjectTextView.setTextColor(mPrimaryTextColor);
|
subjectTextView.setTextColor(mPrimaryTextColor);
|
||||||
titleTextView.setTextColor(mPrimaryTextColor);
|
titleTextView.setTextColor(mPrimaryTextColor);
|
||||||
contentCustomMarkwonView.setTextColor(mSecondaryTextColor);
|
contentCustomMarkwonView.setTextColor(mSecondaryTextColor);
|
||||||
|
|
||||||
|
contentCustomMarkwonView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user