blob: 940b6b76cf886e058376a77ea9856e59f0f73fe6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package CustomView;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.AttributeSet;
import androidx.annotation.Nullable;
import ml.docilealligator.infinityforreddit.LinkResolverActivity;
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 context) {
SpannableConfiguration configuration = SpannableConfiguration.builder(context).linkResolver((view, link) -> {
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 {
intent.setData(uri);
}
context.startActivity(intent);
}).build();
super.setMarkdown(configuration, markdown);
}
}
|