From 8b81829bd73bce33f291417b4ac6be7dd8081bc0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 15 Aug 2019 09:09:27 +0800 Subject: [PATCH] up --- .../app/ui/bookinfo/BookInfoActivity.kt | 2 +- .../app/ui/changesource/ChangeSourceDialog.kt | 34 ++++++++++++++++--- .../ui/changesource/ChangeSourceViewModel.kt | 11 ++++++ 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt index c72da24b6..b43433de7 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt @@ -120,7 +120,7 @@ class BookInfoActivity : VMBaseActivity(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") 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 f8bf69c21..b4d2f4589 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 @@ -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() { 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 new file mode 100644 index 000000000..d5e36c5e3 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -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 = "" + +} \ No newline at end of file