mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 16:09:16 +01:00
Fix backup issue. Closes #806
This commit is contained in:
parent
211f7b591b
commit
73d1a1a05e
@ -50,9 +50,9 @@ class BackupCreateService : IntentService(NAME) {
|
|||||||
* @param flags determines what to backup
|
* @param flags determines what to backup
|
||||||
* @param isJob backup called from job
|
* @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 {
|
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_IS_JOB, isJob)
|
||||||
putExtra(EXTRA_FLAGS, flags)
|
putExtra(EXTRA_FLAGS, flags)
|
||||||
}
|
}
|
||||||
@ -67,11 +67,11 @@ class BackupCreateService : IntentService(NAME) {
|
|||||||
if (intent == null) return
|
if (intent == null) return
|
||||||
|
|
||||||
// Get values
|
// Get values
|
||||||
val uri = intent.getStringExtra(BackupConst.EXTRA_URI)
|
val uri = intent.getParcelableExtra<Uri>(BackupConst.EXTRA_URI)
|
||||||
val isJob = intent.getBooleanExtra(EXTRA_IS_JOB, false)
|
val isJob = intent.getBooleanExtra(EXTRA_IS_JOB, false)
|
||||||
val flags = intent.getIntExtra(EXTRA_FLAGS, 0)
|
val flags = intent.getIntExtra(EXTRA_FLAGS, 0)
|
||||||
// Create backup
|
// Create backup
|
||||||
createBackupFromApp(Uri.parse(uri), flags, isJob)
|
createBackupFromApp(uri, flags, isJob)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.data.backup
|
package eu.kanade.tachiyomi.data.backup
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
import com.evernote.android.job.Job
|
import com.evernote.android.job.Job
|
||||||
import com.evernote.android.job.JobManager
|
import com.evernote.android.job.JobManager
|
||||||
import com.evernote.android.job.JobRequest
|
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 eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class BackupCreatorJob : Job() {
|
class BackupCreatorJob : Job() {
|
||||||
|
|
||||||
override fun onRunJob(params: Params): Result {
|
override fun onRunJob(params: Params): Result {
|
||||||
val preferences = Injekt.get<PreferencesHelper>()
|
val preferences = Injekt.get<PreferencesHelper>()
|
||||||
val path = preferences.backupsDirectory().getOrDefault()
|
val uri = Uri.fromFile(File(preferences.backupsDirectory().getOrDefault()))
|
||||||
val flags = BackupCreateService.BACKUP_ALL
|
val flags = BackupCreateService.BACKUP_ALL
|
||||||
BackupCreateService.makeBackup(context, path, flags, true)
|
BackupCreateService.makeBackup(context, uri, flags, true)
|
||||||
return Result.SUCCESS
|
return Result.SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,11 +177,11 @@ class SettingsBackupController : SettingsController() {
|
|||||||
}
|
}
|
||||||
CODE_BACKUP_CREATE -> if (data != null && resultCode == Activity.RESULT_OK) {
|
CODE_BACKUP_CREATE -> if (data != null && resultCode == Activity.RESULT_OK) {
|
||||||
val activity = activity ?: return
|
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 dir = data.data.path
|
||||||
val file = File(dir, Backup.getDefaultFilename())
|
val file = File(dir, Backup.getDefaultFilename())
|
||||||
|
|
||||||
file.absolutePath
|
Uri.fromFile(file)
|
||||||
} else {
|
} else {
|
||||||
val uri = data.data
|
val uri = data.data
|
||||||
val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
||||||
@ -190,11 +190,11 @@ class SettingsBackupController : SettingsController() {
|
|||||||
activity.contentResolver.takePersistableUriPermission(uri, flags)
|
activity.contentResolver.takePersistableUriPermission(uri, flags)
|
||||||
val file = UniFile.fromUri(activity, uri)
|
val file = UniFile.fromUri(activity, uri)
|
||||||
|
|
||||||
file.uri.toString()
|
file.uri
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatingBackupDialog().showDialog(router, TAG_CREATING_BACKUP_DIALOG)
|
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) {
|
CODE_BACKUP_RESTORE -> if (data != null && resultCode == Activity.RESULT_OK) {
|
||||||
val uri = data.data
|
val uri = data.data
|
||||||
|
Loading…
Reference in New Issue
Block a user