pull/43/head
kunfei 5 years ago
parent 5b827ca9b0
commit 98b3d25377
  1. 4
      app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt
  2. 18
      app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt
  3. 6
      app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt

@ -167,10 +167,14 @@ abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context) : Rec
synchronized(lock) {
val oldSize = getActualItemCount()
if (this.items.addAll(newItems)) {
if (oldSize == 0 && getHeaderCount() == 0) {
notifyDataSetChanged()
} else {
notifyItemRangeInserted(oldSize + getHeaderCount(), newItems.size)
}
}
}
}
fun removeItem(position: Int) {
synchronized(lock) {

@ -24,6 +24,7 @@ class ExploreShowActivity : VMBaseActivity<ExploreShowViewModel>(R.layout.activi
private lateinit var adapter: ExploreShowAdapter
private lateinit var loadMoreView: View
private var hasMore = true
private var isLoading = true
override fun onActivityCreated(savedInstanceState: Bundle?) {
title_bar.title = intent.getStringExtra("exploreName")
@ -41,9 +42,26 @@ class ExploreShowActivity : VMBaseActivity<ExploreShowViewModel>(R.layout.activi
LayoutInflater.from(this).inflate(R.layout.view_load_more, recycler_view, false)
adapter.addFooterView(loadMoreView)
loadMoreView.rotate_loading.show()
recycler_view.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (!recyclerView.canScrollVertically(1)) {
scrollToBottom()
}
}
})
}
private fun scrollToBottom() {
adapter.let {
if (hasMore && !isLoading) {
viewModel.explore()
}
}
}
private fun upData(books: List<SearchBook>) {
isLoading = false
if (books.isEmpty() && adapter.isEmpty()) {
hasMore = false
loadMoreView.rotate_loading.hide(View.INVISIBLE)

@ -29,8 +29,9 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application
}
fun explore() {
bookSource?.let { source ->
exploreUrl?.let { url ->
val source = bookSource
val url = exploreUrl
if (source != null && url != null) {
WebBook(source).exploreBook(url, page, this)
.timeout(30000L)
.onSuccess(IO) { searchBooks ->
@ -42,6 +43,5 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application
}
}
}
}
}
Loading…
Cancel
Save