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() {