feat: 优化

pull/209/head
kunfei 5 years ago
parent 7d59375fc1
commit 455418ecaa
  1. 7
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt

@ -58,7 +58,10 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) :
popupMenu.inflate(R.menu.change_source_item)
popupMenu.setOnMenuItemClickListener {
when (it.itemId) {
R.id.menu_disable_book_source -> callBack.disableSource(searchBook.origin)
R.id.menu_disable_book_source -> {
callBack.disableSource(searchBook)
removeItem(searchBook)
}
}
true
}
@ -68,6 +71,6 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) :
interface CallBack {
val bookUrl: String?
fun changeTo(searchBook: SearchBook)
fun disableSource(sourceUrl: String)
fun disableSource(searchBook: SearchBook)
}
}

@ -185,8 +185,8 @@ class ChangeSourceDialog : BaseDialogFragment(),
override val bookUrl: String?
get() = callBack?.oldBook?.bookUrl
override fun disableSource(sourceUrl: String) {
viewModel.disableSource(sourceUrl)
override fun disableSource(searchBook: SearchBook) {
viewModel.disableSource(searchBook)
}
interface CallBack {

@ -165,12 +165,13 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
searchPool.close()
}
fun disableSource(sourceUrl: String) {
fun disableSource(searchBook: SearchBook) {
execute {
App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source ->
App.db.bookSourceDao().getBookSource(searchBook.origin)?.let { source ->
source.enabled = false
App.db.bookSourceDao().update(source)
}
searchBooks.remove(searchBook)
}
}

Loading…
Cancel
Save