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 {
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
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)
var hasPermission = true
it.forEach { (t, u) ->
if (!u) {
hasPermission = false
toastOnUi(t)
}
}
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)

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

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

@ -280,15 +280,24 @@ class ThemeConfigFragment : BasePreferenceFragment(),
}
} else {
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
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()
var hasPermission = true
it.forEach { (t, u) ->
if (!u) {
hasPermission = false
toastOnUi(t)
}
}
if (hasPermission) {
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)

@ -163,7 +163,16 @@ class FontSelectDialog : BaseDialogFragment(),
private fun loadFontFilesByPermission(path: String) {
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)
}

Loading…
Cancel
Save