pull/1319/head
gedoor 3 years ago
parent 82a218947e
commit e24f62186a
  1. 3
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  2. 20
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  3. 14
      app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  5. 11
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  8. 6
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  9. 8
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt
  10. 5
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt
  11. 4
      app/src/main/java/io/legado/app/utils/FragmentExtensions.kt

@ -5,6 +5,7 @@ import androidx.activity.viewModels
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.utils.showDialog
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -26,7 +27,7 @@ class FileAssociationActivity :
} }
viewModel.importBookSourceLive.observe(this) { viewModel.importBookSourceLive.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.hide()
ImportBookSourceDialog.start(supportFragmentManager, it, true) supportFragmentManager.showDialog(ImportBookSourceDialog(it, true))
} }
viewModel.importRssSourceLive.observe(this) { viewModel.importRssSourceLive.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.hide()

@ -9,7 +9,6 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R import io.legado.app.R
@ -27,30 +26,25 @@ import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.dialog.WaitDialog import io.legado.app.ui.widget.dialog.WaitDialog
import io.legado.app.utils.* import io.legado.app.utils.dp
import io.legado.app.utils.putPrefBoolean
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
/** /**
* 导入书源弹出窗口 * 导入书源弹出窗口
*/ */
class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class ImportBookSourceDialog() : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
companion object { constructor(source: String, finishOnDismiss: Boolean = false) : this() {
arguments = Bundle().apply {
fun start(
fragmentManager: FragmentManager,
source: String,
finishOnDismiss: Boolean = false
) {
fragmentManager.showDialog<ImportBookSourceDialog> {
putString("source", source) putString("source", source)
putBoolean("finishOnDismiss", finishOnDismiss) putBoolean("finishOnDismiss", finishOnDismiss)
} }
} }
}
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
private val viewModel by viewModels<ImportBookSourceViewModel>() private val viewModel by viewModels<ImportBookSourceViewModel>()
private val adapter by lazy { SourcesAdapter(requireContext()) } private val adapter by lazy { SourcesAdapter(requireContext()) }

@ -6,6 +6,7 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.showDialog
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -22,8 +23,9 @@ class OnLineImportActivity :
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.successLive.observe(this) { viewModel.successLive.observe(this) {
when (it.first) { when (it.first) {
"bookSource" -> ImportBookSourceDialog "bookSource" -> supportFragmentManager.showDialog(
.start(supportFragmentManager, it.second, true) ImportBookSourceDialog(it.second, true)
)
"rssSource" -> ImportRssSourceDialog "rssSource" -> ImportRssSourceDialog
.start(supportFragmentManager, it.second, true) .start(supportFragmentManager, it.second, true)
"replaceRule" -> ImportReplaceRuleDialog "replaceRule" -> ImportReplaceRuleDialog
@ -40,7 +42,9 @@ class OnLineImportActivity :
return return
} }
when (it.path) { when (it.path) {
"/bookSource" -> ImportBookSourceDialog.start(supportFragmentManager, url, true) "/bookSource" -> supportFragmentManager.showDialog(
ImportBookSourceDialog(url, true)
)
"/rssSource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true) "/rssSource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true)
"/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true) "/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true)
"/textTocRule" -> viewModel.getText(url) { json -> "/textTocRule" -> viewModel.getText(url) { json ->
@ -56,7 +60,9 @@ class OnLineImportActivity :
viewModel.importReadConfig(bytes, this::finallyDialog) viewModel.importReadConfig(bytes, this::finallyDialog)
} }
"/importonline" -> when (it.host) { "/importonline" -> when (it.host) {
"booksource" -> ImportBookSourceDialog.start(supportFragmentManager, url, true) "booksource" -> supportFragmentManager.showDialog(
ImportBookSourceDialog(url, true)
)
"rsssource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true) "rsssource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true)
"replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true) "replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true)
else -> { else -> {

@ -95,7 +95,7 @@ class AudioPlayActivity :
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_change_source -> AudioPlay.book?.let { R.id.menu_change_source -> AudioPlay.book?.let {
ChangeSourceDialog.show(supportFragmentManager, it.name, it.author) supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author))
} }
R.id.menu_login -> AudioPlay.bookSource?.let { R.id.menu_login -> AudioPlay.bookSource?.let {
startActivity<SourceLoginActivity> { startActivity<SourceLoginActivity> {

@ -5,7 +5,6 @@ import android.view.*
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -29,20 +28,16 @@ import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class ChangeSourceDialog : BaseDialogFragment(), class ChangeSourceDialog() : BaseDialogFragment(),
Toolbar.OnMenuItemClickListener, Toolbar.OnMenuItemClickListener,
ChangeSourceAdapter.CallBack { ChangeSourceAdapter.CallBack {
companion object { constructor(name: String, author: String) : this() {
const val tag = "changeSourceDialog" arguments = Bundle().apply {
fun show(manager: FragmentManager, name: String, author: String) {
manager.showDialog<ChangeSourceDialog> {
putString("name", name) putString("name", name)
putString("author", author) putString("author", author)
} }
} }
}
private val binding by viewBinding(DialogChangeSourceBinding::bind) private val binding by viewBinding(DialogChangeSourceBinding::bind)
private val groups = linkedSetOf<String>() private val groups = linkedSetOf<String>()

@ -288,7 +288,7 @@ class BookInfoActivity :
} }
tvChangeSource.setOnClickListener { tvChangeSource.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
ChangeSourceDialog.show(supportFragmentManager, it.name, it.author) supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author))
} }
} }
tvTocView.setOnClickListener { tvTocView.setOnClickListener {

@ -226,7 +226,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
R.id.menu_change_source -> { R.id.menu_change_source -> {
binding.readMenu.runMenuOut() binding.readMenu.runMenuOut()
ReadBook.book?.let { ReadBook.book?.let {
ChangeSourceDialog.show(supportFragmentManager, it.name, it.author) supportFragmentManager.showDialog(ChangeSourceDialog(it.name, it.author))
} }
} }
R.id.menu_refresh -> { R.id.menu_refresh -> {

@ -62,13 +62,13 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private var snackBar: Snackbar? = null private var snackBar: Snackbar? = null
private val qrResult = registerForActivityResult(QrCodeResult()) { private val qrResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult it ?: return@registerForActivityResult
ImportBookSourceDialog.start(supportFragmentManager, it) supportFragmentManager.showDialog(ImportBookSourceDialog(it))
} }
private val importDoc = registerForActivityResult(HandleFileContract()) { uri -> private val importDoc = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult uri ?: return@registerForActivityResult
try { try {
uri.readText(this)?.let { uri.readText(this)?.let {
ImportBookSourceDialog.start(supportFragmentManager, it) supportFragmentManager.showDialog(ImportBookSourceDialog(it))
} }
} catch (e: Exception) { } catch (e: Exception) {
toastOnUi("readTextError:${e.localizedMessage}") toastOnUi("readTextError:${e.localizedMessage}")
@ -440,7 +440,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
cacheUrls.add(0, it) cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
ImportBookSourceDialog.start(supportFragmentManager, it) supportFragmentManager.showDialog(ImportBookSourceDialog(it))
} }
} }
cancelButton() cancelButton()

@ -30,10 +30,10 @@ class RssArticlesFragment() : VMBaseFragment<RssArticlesViewModel>(R.layout.frag
BaseRssArticlesAdapter.CallBack { BaseRssArticlesAdapter.CallBack {
constructor(sortName: String, sortUrl: String) : this() { constructor(sortName: String, sortUrl: String) : this() {
val bundle = Bundle() arguments = Bundle().apply {
bundle.putString("sortName", sortName) putString("sortName", sortName)
bundle.putString("sortUrl", sortUrl) putString("sortUrl", sortUrl)
arguments = bundle }
} }
private val binding by viewBinding(FragmentRssArticlesBinding::bind) private val binding by viewBinding(FragmentRssArticlesBinding::bind)

@ -16,6 +16,7 @@ import io.legado.app.ui.association.ImportBookSourceDialog
import io.legado.app.ui.association.ImportReplaceRuleDialog import io.legado.app.ui.association.ImportReplaceRuleDialog
import io.legado.app.ui.association.ImportRssSourceDialog import io.legado.app.ui.association.ImportRssSourceDialog
import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.utils.showDialog
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -70,9 +71,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun openSubscription(ruleSub: RuleSub) { override fun openSubscription(ruleSub: RuleSub) {
when (ruleSub.type) { when (ruleSub.type) {
0 -> { 0 -> supportFragmentManager.showDialog(ImportBookSourceDialog(ruleSub.url))
ImportBookSourceDialog.start(supportFragmentManager, ruleSub.url)
}
1 -> { 1 -> {
ImportRssSourceDialog.start(supportFragmentManager, ruleSub.url) ImportRssSourceDialog.start(supportFragmentManager, ruleSub.url)
} }

@ -24,6 +24,10 @@ inline fun <reified T : DialogFragment> FragmentManager.showDialog(
dialog.show(this, T::class.simpleName) dialog.show(this, T::class.simpleName)
} }
fun FragmentManager.showDialog(dialogFragment: DialogFragment) {
dialogFragment.show(this, dialogFragment::class.simpleName)
}
fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) = fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) =
requireContext().defaultSharedPreferences.getBoolean(key, defValue) requireContext().defaultSharedPreferences.getBoolean(key, defValue)

Loading…
Cancel
Save