pull/525/head
gedoor 4 years ago
parent 9f4a2e623f
commit 30451d35ab
  1. 3
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  2. 30
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt

@ -93,7 +93,8 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode) R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode)
R.id.menu_group_manage -> GroupManageDialog() R.id.menu_group_manage -> GroupManageDialog()
.show(supportFragmentManager, "rssGroupManage") .show(supportFragmentManager, "rssGroupManage")
R.id.menu_share_source -> { R.id.menu_share_source -> viewModel.shareSelection(adapter.getSelection()) {
startActivity(Intent.createChooser(it, getString(R.string.share_selected_source)))
} }
R.id.menu_help -> showHelp() R.id.menu_help -> showHelp()
else -> if (item.groupId == R.id.source_group) { else -> if (item.groupId == R.id.source_group) {

@ -1,15 +1,15 @@
package io.legado.app.ui.rss.source.manage package io.legado.app.ui.rss.source.manage
import android.app.Application import android.app.Application
import android.content.Intent
import android.text.TextUtils import android.text.TextUtils
import androidx.core.content.FileProvider
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.App import io.legado.app.App
import io.legado.app.BuildConfig
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.utils.FileUtils import io.legado.app.utils.*
import io.legado.app.utils.GSON
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.writeText
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.io.File import java.io.File
@ -104,6 +104,28 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun shareSelection(sources: List<RssSource>, success: ((intent: Intent) -> Unit)) {
execute {
val intent = Intent(Intent.ACTION_SEND)
val file = FileUtils.createFileWithReplace("${context.filesDir}/shareRssSource.json")
file.writeText(GSON.toJson(sources))
val fileUri = FileProvider.getUriForFile(
context,
BuildConfig.APPLICATION_ID + ".fileProvider",
file
)
intent.type = "text/*"
intent.putExtra(Intent.EXTRA_STREAM, fileUri)
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent
}.onSuccess {
success.invoke(it)
}.onError {
toast(it.msg)
}
}
fun addGroup(group: String) { fun addGroup(group: String) {
execute { execute {
val sources = App.db.rssSourceDao().noGroup val sources = App.db.rssSourceDao().noGroup

Loading…
Cancel
Save