统一导入url为 legado://import/

pull/1155/head
gedoor 3 years ago
parent b9967c52ba
commit 1f761a5713
  1. 26
      app/src/main/AndroidManifest.xml
  2. 4
      app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt
  5. 2
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt
  6. 82
      app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt

@ -319,6 +319,32 @@
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="import"
android:scheme="legado" />
</intent-filter>
</activity>
<!-- 一键导入 -->
<activity
android:name=".ui.association.OnLineImportActivity"
android:configChanges="locale|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout"
android:theme="@style/AppTheme.Transparent">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="import"
android:scheme="legado" />
</intent-filter>
</activity>
<!-- 导入书源 -->
<activity

@ -21,13 +21,13 @@ class SharedReceiverActivity : AppCompatActivity() {
private fun initIntent() {
when {
Intent.ACTION_SEND == intent.action && intent.type == receivingType -> {
intent.action == Intent.ACTION_SEND && intent.type == receivingType -> {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
dispose(it)
}
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& Intent.ACTION_PROCESS_TEXT == intent.action
&& intent.action == Intent.ACTION_PROCESS_TEXT
&& intent.type == receivingType -> {
intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let {
dispose(it)

@ -60,7 +60,7 @@ class ImportBookSourceActivity :
finish()
}
}
}
} ?: finish()
}
private fun errorDialog(msg: String) {

@ -59,7 +59,7 @@ class ImportReplaceRuleActivity :
finish()
}
}
}
} ?: finish()
}
private fun errorDialog(msg: String) {

@ -59,7 +59,7 @@ class ImportRssSourceActivity :
finish()
}
}
}
} ?: finish()
}
private fun errorDialog(msg: String) {

@ -0,0 +1,82 @@
package io.legado.app.ui.association
import android.os.Bundle
import androidx.activity.viewModels
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.constant.Theme
import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding
class OnLineImportActivity : BaseActivity<ActivityTranslucenceBinding>(theme = Theme.Transparent) {
override val binding by viewBinding(ActivityTranslucenceBinding::inflate)
override fun onActivityCreated(savedInstanceState: Bundle?) {
intent.data?.let {
when (it.path) {
"bookSource" -> it.getQueryParameter("src")?.let { url ->
importBookSource(url)
}
"rssSource" -> it.getQueryParameter("src")?.let { url ->
importRssSource(url)
}
"replaceRule" -> it.getQueryParameter("src")?.let { url ->
startActivity<ImportReplaceRuleActivity> {
putExtra("source", url)
}
}
else -> {
}
}
}
}
private fun importBookSource(url: String) {
val viewModel by viewModels<ImportBookSourceViewModel>()
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))
}
})
viewModel.importSource(url)
}
private fun importRssSource(url: String) {
val viewModel by viewModels<ImportRssSourceViewModel>()
binding.rotateLoading.show()
viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide()
errorDialog(it)
})
viewModel.successLiveData.observe(this, {
binding.rotateLoading.hide()
if (it > 0) {
ImportRssSourceDialog().show(supportFragmentManager, "SourceDialog")
} else {
errorDialog(getString(R.string.wrong_format))
}
})
viewModel.importSource(url)
}
private fun errorDialog(msg: String) {
alert(getString(R.string.error), msg) {
okButton { }
onDismiss {
finish()
}
}.show()
}
}
Loading…
Cancel
Save