From 81d6580faae9a9c4f0d4517099914800a449e2c7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 5 Mar 2020 18:45:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/changecover/ChangeCoverDialog.kt | 9 ++------- .../app/ui/book/changecover/ChangeCoverViewModel.kt | 12 +++++++++++- .../ui/book/changesource/ChangeSourceViewModel.kt | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt index 7a091c145..fdc64fa5f 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt @@ -62,17 +62,12 @@ class ChangeCoverDialog : DialogFragment(), }) tool_bar.setTitle(R.string.change_cover_source) arguments?.let { bundle -> - bundle.getString("name")?.let { - viewModel.name = it - } - bundle.getString("author")?.let { - viewModel.author = it - } + viewModel.initData(bundle) } recycler_view.layoutManager = GridLayoutManager(requireContext(), 3) adapter = CoverAdapter(requireContext(), this) recycler_view.adapter = adapter - viewModel.initData() + viewModel.loadDbSearchBook() } override fun changeTo(coverUrl: String) { diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt index 3ef77e076..d46f9ae48 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.book.changecover import android.app.Application +import android.os.Bundle import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel @@ -21,7 +22,16 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application private var task: Coroutine<*>? = null val searchStateData = MutableLiveData() - fun initData() { + fun initData(bundle: Bundle) { + bundle.getString("name")?.let { + name = it + } + bundle.getString("author")?.let { + author = it.replace("作者:", "") + } + } + + fun loadDbSearchBook() { execute { App.db.searchBookDao().getEnableHasCover(name, author) }.onSuccess { 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 06fd27a18..3e3c27265 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 @@ -35,7 +35,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio name = it } bundle.getString("author")?.let { - author = it + author = it.replace("作者:", "") } } }