|
|
@@ -1,10 +1,13 @@
|
|
|
package io.legado.app.ui.config.backupConfig
|
|
|
|
|
|
+import android.content.Context
|
|
|
+import android.net.Uri
|
|
|
import androidx.lifecycle.ViewModel
|
|
|
import androidx.lifecycle.viewModelScope
|
|
|
import io.legado.app.R
|
|
|
import io.legado.app.domain.usecase.WebDavBackupUseCase
|
|
|
import io.legado.app.help.storage.Backup
|
|
|
+import io.legado.app.help.storage.Restore
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.withContext
|
|
|
@@ -83,4 +86,19 @@ class BackupConfigViewModel(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ fun restore(context: Context, uri: Uri, onSuccess: () -> Unit, onError: (String) -> Unit) {
|
|
|
+ viewModelScope.launch(Dispatchers.IO) {
|
|
|
+ try {
|
|
|
+ Restore.restore(context, uri)
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ onSuccess()
|
|
|
+ }
|
|
|
+ } catch (e: Exception) {
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ onError(e.localizedMessage ?: appCtx.getString(R.string.restore_error))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|