From 30451d35ab8fe8a707c525f168120fb390baf616 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 6 Dec 2020 17:42:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/rss/source/manage/RssSourceActivity.kt | 3 +- .../rss/source/manage/RssSourceViewModel.kt | 30 ++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index d2346e67d..39822da96 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -93,7 +93,8 @@ class RssSourceActivity : VMBaseActivity startActivityForResult(qrRequestCode) R.id.menu_group_manage -> GroupManageDialog() .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() else -> if (item.groupId == R.id.source_group) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 5c72b503d..1d96f1a15 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -1,15 +1,15 @@ package io.legado.app.ui.rss.source.manage import android.app.Application +import android.content.Intent import android.text.TextUtils +import androidx.core.content.FileProvider import androidx.documentfile.provider.DocumentFile import io.legado.app.App +import io.legado.app.BuildConfig import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssSource -import io.legado.app.utils.FileUtils -import io.legado.app.utils.GSON -import io.legado.app.utils.splitNotBlank -import io.legado.app.utils.writeText +import io.legado.app.utils.* import org.jetbrains.anko.toast import java.io.File @@ -104,6 +104,28 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) } } + fun shareSelection(sources: List, 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) { execute { val sources = App.db.rssSourceDao().noGroup