diff --git a/app/src/main/kotlin/org/cru/godtools/ui/languages/downloadable/LanguageDownloadProgressIndicator.kt b/app/src/main/kotlin/org/cru/godtools/ui/languages/downloadable/LanguageDownloadProgressIndicator.kt index c659fa927f..c028f5bef2 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/languages/downloadable/LanguageDownloadProgressIndicator.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/languages/downloadable/LanguageDownloadProgressIndicator.kt @@ -2,6 +2,9 @@ package org.cru.godtools.ui.languages.downloadable import androidx.compose.animation.core.animateFloatAsState import androidx.compose.foundation.border +import androidx.compose.foundation.layout.BoxWithConstraints +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape @@ -14,20 +17,23 @@ 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.platform.LocalDensity import androidx.compose.ui.unit.dp +private val DEFAULT_ICON_SIZE = 24.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) + val contentModifier = modifier + .size(DEFAULT_ICON_SIZE) + .aspectRatio(1f) when { !isPinned -> Icon( @@ -51,15 +57,19 @@ internal fun LanguageDownloadProgressIndicator( }, ) - 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) - ) + BoxWithConstraints(contentModifier) { + val size = with(LocalDensity.current) { constraints.maxWidth.toDp() } + val iconPadding = size / 12 + CircularProgressIndicator( + progress = { progress }, + color = MaterialTheme.colorScheme.primary, + strokeWidth = (size / 2) - iconPadding, + modifier = Modifier + .fillMaxSize() + .padding(iconPadding) + .border(size / 12, MaterialTheme.colorScheme.primary, CircleShape) + ) + } } } } diff --git a/app/src/test/snapshots/images/org.cru.godtools.ui.languages.downloadable_LanguageDownloadProgressIndicatorPaparazziTest_LanguageDownloadProgressIndicator() - Download complete.png b/app/src/test/snapshots/images/org.cru.godtools.ui.languages.downloadable_LanguageDownloadProgressIndicatorPaparazziTest_LanguageDownloadProgressIndicator() - Download complete.png new file mode 100644 index 0000000000..1704cc9a7a --- /dev/null +++ b/app/src/test/snapshots/images/org.cru.godtools.ui.languages.downloadable_LanguageDownloadProgressIndicatorPaparazziTest_LanguageDownloadProgressIndicator() - Download complete.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9de0206cebc30c67d1945f926162c1b673d5536e60f70bded008bcafa8ba15ea +size 22356 diff --git a/app/src/test/snapshots/images/org.cru.godtools.ui.languages.downloadable_LanguageDownloadProgressIndicatorPaparazziTest_LanguageDownloadProgressIndicator() - Download in progress.png b/app/src/test/snapshots/images/org.cru.godtools.ui.languages.downloadable_LanguageDownloadProgressIndicatorPaparazziTest_LanguageDownloadProgressIndicator() - Download in progress.png new file mode 100644 index 0000000000..26e45cb983 --- /dev/null +++ b/app/src/test/snapshots/images/org.cru.godtools.ui.languages.downloadable_LanguageDownloadProgressIndicatorPaparazziTest_LanguageDownloadProgressIndicator() - Download in progress.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aab98c677dbb72dd2f5445fffd83fb92fc6510571b2c1ccb8cbea893158aee15 +size 18601 diff --git a/app/src/test/snapshots/images/org.cru.godtools.ui.languages.downloadable_LanguageDownloadProgressIndicatorPaparazziTest_LanguageDownloadProgressIndicator() - Nothing downloaded.png b/app/src/test/snapshots/images/org.cru.godtools.ui.languages.downloadable_LanguageDownloadProgressIndicatorPaparazziTest_LanguageDownloadProgressIndicator() - Nothing downloaded.png new file mode 100644 index 0000000000..54561c469d --- /dev/null +++ b/app/src/test/snapshots/images/org.cru.godtools.ui.languages.downloadable_LanguageDownloadProgressIndicatorPaparazziTest_LanguageDownloadProgressIndicator() - Nothing downloaded.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a87bd15c924e69da1ef7c907a5653e99416a41b27e79199711badf013705a622 +size 19099 diff --git a/app/src/testDebug/kotlin/org/cru/godtools/ui/languages/downloadable/LanguageDownloadProgressIndicatorPaparazziTest.kt b/app/src/testDebug/kotlin/org/cru/godtools/ui/languages/downloadable/LanguageDownloadProgressIndicatorPaparazziTest.kt new file mode 100644 index 0000000000..cbf9977209 --- /dev/null +++ b/app/src/testDebug/kotlin/org/cru/godtools/ui/languages/downloadable/LanguageDownloadProgressIndicatorPaparazziTest.kt @@ -0,0 +1,38 @@ +package org.cru.godtools.ui.languages.downloadable + +import app.cash.paparazzi.Paparazzi +import kotlin.test.Test +import org.cru.godtools.base.ui.theme.GodToolsTheme +import org.junit.Rule + +class LanguageDownloadProgressIndicatorPaparazziTest { + @get:Rule + val paparazzi = Paparazzi() + + @Test + fun `LanguageDownloadProgressIndicator() - Nothing downloaded`() { + paparazzi.snapshot { + GodToolsTheme(disableDagger = true) { + LanguageDownloadProgressIndicator(isPinned = true, downloaded = 0, total = 5) + } + } + } + + @Test + fun `LanguageDownloadProgressIndicator() - Download in progress`() { + paparazzi.snapshot { + GodToolsTheme(disableDagger = true) { + LanguageDownloadProgressIndicator(isPinned = true, downloaded = 2, total = 5) + } + } + } + + @Test + fun `LanguageDownloadProgressIndicator() - Download complete`() { + paparazzi.snapshot { + GodToolsTheme(disableDagger = true) { + LanguageDownloadProgressIndicator(isPinned = true, downloaded = 5, total = 5) + } + } + } +} diff --git a/ui/base/src/main/kotlin/org/cru/godtools/base/ui/compose/CompositionLocals.kt b/ui/base/src/main/kotlin/org/cru/godtools/base/ui/compose/CompositionLocals.kt index ba94edf0b4..6d9673d3e3 100644 --- a/ui/base/src/main/kotlin/org/cru/godtools/base/ui/compose/CompositionLocals.kt +++ b/ui/base/src/main/kotlin/org/cru/godtools/base/ui/compose/CompositionLocals.kt @@ -21,11 +21,13 @@ import org.greenrobot.eventbus.EventBus val LocalEventBus = staticCompositionLocalOf { error("No EventBus available") } @Composable -internal fun CompositionLocals(content: @Composable () -> Unit) { +internal fun CompositionLocals(disableDagger: Boolean = false, content: @Composable () -> Unit) { val context = LocalContext.current val daggerComponents = when { - LocalInspectionMode.current -> object : ComposeEntryPoint { - override val eventBus = EventBus() + LocalInspectionMode.current || disableDagger -> remember { + object : ComposeEntryPoint { + override val eventBus = EventBus() + } } else -> remember { EntryPointAccessors.fromApplication(context) } } diff --git a/ui/base/src/main/kotlin/org/cru/godtools/base/ui/theme/GodToolsTheme.kt b/ui/base/src/main/kotlin/org/cru/godtools/base/ui/theme/GodToolsTheme.kt index 64f2207b9b..f03d56ead2 100644 --- a/ui/base/src/main/kotlin/org/cru/godtools/base/ui/theme/GodToolsTheme.kt +++ b/ui/base/src/main/kotlin/org/cru/godtools/base/ui/theme/GodToolsTheme.kt @@ -114,7 +114,7 @@ object GodToolsTheme { } @Composable -fun GodToolsTheme(content: @Composable () -> Unit) { +fun GodToolsTheme(disableDagger: Boolean = false, content: @Composable () -> Unit) { val isDarkTheme = isSystemInDarkTheme() && BuildConfig.DEBUG MaterialTheme( colorScheme = when { @@ -123,7 +123,7 @@ fun GodToolsTheme(content: @Composable () -> Unit) { }, typography = GodToolsTheme.typography ) { - CompositionLocals { + CompositionLocals(disableDagger) { CompositionLocalProvider( LocalLightColorSchemeActive provides !isDarkTheme, LocalContentColor provides contentColorFor(MaterialTheme.colorScheme.background),