From 65d943dc915a66f8de39750905742ae15ef48c2e Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 31 Aug 2021 22:45:54 +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 --- .../book/source/manage/BookSourceActivity.kt | 23 +++++++++------- .../book/source/manage/BookSourceViewModel.kt | 27 ------------------- .../app/ui/document/HandleFileActivity.kt | 3 ++- .../main/bookshelf/BaseBookshelfFragment.kt | 4 +-- app/src/main/res/values-es-rES/strings.xml | 2 ++ app/src/main/res/values-ja-rJP/strings.xml | 2 ++ app/src/main/res/values-pt-rBR/strings.xml | 2 ++ app/src/main/res/values-zh-rHK/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values-zh/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 11 files changed, 31 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 9adde1cdf..51490b8d1 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -10,7 +10,6 @@ import androidx.activity.viewModels import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.core.os.bundleOf -import androidx.documentfile.provider.DocumentFile import androidx.recyclerview.widget.ItemTouchHelper import com.google.android.material.snackbar.Snackbar import io.legado.app.R @@ -42,7 +41,6 @@ import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.* import kotlinx.coroutines.flow.* -import java.io.File import kotlin.math.min class BookSourceActivity : VMBaseActivity(), @@ -77,15 +75,16 @@ class BookSourceActivity : 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?) { @@ -331,7 +330,11 @@ class BookSourceActivity : VMBaseActivity viewModel.bottomSource(*adapter.selection.toTypedArray()) R.id.menu_add_group -> selectionAddToGroups() R.id.menu_remove_group -> selectionRemoveFromGroups() - R.id.menu_export_selection -> exportDir.launch(null) + R.id.menu_export_selection -> exportDir.launch { + mode = HandleFileContract.EXPORT + fileName = "bookSource.json" + file = GSON.toJson(adapter.selection).toByteArray() + } } return true } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 6cc8ea56a..d24047480 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.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.constant.AppPattern import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource import io.legado.app.utils.* -import java.io.File class BookSourceViewModel(application: Application) : BaseViewModel(application) { @@ -137,31 +135,6 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) } } - fun exportSelection(sources: List, file: File) { - execute { - val json = GSON.toJson(sources) - FileUtils.createFileIfNotExist(file, "exportBookSource.json") - .writeText(json) - }.onSuccess { - context.longToastOnUi("成功导出至\n${file.absolutePath}") - }.onError { - context.longToastOnUi("导出失败\n${it.localizedMessage}") - } - } - - fun exportSelection(sources: List, doc: DocumentFile) { - execute { - val json = GSON.toJson(sources) - doc.findFile("exportBookSource.json")?.delete() - doc.createFile("", "exportBookSource.json") - ?.writeText(context, json) - }.onSuccess { - context.longToastOnUi("成功导出至\n${doc.uri.path}") - }.onError { - context.longToastOnUi("导出失败\n${it.localizedMessage}") - } - } - fun shareSelection(sources: List, success: ((intent: Intent) -> Unit)) { execute { val tmpSharePath = "${context.filesDir}/shareBookSource.json" diff --git a/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt b/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt index 1bae24ae9..a3871a024 100644 --- a/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt +++ b/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt @@ -100,7 +100,8 @@ class HandleFileActivity : 111 -> getFileData()?.let { viewModel.upload(it.first, it.second) { url -> val uri = Uri.parse(url) - onResult(Intent().setData(uri)) + setResult(RESULT_OK, Intent().setData(uri)) + finish() } } else -> { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt index a7c35b1ca..1923583af 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt @@ -34,9 +34,9 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment - alert("导出成功") { + alert(R.string.export_success) { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { - editView.hint = "路径" + editView.hint = getString(R.string.path) editView.setText(uri.toString()) } customView { alertBinding.root } diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 554b84c99..4c3ca9c4f 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -867,4 +867,6 @@ 上传URL 下载URL规则 Ordenar por tiempo de respuesta + 导出成功 + 路径 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 8256a5bd3..9b4cfa620 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -867,4 +867,6 @@ 上传URL 下载URL规则 Sort by respond time + 导出成功 + 路径 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index d1b501673..a5be3a2bd 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -867,5 +867,7 @@ 上传URL 下载URL规则 Classificar por tempo de resposta + 导出成功 + 路径 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 576dade3b..e605675be 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -864,5 +864,7 @@ 上传URL 下载URL规则 響應時間排序 + 导出成功 + 路径 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 0b263ffef..40294fd8d 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -865,5 +865,7 @@ 上传URL 下载URL规则 響應時間排序 + 导出成功 + 路径 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index eea47f6a5..1f3f87bd6 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -866,5 +866,7 @@ 上传URL 下载URL规则 响应时间排序 + 导出成功 + 路径 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0db00b65b..07d23e8cc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -867,5 +867,7 @@ 使用Cronet网络组件 上传URL 下载URL规则 + 导出成功 + 路径