pull/90/head^2
kunfei 5 years ago
parent 7712df964e
commit 5e6ddf402b
  1. 5
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 4
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  4. 18
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt
  5. 8
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt
  6. 4
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  7. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -60,7 +60,10 @@ interface BookDao {
fun insert(vararg book: Book)
@Update
fun update(vararg books: Book)
fun update(vararg book: Book)
@Delete
fun delete(vararg book: Book)
@Query("delete from books where bookUrl = :bookUrl")
fun delete(bookUrl: String)

@ -91,7 +91,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
fun changeTo(book1: Book) {
execute {
AudioPlay.book?.let {
App.db.bookDao().delete(it.bookUrl)
App.db.bookDao().delete(it)
}
withContext(Dispatchers.Main) {
@ -142,7 +142,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
fun removeFromBookshelf(success: (() -> Unit)?) {
execute {
AudioPlay.book?.let {
App.db.bookDao().delete(it.bookUrl)
App.db.bookDao().delete(it)
}
}.onSuccess {
success?.invoke()

@ -107,10 +107,10 @@ class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activi
getString(R.string.select_count, adapter.selectedBooks.size, adapter.getItems().size)
}
override fun deleteBook(bookUrl: String) {
override fun deleteBook(book: Book) {
alert(titleResource = R.string.sure, messageResource = R.string.sure_del) {
okButton {
viewModel.deleteBook(bookUrl)
viewModel.deleteBook(book)
}
}.show().applyTint()
}

@ -13,7 +13,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<Book>(context, R.layout.item_arrange_book) {
val selectedBooks: HashSet<String> = hashSetOf()
val selectedBooks: HashSet<Book> = hashSetOf()
fun isSelectAll(): Boolean {
return if (selectedBooks.isEmpty()) {
@ -26,7 +26,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
fun selectAll(selectAll: Boolean) {
if (selectAll) {
getItems().forEach {
selectedBooks.add(it.bookUrl)
selectedBooks.add(it)
}
notifyDataSetChanged()
callBack.upSelectCount()
@ -42,26 +42,26 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
tv_name.text = item.name
tv_author.text = context.getString(R.string.author_show, item.author)
tv_group.text = getGroupName(item.group)
checkbox.isChecked = selectedBooks.contains(item.bookUrl)
checkbox.isChecked = selectedBooks.contains(item)
checkbox.onClick {
if (checkbox.isChecked) {
selectedBooks.add(item.bookUrl)
selectedBooks.add(item)
} else {
selectedBooks.remove(item.bookUrl)
selectedBooks.remove(item)
}
callBack.upSelectCount()
}
onClick {
checkbox.isChecked = !checkbox.isChecked
if (checkbox.isChecked) {
selectedBooks.add(item.bookUrl)
selectedBooks.add(item)
} else {
selectedBooks.remove(item.bookUrl)
selectedBooks.remove(item)
}
callBack.upSelectCount()
}
tv_delete.onClick {
callBack.deleteBook(item.bookUrl)
callBack.deleteBook(item)
}
tv_group.onClick {
callBack.selectGroup()
@ -81,7 +81,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
interface CallBack {
val groupList: List<BookGroup>
fun upSelectCount()
fun deleteBook(bookUrl: String)
fun deleteBook(book: Book)
fun selectGroup()
}
}

@ -1,14 +1,18 @@
package io.legado.app.ui.book.arrange
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book
class ArrangeBookViewModel(application: Application) : BaseViewModel(application) {
fun deleteBook(vararg bookUrl: String) {
fun deleteBook(vararg book: Book) {
execute {
App.db.bookDao().delete()
}
}
}

@ -137,7 +137,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
execute {
if (inBookshelf) {
bookData.value?.let {
App.db.bookDao().delete(it.bookUrl)
App.db.bookDao().delete(it)
}
App.db.bookDao().insert(book)
}
@ -202,7 +202,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun delBook(success: (() -> Unit)?) {
execute {
bookData.value?.let {
App.db.bookDao().delete(it.bookUrl)
App.db.bookDao().delete(it)
}
inBookshelf = false
}.onSuccess {

@ -128,7 +128,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun changeTo(book1: Book) {
execute {
ReadBook.book?.let {
App.db.bookDao().delete(it.bookUrl)
App.db.bookDao().delete(it)
}
ReadBook.prevTextChapter = null
ReadBook.curTextChapter = null
@ -185,7 +185,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun removeFromBookshelf(success: (() -> Unit)?) {
execute {
ReadBook.book?.let {
App.db.bookDao().delete(it.bookUrl)
App.db.bookDao().delete(it)
}
}.onSuccess {
success?.invoke()

Loading…
Cancel
Save