From e0cf4ec485414ab91ed4c751743730a14ebb0ddc Mon Sep 17 00:00:00 2001 From: Sergei Kozelko Date: Fri, 9 Sep 2022 08:34:00 +0300 Subject: Fix markdown in rules screen (#1050) * Display tables in rules screen * Parse spoiler and headings in rules screen --- .../activities/RulesActivity.java | 6 +- .../adapters/RulesRecyclerViewAdapter.java | 65 ++++++++++++++++++---- 2 files changed, 59 insertions(+), 12 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java index f7ab30ad..21bf5f85 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java @@ -20,6 +20,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; import com.r0adkll.slidr.Slidr; +import com.r0adkll.slidr.model.SlidrInterface; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -87,8 +88,9 @@ public class RulesActivity extends BaseActivity { applyCustomTheme(); + SlidrInterface slidrInterface = null; if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) { - Slidr.attach(this); + slidrInterface = Slidr.attach(this); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -119,7 +121,7 @@ public class RulesActivity extends BaseActivity { mSubredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); - mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper); + mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper, slidrInterface); recyclerView.setAdapter(mAdapter); FetchRules.fetchRules(mExecutor, new Handler(), mRetrofit, mSubredditName, new FetchRules.FetchRulesListener() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java index abbfc00c..33c3dd81 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -11,8 +11,13 @@ import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; +import com.r0adkll.slidr.model.SlidrInterface; + +import org.commonmark.ext.gfm.tables.TableBlock; + import java.util.ArrayList; import butterknife.BindView; @@ -30,6 +35,9 @@ import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; +import io.noties.markwon.recycler.MarkwonAdapter; +import io.noties.markwon.recycler.table.TableEntry; +import io.noties.markwon.recycler.table.TableEntryPlugin; import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Rule; @@ -37,18 +45,28 @@ import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; +import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; +import ml.docilealligator.infinityforreddit.markdown.RedditHeadingPlugin; +import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { private BaseActivity activity; private Markwon markwon; + @Nullable + private final SlidrInterface slidrInterface; private ArrayList rules; private int mPrimaryTextColor; - private int mSecondaryTextColor; - public RulesRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper) { + public RulesRecyclerViewAdapter(@NonNull BaseActivity activity, + @NonNull CustomThemeWrapper customThemeWrapper, + @Nullable SlidrInterface slidrInterface) { this.activity = activity; + this.slidrInterface = slidrInterface; + mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor(); + int spoilerBackgroundColor = mPrimaryTextColor | 0xFF000000; markwon = Markwon.builder(activity) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); @@ -101,10 +119,11 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter builder + .tableLayout(R.layout.adapter_table_block, R.id.table_layout) + .textLayoutIsRoot(R.layout.view_table_entry_cell))) + .build(); + LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(activity, + new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() { + @Override + public void onScrolledLeft() { + if (slidrInterface != null) { + slidrInterface.lock(); + } + } + + @Override + public void onScrolledRight() { + if (slidrInterface != null) { + slidrInterface.unlock(); + } + } + }); + descriptionMarkwonView.setLayoutManager(linearLayoutManager); + descriptionMarkwonView.setAdapter(markwonAdapter); } } } -- cgit v1.2.3