aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockScrollView.java73
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/customviews/slidr/widget/SliderPanel.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java52
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java9
-rw-r--r--app/src/main/res/layout/adapter_table_block.xml4
13 files changed, 66 insertions, 92 deletions
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<Comment
}
});
commentMarkdownView.setLayoutManager(linearLayoutManager);
- markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(mImageAndGifEntry);
+ markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(mActivity, mImageAndGifEntry);
markwonAdapter.setOnClickListener(view -> {
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<RecyclerVi
}
});
commentMarkdownView.setLayoutManager(linearLayoutManager);
- mMarkwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(mImageAndGifEntry);
+ mMarkwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(mActivity, mImageAndGifEntry);
commentMarkdownView.setAdapter(mMarkwonAdapter);
itemView.setBackgroundColor(mCommentBackgroundColor);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
index 0ee06061..c51cfab8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
@@ -421,7 +421,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
activity.startActivity(intent);
}
});
- mMarkwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(mImageAndGifEntry);
+ mMarkwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(mActivity, mImageAndGifEntry);
}
public void setCanStartActivity(boolean canStartActivity) {
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 02600b27..6170d7dd 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java
@@ -172,7 +172,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
if (activity.typeface != null) {
binding.shortNameTextViewItemRule.setTypeface(activity.typeface);
}
- markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(imageAndGifEntry);
+ markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(activity, imageAndGifEntry);
SwipeLockLinearLayoutManager swipeLockLinearLayoutManager = new SwipeLockLinearLayoutManager(activity,
new SwipeLockInterface() {
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockScrollView.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockScrollView.java
deleted file mode 100644
index 557a26f0..00000000
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockScrollView.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package ml.docilealligator.infinityforreddit.customviews;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.widget.HorizontalScrollView;
-
-import androidx.annotation.Nullable;
-
-/** {@link HorizontalScrollView} that listens for touch events and locks swipes
- * if it can be scrolled to the right. {@link SwipeLockInterface} must be set for
- * locking to work.
- */
-public class SwipeLockScrollView extends HorizontalScrollView implements SwipeLockView {
- @Nullable
- private SwipeLockInterface swipeLockInterface = null;
- private boolean locked = false;
-
- public SwipeLockScrollView(Context context) {
- super(context);
- }
-
- public SwipeLockScrollView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public SwipeLockScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- }
-
- @Override
- public void setSwipeLockInterface(@Nullable SwipeLockInterface swipeLockInterface) {
- this.swipeLockInterface = swipeLockInterface;
- }
-
- @Override
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- updateSwipeLock(ev);
- return super.onInterceptTouchEvent(ev);
- }
-
- @SuppressLint("ClickableViewAccessibility") // we are just listening to touch events
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- updateSwipeLock(ev);
- return super.onTouchEvent(ev);
- }
-
- /**
- * Unlocks swipe if the view cannot be scrolled right anymore or if {@code ev} is
- * {@link MotionEvent#ACTION_UP} or {@link MotionEvent#ACTION_CANCEL}
- */
- private void updateSwipeLock(MotionEvent ev) {
- if (swipeLockInterface != null) {
- int action = ev.getAction();
- if (action == MotionEvent.ACTION_UP ||
- action == MotionEvent.ACTION_CANCEL) {
- // calling SlidrInterface#unlock aborts the swipe
- // so don't call unlock if it is already unlocked
- if (locked) {
- swipeLockInterface.unlockSwipe();
- locked = false;
- }
- } else {
- if (!locked) {
- swipeLockInterface.lockSwipe();
- locked = true;
- }
- }
- }
- }
-}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/slidr/widget/SliderPanel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/slidr/widget/SliderPanel.java
index 831e896d..e4cb842b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/slidr/widget/SliderPanel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/slidr/widget/SliderPanel.java
@@ -123,6 +123,10 @@ public class SliderPanel extends FrameLayout {
return defaultSlidrInterface;
}
+ public boolean isLocked() {
+ return isLocked;
+ }
+
private final SlidrInterface defaultSlidrInterface = new SlidrInterface() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
index 5c0f6808..11b9dae3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
@@ -177,7 +177,7 @@ public class SidebarFragment extends Fragment {
Markwon markwon = MarkdownUtils.createFullRedditMarkwon(activity,
miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor,
spoilerBackgroundColor, onLinkLongClickListener);
- CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(imageAndGifEntry);
+ CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(activity, imageAndGifEntry);
markwonAdapter.setOnLongClickListener(view -> {
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<Entry<Node, Holder>> entries;
private final Entry<Node, Holder> defaultEntry;
private final MarkwonReducer reducer;
@@ -43,9 +46,11 @@ public class CustomMarkwonAdapter extends MarkwonAdapter {
@SuppressWarnings("WeakerAccess")
CustomMarkwonAdapter(
+ @NonNull BaseActivity activity,
@NonNull SparseArray<Entry<Node, Holder>> entries,
@NonNull Entry<Node, Holder> 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<? extends Node, ? extends Holder> defaultEntry) {
+ public static CustomBuilderImpl builder(@NonNull BaseActivity activity, @NonNull Entry<? extends Node, ? extends Holder> defaultEntry) {
//noinspection unchecked
- return new CustomBuilderImpl((Entry<Node, Holder>) defaultEntry);
+ return new CustomBuilderImpl(activity, (Entry<Node, Holder>) 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<Entry<Node, Holder>> entries = new SparseArray<>(3);
private final Entry<Node, Holder> defaultEntry;
private MarkwonReducer reducer;
- CustomBuilderImpl(@NonNull Entry<Node, Holder> defaultEntry) {
+ CustomBuilderImpl(@NonNull BaseActivity activity, @NonNull Entry<Node, Holder> 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 @@
<?xml version="1.0" encoding="utf-8"?>
-<ml.docilealligator.infinityforreddit.customviews.SwipeLockScrollView
+<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -13,4 +13,4 @@
android:layout_height="wrap_content"
android:stretchColumns="*" />
-</ml.docilealligator.infinityforreddit.customviews.SwipeLockScrollView>
+</HorizontalScrollView>