From 73d1a1a05e5017d7d7bcb8c120d81461138aa53b Mon Sep 17 00:00:00 2001 From: inorichi Date: Wed, 24 May 2017 11:15:40 +0200 Subject: [PATCH] Fix backup issue. Closes #806 --- .../kanade/tachiyomi/data/backup/BackupCreateService.kt | 8 ++++---- .../eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt | 6 ++++-- .../tachiyomi/ui/setting/SettingsBackupController.kt | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt index 2f5cdb7b80..19fc67bc9a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt @@ -50,9 +50,9 @@ class BackupCreateService : IntentService(NAME) { * @param flags determines what to backup * @param isJob backup called from job */ - fun makeBackup(context: Context, path: String, flags: Int, isJob: Boolean = false) { + fun makeBackup(context: Context, uri: Uri, flags: Int, isJob: Boolean = false) { val intent = Intent(context, BackupCreateService::class.java).apply { - putExtra(BackupConst.EXTRA_URI, path) + putExtra(BackupConst.EXTRA_URI, uri) putExtra(EXTRA_IS_JOB, isJob) putExtra(EXTRA_FLAGS, flags) } @@ -67,11 +67,11 @@ class BackupCreateService : IntentService(NAME) { if (intent == null) return // Get values - val uri = intent.getStringExtra(BackupConst.EXTRA_URI) + val uri = intent.getParcelableExtra(BackupConst.EXTRA_URI) val isJob = intent.getBooleanExtra(EXTRA_IS_JOB, false) val flags = intent.getIntExtra(EXTRA_FLAGS, 0) // Create backup - createBackupFromApp(Uri.parse(uri), flags, isJob) + createBackupFromApp(uri, flags, isJob) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt index 442eedfb01..b23157c504 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.data.backup +import android.net.Uri import com.evernote.android.job.Job import com.evernote.android.job.JobManager import com.evernote.android.job.JobRequest @@ -7,14 +8,15 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import java.io.File class BackupCreatorJob : Job() { override fun onRunJob(params: Params): Result { val preferences = Injekt.get() - val path = preferences.backupsDirectory().getOrDefault() + val uri = Uri.fromFile(File(preferences.backupsDirectory().getOrDefault())) val flags = BackupCreateService.BACKUP_ALL - BackupCreateService.makeBackup(context, path, flags, true) + BackupCreateService.makeBackup(context, uri, flags, true) return Result.SUCCESS } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index 4734e3de74..bd46058fa1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -177,11 +177,11 @@ class SettingsBackupController : SettingsController() { } CODE_BACKUP_CREATE -> if (data != null && resultCode == Activity.RESULT_OK) { val activity = activity ?: return - val path = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + val uri = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { val dir = data.data.path val file = File(dir, Backup.getDefaultFilename()) - file.absolutePath + Uri.fromFile(file) } else { val uri = data.data val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or @@ -190,11 +190,11 @@ class SettingsBackupController : SettingsController() { activity.contentResolver.takePersistableUriPermission(uri, flags) val file = UniFile.fromUri(activity, uri) - file.uri.toString() + file.uri } CreatingBackupDialog().showDialog(router, TAG_CREATING_BACKUP_DIALOG) - BackupCreateService.makeBackup(activity, path, backupFlags) + BackupCreateService.makeBackup(activity, uri, backupFlags) } CODE_BACKUP_RESTORE -> if (data != null && resultCode == Activity.RESULT_OK) { val uri = data.data