diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index 2e7445a11..c4ae61ac1 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -10,7 +10,6 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView -import androidx.documentfile.provider.DocumentFile import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R @@ -39,7 +38,6 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Job import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch -import java.io.File /** * 替换规则管理 @@ -79,15 +77,16 @@ class ReplaceRuleActivity : VMBaseActivity uri ?: return@registerForActivityResult - if (uri.isContentScheme()) { - DocumentFile.fromTreeUri(this, uri)?.let { - viewModel.exportSelection(adapter.selection, it) + alert(R.string.export_success) { + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + editView.hint = getString(R.string.path) + editView.setText(uri.toString()) } - } else { - uri.path?.let { - viewModel.exportSelection(adapter.selection, File(it)) + customView { alertBinding.root } + okButton { + sendToClip(uri.toString()) } - } + }.show() } override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -231,7 +230,11 @@ class ReplaceRuleActivity : VMBaseActivity viewModel.disableSelection(adapter.selection) R.id.menu_top_sel -> viewModel.topSelect(adapter.selection) R.id.menu_bottom_sel -> viewModel.bottomSelect(adapter.selection) - R.id.menu_export_selection -> exportDir.launch(null) + R.id.menu_export_selection -> exportDir.launch { + mode = HandleFileContract.EXPORT + fileName = "exportReplaceRule.json" + file = GSON.toJson(adapter.selection).toByteArray() + } } return false } diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt index 48a9abc2e..9f8aaa92e 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt @@ -2,12 +2,10 @@ package io.legado.app.ui.replace import android.app.Application import android.text.TextUtils -import androidx.documentfile.provider.DocumentFile import io.legado.app.base.BaseViewModel import io.legado.app.data.appDb import io.legado.app.data.entities.ReplaceRule -import io.legado.app.utils.* -import java.io.File +import io.legado.app.utils.splitNotBlank class ReplaceRuleViewModel(application: Application) : BaseViewModel(application) { @@ -93,31 +91,6 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application } } - fun exportSelection(sources: LinkedHashSet, file: File) { - execute { - val json = GSON.toJson(sources) - FileUtils.createFileIfNotExist(file, "exportReplaceRule.json") - .writeText(json) - }.onSuccess { - context.toastOnUi("成功导出至\n${file.absolutePath}") - }.onError { - context.toastOnUi("导出失败\n${it.localizedMessage}") - } - } - - fun exportSelection(sources: LinkedHashSet, doc: DocumentFile) { - execute { - val json = GSON.toJson(sources) - doc.findFile("exportReplaceRule.json")?.delete() - doc.createFile("", "exportReplaceRule.json") - ?.writeText(context, json) - }.onSuccess { - context.toastOnUi("成功导出至\n${doc.uri.path}") - }.onError { - context.toastOnUi("导出失败\n${it.localizedMessage}") - } - } - fun addGroup(group: String) { execute { val sources = appDb.replaceRuleDao.noGroup 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 a0e4de3b9..8e4562176 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 @@ -9,7 +9,6 @@ import android.view.SubMenu import androidx.activity.viewModels import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView -import androidx.documentfile.provider.DocumentFile import androidx.recyclerview.widget.ItemTouchHelper import io.legado.app.R import io.legado.app.base.VMBaseActivity @@ -35,7 +34,6 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Job import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch -import java.io.File /** * 订阅源管理 @@ -67,15 +65,16 @@ class RssSourceActivity : VMBaseActivity uri ?: return@registerForActivityResult - if (uri.isContentScheme()) { - DocumentFile.fromTreeUri(this, uri)?.let { - viewModel.exportSelection(adapter.selection, it) + alert(R.string.export_success) { + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + editView.hint = getString(R.string.path) + editView.setText(uri.toString()) } - } else { - uri.path?.let { - viewModel.exportSelection(adapter.selection, File(it)) + customView { alertBinding.root } + okButton { + sendToClip(uri.toString()) } - } + }.show() } override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -126,7 +125,11 @@ class RssSourceActivity : VMBaseActivity viewModel.enableSelection(adapter.selection) R.id.menu_disable_selection -> viewModel.disableSelection(adapter.selection) R.id.menu_del_selection -> viewModel.delSelection(adapter.selection) - R.id.menu_export_selection -> exportDir.launch(null) + R.id.menu_export_selection -> exportDir.launch { + mode = HandleFileContract.EXPORT + fileName = "exportRssSource.json" + file = GSON.toJson(adapter.selection).toByteArray() + } R.id.menu_top_sel -> viewModel.topSource(*adapter.selection.toTypedArray()) R.id.menu_bottom_sel -> viewModel.bottomSource(*adapter.selection.toTypedArray()) } 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 76b0ac1fe..b0a80eec2 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 @@ -4,14 +4,12 @@ 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.base.BaseViewModel import io.legado.app.constant.AppConst import io.legado.app.data.appDb import io.legado.app.data.entities.RssSource import io.legado.app.help.DefaultData import io.legado.app.utils.* -import java.io.File class RssSourceViewModel(application: Application) : BaseViewModel(application) { @@ -79,31 +77,6 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) } } - fun exportSelection(sources: List, file: File) { - execute { - val json = GSON.toJson(sources) - FileUtils.createFileIfNotExist(file, "exportRssSource.json") - .writeText(json) - }.onSuccess { - context.toastOnUi("成功导出至\n${file.absolutePath}") - }.onError { - context.toastOnUi("导出失败\n${it.localizedMessage}") - } - } - - fun exportSelection(sources: List, doc: DocumentFile) { - execute { - val json = GSON.toJson(sources) - doc.findFile("exportRssSource.json")?.delete() - doc.createFile("", "exportRssSource.json") - ?.writeText(context, json) - }.onSuccess { - context.toastOnUi("成功导出至\n${doc.uri.path}") - }.onError { - context.toastOnUi("导出失败\n${it.localizedMessage}") - } - } - fun shareSelection(sources: List, success: ((intent: Intent) -> Unit)) { execute { val tmpSharePath = "${context.filesDir}/shareRssSource.json"