diff --git a/app/src/androidTest/java/com/stevesoltys/seedvault/KoinInstrumentationTestApp.kt b/app/src/androidTest/java/com/stevesoltys/seedvault/KoinInstrumentationTestApp.kt
index 60d0ece9..6c0fbdf5 100644
--- a/app/src/androidTest/java/com/stevesoltys/seedvault/KoinInstrumentationTestApp.kt
+++ b/app/src/androidTest/java/com/stevesoltys/seedvault/KoinInstrumentationTestApp.kt
@@ -57,6 +57,7 @@ class KoinInstrumentationTestApp : App() {
iconManager = get(),
storageBackup = get(),
pluginManager = get(),
+ fileSelectionManager = get(),
)
)
currentRestoreViewModel!!
diff --git a/app/src/main/java/com/stevesoltys/seedvault/App.kt b/app/src/main/java/com/stevesoltys/seedvault/App.kt
index 9389eb05..0189cbe7 100644
--- a/app/src/main/java/com/stevesoltys/seedvault/App.kt
+++ b/app/src/main/java/com/stevesoltys/seedvault/App.kt
@@ -28,8 +28,8 @@ import com.stevesoltys.seedvault.metadata.metadataModule
import com.stevesoltys.seedvault.plugins.StoragePluginManager
import com.stevesoltys.seedvault.plugins.saf.storagePluginModuleSaf
import com.stevesoltys.seedvault.plugins.webdav.storagePluginModuleWebDav
-import com.stevesoltys.seedvault.restore.RestoreViewModel
import com.stevesoltys.seedvault.restore.install.installModule
+import com.stevesoltys.seedvault.restore.restoreUiModule
import com.stevesoltys.seedvault.settings.AppListRetriever
import com.stevesoltys.seedvault.settings.SettingsManager
import com.stevesoltys.seedvault.settings.SettingsViewModel
@@ -37,7 +37,6 @@ import com.stevesoltys.seedvault.storage.storageModule
import com.stevesoltys.seedvault.transport.TRANSPORT_ID
import com.stevesoltys.seedvault.transport.backup.backupModule
import com.stevesoltys.seedvault.transport.restore.restoreModule
-import com.stevesoltys.seedvault.ui.files.FileSelectionViewModel
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager
import com.stevesoltys.seedvault.ui.recoverycode.RecoveryCodeViewModel
import com.stevesoltys.seedvault.ui.storage.BackupStorageViewModel
@@ -97,20 +96,6 @@ open class App : Application() {
)
}
viewModel { RestoreStorageViewModel(this@App, get(), get(), get(), get()) }
- viewModel {
- RestoreViewModel(
- app = this@App,
- settingsManager = get(),
- keyManager = get(),
- backupManager = get(),
- restoreCoordinator = get(),
- apkRestore = get(),
- iconManager = get(),
- storageBackup = get(),
- pluginManager = get(),
- )
- }
- viewModel { FileSelectionViewModel(this@App, get()) }
}
override fun onCreate() {
@@ -155,6 +140,7 @@ open class App : Application() {
installModule,
storageModule,
workerModule,
+ restoreUiModule,
appModule
)
diff --git a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreUiModule.kt b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreUiModule.kt
new file mode 100644
index 00000000..41abcddf
--- /dev/null
+++ b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreUiModule.kt
@@ -0,0 +1,31 @@
+/*
+ * SPDX-FileCopyrightText: 2020 The Calyx Institute
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package com.stevesoltys.seedvault.restore
+
+import com.stevesoltys.seedvault.ui.files.FileSelectionViewModel
+import org.calyxos.backup.storage.ui.restore.FileSelectionManager
+import org.koin.android.ext.koin.androidApplication
+import org.koin.androidx.viewmodel.dsl.viewModel
+import org.koin.dsl.module
+
+val restoreUiModule = module {
+ single { FileSelectionManager() }
+ viewModel {
+ RestoreViewModel(
+ app = androidApplication(),
+ settingsManager = get(),
+ keyManager = get(),
+ backupManager = get(),
+ restoreCoordinator = get(),
+ apkRestore = get(),
+ iconManager = get(),
+ storageBackup = get(),
+ pluginManager = get(),
+ fileSelectionManager = get(),
+ )
+ }
+ viewModel { FileSelectionViewModel(androidApplication(), get()) }
+}
diff --git a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreViewModel.kt b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreViewModel.kt
index 6a838828..8e7989f5 100644
--- a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreViewModel.kt
+++ b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreViewModel.kt
@@ -64,6 +64,7 @@ internal class RestoreViewModel(
private val iconManager: IconManager,
storageBackup: StorageBackup,
pluginManager: StoragePluginManager,
+ override val fileSelectionManager: FileSelectionManager,
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO,
) : RequireProvisioningViewModel(app, settingsManager, keyManager, pluginManager),
RestorableBackupClickListener, SnapshotViewModel {
@@ -99,8 +100,6 @@ internal class RestoreViewModel(
get() = appDataRestoreManager.restoreBackupResult
override val snapshots = storageBackup.getBackupSnapshots().asLiveData(ioDispatcher)
- override val fileSelectionManager: FileSelectionManager
- get() = TODO("Not yet implemented")
internal fun loadRestoreSets() = viewModelScope.launch(ioDispatcher) {
val backups = restoreCoordinator.getAvailableMetadata()?.mapNotNull { (token, metadata) ->
diff --git a/app/src/main/java/com/stevesoltys/seedvault/storage/Services.kt b/app/src/main/java/com/stevesoltys/seedvault/storage/Services.kt
index ae32f4b2..8675483a 100644
--- a/app/src/main/java/com/stevesoltys/seedvault/storage/Services.kt
+++ b/app/src/main/java/com/stevesoltys/seedvault/storage/Services.kt
@@ -18,6 +18,7 @@ import org.calyxos.backup.storage.backup.BackupService
import org.calyxos.backup.storage.backup.NotificationBackupObserver
import org.calyxos.backup.storage.restore.NotificationRestoreObserver
import org.calyxos.backup.storage.restore.RestoreService
+import org.calyxos.backup.storage.ui.restore.FileSelectionManager
import org.koin.android.ext.android.inject
/*
@@ -70,6 +71,7 @@ internal class StorageBackupService : BackupService() {
internal class StorageRestoreService : RestoreService() {
override val storageBackup: StorageBackup by inject()
+ override val fileSelectionManager: FileSelectionManager by inject()
// use lazy delegate because context isn't available during construction time
override val restoreObserver: RestoreObserver by lazy {
diff --git a/app/src/main/res/layout/fragment_restore_app_selection.xml b/app/src/main/res/layout/fragment_restore_app_selection.xml
index 07f215d3..0d627ed8 100644
--- a/app/src/main/res/layout/fragment_restore_app_selection.xml
+++ b/app/src/main/res/layout/fragment_restore_app_selection.xml
@@ -108,10 +108,6 @@
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
- app:layout_constraintBottom_toTopOf="@+id/button"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/backupNameView"
tools:listitem="@layout/list_item_app_status" />
+ app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior" />
diff --git a/storage/demo/src/main/java/de/grobox/storagebackuptester/App.kt b/storage/demo/src/main/java/de/grobox/storagebackuptester/App.kt
index 11bfebd9..5582b4ca 100644
--- a/storage/demo/src/main/java/de/grobox/storagebackuptester/App.kt
+++ b/storage/demo/src/main/java/de/grobox/storagebackuptester/App.kt
@@ -12,6 +12,7 @@ import android.util.Log
import de.grobox.storagebackuptester.plugin.TestSafStoragePlugin
import de.grobox.storagebackuptester.settings.SettingsManager
import org.calyxos.backup.storage.api.StorageBackup
+import org.calyxos.backup.storage.ui.restore.FileSelectionManager
class App : Application() {
@@ -20,6 +21,7 @@ class App : Application() {
val plugin = TestSafStoragePlugin(this) { settingsManager.getBackupLocation() }
StorageBackup(this, { plugin })
}
+ val fileSelectionManager: FileSelectionManager get() = FileSelectionManager()
override fun onCreate() {
super.onCreate()
diff --git a/storage/demo/src/main/java/de/grobox/storagebackuptester/Job.kt b/storage/demo/src/main/java/de/grobox/storagebackuptester/Job.kt
index f9cf529f..54b16425 100644
--- a/storage/demo/src/main/java/de/grobox/storagebackuptester/Job.kt
+++ b/storage/demo/src/main/java/de/grobox/storagebackuptester/Job.kt
@@ -14,6 +14,7 @@ import org.calyxos.backup.storage.backup.BackupService
import org.calyxos.backup.storage.backup.NotificationBackupObserver
import org.calyxos.backup.storage.restore.NotificationRestoreObserver
import org.calyxos.backup.storage.restore.RestoreService
+import org.calyxos.backup.storage.ui.restore.FileSelectionManager
import java.util.concurrent.TimeUnit.HOURS
// debug with:
@@ -45,6 +46,8 @@ class DemoBackupService : BackupService() {
class DemoRestoreService : RestoreService() {
// use lazy delegate because context isn't available during construction time
override val storageBackup: StorageBackup by lazy { (application as App).storageBackup }
+ override val fileSelectionManager: FileSelectionManager
+ get() = (application as App).fileSelectionManager
override val restoreObserver: RestoreObserver by lazy {
NotificationRestoreObserver(applicationContext)
}
diff --git a/storage/demo/src/main/java/de/grobox/storagebackuptester/MainViewModel.kt b/storage/demo/src/main/java/de/grobox/storagebackuptester/MainViewModel.kt
index a0dd1728..9bc7f134 100644
--- a/storage/demo/src/main/java/de/grobox/storagebackuptester/MainViewModel.kt
+++ b/storage/demo/src/main/java/de/grobox/storagebackuptester/MainViewModel.kt
@@ -24,11 +24,11 @@ import kotlinx.coroutines.withContext
import org.calyxos.backup.storage.api.SnapshotItem
import org.calyxos.backup.storage.api.SnapshotResult
import org.calyxos.backup.storage.api.StorageBackup
+import org.calyxos.backup.storage.api.StoredSnapshot
import org.calyxos.backup.storage.backup.BackupJobService
import org.calyxos.backup.storage.scanner.DocumentScanner
import org.calyxos.backup.storage.scanner.MediaScanner
import org.calyxos.backup.storage.ui.backup.BackupContentViewModel
-import org.calyxos.backup.storage.ui.restore.FileSelectionManager
import org.calyxos.backup.storage.ui.restore.SnapshotViewModel
private val logEmptyState = """
@@ -48,7 +48,7 @@ class MainViewModel(application: Application) : BackupContentViewModel(applicati
private val app: App = application as App
private val settingsManager = app.settingsManager
override val storageBackup: StorageBackup = app.storageBackup
- override val fileSelectionManager = FileSelectionManager()
+ override val fileSelectionManager = app.fileSelectionManager
private val _backupLog = MutableLiveData(BackupProgress(0, 0, logEmptyState))
val backupLog: LiveData = _backupLog
@@ -64,6 +64,7 @@ class MainViewModel(application: Application) : BackupContentViewModel(applicati
override val snapshots: LiveData
get() = storageBackup.getBackupSnapshots().asLiveData(Dispatchers.IO)
+ private var storedSnapshot: StoredSnapshot? = null
init {
viewModelScope.launch { loadContent() }
@@ -128,11 +129,12 @@ class MainViewModel(application: Application) : BackupContentViewModel(applicati
fun onSnapshotClicked(item: SnapshotItem) {
val snapshot = item.snapshot ?: error("${item.storedSnapshot} had null snapshot")
fileSelectionManager.onSnapshotChosen(snapshot)
+ storedSnapshot = item.storedSnapshot
}
- fun onFilesSelected(item: SnapshotItem) {
- val snapshot = item.snapshot
- check(snapshot != null)
+ fun onFilesSelected() {
+ val storedSnapshot = this.storedSnapshot ?: error("No snapshot stored")
+ val snapshot = fileSelectionManager.getBackupSnapshotAndReset()
// example for how to do restore via foreground service
// app.startForegroundService(Intent(app, DemoRestoreService::class.java).apply {
@@ -144,8 +146,9 @@ class MainViewModel(application: Application) : BackupContentViewModel(applicati
_restoreProgressVisible.value = true
val restoreObserver = RestoreStats(app, _restoreLog)
viewModelScope.launch {
- storageBackup.restoreBackupSnapshot(item.storedSnapshot, snapshot, restoreObserver)
+ storageBackup.restoreBackupSnapshot(storedSnapshot, snapshot, restoreObserver)
_restoreProgressVisible.value = false
+ this@MainViewModel.storedSnapshot = null
}
}
diff --git a/storage/demo/src/main/java/de/grobox/storagebackuptester/restore/DemoFileSelectionFragment.kt b/storage/demo/src/main/java/de/grobox/storagebackuptester/restore/DemoFileSelectionFragment.kt
index 35afa54c..b55791e4 100644
--- a/storage/demo/src/main/java/de/grobox/storagebackuptester/restore/DemoFileSelectionFragment.kt
+++ b/storage/demo/src/main/java/de/grobox/storagebackuptester/restore/DemoFileSelectionFragment.kt
@@ -9,8 +9,10 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.view.ViewStub
import androidx.fragment.app.activityViewModels
import de.grobox.storagebackuptester.MainViewModel
+import de.grobox.storagebackuptester.R
import org.calyxos.backup.storage.ui.restore.FileSelectionFragment
class DemoFileSelectionFragment : FileSelectionFragment() {
@@ -23,14 +25,17 @@ class DemoFileSelectionFragment : FileSelectionFragment() {
savedInstanceState: Bundle?,
): View {
val v = super.onCreateView(inflater, container, savedInstanceState)
- // val topStub: ViewStub = v.findViewById(R.id.topStub)
- // topStub.layoutResource = R.layout.footer_snapshot
- // val header = topStub.inflate()
- // header.findViewById