pull/32/head
kunfei 5 years ago
parent c2b88b50fd
commit ec5a990dd7
  1. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt
  2. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  3. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@ -65,6 +65,13 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
callBack?.openBookInfo(book)
true
}
callBack?.let {
if (book.bookUrl in it.updateList()) {
rl_loading.show()
} else {
rl_loading.hide()
}
} ?: rl_loading.hide()
}
}
@ -72,5 +79,6 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
fun open(book: Book)
fun openBookInfo(book: Book)
fun search()
fun updateList(): List<String>
}
}

@ -73,6 +73,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
refresh_layout.setColorSchemeColors(accentColor)
refresh_layout.setOnRefreshListener {
refresh_layout.isRefreshing = false
viewModel.upChapterList()
}
tv_recent_reading.textColor = accentColor
rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
@ -117,6 +118,10 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
}
override fun updateList(): List<String> {
return viewModel.updateList
}
override fun onQueryTextSubmit(query: String?): Boolean {
context?.startActivity<SearchActivity>(Pair("key", query))
return false

@ -10,6 +10,9 @@ import kotlinx.coroutines.Dispatchers.IO
class BookshelfViewModel(application: Application) : BaseViewModel(application) {
val updateList = arrayListOf<String>()
fun saveBookGroup(group: String?) {
if (!group.isNullOrBlank()) {
execute {
@ -30,13 +33,14 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
if (book.origin != BookType.local) {
val bookSource = App.db.bookSourceDao().getBookSource(book.origin)
bookSource?.let {
updateList.add(book.bookUrl)
WebBook(bookSource).getChapterList(book).onSuccess(IO) {
it?.let {
if (it.size > App.db.bookChapterDao().getChapterCount(book.bookUrl)) {
}
App.db.bookChapterDao().insert(*it.toTypedArray())
}
}
}.onFinally { updateList.remove(book.bookUrl) }
}
}
}

Loading…
Cancel
Save