From 5d050204e7f533958215004c0cdf24ec664c8437 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 22 May 2024 23:49:40 -0400 Subject: Fix https://github.com/Docile-Alligator/Infinity-For-Reddit/issues/1625 --- .../activities/CommentActivity.java | 2 +- .../activities/FullMarkdownActivity.java | 2 +- .../infinityforreddit/activities/WikiActivity.java | 2 +- .../CommentsListingRecyclerViewAdapter.java | 2 +- .../adapters/CommentsRecyclerViewAdapter.java | 2 +- .../adapters/PostDetailRecyclerViewAdapter.java | 2 +- .../adapters/RulesRecyclerViewAdapter.java | 2 +- .../customviews/SwipeLockScrollView.java | 73 ---------------------- .../customviews/slidr/widget/SliderPanel.java | 4 ++ .../fragments/SidebarFragment.java | 2 +- .../markdown/CustomMarkwonAdapter.java | 52 +++++++++++++-- .../infinityforreddit/markdown/MarkdownUtils.java | 9 +-- app/src/main/res/layout/adapter_table_block.xml | 4 +- 13 files changed, 66 insertions(+), 92 deletions(-) delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockScrollView.java (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java index af4ec114..fab5e216 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -240,7 +240,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this, miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, parentTextColor, parentSpoilerBackgroundColor, null); - CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(imageAndGifEntry); + CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(this, imageAndGifEntry); markwonAdapter.setOnLongClickListener(view -> { Utils.hideKeyboard(CommentActivity.this); CopyTextBottomSheetFragment.show(getSupportFragmentManager(), diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java index 5fea5dae..2b744929 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -125,7 +125,7 @@ public class FullMarkdownActivity extends BaseActivity { Markwon markwon = MarkdownUtils.createContentPreviewRedditMarkwon(this, miscPlugin, markdownColor, markdownColor | 0xFF000000); - CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(); + CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(this); LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() { @Override public void lockSwipe() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index 3b14e50a..fede7776 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -189,7 +189,7 @@ public class WikiActivity extends BaseActivity { markwon = MarkdownUtils.createFullRedditMarkwon(this, miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener); - markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(imageAndGifEntry); + markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(this, imageAndGifEntry); LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() { @Override public void lockSwipe() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index 567af63e..296bb8a3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -560,7 +560,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { if (view instanceof SpoilerOnClickTextView) { if (((SpoilerOnClickTextView) view).isSpoilerOnClick()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 8cb5bc4f..dd6b9c91 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -1361,7 +1361,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { if (sidebarDescription != null && !sidebarDescription.equals("")) { Bundle bundle = new Bundle(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java index e83d5597..dbe4b23f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.markdown; import android.util.SparseArray; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.HorizontalScrollView; @@ -24,9 +25,11 @@ import io.noties.markwon.MarkwonReducer; import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.SimpleEntry; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; public class CustomMarkwonAdapter extends MarkwonAdapter { + private BaseActivity activity; private final SparseArray> entries; private final Entry defaultEntry; private final MarkwonReducer reducer; @@ -43,9 +46,11 @@ public class CustomMarkwonAdapter extends MarkwonAdapter { @SuppressWarnings("WeakerAccess") CustomMarkwonAdapter( + @NonNull BaseActivity activity, @NonNull SparseArray> entries, @NonNull Entry defaultEntry, @NonNull MarkwonReducer reducer) { + this.activity = activity; this.entries = entries; this.defaultEntry = defaultEntry; this.reducer = reducer; @@ -63,16 +68,17 @@ public class CustomMarkwonAdapter extends MarkwonAdapter { @NonNull public static CustomBuilderImpl builder( + @NonNull BaseActivity activity, @LayoutRes int defaultEntryLayoutResId, @IdRes int defaultEntryTextViewResId ) { - return builder(SimpleEntry.create(defaultEntryLayoutResId, defaultEntryTextViewResId)); + return builder(activity, SimpleEntry.create(defaultEntryLayoutResId, defaultEntryTextViewResId)); } @NonNull - public static CustomBuilderImpl builder(@NonNull Entry defaultEntry) { + public static CustomBuilderImpl builder(@NonNull BaseActivity activity, @NonNull Entry defaultEntry) { //noinspection unchecked - return new CustomBuilderImpl((Entry) defaultEntry); + return new CustomBuilderImpl(activity, (Entry) defaultEntry); } @Override @@ -136,6 +142,39 @@ public class CustomMarkwonAdapter extends MarkwonAdapter { return false; }); } else if (holder.itemView instanceof HorizontalScrollView) { + holder.itemView.setOnTouchListener(new View.OnTouchListener() { + boolean isSliderPanelLockedAlready; + boolean isViewPager2UserInputEnabledAlready; + @Override + public boolean onTouch(View v, MotionEvent motionEvent) { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { + if (activity.mSliderPanel != null) { + activity.mSliderPanel.requestDisallowInterceptTouchEvent(false); + } + + if (activity.mViewPager2 != null && isViewPager2UserInputEnabledAlready) { + activity.mViewPager2.setUserInputEnabled(true); + } + + if (!isSliderPanelLockedAlready) { + activity.unlockSwipeRightToGoBack(); + } + } else { + if (activity.mSliderPanel != null) { + isSliderPanelLockedAlready = activity.mSliderPanel.isLocked(); + activity.mSliderPanel.requestDisallowInterceptTouchEvent(true); + } + if (activity.mViewPager2 != null) { + isViewPager2UserInputEnabledAlready = activity.mViewPager2.isUserInputEnabled(); + activity.mViewPager2.setUserInputEnabled(false); + } + activity.lockSwipeRightToGoBack(); + } + + return false; + } + }); + TableLayout tableLayout = holder.itemView.findViewById(R.id.table_layout); if (tableLayout != null) { for (int i = 0; i < tableLayout.getChildCount(); i++) { @@ -246,13 +285,16 @@ public class CustomMarkwonAdapter extends MarkwonAdapter { public static class CustomBuilderImpl implements Builder { + private final BaseActivity activity; + private final SparseArray> entries = new SparseArray<>(3); private final Entry defaultEntry; private MarkwonReducer reducer; - CustomBuilderImpl(@NonNull Entry defaultEntry) { + CustomBuilderImpl(@NonNull BaseActivity activity, @NonNull Entry defaultEntry) { + this.activity = activity; this.defaultEntry = defaultEntry; } @@ -281,7 +323,7 @@ public class CustomMarkwonAdapter extends MarkwonAdapter { reducer = MarkwonReducer.directChildren(); } - return new CustomMarkwonAdapter(entries, defaultEntry, reducer); + return new CustomMarkwonAdapter(activity, entries, defaultEntry, reducer); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java index 4c3fd287..1421a00f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java @@ -20,6 +20,7 @@ import io.noties.markwon.movement.MovementMethodPlugin; import io.noties.markwon.recycler.table.TableEntry; import io.noties.markwon.recycler.table.TableEntryPlugin; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; public class MarkdownUtils { /** @@ -138,8 +139,8 @@ public class MarkdownUtils { * Creates a CustomMarkwonAdapter configured with support for tables and images. */ @NonNull - public static CustomMarkwonAdapter createCustomTablesAndImagesAdapter(ImageAndGifEntry imageAndGifEntry) { - return CustomMarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text) + public static CustomMarkwonAdapter createCustomTablesAndImagesAdapter(@NonNull BaseActivity activity, ImageAndGifEntry imageAndGifEntry) { + return CustomMarkwonAdapter.builder(activity, R.layout.adapter_default_entry, R.id.text) .include(TableBlock.class, TableEntry.create(builder -> builder .tableLayout(R.layout.adapter_table_block, R.id.table_layout) .textLayoutIsRoot(R.layout.view_table_entry_cell))) @@ -148,8 +149,8 @@ public class MarkdownUtils { } @NonNull - public static CustomMarkwonAdapter createCustomTablesAdapter() { - return CustomMarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text) + public static CustomMarkwonAdapter createCustomTablesAdapter(@NonNull BaseActivity activity) { + return CustomMarkwonAdapter.builder(activity, R.layout.adapter_default_entry, R.id.text) .include(TableBlock.class, TableEntry.create(builder -> builder .tableLayout(R.layout.adapter_table_block, R.id.table_layout) .textLayoutIsRoot(R.layout.view_table_entry_cell))) diff --git a/app/src/main/res/layout/adapter_table_block.xml b/app/src/main/res/layout/adapter_table_block.xml index a4adce5f..e924f89e 100644 --- a/app/src/main/res/layout/adapter_table_block.xml +++ b/app/src/main/res/layout/adapter_table_block.xml @@ -1,5 +1,5 @@ - - + -- cgit v1.2.3