77
88package com.nextcloud.talk.utils
99
10+ import android.annotation.SuppressLint
1011import android.content.Context
11- import android.util.Log
12+ import android.content.Intent
13+ import android.text.method.ScrollingMovementMethod
1214import android.view.View
15+ import androidx.core.net.toUri
1316import com.nextcloud.talk.R
1417import io.noties.markwon.AbstractMarkwonPlugin
18+ import io.noties.markwon.LinkResolverDef
1519import io.noties.markwon.Markwon
1620import io.noties.markwon.MarkwonConfiguration
1721import io.noties.markwon.core.MarkwonTheme
1822import io.noties.markwon.ext.strikethrough.StrikethroughPlugin
1923import io.noties.markwon.ext.tasklist.TaskListDrawable
2024import io.noties.markwon.ext.tasklist.TaskListPlugin
25+ import io.noties.markwon.movement.MovementMethodPlugin
2126
2227object MarkwonUtils {
2328 private const val TAG = " MarkwonUtils"
@@ -31,13 +36,28 @@ object MarkwonUtils {
3136 }
3237
3338 override fun configureConfiguration (builder : MarkwonConfiguration .Builder ) {
34- builder.linkResolver { view: View ? , link: String? ->
35- Log .i(TAG , " Link action not implemented $view / $link " )
36- }
39+ builder.linkResolver(object : LinkResolverDef () {
40+ @SuppressLint(" SuspiciousIndentation" )
41+ override fun resolve (view : View , link : String ) {
42+ var linkToOpen = link
43+ if (! (linkToOpen.contains(" http://" ) || linkToOpen.contains(" https://" ))) {
44+ linkToOpen = " https://$link "
45+ } else {
46+ linkToOpen = link
47+ }
48+
49+ val browserIntent = Intent (
50+ Intent .ACTION_VIEW ,
51+ linkToOpen.toUri()
52+ )
53+ context.startActivity(browserIntent)
54+ }
55+ })
3756 }
3857 })
3958 .usePlugin(TaskListPlugin .create(drawable))
4059 .usePlugin(StrikethroughPlugin .create())
60+ .usePlugin(MovementMethodPlugin .create(ScrollingMovementMethod .getInstance()))
4161 .build()
4262 }
4363}
0 commit comments