pull/1171/head
gedoor 3 years ago
parent 64c8ada0ad
commit 1c10b4e7fe
  1. 5
      app/src/main/AndroidManifest.xml
  2. 4
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  3. 12
      app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt
  4. 62
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt
  5. 64
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  6. 14
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  7. 6
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt
  8. 9
      app/src/main/res/layout/dialog_recycler_view.xml

@ -335,11 +335,6 @@
<data android:scheme="yuedu" /> <data android:scheme="yuedu" />
</intent-filter> </intent-filter>
</activity> </activity>
<!-- 导入书源 -->
<activity
android:name=".ui.association.ImportBookSourceActivity"
android:configChanges="locale|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout"
android:theme="@style/AppTheme.Transparent" />
<!-- 导入订阅源 --> <!-- 导入订阅源 -->
<activity <activity
android:name=".ui.association.ImportRssSourceActivity" android:name=".ui.association.ImportRssSourceActivity"

@ -19,6 +19,10 @@ class FileAssociationActivity :
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.rotateLoading.show() binding.rotateLoading.show()
viewModel.importBookSourceLive.observe(this) {
binding.rotateLoading.hide()
ImportBookSourceDialog.start(supportFragmentManager, it)
}
viewModel.errorLiveData.observe(this, { viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide() binding.rotateLoading.hide()
toastOnUi(it) toastOnUi(it)

@ -15,7 +15,7 @@ import io.legado.app.utils.readText
import java.io.File import java.io.File
class FileAssociationViewModel(application: Application) : BaseViewModel(application) { class FileAssociationViewModel(application: Application) : BaseViewModel(application) {
val importBookSourceLive = MutableLiveData<String>()
val successLiveData = MutableLiveData<Intent>() val successLiveData = MutableLiveData<Intent>()
val errorLiveData = MutableLiveData<String>() val errorLiveData = MutableLiveData<String>()
@ -34,15 +34,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
//暂时根据文件内容判断属于什么 //暂时根据文件内容判断属于什么
when { when {
content.contains("bookSourceUrl") -> { content.contains("bookSourceUrl") -> {
successLiveData.postValue( importBookSourceLive.postValue(IntentDataHelp.putData(content))
Intent(
context,
ImportBookSourceActivity::class.java
).apply {
val dataKey = IntentDataHelp.putData(content)
putExtra("dataKey", dataKey)
}
)
return@execute return@execute
} }
content.contains("sourceUrl") -> { content.contains("sourceUrl") -> {

@ -1,62 +0,0 @@
package io.legado.app.ui.association
import android.os.Bundle
import androidx.activity.viewModels
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Theme
import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.viewbindingdelegate.viewBinding
class ImportBookSourceActivity :
VMBaseActivity<ActivityTranslucenceBinding, ImportBookSourceViewModel>(
theme = Theme.Transparent
) {
override val binding by viewBinding(ActivityTranslucenceBinding::inflate)
override val viewModel by viewModels<ImportBookSourceViewModel>()
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.rotateLoading.show()
viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide()
errorDialog(it)
})
viewModel.successLiveData.observe(this, {
binding.rotateLoading.hide()
if (it > 0) {
ImportBookSourceDialog().show(supportFragmentManager, "SourceDialog")
} else {
errorDialog(getString(R.string.wrong_format))
}
})
initData()
}
private fun initData() {
intent.getStringExtra("dataKey")?.let {
IntentDataHelp.getData<String>(it)?.let { source ->
viewModel.importSource(source)
return
}
}
intent.getStringExtra("source")?.let {
viewModel.importSource(it)
return
}
finish()
}
private fun errorDialog(msg: String) {
alert(getString(R.string.error), msg) {
okButton { }
onDismiss {
finish()
}
}.show()
}
}

@ -2,14 +2,14 @@ package io.legado.app.ui.association
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MenuItem 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.activityViewModels import androidx.fragment.app.FragmentManager
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
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
@ -23,13 +23,11 @@ import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.databinding.ItemSourceImportBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.widget.dialog.WaitDialog import io.legado.app.ui.widget.dialog.WaitDialog
import io.legado.app.utils.dp import io.legado.app.utils.*
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
/** /**
@ -37,10 +35,21 @@ import io.legado.app.utils.visible
*/ */
class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private val binding by viewBinding(DialogRecyclerViewBinding::bind) companion object {
fun start(fragmentManager: FragmentManager, source: String) {
ImportBookSourceDialog().apply {
arguments = Bundle().apply {
putString("source", source)
}
}.show(fragmentManager, "importBookSource")
}
val viewModel: ImportBookSourceViewModel by activityViewModels() }
lateinit var adapter: SourcesAdapter
private val binding by viewBinding(DialogRecyclerViewBinding::bind)
private val viewModel by viewModels<ImportBookSourceViewModel>()
private lateinit var adapter: SourcesAdapter
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
@ -60,11 +69,11 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setTitle(R.string.import_book_source) binding.toolBar.setTitle(R.string.import_book_source)
binding.rotateLoading.show()
initMenu() initMenu()
adapter = SourcesAdapter(requireContext()) adapter = SourcesAdapter(requireContext())
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
adapter.setItems(viewModel.allSources)
binding.tvCancel.visible() binding.tvCancel.visible()
binding.tvCancel.setOnClickListener { binding.tvCancel.setOnClickListener {
dismissAllowingStateLoss() dismissAllowingStateLoss()
@ -90,6 +99,31 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
upSelectText() upSelectText()
} }
viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide()
errorDialog(it)
})
viewModel.successLiveData.observe(this, {
binding.rotateLoading.hide()
if (it > 0) {
adapter.setItems(viewModel.allSources)
} else {
errorDialog(getString(R.string.wrong_format))
}
})
val source = arguments?.getString("source")
if (source.isNullOrEmpty()) {
dismiss()
return
}
if (source.isAbsUrl()) {
viewModel.importSource(source)
} else {
IntentDataHelp.getData<String>(source)?.let {
viewModel.importSource(it)
return
}
}
} }
private fun upSelectText() { private fun upSelectText() {
@ -148,9 +182,13 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
return false return false
} }
override fun onDismiss(dialog: DialogInterface) { private fun errorDialog(msg: String) {
super.onDismiss(dialog) alert(getString(R.string.error), msg) {
activity?.finish() okButton { }
onDismiss {
}
}.show()
} }
inner class SourcesAdapter(context: Context) : inner class SourcesAdapter(context: Context) :

@ -27,7 +27,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.service.help.CheckSource import io.legado.app.service.help.CheckSource
import io.legado.app.ui.association.ImportBookSourceActivity import io.legado.app.ui.association.ImportBookSourceDialog
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.document.FilePicker import io.legado.app.ui.document.FilePicker
@ -63,18 +63,14 @@ 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
startActivity<ImportBookSourceActivity> { ImportBookSourceDialog.start(supportFragmentManager, it)
putExtra("source", it)
}
} }
private val importDoc = registerForActivityResult(FilePicker()) { uri -> private val importDoc = registerForActivityResult(FilePicker()) { uri ->
uri ?: return@registerForActivityResult uri ?: return@registerForActivityResult
try { try {
uri.readText(this)?.let { uri.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it) val dataKey = IntentDataHelp.putData(it)
startActivity<ImportBookSourceActivity> { ImportBookSourceDialog.start(supportFragmentManager, dataKey)
putExtra("dataKey", dataKey)
}
} }
} catch (e: Exception) { } catch (e: Exception) {
toastOnUi("readTextError:${e.localizedMessage}") toastOnUi("readTextError:${e.localizedMessage}")
@ -421,9 +417,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
cacheUrls.add(0, it) cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
startActivity<ImportBookSourceActivity> { ImportBookSourceDialog.start(supportFragmentManager, it)
putExtra("source", it)
}
} }
} }
cancelButton() cancelButton()

