-
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.
create a LanguageDownloadProgressIndicator for the downloadable langu…
…ages UI
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...n/org/cru/godtools/ui/languages/downloadable/LanguageDownloadProgressIndicator+Preview.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 @@ | ||
package org.cru.godtools.ui.languages.downloadable | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import org.cru.godtools.base.ui.theme.GodToolsTheme | ||
|
||
@Preview | ||
@Composable | ||
private fun LanguageDownloadProgressIndicatorNotPinned() { | ||
GodToolsTheme { LanguageDownloadProgressIndicator(isPinned = false, downloaded = 0, total = 5) } | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun LanguageDownloadProgressIndicatorInProgress() { | ||
GodToolsTheme { LanguageDownloadProgressIndicator(isPinned = true, downloaded = 2, total = 5) } | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun LanguageDownloadProgressIndicatorDownloaded() { | ||
GodToolsTheme { LanguageDownloadProgressIndicator(isPinned = true, downloaded = 5, total = 5) } | ||
} |
65 changes: 65 additions & 0 deletions
65
...in/kotlin/org/cru/godtools/ui/languages/downloadable/LanguageDownloadProgressIndicator.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,65 @@ | ||
package org.cru.godtools.ui.languages.downloadable | ||
|
||
import androidx.compose.animation.core.animateFloatAsState | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.outlined.CheckCircle | ||
import androidx.compose.material.icons.outlined.DownloadForOffline | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
internal fun LanguageDownloadProgressIndicator( | ||
isPinned: Boolean, | ||
downloaded: Int, | ||
total: Int, | ||
modifier: Modifier = Modifier, | ||
iconSize: Dp = 24.dp, | ||
) { | ||
val total = total.coerceAtLeast(0) | ||
val downloaded = downloaded.coerceIn(0, total) | ||
val contentModifier = modifier.size(iconSize) | ||
|
||
when { | ||
!isPinned -> Icon( | ||
Icons.Outlined.DownloadForOffline, | ||
null, | ||
modifier = contentModifier, | ||
tint = MaterialTheme.colorScheme.outline, | ||
) | ||
downloaded == total -> Icon( | ||
Icons.Outlined.CheckCircle, | ||
null, | ||
modifier = contentModifier, | ||
tint = MaterialTheme.colorScheme.primary, | ||
) | ||
else -> { | ||
val progress by animateFloatAsState( | ||
label = "Download Progress", | ||
targetValue = when (total) { | ||
0 -> 1f | ||
else -> downloaded.toFloat() / total | ||
}, | ||
) | ||
|
||
val iconPadding = iconSize / 12 | ||
CircularProgressIndicator( | ||
progress = progress, | ||
color = MaterialTheme.colorScheme.primary, | ||
strokeWidth = (iconSize / 2) - iconPadding, | ||
modifier = contentModifier | ||
.padding(iconPadding) | ||
.border(iconSize / 12, MaterialTheme.colorScheme.primary, CircleShape) | ||
) | ||
} | ||
} | ||
} |