aboutsummaryrefslogblamecommitdiff
path: root/app/src/main/java/CustomView/CustomMarkwonView.java
blob: 940b6b76cf886e058376a77ea9856e59f0f73fe6 (plain) (tree)
1
2
3
4
5
6
7
8
9







                                    
 
                                                                 












                                                                   

                                                                                                                     



                                                                              
                    
                                    
             
                                          




                                                   
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);
    }
}