diff --git a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt index 94c176028..144628dc5 100644 --- a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt @@ -20,7 +20,7 @@ import kotlinx.coroutines.CoroutineScope import org.jetbrains.anko.sdk27.listeners.onClick -class FindBookAdapter(private val scope: CoroutineScope) : +class FindBookAdapter(private val scope: CoroutineScope, val callBack: CallBack) : PagedListAdapter(DIFF_CALLBACK) { var exIndex = 0 @@ -58,6 +58,7 @@ class FindBookAdapter(private val scope: CoroutineScope) : notifyItemChanged(position) } notifyItemChanged(oldEx) + callBack.scrollTo(position) } if (exIndex == position) { rotate_loading.show() @@ -65,7 +66,6 @@ class FindBookAdapter(private val scope: CoroutineScope) : bookSource.getExploreRule().getExploreKinds(bookSource.bookSourceUrl) }.onSuccess { it?.let { - rotate_loading.hide() gl_child.visible() var rowNum = 0 var columnNum = 0 @@ -89,12 +89,20 @@ class FindBookAdapter(private val scope: CoroutineScope) : } } } + }.onFinally { + rotate_loading.hide() } } else { + rotate_loading.hide() gl_child.gone() } } } class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) + + interface CallBack { + + fun scrollTo(pos: Int) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt index e991b501a..97a532801 100644 --- a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt @@ -16,10 +16,11 @@ import io.legado.app.lib.theme.ATH import kotlinx.android.synthetic.main.fragment_find_book.* import kotlinx.android.synthetic.main.view_title_bar.* -class FindBookFragment : BaseFragment(R.layout.fragment_find_book) { +class FindBookFragment : BaseFragment(R.layout.fragment_find_book), + FindBookAdapter.CallBack { private lateinit var adapter: FindBookAdapter - private var findLiveData:LiveData>? = null + private var findLiveData: LiveData>? = null override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) @@ -34,7 +35,7 @@ class FindBookFragment : BaseFragment(R.layout.fragment_find_book) { private fun initRecyclerView() { ATH.applyEdgeEffectColor(rv_find) rv_find.layoutManager = LinearLayoutManager(context) - adapter = FindBookAdapter(this) + adapter = FindBookAdapter(this, this) rv_find.adapter = adapter } @@ -43,4 +44,8 @@ class FindBookFragment : BaseFragment(R.layout.fragment_find_book) { findLiveData = LivePagedListBuilder(App.db.bookSourceDao().observeFind(), 2000).build() findLiveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) }) } + + override fun scrollTo(pos: Int) { + rv_find.scrollToPosition(pos) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/item_find_book.xml b/app/src/main/res/layout/item_find_book.xml index 1d3fa7c4c..eef807484 100644 --- a/app/src/main/res/layout/item_find_book.xml +++ b/app/src/main/res/layout/item_find_book.xml @@ -6,6 +6,7 @@ android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="10dp" + android:gravity="center" android:orientation="vertical"> + android:visibility="gone" + app:loading_width="2dp" /> \ No newline at end of file