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)