pull/913/head
gedoor 4 years ago
parent 2dc6766f43
commit e74a7cdb4f
  1. 23
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt
  2. 17
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  3. 19
      app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt
  4. 27
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  5. 11
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt

@ -118,13 +118,22 @@ class BookInfoEditActivity :
} }
} else { } else {
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
RealPathUtil.getPath(this, uri)?.let { path -> var hasPermission = true
val imgFile = File(path) it.forEach { (t, u) ->
if (imgFile.exists()) { if (!u) {
var file = this.externalFilesDir hasPermission = false
file = FileUtils.createFileIfNotExist(file, "covers", imgFile.name) toastOnUi(t)
file.writeBytes(imgFile.readBytes()) }
coverChangeTo(file.absolutePath) }
if (hasPermission) {
RealPathUtil.getPath(this, uri)?.let { path ->
val imgFile = File(path)
if (imgFile.exists()) {
var file = this.externalFilesDir
file = FileUtils.createFileIfNotExist(file, "covers", imgFile.name)
file.writeBytes(imgFile.readBytes())
coverChangeTo(file.absolutePath)
}
} }
} }
}.launch(Permissions.Group.STORAGE) }.launch(Permissions.Group.STORAGE)

@ -149,10 +149,19 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
else -> { else -> {
binding.tvEmptyMsg.visible() binding.tvEmptyMsg.visible()
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
rootDoc = null var hasPermission = true
subDocs.clear() it.forEach { (t, u) ->
path = lastPath if (!u) {
upPath() hasPermission = false
toastOnUi(t)
}
}
if (hasPermission) {
rootDoc = null
subDocs.clear()
path = lastPath
upPath()
}
}.launch(Permissions.Group.STORAGE) }.launch(Permissions.Group.STORAGE)
} }
} }

@ -57,11 +57,20 @@ object BackupRestoreUi {
path: String path: String
) { ) {
fragment.registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { fragment.registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
Coroutine.async { var hasPermission = true
AppConfig.backupPath = path it.forEach { (t, u) ->
Backup.backup(fragment.requireContext(), path) if (!u) {
}.onSuccess { hasPermission = false
fragment.toastOnUi(R.string.backup_success) fragment.toastOnUi(t)
}
}
if (hasPermission) {
Coroutine.async {
AppConfig.backupPath = path
Backup.backup(fragment.requireContext(), path)
}.onSuccess {
fragment.toastOnUi(R.string.backup_success)
}
} }
}.launch(Permissions.Group.STORAGE) }.launch(Permissions.Group.STORAGE)
} }

@ -280,15 +280,24 @@ class ThemeConfigFragment : BasePreferenceFragment(),
} }
} else { } else {
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
RealPathUtil.getPath(requireContext(), uri)?.let { path -> var hasPermission = true
val imgFile = File(path) it.forEach { (t, u) ->
if (imgFile.exists()) { if (!u) {
var file = requireContext().externalFilesDir hasPermission = false
file = FileUtils.createFileIfNotExist(file, preferenceKey, imgFile.name) toastOnUi(t)
file.writeBytes(imgFile.readBytes()) }
putPrefString(preferenceKey, file.absolutePath) }
upPreferenceSummary(preferenceKey, file.absolutePath) if (hasPermission) {
success() RealPathUtil.getPath(requireContext(), uri)?.let { path ->
val imgFile = File(path)
if (imgFile.exists()) {
var file = requireContext().externalFilesDir
file = FileUtils.createFileIfNotExist(file, preferenceKey, imgFile.name)
file.writeBytes(imgFile.readBytes())
putPrefString(preferenceKey, file.absolutePath)
upPreferenceSummary(preferenceKey, file.absolutePath)
success()
}
} }
} }
}.launch(Permissions.Group.STORAGE) }.launch(Permissions.Group.STORAGE)

@ -163,7 +163,16 @@ class FontSelectDialog : BaseDialogFragment(),
private fun loadFontFilesByPermission(path: String) { private fun loadFontFilesByPermission(path: String) {
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
loadFontFiles(path) var hasPermission = true
it.forEach { (t, u) ->
if (!u) {
hasPermission = false
toastOnUi(t)
}
}
if (hasPermission) {
loadFontFiles(path)
}
}.launch(Permissions.Group.STORAGE) }.launch(Permissions.Group.STORAGE)
} }

Loading…
Cancel
Save