From 68ee7bae7662aaddc1e7acbff13aaff05d86d9fe Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 16 Feb 2020 18:29:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/main/explore/ExploreAdapter.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index 4d29a79c3..6c4691284 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -23,8 +23,8 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_find_book) { - private var exIndex = 0 + private var scrollTo = -1 override fun convert(holder: ItemViewHolder, item: BookSource, payloads: MutableList) { with(holder.itemView) { @@ -35,6 +35,9 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca iv_status.setImageResource(R.drawable.ic_remove) rotate_loading.loadingColor = context.accentColor rotate_loading.show() + if (scrollTo >= 0) { + callBack.scrollTo(scrollTo) + } Coroutine.async(scope) { item.getExploreKinds() }.onSuccess { kindList -> @@ -59,6 +62,10 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca } }.onFinally { rotate_loading.hide() + if (scrollTo >= 0) { + callBack.scrollTo(scrollTo) + scrollTo = -1 + } } } else { iv_status.setImageResource(R.drawable.ic_add) @@ -76,11 +83,10 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca exIndex = if (exIndex == position) -1 else position notifyItemChanged(oldEx, false) if (exIndex != -1) { + scrollTo = position + callBack.scrollTo(position) notifyItemChanged(position, false) } - postDelayed({ - callBack.scrollTo(position) - }, 200) } ll_title.onLongClick { showMenu(ll_title, holder.layoutPosition)