aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java27
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CustomView/MarkwonLinearLayoutManager.java42
3 files changed, 81 insertions, 8 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
index c51c2bc5..11cc629d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
@@ -37,7 +37,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.livefront.bridge.Bridge;
import com.r0adkll.slidr.Slidr;
-import com.r0adkll.slidr.model.SlidrConfig;
+import com.r0adkll.slidr.model.SlidrInterface;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -176,7 +176,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
private LinearLayoutManager mLinearLayoutManager;
private CommentAndPostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller mSmoothScroller;
- private PostCommentSortTypeBottomSheetFragment postCommentSortTypeBottomSheetFragment;
+ private PostCommentSortTypeBottomSheetFragment mPostCommentSortTypeBottomSheetFragment;
+ private SlidrInterface mSlidrInterface;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -193,8 +194,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
EventBus.getDefault().register(this);
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
- SlidrConfig config = new SlidrConfig.Builder().sensitivity(0.1f).build();
- Slidr.attach(this, config);
+ mSlidrInterface = Slidr.attach(this);
}
Resources resources = getResources();
@@ -349,7 +349,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
postListPosition = getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, -1);
}
- postCommentSortTypeBottomSheetFragment = new PostCommentSortTypeBottomSheetFragment();
+ mPostCommentSortTypeBottomSheetFragment = new PostCommentSortTypeBottomSheetFragment();
}
@Override
@@ -1306,7 +1306,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
return true;
case R.id.action_sort_view_post_detail_activity:
if (mPost != null) {
- postCommentSortTypeBottomSheetFragment.show(getSupportFragmentManager(), postCommentSortTypeBottomSheetFragment.getTag());
+ mPostCommentSortTypeBottomSheetFragment.show(getSupportFragmentManager(), mPostCommentSortTypeBottomSheetFragment.getTag());
}
return true;
case R.id.action_view_crosspost_parent_view_post_detail_activity:
@@ -1524,4 +1524,12 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
fetchComments(false, false, sortType.getType().value);
mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply();
}
+
+ public void lockSwipeRightToGoBack() {
+ mSlidrInterface.lock();
+ }
+
+ public void unlockSwipeRightToGoBack() {
+ mSlidrInterface.unlock();
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
index 806d60a7..cd56c175 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -72,6 +72,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.LoadSubredditIconAsyncTask
import ml.docilealligator.infinityforreddit.AsyncTask.LoadUserDataAsyncTask;
import ml.docilealligator.infinityforreddit.CommentData;
import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView;
+import ml.docilealligator.infinityforreddit.CustomView.MarkwonLinearLayoutManager;
import ml.docilealligator.infinityforreddit.FetchComment;
import ml.docilealligator.infinityforreddit.Fragment.ModifyCommentBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Post;
@@ -507,7 +508,18 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
if (mPost.getSelfText() != null && !mPost.getSelfText().equals("")) {
((PostDetailViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE);
- ((PostDetailViewHolder) holder).mContentMarkdownView.setLayoutManager(new LinearLayoutManager(mActivity));
+ LinearLayoutManager linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
+ @Override
+ public void onScrolledLeft() {
+ ((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack();
+ }
+
+ @Override
+ public void onScrolledRight() {
+ ((ViewPostDetailActivity) mActivity).unlockSwipeRightToGoBack();
+ }
+ });
+ ((PostDetailViewHolder) holder).mContentMarkdownView.setLayoutManager(linearLayoutManager);
((PostDetailViewHolder) holder).mContentMarkdownView.setAdapter(mMarkwonAdapter);
mMarkwonAdapter.setMarkdown(mMarkwon, mPost.getSelfText());
mMarkwonAdapter.notifyDataSetChanged();
@@ -530,7 +542,18 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
if (!mPost.getSelfText().equals("")) {
((PostDetailViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE);
- ((PostDetailViewHolder) holder).mContentMarkdownView.setLayoutManager(new LinearLayoutManager(mActivity));
+ LinearLayoutManager linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
+ @Override
+ public void onScrolledLeft() {
+ ((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack();
+ }
+
+ @Override
+ public void onScrolledRight() {
+ ((ViewPostDetailActivity) mActivity).unlockSwipeRightToGoBack();
+ }
+ });
+ ((PostDetailViewHolder) holder).mContentMarkdownView.setLayoutManager(linearLayoutManager);
((PostDetailViewHolder) holder).mContentMarkdownView.setAdapter(mMarkwonAdapter);
mMarkwonAdapter.setMarkdown(mMarkwon, mPost.getSelfText());
mMarkwonAdapter.notifyDataSetChanged();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomView/MarkwonLinearLayoutManager.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomView/MarkwonLinearLayoutManager.java
new file mode 100644
index 00000000..56f3dddc
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomView/MarkwonLinearLayoutManager.java
@@ -0,0 +1,42 @@
+package ml.docilealligator.infinityforreddit.CustomView;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewTreeObserver;
+import android.widget.HorizontalScrollView;
+
+import androidx.recyclerview.widget.LinearLayoutManager;
+
+public class MarkwonLinearLayoutManager extends LinearLayoutManager {
+ public interface HorizontalScrollViewScrolledListener {
+ void onScrolledLeft();
+ void onScrolledRight();
+ }
+
+ private HorizontalScrollViewScrolledListener horizontalScrollViewScrolledListener;
+
+ public MarkwonLinearLayoutManager(Context context, HorizontalScrollViewScrolledListener horizontalScrollViewScrolledListener) {
+ super(context);
+ this.horizontalScrollViewScrolledListener = horizontalScrollViewScrolledListener;
+ }
+
+ @Override
+ public void addView(View child) {
+ super.addView(child);
+ if (child instanceof HorizontalScrollView) {
+ child.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
+ private int x = 0;
+ @Override
+ public void onScrollChanged() {
+ if (child.getScrollX() < x) {
+ horizontalScrollViewScrolledListener.onScrolledLeft();
+ } else {
+ horizontalScrollViewScrolledListener.onScrolledRight();
+ }
+
+ x = child.getScrollX();
+ }
+ });
+ }
+ }
+}