pull/1415/head
gedoor 3 years ago
parent 4ad07aefc3
commit 39bc7e29d0
  1. 28
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  2. 5
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  3. 17
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  4. 9
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  5. 5
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  6. 10
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  7. 7
      app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt
  8. 19
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt
  9. 27
      app/src/main/java/io/legado/app/ui/document/HandleFileContract.kt
  10. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt
  11. 9
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  12. 7
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  13. 9
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  14. 5
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt

@ -46,19 +46,19 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private val adapter by lazy { CacheAdapter(this, this) }
private var booksFlowJob: Job? = null
private var menu: Menu? = null
private var exportPosition = -1
private val groupList: ArrayList<BookGroup> = arrayListOf()
private var groupId: Long = -1
private val exportDir = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
private val exportDir = registerForActivityResult(HandleFileContract()) { result ->
result.uri?.let { uri ->
if (uri.isContentScheme()) {
ACache.get(this@CacheActivity).put(exportBookPathKey, uri.toString())
startExport(uri.toString())
startExport(uri.toString(), result.requestCode)
} else {
uri.path?.let { path ->
ACache.get(this@CacheActivity).put(exportBookPathKey, path)
startExport(path)
startExport(path, result.requestCode)
}
}
}
}
@ -128,8 +128,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
R.id.menu_export_no_chapter_name -> AppConfig.exportNoChapterName = !item.isChecked
R.id.menu_export_web_dav -> AppConfig.exportToWebDav = !item.isChecked
R.id.menu_export_folder -> {
exportPosition = -1
selectExportFolder()
selectExportFolder(-1)
}
R.id.menu_export_file_name -> alertExportFileName()
R.id.menu_export_type -> showExportTypeConfig()
@ -236,26 +235,24 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
}
override fun export(position: Int) {
exportPosition = position
val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey)
if (path.isNullOrEmpty()) {
selectExportFolder()
selectExportFolder(position)
} else {
startExport(path)
startExport(path, position)
}
}
private fun exportAll() {
exportPosition = -10
val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey)
if (path.isNullOrEmpty()) {
selectExportFolder()
selectExportFolder(-10)
} else {
startExport(path)
startExport(path, -10)
}
}
private fun selectExportFolder() {
private fun selectExportFolder(exportPosition: Int) {
val default = arrayListOf<SelectItem<Int>>()
val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey)
if (!path.isNullOrEmpty()) {
@ -263,10 +260,11 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
}
exportDir.launch {
otherActions = default
requestCode = exportPosition
}
}
private fun startExport(path: String) {
private fun startExport(path: String, exportPosition: Int) {
if (exportPosition == -10) {
if (adapter.getItems().isNotEmpty()) {
adapter.getItems().forEach { book ->

@ -49,8 +49,8 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
private val adapter by lazy { ImportBookAdapter(this, this) }
private var sdPath = FileUtils.getSdCardPath()
private var path = sdPath
private val selectFolder = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
private val selectFolder = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
if (uri.isContentScheme()) {
AppConfig.importBookPath = uri.toString()
initRootDoc()
@ -61,6 +61,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
}
}
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()

@ -5,7 +5,10 @@ import android.content.DialogInterface
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import android.view.*
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.documentfile.provider.DocumentFile
import com.jaredrummler.android.colorpicker.ColorPickerDialog
import io.legado.app.R
@ -50,15 +53,17 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
}
}
private val selectExportDir = registerForActivityResult(HandleFileContract()) {
it ?: return@registerForActivityResult
exportConfig(it)
it.uri?.let { uri ->
exportConfig(uri)
}
}
private val selectImportDoc = registerForActivityResult(HandleFileContract()) {
it ?: return@registerForActivityResult
if (it.toString() == importFormNet) {
it.uri?.let { uri ->
if (uri.toString() == importFormNet) {
importNetConfigAlert()
} else {
importConfig(it)
importConfig(uri)
}
}
}

@ -39,12 +39,12 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
private val adapter by lazy { Adapter(requireContext()) }
private var ttsEngine: String? = AppConfig.ttsEngine
private val importDocResult = registerForActivityResult(HandleFileContract()) {
it?.let {
viewModel.importLocal(it)
it.uri?.let { uri ->
viewModel.importLocal(uri)
}
}
private val exportDirResult = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
private val exportDirResult = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
alert(R.string.export_success) {
if (uri.toString().isAbsUrl()) {
DirectLinkUpload.getSummary()?.let { summary ->
@ -61,6 +61,7 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
}
}
}
}
override fun onStart() {
super.onStart()

@ -54,14 +54,15 @@ class BookSourceEditActivity :
upRecyclerView(source)
}
}
private val selectDoc = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
private val selectDoc = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
if (uri.isContentScheme()) {
sendText(uri.toString())
} else {
sendText(uri.path.toString())
}
}
}
private var mSoftKeyboardTool: PopupWindow? = null
private var mIsSoftKeyBoardShowing = false

