pull/32/head
kunfei 5 years ago
parent 4bdc7eb890
commit 029a73f09b
  1. 12
      app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt
  2. 9
      app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt
  3. 4
      app/src/main/res/layout/item_find_book.xml

@ -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<BookSource, FindBookAdapter.MyViewHolder>(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)
}
}

@ -16,7 +16,8 @@ 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<PagedList<BookSource>>? = null
@ -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)
}
}

@ -6,6 +6,7 @@
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
@ -51,6 +52,7 @@
android:id="@+id/rotate_loading"
android:layout_width="36dp"
android:layout_height="36dp"
android:visibility="gone" />
android:visibility="gone"
app:loading_width="2dp" />
</LinearLayout>
Loading…
Cancel
Save