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) callBack?.openBookInfo(book)
true 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 open(book: Book)
fun openBookInfo(book: Book) fun openBookInfo(book: Book)
fun search() fun search()
fun updateList(): List<String>
} }
} }

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

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

Loading…
Cancel
Save