mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-30 21:07:11 +01:00
Long press a url to see options in RulesRecyclerViewAdapter.
This commit is contained in:
parent
d1aa3df4a7
commit
9830db0303
@ -1,8 +1,8 @@
|
||||
package ml.docilealligator.infinityforreddit.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.style.SuperscriptSpan;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.LayoutInflater;
|
||||
@ -11,6 +11,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -23,11 +24,14 @@ import io.noties.markwon.MarkwonConfiguration;
|
||||
import io.noties.markwon.core.MarkwonTheme;
|
||||
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||
import io.noties.markwon.linkify.LinkifyPlugin;
|
||||
import io.noties.markwon.movement.MovementMethodPlugin;
|
||||
import io.noties.markwon.simple.ext.SimpleExtPlugin;
|
||||
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
|
||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.Rule;
|
||||
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
|
||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
|
||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||
|
||||
public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecyclerViewAdapter.RuleViewHolder> {
|
||||
private Markwon markwon;
|
||||
@ -35,16 +39,16 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
|
||||
private int mPrimaryTextColor;
|
||||
private int mSecondaryTextColor;
|
||||
|
||||
public RulesRecyclerViewAdapter(Context context, CustomThemeWrapper customThemeWrapper) {
|
||||
markwon = Markwon.builder(context)
|
||||
public RulesRecyclerViewAdapter(AppCompatActivity activity, CustomThemeWrapper customThemeWrapper) {
|
||||
markwon = Markwon.builder(activity)
|
||||
.usePlugin(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
|
||||
builder.linkResolver((view, link) -> {
|
||||
Intent intent = new Intent(context, LinkResolverActivity.class);
|
||||
Intent intent = new Intent(activity, LinkResolverActivity.class);
|
||||
Uri uri = Uri.parse(link);
|
||||
intent.setData(uri);
|
||||
context.startActivity(intent);
|
||||
activity.startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
@ -53,6 +57,16 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
|
||||
builder.linkColor(customThemeWrapper.getLinkColor());
|
||||
}
|
||||
})
|
||||
.usePlugin(MovementMethodPlugin.create(BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, activity).setOnLinkLongClickListener((textView, url) -> {
|
||||
if (activity != null && !activity.isDestroyed() && !activity.isFinishing()) {
|
||||
UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url);
|
||||
urlMenuBottomSheetFragment.setArguments(bundle);
|
||||
urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag());
|
||||
}
|
||||
return true;
|
||||
})))
|
||||
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
|
||||
.usePlugin(StrikethroughPlugin.create())
|
||||
.usePlugin(SimpleExtPlugin.create(plugin ->
|
||||
|
Loading…
Reference in New Issue
Block a user