|
|
|
@ -3,7 +3,6 @@ package io.legado.app.ui.config |
|
|
|
|
import android.app.Activity.RESULT_OK |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.net.Uri |
|
|
|
|
import android.os.Build |
|
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
|
import io.legado.app.App |
|
|
|
@ -23,6 +22,7 @@ import io.legado.app.utils.isContentPath |
|
|
|
|
import io.legado.app.utils.toast |
|
|
|
|
import kotlinx.coroutines.Dispatchers.Main |
|
|
|
|
import org.jetbrains.anko.toast |
|
|
|
|
import java.io.File |
|
|
|
|
|
|
|
|
|
object BackupRestoreUi { |
|
|
|
|
private const val selectFolderRequestCode = 21 |
|
|
|
@ -123,22 +123,7 @@ object BackupRestoreUi { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun importOldData(fragment: Fragment) { |
|
|
|
|
FilePicker.selectFolder(fragment, oldDataRequestCode) { |
|
|
|
|
importOldUsePermission(fragment) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun importOldUsePermission(fragment: Fragment) { |
|
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { |
|
|
|
|
fragment.toast(R.string.a10_permission_toast) |
|
|
|
|
} |
|
|
|
|
PermissionsCompat.Builder(fragment) |
|
|
|
|
.addPermissions(*Permissions.Group.STORAGE) |
|
|
|
|
.rationale(R.string.tip_perm_request_storage) |
|
|
|
|
.onGranted { |
|
|
|
|
ImportOldData.import(fragment.requireContext()) |
|
|
|
|
} |
|
|
|
|
.request() |
|
|
|
|
FilePicker.selectFolder(fragment, oldDataRequestCode) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun onFilePicked(requestCode: Int, currentPath: String) { |
|
|
|
@ -162,6 +147,9 @@ object BackupRestoreUi { |
|
|
|
|
selectFolderRequestCode -> { |
|
|
|
|
AppConfig.backupPath = currentPath |
|
|
|
|
} |
|
|
|
|
oldDataRequestCode -> { |
|
|
|
|
ImportOldData.import(App.INSTANCE, File(currentPath)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|