pull/940/head
gedoor 4 years ago
parent bd3e196688
commit 83d1da4947
  1. 5
      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. 16
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt
  4. 6
      app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt

@ -1,6 +1,5 @@
package io.legado.app.ui.book.cache package io.legado.app.ui.book.cache
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -42,10 +41,6 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private val exportDir = registerForActivityResult(FilePicker()) { uri -> private val exportDir = registerForActivityResult(FilePicker()) { uri ->
uri ?: return@registerForActivityResult uri ?: return@registerForActivityResult
if (uri.isContentScheme()) { if (uri.isContentScheme()) {
contentResolver.takePersistableUriPermission(
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
ACache.get(this@CacheActivity).put(exportBookPathKey, uri.toString()) ACache.get(this@CacheActivity).put(exportBookPathKey, uri.toString())
startExport(uri.toString()) startExport(uri.toString())
} else { } else {

@ -1,6 +1,5 @@
package io.legado.app.ui.book.local package io.legado.app.ui.book.local
import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@ -46,10 +45,6 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
private val selectFolder = registerForActivityResult(FilePicker()) { uri -> private val selectFolder = registerForActivityResult(FilePicker()) { uri ->
uri ?: return@registerForActivityResult uri ?: return@registerForActivityResult
if (uri.isContentScheme()) { if (uri.isContentScheme()) {
contentResolver.takePersistableUriPermission(
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
AppConfig.importBookPath = uri.toString() AppConfig.importBookPath = uri.toString()
initRootDoc() initRootDoc()
} else { } else {

@ -1,6 +1,5 @@
package io.legado.app.ui.config package io.legado.app.ui.config
import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
@ -40,11 +39,6 @@ class BackupConfigFragment : BasePreferenceFragment(),
private val selectBackupPath = registerForActivityResult(FilePicker()) { uri -> private val selectBackupPath = registerForActivityResult(FilePicker()) { uri ->
uri ?: return@registerForActivityResult uri ?: return@registerForActivityResult
if (uri.isContentScheme()) { if (uri.isContentScheme()) {
appCtx.contentResolver.takePersistableUriPermission(
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
AppConfig.backupPath = uri.toString() AppConfig.backupPath = uri.toString()
} else { } else {
AppConfig.backupPath = uri.path AppConfig.backupPath = uri.path
@ -53,11 +47,6 @@ class BackupConfigFragment : BasePreferenceFragment(),
private val backupDir = registerForActivityResult(FilePicker()) { uri -> private val backupDir = registerForActivityResult(FilePicker()) { uri ->
uri ?: return@registerForActivityResult uri ?: return@registerForActivityResult
if (uri.isContentScheme()) { if (uri.isContentScheme()) {
appCtx.contentResolver.takePersistableUriPermission(
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
AppConfig.backupPath = uri.toString() AppConfig.backupPath = uri.toString()
Coroutine.async { Coroutine.async {
Backup.backup(appCtx, uri.toString()) Backup.backup(appCtx, uri.toString())
@ -78,11 +67,6 @@ class BackupConfigFragment : BasePreferenceFragment(),
private val restoreDir = registerForActivityResult(FilePicker()) { uri -> private val restoreDir = registerForActivityResult(FilePicker()) { uri ->
uri ?: return@registerForActivityResult uri ?: return@registerForActivityResult
if (uri.isContentScheme()) { if (uri.isContentScheme()) {
appCtx.contentResolver.takePersistableUriPermission(
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
AppConfig.backupPath = uri.toString() AppConfig.backupPath = uri.toString()
Coroutine.async { Coroutine.async {
Restore.restore(appCtx, uri.toString()) Restore.restore(appCtx, uri.toString())

@ -23,6 +23,12 @@ class FilePickerActivity :
private val selectDocTree = private val selectDocTree =
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) {
if (it.isContentScheme()) {
contentResolver.takePersistableUriPermission(
it,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
}
onResult(Intent().setData(it)) onResult(Intent().setData(it))
} }

Loading…
Cancel
Save