From 455418ecaa926a1f6fbb73419fccb0a3c7e83b1b Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 1 May 2020 23:12:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/changesource/ChangeSourceAdapter.kt | 7 +++++-- .../legado/app/ui/book/changesource/ChangeSourceDialog.kt | 4 ++-- .../app/ui/book/changesource/ChangeSourceViewModel.kt | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index 287754b84..3a148a2c2 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.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) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index 75df41680..09fa066ec 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index 93b02a425..e5adf9e85 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -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) } }