feat: 优化代码

pull/127/head
kunfei 5 years ago
parent 7d7ab7e4bf
commit 81d6580faa
  1. 9
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt
  2. 12
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.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) {

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

@ -35,7 +35,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
name = it
}
bundle.getString("author")?.let {
author = it
author = it.replace("作者:", "")
}
}
}

Loading…
Cancel
Save