From 6c92f21a2682f1db8c73f0d1a7002c227eeb8eb8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 15:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/changecover/ChangeCoverDialog.kt | 4 ++-- .../legado/app/ui/changecover/ChangeCoverViewModel.kt | 11 +++++++++++ .../java/io/legado/app/ui/changecover/CoverAdapter.kt | 3 +++ .../legado/app/ui/changesource/ChangeSourceDialog.kt | 6 +----- .../app/ui/changesource/ChangeSourceViewModel.kt | 4 ++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index f566cbbbb..0eb939fe4 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -13,7 +13,7 @@ import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.dialog_change_source.* -class ChangeCoverDialog : DialogFragment() { +class ChangeCoverDialog : DialogFragment(), ChangeCoverViewModel.CallBack { companion object { const val tag = "changeCoverDialog" @@ -32,7 +32,7 @@ class ChangeCoverDialog : DialogFragment() { private var callBack: CallBack? = null private lateinit var viewModel: ChangeCoverViewModel - private lateinit var adapter: CoverAdapter + override lateinit var adapter: CoverAdapter override fun onStart() { super.onStart() diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt index 5f12c56b2..b38ced035 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.changecover import android.app.Application +import io.legado.app.App import io.legado.app.base.BaseViewModel class ChangeCoverViewModel(application: Application) : BaseViewModel(application) { @@ -8,5 +9,15 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application var name: String = "" var author: String = "" + fun initData() { + execute { + App.db.searchBookDao().getByNameAuthorEnable(name, author).let { + } + } + } + + interface CallBack { + var adapter: CoverAdapter + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt index 408acbeb4..0290d7749 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt @@ -22,4 +22,7 @@ class CoverAdapter(context: Context) : } } + interface CallBack { + fun changeTo() + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index edf3057a3..1097a936c 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -40,7 +40,7 @@ class ChangeSourceDialog : DialogFragment(), private var callBack: CallBack? = null private lateinit var viewModel: ChangeSourceViewModel - private lateinit var changeSourceAdapter: ChangeSourceAdapter + override lateinit var changeSourceAdapter: ChangeSourceAdapter override fun onStart() { super.onStart() @@ -139,10 +139,6 @@ class ChangeSourceDialog : DialogFragment(), override val bookUrl: String? get() = callBack?.oldBook?.bookUrl - override fun adapter(): ChangeSourceAdapter { - return changeSourceAdapter - } - interface CallBack { val oldBook: Book? fun changeTo(book: Book) diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 3b16a4359..cccdd0e71 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -40,7 +40,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio private fun upAdapter() { execute { - callBack?.adapter()?.let { + callBack?.changeSourceAdapter?.let { val books = searchBooks.toList() books.sorted() val diffResult = DiffUtil.calculateDiff(DiffCallBack(it.getItems(), books)) @@ -131,7 +131,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } interface CallBack { - fun adapter(): ChangeSourceAdapter + var changeSourceAdapter: ChangeSourceAdapter } override fun onCleared() {