Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
Document installer components
Browse files Browse the repository at this point in the history
  • Loading branch information
wingio committed Jan 27, 2024
1 parent f98f0d2 commit 22cfaec
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ import dev.beefers.vendetta.manager.installer.step.download.base.DownloadStep
import dev.beefers.vendetta.manager.ui.viewmodel.installer.InstallerViewModel
import dev.beefers.vendetta.manager.utils.thenIf

/**
* Collapsable card containing a group of steps
*
* @param name The name of this group
* @param isCurrent Whether this card is expanded
* @param steps The steps belonging to this group
* @param onClick Action taken when the header of the group is clicked
*/
@Composable
fun StepGroupCard(
name: String,
Expand Down Expand Up @@ -73,7 +81,7 @@ fun StepGroupCard(

if (status != StepStatus.ONGOING && status != StepStatus.QUEUED) {
Text(
text = "%.2fs".format(steps.sumOf { it.durationMs } / 1000f),
text = "%.2fs".format(steps.sumOf { it.durationMs } / 1000f), // Displays the duration rounded to the hundredths place. ex. 10.13s
style = MaterialTheme.typography.labelMedium
)
}
Expand All @@ -98,44 +106,14 @@ fun StepGroupCard(
.padding(16.dp)
.padding(start = 4.dp)
) {
steps.forEach {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
val progress by animateFloatAsState(it.progress ?: 0f, label = "Progress")

StepIcon(it.status, size = 18.dp, progress = if(it.progress == null) null else progress)

Text(
text = stringResource(it.nameRes),
style = MaterialTheme.typography.labelLarge,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f, true),
)

if (it.status != StepStatus.ONGOING && it.status != StepStatus.QUEUED) {
if ((it as? DownloadStep)?.cached == true) {
val style = MaterialTheme.typography.labelSmall.copy(
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f),
fontStyle = FontStyle.Italic,
fontSize = 11.sp
)
Text(
text = stringResource(R.string.installer_cached),
style = style,
maxLines = 1,
)
}

Text(
text = "%.2fs".format((it.durationMs / 1000f)),
style = MaterialTheme.typography.labelSmall,
maxLines = 1,
)
}
}
steps.forEach { step ->
StepRow(
name = stringResource(step.nameRes),
status = step.status,
progress = step.progress,
cached = (step as? DownloadStep)?.cached ?: false,
duration = step.durationMs / 1000f
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ import dev.beefers.vendetta.manager.ui.viewmodel.installer.InstallerViewModel
import kotlin.math.floor
import kotlin.math.roundToInt

/**
* Icon representing the status of a step
*
* Ongoing - Progress indicator
*
* Queued - Outlined circle, tinted grey
*
* Successful - Green check
*
* Unsuccessful - Red X
*/
@Composable
fun StepIcon(
status: StepStatus,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package dev.beefers.vendetta.manager.ui.widgets.installer

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import dev.beefers.vendetta.manager.R
import dev.beefers.vendetta.manager.installer.step.StepStatus

/**
* Displays a steps name, status, and progress
*
* @param name The name of the step
* @param status The steps current status
* @param progress Represents the download progress, as a decimal
* @param cached Whether the file this step downloads was already cached
* @param duration How long the step took to run, in seconds
* @param modifier [Modifier] for this StepRow
*/
@Composable
fun StepRow(
name: String,
status: StepStatus,
progress: Float?,
cached: Boolean,
duration: Float,
modifier: Modifier = Modifier
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp),
modifier = modifier
) {
@Suppress("LocalVariableName")
val _progress by animateFloatAsState(progress ?: 0f, label = "Progress") // Smoothly animate the progress indicator

StepIcon(status, size = 18.dp, progress = if(progress == null) null else _progress)

Text(
text = name,
style = MaterialTheme.typography.labelLarge,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f, true),
)

if (status != StepStatus.ONGOING && status != StepStatus.QUEUED) { // Only display for completed steps
if (cached) {
Text(
text = stringResource(R.string.installer_cached),
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f),
fontStyle = FontStyle.Italic,
fontSize = 11.sp,
maxLines = 1,
)
}

Text(
text = "%.2fs".format(duration), // Displays the duration rounded to the hundredths place. ex. 10.13s
style = MaterialTheme.typography.labelSmall,
maxLines = 1,
)
}
}
}

0 comments on commit 22cfaec

Please sign in to comment.