@ -64,16 +64,17 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
it ?: return@registerForActivityResult
showDialogFragment(ImportBookSourceDialog(it))
}
private val importDoc = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
private val importDoc = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
try {
showDialogFragment(ImportBookSourceDialog(uri.readText(this)))
} catch (e: Exception) {
toastOnUi("readTextError:${e.localizedMessage}")
}
}
private val exportDir = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
}
private val exportDir = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
alert(R.string.export_success) {
if (uri.toString().isAbsUrl()) {
DirectLinkUpload.getSummary()?.let { summary ->
@ -90,6 +91,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
}
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()

@ -33,9 +33,10 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
private var customWebViewCallback: WebChromeClient.CustomViewCallback? = null
private var webPic: String? = null
private val saveImage = registerForActivityResult(HandleFileContract()) {
it ?: return@registerForActivityResult
ACache.get(this).put(imagePathKey, it.toString())
viewModel.saveImage(webPic, it.toString())
it.uri?.let { uri ->
ACache.get(this).put(imagePathKey, uri.toString())
viewModel.saveImage(webPic, uri.toString())
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {

@ -38,16 +38,17 @@ import splitties.init.appCtx
class BackupConfigFragment : BasePreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener {
private val selectBackupPath = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
private val selectBackupPath = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
if (uri.isContentScheme()) {
AppConfig.backupPath = uri.toString()
} else {
AppConfig.backupPath = uri.path
}
}
private val backupDir = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
}
private val backupDir = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
if (uri.isContentScheme()) {
AppConfig.backupPath = uri.toString()
Coroutine.async {
@ -70,8 +71,9 @@ class BackupConfigFragment : BasePreferenceFragment(),
}
}
}
private val restoreDir = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
}
private val restoreDir = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
if (uri.isContentScheme()) {
AppConfig.backupPath = uri.toString()
Coroutine.async {
@ -86,8 +88,9 @@ class BackupConfigFragment : BasePreferenceFragment(),
}
}
}
private val restoreOld = registerForActivityResult(HandleFileContract()) { uri ->
uri?.let {
}
private val restoreOld = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
ImportOldData.importUri(appCtx, uri)
}
}

@ -11,13 +11,9 @@ import io.legado.app.utils.putJson
@Suppress("unused")
class HandleFileContract :
ActivityResultContract<HandleFileContract.HandleFileParam.() -> Unit, Uri?>() {
ActivityResultContract<HandleFileContract.HandleFileParam.() -> Unit, HandleFileContract.Result>() {
companion object {
const val DIR = 0
const val FILE = 1
const val EXPORT = 3
}
private var requestCode: Int = 0
override fun createIntent(context: Context, input: (HandleFileParam.() -> Unit)?): Intent {
val intent = Intent(context, HandleFileActivity::class.java)
@ -26,6 +22,7 @@ class HandleFileContract :
handleFileParam.apply(input)
}
handleFileParam.let {
requestCode = it.requestCode
intent.putExtra("mode", it.mode)
intent.putExtra("title", it.title)
intent.putExtra("allowExtensions", it.allowExtensions)
@ -39,11 +36,17 @@ class HandleFileContract :
return intent
}
override fun parseResult(resultCode: Int, intent: Intent?): Uri? {
override fun parseResult(resultCode: Int, intent: Intent?): Result {
if (resultCode == RESULT_OK) {
return intent?.data
return Result(intent?.data, requestCode)
}
return null
return Result(null, requestCode)
}
companion object {
const val DIR = 0
const val FILE = 1
const val EXPORT = 3
}
@Suppress("ArrayInDataClass")
@ -53,6 +56,12 @@ class HandleFileContract :
var allowExtensions: Array<String> = arrayOf(),
var otherActions: ArrayList<SelectItem<Int>>? = null,
var fileData: Triple<String, ByteArray, String>? = null,
var requestCode: Int = 0
)
data class Result(
val uri: Uri?,
val requestCode: Int
)
}

@ -31,12 +31,16 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
override val viewModel by viewModels<BookshelfViewModel>()
private val importBookshelf = registerForActivityResult(HandleFileContract()) {
it?.readText(requireContext())?.let { text ->
kotlin.runCatching {
it.uri?.readText(requireContext())?.let { text ->
viewModel.importBookshelf(text, groupId)
}
}.onFailure {
toastOnUi(it.localizedMessage ?: "ERROR")
}
}
private val exportResult = registerForActivityResult(HandleFileContract()) {
it?.let { uri ->
it.uri?.let { uri ->
alert(R.string.export_success) {
if (uri.toString().isAbsUrl()) {
DirectLinkUpload.getSummary()?.let { summary ->

@ -71,9 +71,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
setResult(RESULT_OK)
}
}
private val importDoc = registerForActivityResult(HandleFileContract()) { uri ->
private val importDoc = registerForActivityResult(HandleFileContract()) {
kotlin.runCatching {
uri?.readText(this)?.let {
it.uri?.readText(this)?.let {
showDialogFragment(
ImportReplaceRuleDialog(it)
)
@ -82,8 +82,8 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
toastOnUi("readTextError:${it.localizedMessage}")
}
}
private val exportResult = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
private val exportResult = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
alert(R.string.export_success) {
if (uri.toString().isAbsUrl()) {
DirectLinkUpload.getSummary()?.let { summary ->
@ -100,6 +100,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
}
}
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()

@ -42,9 +42,10 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
private var customWebViewCallback: WebChromeClient.CustomViewCallback? = null
private var webPic: String? = null
private val saveImage = registerForActivityResult(HandleFileContract()) {
it ?: return@registerForActivityResult
ACache.get(this).put(imagePathKey, it.toString())
viewModel.saveImage(webPic, it.toString())
it.uri?.let { uri ->
ACache.get(this).put(imagePathKey, uri.toString())
viewModel.saveImage(webPic, uri.toString())
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {

@ -57,9 +57,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
ImportRssSourceDialog(it)
)
}
private val importDoc = registerForActivityResult(HandleFileContract()) { uri ->
private val importDoc = registerForActivityResult(HandleFileContract()) {
kotlin.runCatching {
uri?.readText(this)?.let {
it.uri?.readText(this)?.let {
showDialogFragment(
ImportRssSourceDialog(it)
)
@ -68,8 +68,8 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
toastOnUi("readTextError:${it.localizedMessage}")
}
}
private val exportResult = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
private val exportResult = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
alert(R.string.export_success) {
if (uri.toString().isAbsUrl()) {
DirectLinkUpload.getSummary()?.let { summary ->
@ -86,6 +86,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
}
}
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()

@ -40,8 +40,8 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select),
val curFontPath = callBack?.curFontPath ?: ""
FontAdapter(requireContext(), curFontPath, this)
}
private val selectFontDir = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
private val selectFontDir = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
if (uri.toString().isContentScheme()) {
putPrefString(PreferKey.fontFolder, uri.toString())
val doc = DocumentFile.fromTreeUri(requireContext(), uri)
@ -63,6 +63,7 @@ class FontSelectDialog : BaseDialogFragment(R.layout.dialog_font_select),
}
}
}
}
override fun onStart() {
super.onStart()

Loading…
Cancel
Save