forked from seedvault-app/seedvault
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show app backup check success screen
- Loading branch information
Showing
8 changed files
with
252 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/stevesoltys/seedvault/repo/CheckerResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 The Calyx Institute | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.stevesoltys.seedvault.repo | ||
|
||
import com.stevesoltys.seedvault.proto.Snapshot | ||
|
||
sealed class CheckerResult { | ||
data class Success( | ||
val snapshots: List<Snapshot>, | ||
val percent: Int, | ||
val size: Long, | ||
) : CheckerResult() | ||
|
||
data class Error( | ||
val snapshots: List<Snapshot>, | ||
val errors: Map<String, Exception>, | ||
) : CheckerResult() | ||
|
||
data class GeneralError(val e: Exception) : CheckerResult() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
app/src/main/java/com/stevesoltys/seedvault/ui/check/AppCheckResultActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 The Calyx Institute | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.stevesoltys.seedvault.ui.check | ||
|
||
import android.os.Bundle | ||
import android.text.format.Formatter.formatShortFileSize | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.stevesoltys.seedvault.R | ||
import com.stevesoltys.seedvault.repo.Checker | ||
import com.stevesoltys.seedvault.repo.CheckerResult | ||
import com.stevesoltys.seedvault.restore.RestoreSetAdapter | ||
import com.stevesoltys.seedvault.transport.restore.RestorableBackup | ||
import com.stevesoltys.seedvault.ui.BackupActivity | ||
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.koin.android.ext.android.inject | ||
|
||
internal const val ACTION_FINISHED = "FINISHED" | ||
internal const val ACTION_SHOW = "SHOW" | ||
|
||
class AppCheckResultActivity : BackupActivity() { | ||
|
||
private val log = KotlinLogging.logger { } | ||
|
||
private val checker: Checker by inject() | ||
private val notificationManager: BackupNotificationManager by inject() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
if (savedInstanceState == null) when (intent.action) { | ||
ACTION_FINISHED -> { | ||
notificationManager.onCheckCompleteNotificationSeen() | ||
checker.clear() | ||
finish() | ||
} | ||
ACTION_SHOW -> { | ||
notificationManager.onCheckCompleteNotificationSeen() | ||
onActionReceived() | ||
} | ||
else -> { | ||
log.error { "Unknown action: ${intent.action}" } | ||
finish() | ||
} | ||
} | ||
} | ||
|
||
private fun onActionReceived() { | ||
when (val result = checker.checkerResult) { | ||
is CheckerResult.Success -> onSuccess(result) | ||
is CheckerResult.Error -> { | ||
// TODO | ||
log.info { "snapshots: ${result.snapshots.size}, errors: ${result.errors.size}" } | ||
} | ||
is CheckerResult.GeneralError, null -> { | ||
// TODO | ||
if (result == null) log.error { "No more result" } | ||
else log.info((result as CheckerResult.GeneralError).e) { "Error: " } | ||
} | ||
} | ||
checker.clear() | ||
} | ||
|
||
private fun onSuccess(result: CheckerResult.Success) { | ||
setContentView(R.layout.activity_check_success) | ||
val intro = getString( | ||
R.string.backup_app_check_success_intro, | ||
result.snapshots.size, | ||
result.percent, | ||
formatShortFileSize(this, result.size), | ||
) | ||
requireViewById<TextView>(R.id.introView).text = intro | ||
|
||
val listView = requireViewById<RecyclerView>(R.id.listView) | ||
listView.adapter = RestoreSetAdapter( | ||
listener = null, | ||
items = result.snapshots.map { snapshot -> | ||
RestorableBackup("", snapshot) | ||
}.sortedByDescending { it.time }, | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
SPDX-FileCopyrightText: 2020 The Calyx Institute | ||
SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fillViewport="true"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<ImageView | ||
android:id="@+id/imageView" | ||
style="@style/SudHeaderIcon" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:srcCompat="@drawable/ic_cloud_done" | ||
app:tint="?android:colorAccent" | ||
tools:ignore="ContentDescription" /> | ||
|
||
<TextView | ||
android:id="@+id/titleView" | ||
style="@style/SudHeaderTitle" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:text="@string/notification_checking_finished_title" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/imageView" /> | ||
|
||
<TextView | ||
android:id="@+id/introView" | ||
style="@style/SudDescription" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/backup_app_check_success_intro" | ||
android:textSize="16sp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/titleView" /> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/listView" | ||
style="@style/SudContent" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="0dp" | ||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" | ||
app:layout_constraintBottom_toTopOf="@+id/disclaimerView" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/introView" | ||
tools:itemCount="4" | ||
tools:listitem="@layout/list_item_restore_set" /> | ||
|
||
<TextView | ||
android:id="@+id/disclaimerView" | ||
style="@style/SudDescription" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/backup_app_check_success_disclaimer" | ||
android:textColor="?colorError" | ||
android:textSize="16sp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/listView" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</ScrollView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters