Create error button
This commit is contained in:
parent
962bbf4665
commit
c4c8a29d62
6 changed files with 90 additions and 11 deletions
|
@ -48,11 +48,14 @@ class BackupWorker @AssistedInject constructor(
|
|||
backupRepository.completeBackup(backup, BackupStatus.SUCCESS)
|
||||
return Result.success(statusData(backup.id, "Backup completed successfully"))
|
||||
} catch (cause: Throwable) {
|
||||
val e = throw BackupFailedException(backup, cause)
|
||||
// TODO raise this error
|
||||
val data = statusData(
|
||||
uuid = backup.id,
|
||||
status = "Backup failed",
|
||||
error = BackupFailedException(backup, cause)
|
||||
)
|
||||
|
||||
backupRepository.completeBackup(backup, BackupStatus.FAILURE)
|
||||
return Result.failure(statusData(backup.id, "Backup failed"))
|
||||
return Result.failure(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,14 +135,22 @@ class BackupWorker @AssistedInject constructor(
|
|||
return destination
|
||||
}
|
||||
|
||||
private fun statusData(uuid: UUID, status: String): Data {
|
||||
private fun statusData(
|
||||
uuid: UUID,
|
||||
status: String,
|
||||
error: Throwable? = null
|
||||
): Data {
|
||||
return Data.Builder()
|
||||
.putUuid("uuid", uuid)
|
||||
.putString("status", status)
|
||||
.putString("error", error?.stackTraceToString())
|
||||
.build()
|
||||
}
|
||||
|
||||
private suspend fun updateStatus(uuid: UUID, status: String) {
|
||||
private suspend fun updateStatus(
|
||||
uuid: UUID,
|
||||
status: String
|
||||
) {
|
||||
setForeground(createForegroundInfo(status))
|
||||
|
||||
val data = statusData(uuid, status)
|
||||
|
|
|
@ -125,13 +125,17 @@ class SettingsActivity : ComponentActivity() {
|
|||
}
|
||||
) {
|
||||
composable<SettingsScreen.Options> {
|
||||
OptionsScreen(navController)
|
||||
OptionsScreen(
|
||||
navController = navController
|
||||
)
|
||||
}
|
||||
composable<SettingsScreen.Content> {
|
||||
ContentScreen(navController)
|
||||
ContentScreen()
|
||||
}
|
||||
composable<SettingsScreen.Destination> {
|
||||
DestinationScreen(navController, onAddDestination = { onAddDestination() })
|
||||
DestinationScreen(
|
||||
onAddDestination = { onAddDestination() }
|
||||
)
|
||||
}
|
||||
// Add more destinations similarly.
|
||||
}
|
||||
|
|
|
@ -3,18 +3,32 @@ package eu.m724.pojavbackup.settings.screen.options
|
|||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.BasicAlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.navigation.NavController
|
||||
import eu.m724.pojavbackup.R
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun OptionsScreen(
|
||||
navController: NavController,
|
||||
|
@ -39,5 +53,53 @@ fun OptionsScreen(
|
|||
|
||||
Text(uiState.backupStatusHeader)
|
||||
Text(uiState.backupStatusDetails)
|
||||
|
||||
val openAlertDialog = remember { mutableStateOf(false) }
|
||||
|
||||
when {
|
||||
openAlertDialog.value -> {
|
||||
BasicAlertDialog(
|
||||
onDismissRequest = { openAlertDialog.value = false },
|
||||
properties = DialogProperties(
|
||||
dialogContentTitle = "Stacktrace"
|
||||
)
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(300.dp)
|
||||
.padding(16.dp)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
) {
|
||||
Text(
|
||||
text = uiState.backupStacktrace.toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (uiState.backupStacktrace != null) {
|
||||
Button(
|
||||
onClick = {
|
||||
openAlertDialog.value = true
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.button_show_error)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BasicAlertDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
modifier: Modifier,
|
||||
properties: DialogProperties,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
|
@ -2,5 +2,6 @@ package eu.m724.pojavbackup.settings.screen.options
|
|||
|
||||
data class OptionsScreenUiState(
|
||||
val backupStatusHeader: String = "",
|
||||
val backupStatusDetails: String = ""
|
||||
val backupStatusDetails: String = "",
|
||||
val backupStacktrace: String? = null
|
||||
)
|
||||
|
|
|
@ -57,9 +57,9 @@ class OptionsScreenViewModel @Inject constructor(
|
|||
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
|
||||
backupStatusHeader = workInfo?.state?.toString() + " " + data?.getString("status").toString(),
|
||||
backupStatusDetails = uuid.toString()
|
||||
backupStatusDetails = uuid.toString(),
|
||||
backupStacktrace = data?.getString("error")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,4 +25,5 @@
|
|||
<string name="dashboard_card_health">Health</string>
|
||||
<string name="dashboard_card_worlds">Worlds</string>
|
||||
<string name="dashboard_card_click">Go to %1$s</string>
|
||||
<string name="button_show_error">Show error</string>
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue