From b9379a787f46f8b5db66a13b76b6f523f1f6c8c0 Mon Sep 17 00:00:00 2001 From: GKF Date: Thu, 1 Nov 2018 15:40:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../help/MyItemTouchHelpCallback.java | 18 ++++++++++++++++++ .../view/fragment/BookListFragment.java | 1 + 2 files changed, 19 insertions(+) diff --git a/app/src/main/java/com/monke/monkeybook/help/MyItemTouchHelpCallback.java b/app/src/main/java/com/monke/monkeybook/help/MyItemTouchHelpCallback.java index f69509ea57..a02cdaa78b 100644 --- a/app/src/main/java/com/monke/monkeybook/help/MyItemTouchHelpCallback.java +++ b/app/src/main/java/com/monke/monkeybook/help/MyItemTouchHelpCallback.java @@ -1,5 +1,7 @@ package com.monke.monkeybook.help; +import android.support.annotation.Nullable; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -10,6 +12,13 @@ */ public class MyItemTouchHelpCallback extends ItemTouchHelper.Callback { + + SwipeRefreshLayout swipeRefreshLayout; + + public void setSwipeRefreshLayout(SwipeRefreshLayout swipeRefreshLayout) { + this.swipeRefreshLayout = swipeRefreshLayout; + } + /** * Item操作的回调 */ @@ -130,6 +139,15 @@ public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { } } + @Override + public void onSelectedChanged(@Nullable RecyclerView.ViewHolder viewHolder, int actionState) { + super.onSelectedChanged(viewHolder, actionState); + if (swipeRefreshLayout != null) { + final boolean swiping = actionState == ItemTouchHelper.ACTION_STATE_DRAG; + swipeRefreshLayout.setEnabled(!swiping); + } + } + public interface OnItemTouchCallbackListener { /** * 当某个Item被滑动删除的时候 diff --git a/app/src/main/java/com/monke/monkeybook/view/fragment/BookListFragment.java b/app/src/main/java/com/monke/monkeybook/view/fragment/BookListFragment.java index f1f0da4536..4b0795fb39 100644 --- a/app/src/main/java/com/monke/monkeybook/view/fragment/BookListFragment.java +++ b/app/src/main/java/com/monke/monkeybook/view/fragment/BookListFragment.java @@ -122,6 +122,7 @@ protected void bindEvent() { refreshLayout.setRefreshing(false); }); MyItemTouchHelpCallback itemTouchHelpCallback = new MyItemTouchHelpCallback(); + itemTouchHelpCallback.setSwipeRefreshLayout(refreshLayout); if (bookPx.equals("2")) { itemTouchHelpCallback.setDragEnable(true); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelpCallback);