From 5012099419eabf732e624aad5fb37ec2a4357694 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 20 Jun 2024 16:30:06 -0300 Subject: [PATCH] Add UI prototype for selecting file to storage demo app --- .../seedvault/restore/RestoreViewModel.kt | 3 + .../storagebackuptester/MainViewModel.kt | 7 + .../restore/DemoFileSelectionFragment.kt | 36 +++++ .../restore/DemoSnapshotFragment.kt | 4 +- .../restore/RestoreFragment.kt | 8 +- .../ui/restore/FileSelectionFragment.kt | 58 ++++++++ .../backup/storage/ui/restore/FilesAdapter.kt | 126 ++++++++++++++++++ .../storage/ui/restore/SnapshotFragment.kt | 6 +- .../src/main/res/drawable/ic_audio_file.xml | 15 +++ .../main/res/drawable/ic_chevron_right.xml | 15 +++ .../lib/src/main/res/drawable/ic_image.xml | 14 ++ .../drawable/ic_indeterminate_check_box.xml | 27 ++++ .../res/drawable/ic_insert_drive_file.xml | 15 +++ .../res/drawable/ic_keyboard_arrow_down.xml | 15 +++ .../src/main/res/drawable/ic_video_file.xml | 14 ++ .../main/res/layout/fragment_select_files.xml | 58 ++++++++ storage/lib/src/main/res/layout/item_file.xml | 54 ++++++++ storage/lib/src/main/res/values/strings.xml | 4 + 18 files changed, 471 insertions(+), 8 deletions(-) create mode 100644 storage/demo/src/main/java/de/grobox/storagebackuptester/restore/DemoFileSelectionFragment.kt create mode 100644 storage/lib/src/main/java/org/calyxos/backup/storage/ui/restore/FileSelectionFragment.kt create mode 100644 storage/lib/src/main/java/org/calyxos/backup/storage/ui/restore/FilesAdapter.kt create mode 100644 storage/lib/src/main/res/drawable/ic_audio_file.xml create mode 100644 storage/lib/src/main/res/drawable/ic_chevron_right.xml create mode 100644 storage/lib/src/main/res/drawable/ic_image.xml create mode 100644 storage/lib/src/main/res/drawable/ic_indeterminate_check_box.xml create mode 100644 storage/lib/src/main/res/drawable/ic_insert_drive_file.xml create mode 100644 storage/lib/src/main/res/drawable/ic_keyboard_arrow_down.xml create mode 100644 storage/lib/src/main/res/drawable/ic_video_file.xml create mode 100644 storage/lib/src/main/res/layout/fragment_select_files.xml create mode 100644 storage/lib/src/main/res/layout/item_file.xml 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 0912fbe2..6a838828 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreViewModel.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreViewModel.kt @@ -46,6 +46,7 @@ import org.calyxos.backup.storage.api.SnapshotItem import org.calyxos.backup.storage.api.StorageBackup import org.calyxos.backup.storage.restore.RestoreService.Companion.EXTRA_TIMESTAMP_START import org.calyxos.backup.storage.restore.RestoreService.Companion.EXTRA_USER_ID +import org.calyxos.backup.storage.ui.restore.FileSelectionManager import org.calyxos.backup.storage.ui.restore.SnapshotViewModel import java.util.LinkedList @@ -98,6 +99,8 @@ 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/storage/demo/src/main/java/de/grobox/storagebackuptester/MainViewModel.kt b/storage/demo/src/main/java/de/grobox/storagebackuptester/MainViewModel.kt index 18159b27..a0dd1728 100644 --- a/storage/demo/src/main/java/de/grobox/storagebackuptester/MainViewModel.kt +++ b/storage/demo/src/main/java/de/grobox/storagebackuptester/MainViewModel.kt @@ -28,6 +28,7 @@ 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 = """ @@ -47,6 +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() private val _backupLog = MutableLiveData(BackupProgress(0, 0, logEmptyState)) val backupLog: LiveData = _backupLog @@ -124,6 +126,11 @@ class MainViewModel(application: Application) : BackupContentViewModel(applicati } fun onSnapshotClicked(item: SnapshotItem) { + val snapshot = item.snapshot ?: error("${item.storedSnapshot} had null snapshot") + fileSelectionManager.onSnapshotChosen(snapshot) + } + + fun onFilesSelected(item: SnapshotItem) { val snapshot = item.snapshot check(snapshot != 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 new file mode 100644 index 00000000..35afa54c --- /dev/null +++ b/storage/demo/src/main/java/de/grobox/storagebackuptester/restore/DemoFileSelectionFragment.kt @@ -0,0 +1,36 @@ +/* + * SPDX-FileCopyrightText: 2021 The Calyx Institute + * SPDX-License-Identifier: Apache-2.0 + */ + +package de.grobox.storagebackuptester.restore + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.activityViewModels +import de.grobox.storagebackuptester.MainViewModel +import org.calyxos.backup.storage.ui.restore.FileSelectionFragment + +class DemoFileSelectionFragment : FileSelectionFragment() { + + override val viewModel: MainViewModel by activityViewModels() + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + 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