diff options
Diffstat (limited to 'app/src/main/java/CustomView/CustomMarkwonView.java')
-rw-r--r-- | app/src/main/java/CustomView/CustomMarkwonView.java | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/app/src/main/java/CustomView/CustomMarkwonView.java b/app/src/main/java/CustomView/CustomMarkwonView.java index d5828f13..940b6b76 100644 --- a/app/src/main/java/CustomView/CustomMarkwonView.java +++ b/app/src/main/java/CustomView/CustomMarkwonView.java @@ -6,11 +6,8 @@ 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 ml.docilealligator.infinityforreddit.LinkResolverActivity; import ru.noties.markwon.SpannableConfiguration; import ru.noties.markwon.view.MarkwonView; @@ -26,30 +23,14 @@ public class CustomMarkwonView extends MarkwonView { public void setMarkdown(@Nullable String markdown, Context context) { SpannableConfiguration configuration = SpannableConfiguration.builder(context).linkResolver((view, link) -> { - if(link.startsWith("/u/") || link.startsWith("u/")) { - Intent intent = new Intent(context, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, link.substring(3)); - context.startActivity(intent); - } else if(link.startsWith("/r/") || link.startsWith("r/")) { - Intent intent = new Intent(context, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, link.substring(3)); - context.startActivity(intent); + Intent intent = new Intent(context, LinkResolverActivity.class); + Uri uri = Uri.parse(link); + if(uri.getScheme() == null && uri.getHost() == null) { + intent.setData(LinkResolverActivity.getRedditUriByPath(link)); } else { - CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); - // add share action to menu list - builder.addDefaultShareMenuItem(); - builder.setToolbarColor(context.getResources().getColor(R.color.colorPrimary)); - CustomTabsIntent customTabsIntent = builder.build(); - Uri uri = Uri.parse(link); - if(uri.getHost() != null && uri.getHost().contains("reddit.com")) { - customTabsIntent.intent.setPackage(context.getPackageName()); - } - String uriString = uri.toString(); - if(!uriString.startsWith("http://") && (!uriString.startsWith("https://"))) { - uriString = "http://" + uriString; - } - customTabsIntent.launchUrl(context, Uri.parse(uriString)); + intent.setData(uri); } + context.startActivity(intent); }).build(); super.setMarkdown(configuration, markdown); |