diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index b9bb67838..eca15ba9c 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -32,7 +32,6 @@ class BookInfoActivity : VMBaseActivity(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(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(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 { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 4dc9d14b2..d42299fe5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -67,7 +67,6 @@ class ReadBookActivity : VMBaseActivity(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(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(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 { 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 674db46c1..038311a37 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 @@ -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) } } diff --git a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt index 6c1fc6fbd..f3fce06f9 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt @@ -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) + } + } \ No newline at end of file