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) fun insert(vararg book: Book)
@Update @Update
fun update(vararg books: Book) fun update(vararg book: Book)
@Delete
fun delete(vararg book: Book)
@Query("delete from books where bookUrl = :bookUrl") @Query("delete from books where bookUrl = :bookUrl")
fun delete(bookUrl: String) fun delete(bookUrl: String)

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

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

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

@ -1,14 +1,18 @@
package io.legado.app.ui.book.arrange package io.legado.app.ui.book.arrange
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book
class ArrangeBookViewModel(application: Application) : BaseViewModel(application) { 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 { execute {
if (inBookshelf) { if (inBookshelf) {
bookData.value?.let { bookData.value?.let {
App.db.bookDao().delete(it.bookUrl) App.db.bookDao().delete(it)
} }
App.db.bookDao().insert(book) App.db.bookDao().insert(book)
} }
@ -202,7 +202,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun delBook(success: (() -> Unit)?) { fun delBook(success: (() -> Unit)?) {
execute { execute {
bookData.value?.let { bookData.value?.let {
App.db.bookDao().delete(it.bookUrl) App.db.bookDao().delete(it)
} }
inBookshelf = false inBookshelf = false
}.onSuccess { }.onSuccess {

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

Loading…
Cancel
Save