Browse Source

TopicActivity fix (propagation of touch events to Viewholders)

pull/70/head
Ezerous 4 years ago
parent
commit
5fe9af78f9
  1. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java
  2. 5
      app/src/main/java/gr/thmmy/mthmmy/views/CustomRecyclerView.java
  3. 48
      app/src/main/java/gr/thmmy/mthmmy/views/ScrollAwareRecyclerView.java
  4. 2
      app/src/main/res/layout/activity_topic.xml

1
app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java

@ -19,7 +19,6 @@ import gr.thmmy.mthmmy.base.BaseFragment;
import gr.thmmy.mthmmy.model.PostSummary;
import gr.thmmy.mthmmy.model.TopicSummary;
import gr.thmmy.mthmmy.views.ReactiveWebView;
import timber.log.Timber;
/**
* {@link RecyclerView.Adapter} that can display a {@link TopicSummary} and makes a call to the

5
app/src/main/java/gr/thmmy/mthmmy/views/CustomRecyclerView.java

@ -5,10 +5,9 @@ import android.util.AttributeSet;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
//Custom RecyclerView, so EdgeEffect and SwipeRefresh both work
public class CustomRecyclerView extends RecyclerView {
public class CustomRecyclerView extends ScrollAwareRecyclerView {
private volatile boolean enableRefreshing = true;
public CustomRecyclerView(Context context) {
@ -40,7 +39,6 @@ public class CustomRecyclerView extends RecyclerView {
else if (((LinearLayoutManager) getLayoutManager()).findFirstCompletelyVisibleItemPosition() != 0)
enableRefreshing = false;
super.onScrollStateChanged(state);
}
@ -51,5 +49,4 @@ public class CustomRecyclerView extends RecyclerView {
else
return super.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, 0, offsetInWindow);
}
}

48
app/src/main/java/gr/thmmy/mthmmy/views/ScrollAwareRecyclerView.java

@ -0,0 +1,48 @@
package gr.thmmy.mthmmy.views;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.recyclerview.widget.RecyclerView;
// Based on https://stackoverflow.com/a/46453825
// Not needed in LatestPostsFragment as there are no other ScrollAware Behaviors to steal touch events
public class ScrollAwareRecyclerView extends RecyclerView {
public ScrollAwareRecyclerView(Context context) {
super(context);
}
public ScrollAwareRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollAwareRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
final int scrollState = getScrollState();
boolean requestCancelDisallowInterceptTouchEvent
= ((scrollState == SCROLL_STATE_SETTLING) || (scrollState == SCROLL_STATE_IDLE));
boolean consumed = super.onInterceptTouchEvent(event);
final int action = event.getActionMasked();
if (action == MotionEvent.ACTION_DOWN) {
if (requestCancelDisallowInterceptTouchEvent) {
getParent().requestDisallowInterceptTouchEvent(false);
// only if it touched the top or the bottom
if (!canScrollVertically(-1) || !canScrollVertically(1)) {
// stop scroll to enable child view to get the touch event
stopScroll();
// do not consume the event
return false;
}
}
}
return consumed;
}
}

2
app/src/main/res/layout/activity_topic.xml

@ -37,7 +37,7 @@
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
<gr.thmmy.mthmmy.views.ScrollAwareRecyclerView
android:id="@+id/topic_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"

Loading…
Cancel
Save