mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Migrate backup & restore feature to use SAF (#1900)
* Migrate backup & restore feature to use SAF * Remove unused imports * Remove unused rx subject * Remove unused dateFormatter * Open picker to current dir * Improve exception messages when handling DocumentFile
This commit is contained in:
@@ -18,17 +18,18 @@
|
||||
*/
|
||||
package com.moez.QKSMS.interactor
|
||||
|
||||
import android.net.Uri
|
||||
import com.moez.QKSMS.repository.BackupRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class PerformRestore @Inject constructor(
|
||||
private val backupRepo: BackupRepository
|
||||
) : Interactor<String>() {
|
||||
) : Interactor<Uri>() {
|
||||
|
||||
override fun buildObservable(params: String): Flowable<*> {
|
||||
override fun buildObservable(params: Uri): Flowable<*> {
|
||||
return Flowable.just(params)
|
||||
.doOnNext(backupRepo::performRestore)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
package com.moez.QKSMS.model
|
||||
|
||||
data class BackupFile(
|
||||
val path: String,
|
||||
val date: Long,
|
||||
val messages: Int,
|
||||
val size: Long
|
||||
)
|
||||
val messages: Int
|
||||
)
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
package com.moez.QKSMS.repository
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.moez.QKSMS.model.BackupFile
|
||||
import io.reactivex.Observable
|
||||
|
||||
@@ -32,19 +34,24 @@ interface BackupRepository {
|
||||
class Finished : Progress(true, false)
|
||||
}
|
||||
|
||||
fun getDefaultBackupPath(): String
|
||||
|
||||
fun getBackupDocumentTree(): DocumentFile?
|
||||
|
||||
fun getBackupPathUriForPicker(): Uri
|
||||
|
||||
fun persistBackupDirectory(directory: Uri)
|
||||
|
||||
fun performBackup()
|
||||
|
||||
fun getBackupProgress(): Observable<Progress>
|
||||
|
||||
/**
|
||||
* Returns a list of all local backups
|
||||
*/
|
||||
fun getBackups(): Observable<List<BackupFile>>
|
||||
fun parseBackup(uri: Uri): BackupFile
|
||||
|
||||
fun performRestore(filePath: String)
|
||||
|
||||
fun stopRestore()
|
||||
fun performRestore(uri: Uri)
|
||||
|
||||
fun getRestoreProgress(): Observable<Progress>
|
||||
|
||||
}
|
||||
fun stopRestore()
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.moez.QKSMS.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import com.f2prateek.rx.preferences2.Preference
|
||||
@@ -85,6 +86,7 @@ class Preferences @Inject constructor(
|
||||
val version = rxPrefs.getInteger("version", context.versionCode)
|
||||
val changelogVersion = rxPrefs.getInteger("changelogVersion", context.versionCode)
|
||||
val hasAskedForNotificationPermission = rxPrefs.getBoolean("hasAskedForNotificationPermission", false)
|
||||
val backupDirectory = rxPrefs.getObject("backupDirectory", Uri.EMPTY, UriPreferenceConverter())
|
||||
@Deprecated("This should only be accessed when migrating to @blockingManager")
|
||||
val sia = rxPrefs.getBoolean("sia", false)
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.moez.QKSMS.util
|
||||
|
||||
import android.net.Uri
|
||||
import com.f2prateek.rx.preferences2.Preference.Converter
|
||||
|
||||
class UriPreferenceConverter : Converter<Uri> {
|
||||
|
||||
override fun deserialize(serialized: String): Uri {
|
||||
return Uri.parse(serialized)
|
||||
}
|
||||
|
||||
override fun serialize(value: Uri): String {
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user