pull/42/head
kunfei 5 years ago
parent 53e5cd51d2
commit c17727804c
  1. 13
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 13
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 17
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt
  4. 12
      app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt

@ -32,7 +32,6 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
override val viewModel: BookInfoViewModel
get() = getViewModel(BookInfoViewModel::class.java)
private var changeSourceDialog: ChangeSourceDialog? = null
private lateinit var adapter: ChapterListAdapter
override fun onActivityCreated(savedInstanceState: Bundle?) {
@ -49,10 +48,6 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
}
} ?: viewModel.loadBook(intent)
initOnClick()
savedInstanceState?.let {
changeSourceDialog =
supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog
}
}
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
@ -194,13 +189,9 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
}
}
tv_change_source.onClick {
if (changeSourceDialog == null) {
viewModel.bookData.value?.let {
changeSourceDialog = ChangeSourceDialog
.newInstance(it.name, it.author)
}
viewModel.bookData.value?.let {
ChangeSourceDialog.show(supportFragmentManager, it.name, it.author)
}
changeSourceDialog?.show(supportFragmentManager, ChangeSourceDialog.tag)
}
tv_current_chapter_info.onClick {
viewModel.bookData.value?.let {

@ -67,7 +67,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
get() = getViewModel(ReadBookViewModel::class.java)
private val requestCodeEditSource = 111
private var changeSourceDialog: ChangeSourceDialog? = null
private var timeElectricityReceiver: TimeElectricityReceiver? = null
override var readAloudStatus = Status.STOP
@ -83,10 +82,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
viewModel.bookData.observe(this, Observer { title_bar.title = it.name })
viewModel.chapterListFinish.observe(this, Observer { loadContent() })
viewModel.initData(intent)
savedInstanceState?.let {
changeSourceDialog =
supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog
}
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
@ -152,13 +147,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
when (item.itemId) {
R.id.menu_change_source -> {
read_menu.runMenuOut()
if (changeSourceDialog == null) {
viewModel.bookData.value?.let {
changeSourceDialog = ChangeSourceDialog
.newInstance(it.name, it.author)
}
viewModel.bookData.value?.let {
ChangeSourceDialog.show(supportFragmentManager, it.name, it.author)
}
changeSourceDialog?.show(supportFragmentManager, ChangeSourceDialog.tag)
}
R.id.menu_refresh -> {
viewModel.bookData.value?.let {

@ -8,6 +8,7 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.appcompat.widget.SearchView
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
@ -25,13 +26,15 @@ class ChangeSourceDialog : DialogFragment(),
companion object {
const val tag = "changeSourceDialog"
fun newInstance(name: String, author: String): ChangeSourceDialog {
return ChangeSourceDialog().apply {
val bundle = Bundle()
bundle.putString("name", name)
bundle.putString("author", author)
arguments = bundle
}
fun show(manager: FragmentManager, name: String, author: String) {
val fragment = (manager.findFragmentByTag(tag) as? ChangeSourceDialog)
?: ChangeSourceDialog().apply {
val bundle = Bundle()
bundle.putString("name", name)
bundle.putString("author", author)
arguments = bundle
}
fragment.show(manager, tag)
}
}

@ -1,5 +1,9 @@
package io.legado.app.ui.filechooser
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
@ -17,4 +21,12 @@ class FileChooserDialog : DialogFragment() {
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return super.onCreateView(inflater, container, savedInstanceState)
}
}
Loading…
Cancel
Save