Superscript is now available.

This commit is contained in:
Alex Ning 2019-11-19 11:31:58 +08:00
parent c7df7399f9
commit 47b57fd50f
12 changed files with 53 additions and 12 deletions

View File

@ -69,6 +69,7 @@ dependencies {
implementation 'io.noties.markwon:core:4.1.2' implementation 'io.noties.markwon:core:4.1.2'
implementation 'io.noties.markwon:linkify:4.1.2' implementation 'io.noties.markwon:linkify:4.1.2'
implementation 'io.noties.markwon:ext-strikethrough:4.1.2' implementation 'io.noties.markwon:ext-strikethrough:4.1.2'
implementation "io.noties.markwon:simple-ext:4.1.2"
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'
implementation 'com.github.Ferfalk:SimpleSearchView:0.1.3' implementation 'com.github.Ferfalk:SimpleSearchView:0.1.3'
implementation 'org.greenrobot:eventbus:3.1.1' implementation 'org.greenrobot:eventbus:3.1.1'

View File

@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.style.SuperscriptSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -32,6 +33,7 @@ import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon; import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.linkify.LinkifyPlugin;
import io.noties.markwon.simple.ext.SimpleExtPlugin;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CommentData; import ml.docilealligator.infinityforreddit.CommentData;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
@ -116,6 +118,12 @@ public class CommentActivity extends BaseActivity {
} }
}) })
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(SimpleExtPlugin.create(plugin ->
plugin.addExtension(1, '^', (configuration, props) -> {
return new SuperscriptSpan();
})
)
)
.build(); .build();
markwon.setMarkdown(commentParentMarkwonView, intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY)); markwon.setMarkdown(commentParentMarkwonView, intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY));
parentFullname = intent.getStringExtra(EXTRA_PARENT_FULLNAME_KEY); parentFullname = intent.getStringExtra(EXTRA_PARENT_FULLNAME_KEY);

View File

@ -32,6 +32,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditAPI; import ml.docilealligator.infinityforreddit.RedditAPI;
import ml.docilealligator.infinityforreddit.Utils.RedditUtils; import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
@ -132,7 +133,7 @@ public class EditCommentActivity extends BaseActivity {
Toast.makeText(EditCommentActivity.this, R.string.edit_success, Toast.LENGTH_SHORT).show(); Toast.makeText(EditCommentActivity.this, R.string.edit_success, Toast.LENGTH_SHORT).show();
Intent returnIntent = new Intent(); Intent returnIntent = new Intent();
returnIntent.putExtra(EXTRA_EDITED_COMMENT_CONTENT, content); returnIntent.putExtra(EXTRA_EDITED_COMMENT_CONTENT, Utils.modifyMarkdown(content));
returnIntent.putExtra(EXTRA_EDITED_COMMENT_POSITION, getIntent().getExtras().getInt(EXTRA_POSITION)); returnIntent.putExtra(EXTRA_EDITED_COMMENT_POSITION, getIntent().getExtras().getInt(EXTRA_POSITION));
setResult(RESULT_OK, returnIntent); setResult(RESULT_OK, returnIntent);

View File

@ -235,7 +235,7 @@ public class RulesActivity extends BaseActivity {
String shortName = rulesArray.getJSONObject(i).getString(JSONUtils.SHORT_NAME_KEY); String shortName = rulesArray.getJSONObject(i).getString(JSONUtils.SHORT_NAME_KEY);
String description = null; String description = null;
if (rulesArray.getJSONObject(i).has(JSONUtils.DESCRIPTION_KEY)) { if (rulesArray.getJSONObject(i).has(JSONUtils.DESCRIPTION_KEY)) {
description = Utils.addSubredditAndUserLink(rulesArray.getJSONObject(i).getString(JSONUtils.DESCRIPTION_KEY)); description = Utils.modifyMarkdown(rulesArray.getJSONObject(i).getString(JSONUtils.DESCRIPTION_KEY));
} }
rules.add(new Rule(shortName, description)); rules.add(new Rule(shortName, description));
} }

View File

@ -8,11 +8,10 @@ import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.style.SuperscriptSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.GestureDetector;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
@ -50,6 +49,7 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.linkify.LinkifyPlugin;
import io.noties.markwon.simple.ext.SimpleExtPlugin;
import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute; import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
@ -146,6 +146,12 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}) })
.usePlugin(StrikethroughPlugin.create()) .usePlugin(StrikethroughPlugin.create())
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(SimpleExtPlugin.create(plugin ->
plugin.addExtension(1, '^', (configuration, props) -> {
return new SuperscriptSpan();
})
)
)
.build(); .build();
mAccessToken = accessToken; mAccessToken = accessToken;
mAccountName = accountName; mAccountName = accountName;

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.style.SuperscriptSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -31,6 +32,7 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.linkify.LinkifyPlugin;
import io.noties.markwon.simple.ext.SimpleExtPlugin;
import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity; import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
@ -97,6 +99,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}) })
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(StrikethroughPlugin.create()) .usePlugin(StrikethroughPlugin.create())
.usePlugin(SimpleExtPlugin.create(plugin ->
plugin.addExtension(1, '^', (configuration, props) -> {
return new SuperscriptSpan();
})
)
)
.build(); .build();
mAccessToken = accessToken; mAccessToken = accessToken;
mAccountName = accountName; mAccountName = accountName;

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
import android.text.style.SuperscriptSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -24,6 +25,7 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.linkify.LinkifyPlugin;
import io.noties.markwon.simple.ext.SimpleExtPlugin;
import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity; import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.Message; import ml.docilealligator.infinityforreddit.Message;
@ -80,6 +82,12 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
}) })
.usePlugin(StrikethroughPlugin.create()) .usePlugin(StrikethroughPlugin.create())
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(SimpleExtPlugin.create(plugin ->
plugin.addExtension(1, '^', (configuration, props) -> {
return new SuperscriptSpan();
})
)
)
.build(); .build();
mAccessToken = accessToken; mAccessToken = accessToken;
mResources = context.getResources(); mResources = context.getResources();

