mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-24 18:08:23 +01:00
Prevent activity from sliding right when the markdown table is swiping left by user by using a custom LinearLayoutManager instead of setting the sensitivity of the Slidr library.
This commit is contained in:
parent
6ef39a3821
commit
d74c7f50fa
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user