Skip to content

Commit

Permalink
Show which files are affected by corrupted in files overview view
Browse files Browse the repository at this point in the history
  • Loading branch information
grote committed Nov 29, 2024
1 parent 4db3e28 commit b19e093
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public sealed class CheckResult {

val goodSnapshots: List<BackupSnapshot>
val badSnapshots: List<BackupSnapshot>
val badChunkIds: Set<String> get() = missingChunkIds + malformedChunkIds

init {
val good = mutableListOf<BackupSnapshot>()
val bad = mutableListOf<BackupSnapshot>()
val badChunkIds = missingChunkIds + malformedChunkIds
snapshots.forEach { snapshot ->
val chunkIds = (snapshot.mediaFilesList.flatMap { it.chunkIdsList } +
snapshot.documentFilesList.flatMap { it.chunkIdsList }).toSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public class SnapshotFilesFragment : Fragment() {
Toast.makeText(requireContext(), R.string.check_error_no_result, LENGTH_LONG).show()
parentFragmentManager.popBackStack()
} else {
fileSelectionManager.onSnapshotChosen(snapshot)
val badChunkIds = (checkResult as? CheckResult.Error)?.badChunkIds
fileSelectionManager.onSnapshotChosen(snapshot, badChunkIds)

val textView: TextView = requireView().requireViewById(R.id.textView)
textView.text = getString(R.string.check_files_text, snapshot.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ public class FileSelectionManager {
public val files: StateFlow<List<FilesItem>> = mFiles.asStateFlow()

@UiThread
public fun onSnapshotChosen(snapshot: BackupSnapshot) {
public fun onSnapshotChosen(snapshot: BackupSnapshot, badChunkIds: Set<String>? = null) {
// clear previous state if existing
clearState()
// store snapshot for later
this.snapshot = snapshot

// cache files from snapshot within [RestorableFile] (for easier processing)
snapshot.mediaFilesList.forEach { mediaFile ->
cacheFileItem(RestorableFile(mediaFile))
cacheFileItem(RestorableFile(mediaFile), badChunkIds)
}
snapshot.documentFilesList.forEach { documentFile ->
cacheFileItem(RestorableFile(documentFile))
cacheFileItem(RestorableFile(documentFile), badChunkIds)
}
// figure out indentation level and display names for folders
val sortedFolders = allFiles.keys.sorted()
Expand All @@ -55,6 +55,7 @@ public class FileSelectionManager {
size = size,
lastModified = if (lastModified == -1L) null else lastModified,
selected = true,
hasIssue = fileItems.any { it.hasIssue },
partiallySelected = false,
expanded = false,
)
Expand Down Expand Up @@ -117,8 +118,15 @@ public class FileSelectionManager {
return snapshotBuilder.build()
}

private fun cacheFileItem(restorableFile: RestorableFile) {
val fileItem = FileItem(restorableFile, 0, true)
private fun cacheFileItem(restorableFile: RestorableFile, badChunkIds: Set<String>?) {
val fileItem = FileItem(
file = restorableFile,
level = 0,
selected = true,
hasIssue = if (badChunkIds == null) false else {
restorableFile.chunkIds.intersect(badChunkIds).isNotEmpty()
},
)
allFiles.getOrPut(restorableFile.dir) {
mutableListOf()
}.add(fileItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ internal class FilesAdapter(

private val context = itemView.context
private val expandView: ImageView = itemView.findViewById(R.id.expandView)
private val warningView: ImageView = itemView.findViewById(R.id.warningImageView)
private val nameView: TextView = itemView.findViewById(R.id.nameView)
private val errorView: TextView = itemView.findViewById(R.id.errorView)
private val infoView: TextView = itemView.findViewById(R.id.infoView)
private val checkBox: CheckBox = itemView.findViewById(R.id.checkBox)

Expand All @@ -89,7 +91,9 @@ internal class FilesAdapter(
else checkBox.toggle()
}
itemView.updatePadding(left = indentPadding * item.level)
warningView.visibility = if (item.hasIssue) VISIBLE else GONE
nameView.text = item.name
errorView.visibility = if (item.hasIssue && item is FileItem) VISIBLE else GONE

val now = System.currentTimeMillis()
var text = Formatter.formatShortFileSize(context, item.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public sealed interface FilesItem {
public val selected: Boolean
public val size: Long
public val lastModified: Long?
public val hasIssue: Boolean
}

public data class FileItem internal constructor(
internal val file: RestorableFile,
override val level: Int,
override val selected: Boolean,
override val hasIssue: Boolean = false,
) : FilesItem {
override val name: String get() = file.name
override val dir: String get() = file.dir
Expand All @@ -35,6 +37,7 @@ public data class FolderItem(
override val size: Long,
override val lastModified: Long?,
override val selected: Boolean,
override val hasIssue: Boolean = false,
val partiallySelected: Boolean,
val expanded: Boolean,
) : FilesItem {
Expand Down
16 changes: 16 additions & 0 deletions storage/lib/src/main/res/drawable/ic_warning.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--
SPDX-FileCopyrightText: 2024 The Calyx Institute
SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?android:attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@android:color/white"
android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z" />

</vector>
1 change: 1 addition & 0 deletions storage/lib/src/main/res/layout/header_snapshot_files.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:paddingBottom="16dp">

<ImageView
Expand Down
32 changes: 29 additions & 3 deletions storage/lib/src/main/res/layout/item_file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,24 @@
android:layout_width="48dp"
android:layout_height="48dp"
android:scaleType="center"
android:src="@drawable/ic_folder"
android:src="@drawable/ic_chevron_right"
app:layout_constraintEnd_toStartOf="@+id/nameView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/warningImageView"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/check_error_title"
android:src="@drawable/ic_warning"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/expandView"
app:layout_constraintEnd_toStartOf="@+id/nameView"
app:tint="?colorError"
tools:visibility="visible" />

<TextView
android:id="@+id/nameView"
android:layout_width="0dp"
Expand All @@ -32,16 +45,29 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="File/folder name which might be quite long, who knows...?" />

<TextView
android:id="@+id/errorView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/check_files_error"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?colorError"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@+id/nameView"
app:layout_constraintStart_toStartOf="@+id/nameView"
app:layout_constraintTop_toBottomOf="@+id/nameView"
tools:visibility="visible" />

<TextView
android:id="@+id/infoView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/nameView"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="@+id/nameView"
app:layout_constraintTop_toBottomOf="@+id/nameView"
app:layout_constraintTop_toBottomOf="@+id/errorView"
tools:text="24h ago - 23 MB" />

<CheckBox
Expand Down
1 change: 1 addition & 0 deletions storage/lib/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@
<string name="check_error_snapshot">This backup has some errors. You may be able to restore it partly.</string>
<string name="check_files_title">Files in backup</string>
<string name="check_files_text">The \"%s\" includes the following files:</string>
<string name="check_files_error">Backup data is corrupted. File won\'t fully restore.</string>

</resources>

0 comments on commit b19e093

Please sign in to comment.