View File

@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Adapter;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.text.style.SuperscriptSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -21,6 +22,7 @@ import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.linkify.LinkifyPlugin;
import io.noties.markwon.simple.ext.SimpleExtPlugin;
import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity; import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Rule; import ml.docilealligator.infinityforreddit.Rule;
@ -48,6 +50,12 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
}) })
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(StrikethroughPlugin.create()) .usePlugin(StrikethroughPlugin.create())
.usePlugin(SimpleExtPlugin.create(plugin ->
plugin.addExtension(1, '^', (configuration, props) -> {
return new SuperscriptSpan();
})
)
)
.build(); .build();
} }

View File

@ -74,7 +74,7 @@ public class FetchMessages {
String author = rawMessageJSON.getString(JSONUtils.AUTHOR_KEY); String author = rawMessageJSON.getString(JSONUtils.AUTHOR_KEY);
String parentFullname = rawMessageJSON.getString(JSONUtils.PARENT_ID_KEY); String parentFullname = rawMessageJSON.getString(JSONUtils.PARENT_ID_KEY);
String title = rawMessageJSON.has(JSONUtils.LINK_TITLE_KEY) ? rawMessageJSON.getString(JSONUtils.LINK_TITLE_KEY) : null; String title = rawMessageJSON.has(JSONUtils.LINK_TITLE_KEY) ? rawMessageJSON.getString(JSONUtils.LINK_TITLE_KEY) : null;
String body = Utils.addSubredditAndUserLink(rawMessageJSON.getString(JSONUtils.BODY_KEY)); String body = Utils.modifyMarkdown(rawMessageJSON.getString(JSONUtils.BODY_KEY));
String context = rawMessageJSON.getString(JSONUtils.CONTEXT_KEY); String context = rawMessageJSON.getString(JSONUtils.CONTEXT_KEY);
String distinguished = rawMessageJSON.getString(JSONUtils.DISTINGUISHED_KEY); String distinguished = rawMessageJSON.getString(JSONUtils.DISTINGUISHED_KEY);
boolean wasComment = rawMessageJSON.getBoolean(JSONUtils.WAS_COMMENT_KEY); boolean wasComment = rawMessageJSON.getBoolean(JSONUtils.WAS_COMMENT_KEY);

View File

@ -129,7 +129,7 @@ public class ParseComment {
String distinguished = singleCommentData.getString(JSONUtils.DISTINGUISHED_KEY); String distinguished = singleCommentData.getString(JSONUtils.DISTINGUISHED_KEY);
String commentContent = ""; String commentContent = "";
if (!singleCommentData.isNull(JSONUtils.BODY_KEY)) { if (!singleCommentData.isNull(JSONUtils.BODY_KEY)) {
commentContent = Utils.addSubredditAndUserLink(singleCommentData.getString(JSONUtils.BODY_KEY).trim()); commentContent = Utils.modifyMarkdown(singleCommentData.getString(JSONUtils.BODY_KEY).trim());
} }
String permalink = Html.fromHtml(singleCommentData.getString(JSONUtils.PERMALINK_KEY)).toString(); String permalink = Html.fromHtml(singleCommentData.getString(JSONUtils.PERMALINK_KEY)).toString();
int score = singleCommentData.getInt(JSONUtils.SCORE_KEY); int score = singleCommentData.getInt(JSONUtils.SCORE_KEY);

View File

@ -126,7 +126,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
post.setSelfText(Utils.addSubredditAndUserLink(data.getString(JSONUtils.SELFTEXT_KEY).trim())); post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()));
if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
post.setSelfTextPlainTrimmed(""); post.setSelfTextPlainTrimmed("");
} else { } else {
@ -147,7 +147,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
post.setSelfText(Utils.addSubredditAndUserLink(data.getString(JSONUtils.SELFTEXT_KEY).trim())); post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()));
} }
} }
} else { } else {
@ -222,7 +222,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
post.setSelfText(Utils.addSubredditAndUserLink(data.getString(JSONUtils.SELFTEXT_KEY).trim())); post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()));
if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
post.setSelfTextPlainTrimmed(""); post.setSelfTextPlainTrimmed("");
} else { } else {
@ -245,7 +245,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
post.setSelfText(Utils.addSubredditAndUserLink(data.getString(JSONUtils.SELFTEXT_KEY).trim())); post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()));
} }
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);

View File

@ -12,8 +12,9 @@ public class Utils {
private static final long MONTH_MILLIS = 30 * DAY_MILLIS; private static final long MONTH_MILLIS = 30 * DAY_MILLIS;
private static final long YEAR_MILLIS = 12 * MONTH_MILLIS; private static final long YEAR_MILLIS = 12 * MONTH_MILLIS;
public static String addSubredditAndUserLink(String markdown) { public static String modifyMarkdown(String markdown) {
return markdown.replaceAll("((?<=[\\s])|^)/{0,1}[rRuU]/\\w+/{0,1}", "[$0]($0)"); return markdown.replaceAll("((?<=[\\s])|^)/{0,1}[rRuU]/\\w+/{0,1}", "[$0]($0)")
.replaceAll("\\^\\w+", "$0^");
} }
public static CharSequence trimTrailingWhitespace(CharSequence source) { public static CharSequence trimTrailingWhitespace(CharSequence source) {