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.databinding.ActivityTranslucenceBinding
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.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -26,7 +27,7 @@ class FileAssociationActivity :
}
viewModel.importBookSourceLive.observe(this) {
binding.rotateLoading.hide()
ImportBookSourceDialog.start(supportFragmentManager, it, true)
supportFragmentManager.showDialog(ImportBookSourceDialog(it, true))
}
viewModel.importRssSourceLive.observe(this) {
binding.rotateLoading.hide()

@ -9,7 +9,6 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
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.theme.primaryColor
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.visible
/**
* 导入书源弹出窗口
*/
class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
class ImportBookSourceDialog() : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
companion object {
fun start(
fragmentManager: FragmentManager,
source: String,
finishOnDismiss: Boolean = false
) {
fragmentManager.showDialog<ImportBookSourceDialog> {
constructor(source: String, finishOnDismiss: Boolean = false) : this() {
arguments = Bundle().apply {
putString("source", source)
putBoolean("finishOnDismiss", finishOnDismiss)
}
}
}
private val binding by viewBinding(DialogRecyclerViewBinding::bind)
private val viewModel by viewModels<ImportBookSourceViewModel>()
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.databinding.ActivityTranslucenceBinding
import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.showDialog
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -22,8 +23,9 @@ class OnLineImportActivity :
override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.successLive.observe(this) {
when (it.first) {
"bookSource" -> ImportBookSourceDialog
.start(supportFragmentManager, it.second, true)
"bookSource" -> supportFragmentManager.showDialog(
ImportBookSourceDialog(it.second, true)
)
"rssSource" -> ImportRssSourceDialog
.start(supportFragmentManager, it.second, true)
"replaceRule" -> ImportReplaceRuleDialog
@ -40,7 +42,9 @@ class OnLineImportActivity :
return
}
when (it.path) {
"/bookSource" -> ImportBookSourceDialog.start(supportFragmentManager, url, true)
"/bookSource" -> supportFragmentManager.showDialog(
ImportBookSourceDialog(url, true)
)
"/rssSource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true)
"/replaceRule" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true)
"/textTocRule" -> viewModel.getText(url) { json ->
@ -56,7 +60,9 @@ class OnLineImportActivity :
viewModel.importReadConfig(bytes, this::finallyDialog)
}
"/importonline" -> when (it.host) {
"booksource" -> ImportBookSourceDialog.start(supportFragmentManager, url, true)
"booksource" -> supportFragmentManager.showDialog(
ImportBookSourceDialog(url, true)
)
"rsssource" -> ImportRssSourceDialog.start(supportFragmentManager, url, true)
"replace" -> ImportReplaceRuleDialog.start(supportFragmentManager, url, true)
else -> {

@ -95,7 +95,7 @@ class AudioPlayActivity :
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
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 {
startActivity<SourceLoginActivity> {

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

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

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

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

@ -30,10 +30,10 @@ class RssArticlesFragment() : VMBaseFragment<RssArticlesViewModel>(R.layout.frag
BaseRssArticlesAdapter.CallBack {
constructor(sortName: String, sortUrl: String) : this() {
val bundle = Bundle()
bundle.putString("sortName", sortName)
bundle.putString("sortUrl", sortUrl)
arguments = bundle
arguments = Bundle().apply {
putString("sortName", sortName)
putString("sortUrl", sortUrl)
}
}
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.ImportRssSourceDialog
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.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
@ -70,9 +71,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun openSubscription(ruleSub: RuleSub) {
when (ruleSub.type) {
0 -> {
ImportBookSourceDialog.start(supportFragmentManager, ruleSub.url)
}
0 -> supportFragmentManager.showDialog(ImportBookSourceDialog(ruleSub.url))
1 -> {
ImportRssSourceDialog.start(supportFragmentManager, ruleSub.url)
}

@ -24,6 +24,10 @@ inline fun <reified T : DialogFragment> FragmentManager.showDialog(
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) =
requireContext().defaultSharedPreferences.getBoolean(key, defValue)

Loading…
Cancel
Save