pull/32/head
kunfei 5 years ago
parent 0875f84eb1
commit 8b81829bd7
  1. 2
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  2. 34
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt
  3. 11
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt

@ -120,7 +120,7 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
tv_change_source.onClick {
if (changeSourceDialog == null) {
viewModel.bookData.value?.let {
changeSourceDialog = ChangeSourceDialog(it.name, it.author)
changeSourceDialog = ChangeSourceDialog.newInstance(it.name, it.author)
}
}
changeSourceDialog?.show(supportFragmentManager, "changeSource")

@ -1,6 +1,7 @@
package io.legado.app.ui.changesource
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -8,17 +9,40 @@ import androidx.appcompat.widget.SearchView
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.dialog_change_source.*
class ChangeSourceDialog(val name: String, val author: String) : DialogFragment() {
class ChangeSourceDialog : DialogFragment() {
companion object {
fun newInstance(name: String, author: String): ChangeSourceDialog {
val changeSourceDialog = ChangeSourceDialog()
val bundle = Bundle()
bundle.putString("name", name)
bundle.putString("author", author)
changeSourceDialog.arguments = bundle
return changeSourceDialog
}
}
private lateinit var viewModel: ChangeSourceViewModel
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
viewModel = getViewModel(ChangeSourceViewModel::class.java)
return inflater.inflate(R.layout.dialog_change_source, container)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
arguments?.let { bundle ->
bundle.getString("name")?.let {
viewModel.name = it
}
bundle.getString("author")?.let {
viewModel.author = it
}
}
tool_bar.inflateMenu(R.menu.search_view)
showTitle()
initRecyclerView()
@ -27,12 +51,14 @@ class ChangeSourceDialog(val name: String, val author: String) : DialogFragment(
override fun onStart() {
super.onStart()
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
val dm = DisplayMetrics()
activity?.windowManager?.defaultDisplay?.getMetrics(dm)
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}
private fun showTitle() {
tool_bar.title = name
tool_bar.subtitle = getString(R.string.author_show, author)
tool_bar.title = viewModel.name
tool_bar.subtitle = getString(R.string.author_show, viewModel.author)
}
private fun initRecyclerView() {

@ -0,0 +1,11 @@
package io.legado.app.ui.changesource
import android.app.Application
import io.legado.app.base.BaseViewModel
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
var name: String = ""
var author: String = ""
}
Loading…
Cancel
Save