@ -13,7 +13,7 @@ import io.legado.app.data.entities.RuleSub
import io.legado.app.databinding.ActivityRuleSubBinding import io.legado.app.databinding.ActivityRuleSubBinding
import io.legado.app.databinding.DialogRuleSubEditBinding import io.legado.app.databinding.DialogRuleSubEditBinding
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.association.ImportBookSourceActivity import io.legado.app.ui.association.ImportBookSourceDialog
import io.legado.app.ui.association.ImportReplaceRuleActivity import io.legado.app.ui.association.ImportReplaceRuleActivity
import io.legado.app.ui.association.ImportRssSourceActivity import io.legado.app.ui.association.ImportRssSourceActivity
import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.ItemTouchCallback
@ -74,9 +74,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun openSubscription(ruleSub: RuleSub) { override fun openSubscription(ruleSub: RuleSub) {
when (ruleSub.type) { when (ruleSub.type) {
0 -> { 0 -> {
startActivity<ImportBookSourceActivity> { ImportBookSourceDialog.start(supportFragmentManager, ruleSub.url)
putExtra("source", ruleSub.url)
}
} }
1 -> { 1 -> {
startActivity<ImportRssSourceActivity> { startActivity<ImportRssSourceActivity> {

@ -25,6 +25,15 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollbars="none" /> android:scrollbars="none" />
<io.legado.app.ui.widget.anima.RotateLoading
android:id="@+id/rotate_loading"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_margin="6dp"
android:visibility="gone"
android:layout_gravity="center"
app:loading_width="2dp" />
</FrameLayout> </FrameLayout>
<com.google.android.flexbox.FlexboxLayout <com.google.android.flexbox.FlexboxLayout

Loading…
Cancel
Save