pull/1295/head
gedoor 3 years ago
parent 14bf8960ff
commit 65d943dc91
  1. 23
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  2. 27
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  3. 3
      app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt
  4. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt
  5. 2
      app/src/main/res/values-es-rES/strings.xml
  6. 2
      app/src/main/res/values-ja-rJP/strings.xml
  7. 2
      app/src/main/res/values-pt-rBR/strings.xml
  8. 2
      app/src/main/res/values-zh-rHK/strings.xml
  9. 2
      app/src/main/res/values-zh-rTW/strings.xml
  10. 2
      app/src/main/res/values-zh/strings.xml
  11. 2
      app/src/main/res/values/strings.xml

@ -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<ActivityBookSourceBinding, BookSourceViewModel>(),
@ -77,15 +75,16 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
private val exportDir = registerForActivityResult(HandleFileContract()) { uri ->
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<ActivityBookSourceBinding, BookSourceV
R.id.menu_bottom_sel -> 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
}

@ -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<BookSource>, 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<BookSource>, 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<BookSource>, success: ((intent: Intent) -> Unit)) {
execute {
val tmpSharePath = "${context.filesDir}/shareBookSource.json"

@ -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 -> {

@ -34,9 +34,9 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
}
private val exportBookshelf = registerForActivityResult(HandleFileContract()) {
it?.let { uri ->
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 }

@ -867,4 +867,6 @@
<string name="upload_url">上传URL</string>
<string name="download_url_rule">下载URL规则</string>
<string name="sort_by_respondTime">Ordenar por tiempo de respuesta</string>
<string name="export_success">导出成功</string>
<string name="path">路径</string>
</resources>

@ -867,4 +867,6 @@
<string name="upload_url">上传URL</string>
<string name="download_url_rule">下载URL规则</string>
<string name="sort_by_respondTime">Sort by respond time</string>
<string name="export_success">导出成功</string>
<string name="path">路径</string>
</resources>

@ -867,5 +867,7 @@
<string name="upload_url">上传URL</string>
<string name="download_url_rule">下载URL规则</string>
<string name="sort_by_respondTime">Classificar por tempo de resposta</string>
<string name="export_success">导出成功</string>
<string name="path">路径</string>
</resources>

@ -864,5 +864,7 @@
<string name="upload_url">上传URL</string>
<string name="download_url_rule">下载URL规则</string>
<string name="sort_by_respondTime">響應時間排序</string>
<string name="export_success">导出成功</string>
<string name="path">路径</string>
</resources>

@ -865,5 +865,7 @@
<string name="upload_url">上传URL</string>
<string name="download_url_rule">下载URL规则</string>
<string name="sort_by_respondTime">響應時間排序</string>
<string name="export_success">导出成功</string>
<string name="path">路径</string>
</resources>

@ -866,5 +866,7 @@
<string name="upload_url">上传URL</string>
<string name="download_url_rule">下载URL规则</string>
<string name="sort_by_respondTime">响应时间排序</string>
<string name="export_success">导出成功</string>
<string name="path">路径</string>
</resources>

@ -867,5 +867,7 @@
<string name="pref_cronet_summary">使用Cronet网络组件</string>
<string name="upload_url">上传URL</string>
<string name="download_url_rule">下载URL规则</string>
<string name="export_success">导出成功</string>
<string name="path">路径</string>
</resources>

Loading…
Cancel
Save