Skip to content

Commit

Permalink
Hide swap mem bar if it is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed May 14, 2024
1 parent 7f44057 commit 906e866
Showing 1 changed file with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,17 @@ private fun MainNavHeaderContent(

Row(
modifier = Modifier
.fillMaxWidth(),
.fillMaxWidth()
.padding(horizontal = if (headerInfo.swap.isEnabled) 0.dp else 12.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
CpuProgressBar(headerInfo, onSurfaceColor)
MemProgressBar(headerInfo, onSurfaceColor)
if (headerInfo.swap.isEnabled) {
FatMemProgressBar(headerInfo, onSurfaceColor)
} else {
MemProgressBar(headerInfo, onSurfaceColor)
}
}
}
}
Expand Down Expand Up @@ -245,6 +250,57 @@ private fun CpuProgressBar(
}
}

@Composable
private fun MemProgressBar(
headerInfo: StatusHeaderInfo,
onSurfaceColor: Int,
) {
val progressColor = getColorAttribute(com.google.android.material.R.attr.colorPrimary)
val progressTrackColor =
getColorAttribute(github.tornaco.android.thanos.module.common.R.attr.progressTrackColor)

Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Start) {
Box(
modifier = Modifier.Companion.align(Alignment.CenterVertically),
contentAlignment = Alignment.Center
) {
val progressBarWidth = 16.dp
val mainProgressSize = 90.dp
CircularProgressBar(
modifier = Modifier
.size(mainProgressSize),
progress = headerInfo.memory.memUsagePercent.toFloat(),
progressMax = 100f,
progressBarColor = Color(progressColor),
progressBarWidth = progressBarWidth,
backgroundProgressBarColor = Color(progressTrackColor),
backgroundProgressBarWidth = progressBarWidth,
roundBorder = true,
startAngle = 0f,
centerContent = {
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Mem",
style = productSansBoldTypography().caption,
color = Color(onSurfaceColor)
)
Text(
modifier = Modifier,
textAlign = TextAlign.Center,
text = "${headerInfo.memory.memUsagePercent}%",
style = MaterialTheme.typography.labelSmall.copy(fontSize = 8.sp),
color = Color(onSurfaceColor)
)
}
}
)
}
}
}

@Composable
private fun AppCpuUsage(usage: AppCpuUsage) {
val onSurfaceColor = getColorAttribute(com.google.android.material.R.attr.colorOnSurface)
Expand All @@ -261,7 +317,7 @@ private fun AppCpuUsage(usage: AppCpuUsage) {
}

@Composable
private fun MemProgressBar(
private fun FatMemProgressBar(
headerInfo: StatusHeaderInfo,
onSurfaceColor: Int,
) {
Expand Down

0 comments on commit 906e866

Please sign in to comment.