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.inflate(R.menu.change_source_item)
popupMenu.setOnMenuItemClickListener { popupMenu.setOnMenuItemClickListener {
when (it.itemId) { 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 true
} }
@ -68,6 +71,6 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) :
interface CallBack { interface CallBack {
val bookUrl: String? val bookUrl: String?
fun changeTo(searchBook: SearchBook) fun changeTo(searchBook: SearchBook)
fun disableSource(sourceUrl: String) fun disableSource(searchBook: SearchBook)
} }
} }

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

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

Loading…
Cancel
Save