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" />
</intent-filter>
</activity>
<!-- 导入书源 -->
<activity
android:name=".ui.association.ImportBookSourceActivity"
android:configChanges="locale|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout"
android:theme="@style/AppTheme.Transparent" />
<!-- 导入订阅源 -->
<activity
android:name=".ui.association.ImportRssSourceActivity"

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

@ -15,7 +15,7 @@ import io.legado.app.utils.readText
import java.io.File
class FileAssociationViewModel(application: Application) : BaseViewModel(application) {
val importBookSourceLive = MutableLiveData<String>()
val successLiveData = MutableLiveData<Intent>()
val errorLiveData = MutableLiveData<String>()
@ -34,15 +34,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
//暂时根据文件内容判断属于什么
when {
content.contains("bookSourceUrl") -> {
successLiveData.postValue(
Intent(
context,
ImportBookSourceActivity::class.java
).apply {
val dataKey = IntentDataHelp.putData(content)
putExtra("dataKey", dataKey)
}
)
importBookSourceLive.postValue(IntentDataHelp.putData(content))
return@execute
}
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.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
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 io.legado.app.R
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.ItemSourceImportBinding
import io.legado.app.help.AppConfig
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.widget.dialog.WaitDialog
import io.legado.app.utils.dp
import io.legado.app.utils.putPrefBoolean
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.*
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 {
private val binding by viewBinding(DialogRecyclerViewBinding::bind)
companion object {
val viewModel: ImportBookSourceViewModel by activityViewModels()
lateinit var adapter: SourcesAdapter
fun start(fragmentManager: FragmentManager, source: String) {
ImportBookSourceDialog().apply {
arguments = Bundle().apply {
putString("source", source)
}
}.show(fragmentManager, "importBookSource")
}
}
private val binding by viewBinding(DialogRecyclerViewBinding::bind)
private val viewModel by viewModels<ImportBookSourceViewModel>()
private lateinit var adapter: SourcesAdapter
override fun onStart() {
super.onStart()
@ -60,11 +69,11 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setTitle(R.string.import_book_source)
binding.rotateLoading.show()
initMenu()
adapter = SourcesAdapter(requireContext())
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter
adapter.setItems(viewModel.allSources)
binding.tvCancel.visible()
binding.tvCancel.setOnClickListener {
dismissAllowingStateLoss()
@ -90,6 +99,31 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
adapter.notifyDataSetChanged()
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() {
@ -148,9 +182,13 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
return false
}
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
activity?.finish()
private fun errorDialog(msg: String) {
alert(getString(R.string.error), msg) {
okButton { }
onDismiss {
}
}.show()
}
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.primaryTextColor
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.edit.BookSourceEditActivity
import io.legado.app.ui.document.FilePicker
@ -63,18 +63,14 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private var snackBar: Snackbar? = null
private val qrResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult
startActivity<ImportBookSourceActivity> {
putExtra("source", it)
}
ImportBookSourceDialog.start(supportFragmentManager, it)
}
private val importDoc = registerForActivityResult(FilePicker()) { uri ->
uri ?: return@registerForActivityResult
try {
uri.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it)
startActivity<ImportBookSourceActivity> {
putExtra("dataKey", dataKey)
}
ImportBookSourceDialog.start(supportFragmentManager, dataKey)
}
} catch (e: Exception) {
toastOnUi("readTextError:${e.localizedMessage}")
@ -421,9 +417,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(","))
}
startActivity<ImportBookSourceActivity> {
putExtra("source", it)
}
ImportBookSourceDialog.start(supportFragmentManager, it)
}
}
cancelButton()

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

@ -25,6 +25,15 @@
android:layout_height="match_parent"
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>
<com.google.android.flexbox.FlexboxLayout

Loading…
Cancel
Save