diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index cbd0f61ce..30d275df7 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.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) diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt index 5adc2c7be..b5dd5bfba 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index 3baabc568..b6204e90b 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -107,10 +107,10 @@ class ArrangeBookActivity : VMBaseActivity(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() } diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt index 44fdecda7..dab74dc4b 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt @@ -13,7 +13,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class ArrangeBookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_arrange_book) { - val selectedBooks: HashSet = hashSetOf() + val selectedBooks: HashSet = 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 fun upSelectCount() - fun deleteBook(bookUrl: String) + fun deleteBook(book: Book) fun selectGroup() } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt index 76e890886..c7e571447 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt @@ -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() + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 0a54aaeac..d7ff22277 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index bb4ef95f0..ed5d9d04d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -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()