aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/CustomView
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-07-18 04:00:46 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-07-18 04:00:46 +0000
commit611d6a90ec39707b4d4161da1eb5b19249e670c4 (patch)
treec5df1e52265e0593ae936be2242727804b886834 /app/src/main/java/CustomView
parent42497bb2475bbd0edaff79a6f1aaf99104e1b84b (diff)
downloadinfinity-for-reddit-611d6a90ec39707b4d4161da1eb5b19249e670c4.tar
infinity-for-reddit-611d6a90ec39707b4d4161da1eb5b19249e670c4.tar.gz
infinity-for-reddit-611d6a90ec39707b4d4161da1eb5b19249e670c4.tar.bz2
infinity-for-reddit-611d6a90ec39707b4d4161da1eb5b19249e670c4.tar.lz
infinity-for-reddit-611d6a90ec39707b4d4161da1eb5b19249e670c4.tar.xz
infinity-for-reddit-611d6a90ec39707b4d4161da1eb5b19249e670c4.tar.zst
infinity-for-reddit-611d6a90ec39707b4d4161da1eb5b19249e670c4.zip
Viewing rules after pressing rules button in PostXXXActivity is available. Extend MarkwonView to support opening reddit subreddit and user links.
Diffstat (limited to 'app/src/main/java/CustomView')
-rw-r--r--app/src/main/java/CustomView/CustomMarkwonView.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/app/src/main/java/CustomView/CustomMarkwonView.java b/app/src/main/java/CustomView/CustomMarkwonView.java
new file mode 100644
index 00000000..c0d59f05
--- /dev/null
+++ b/app/src/main/java/CustomView/CustomMarkwonView.java
@@ -0,0 +1,49 @@
+package CustomView;
+
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.util.AttributeSet;
+
+import androidx.annotation.Nullable;
+import androidx.browser.customtabs.CustomTabsIntent;
+
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.ViewSubredditDetailActivity;
+import ml.docilealligator.infinityforreddit.ViewUserDetailActivity;
+import ru.noties.markwon.SpannableConfiguration;
+import ru.noties.markwon.view.MarkwonView;
+
+public class CustomMarkwonView extends MarkwonView {
+
+ public CustomMarkwonView(Context context) {
+ super(context);
+ }
+
+ public CustomMarkwonView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public void setMarkdown(@Nullable String markdown, Context conte) {
+ SpannableConfiguration configuration = SpannableConfiguration.builder(conte).linkResolver((view, link) -> {
+ if(link.startsWith("/u/") || link.startsWith("u/")) {
+ Intent intent = new Intent(conte, ViewUserDetailActivity.class);
+ intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, link.substring(3));
+ conte.startActivity(intent);
+ } else if(link.startsWith("/r/") || link.startsWith("r/")) {
+ Intent intent = new Intent(conte, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, link.substring(3));
+ conte.startActivity(intent);
+ } else {
+ CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
+ // add share action to menu list
+ builder.addDefaultShareMenuItem();
+ builder.setToolbarColor(conte.getResources().getColor(R.color.colorPrimary));
+ CustomTabsIntent customTabsIntent = builder.build();
+ customTabsIntent.launchUrl(conte, Uri.parse(link));
+ }
+ }).build();
+
+ super.setMarkdown(configuration, markdown);
+ }
+}