Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.flipcash.app.currencycreator

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
Expand Down Expand Up @@ -63,6 +65,7 @@ import com.getcode.opencode.model.financial.Fiat
import com.getcode.opencode.model.financial.LocalFiat
import com.getcode.opencode.model.financial.toFiat
import com.getcode.theme.CodeTheme
import com.getcode.theme.rememberDynamicAccent
import com.getcode.ui.core.unboundedClickable

@Composable
Expand Down Expand Up @@ -136,15 +139,24 @@ fun CurrencyCreatorFlowScreen(
endContent = when (state.currentStep) {
is CurrencyCreatorStep.BillCustomization -> {
{
val (accent, onAccent) = rememberDynamicAccent(
fallbackAccent = CodeTheme.colors.secondary,
fallbackOnAccent = CodeTheme.colors.onAction,
)

Text(
text = stringResource(R.string.action_done),
text = stringResource(R.string.action_next),
style = CodeTheme.typography.textMedium,
color = Color.White,
color = onAccent,
modifier = Modifier
.background(accent, shape = CircleShape)
.unboundedClickable {
topBarController.onEndAction?.invoke()
}
.padding(5.dp),
.padding(
horizontal = CodeTheme.dimens.grid.x2,
vertical = CodeTheme.dimens.grid.x1
),
)
}
}
Expand Down
1 change: 1 addition & 0 deletions ui/theme/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ android {
dependencies { debugImplementation(libs.compose.ui.tools)
implementation(libs.compose.ui.tools.preview)
implementation(libs.compose.material)
implementation(libs.compose.material3)
implementation(libs.compose.accompanist)

implementation(libs.androidx.appcompat)
Expand Down
50 changes: 50 additions & 0 deletions ui/theme/src/main/kotlin/com/getcode/theme/DynamicColor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.getcode.theme

import android.os.Build
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext

/**
* The user's Material You (Monet) accent color, derived from their wallpaper / system theme.
*
* On Android 12+ (API 31) this reads the wallpaper-derived tonal palette via Material3's
* [dynamicDarkColorScheme] and returns its [accent] (`primary`) and [onAccent] (`onPrimary`).
* The app is dark-only, so we always take the *dark* dynamic scheme regardless of the system
* light/dark setting — its tonal steps read correctly on our dark surfaces.
*
* On API < 31 both fields fall back to [fallbackAccent] / [fallbackOnAccent].
*
* Usage:
* ```
* val (accent, onAccent) = rememberDynamicAccent(
* fallbackAccent = CodeTheme.colors.secondary,
* fallbackOnAccent = CodeTheme.colors.onAction,
* )
* Button(colors = ButtonDefaults.buttonColors(containerColor = accent)) {
* Text("Save", color = onAccent)
* }
* ```
*/
@Composable
fun rememberDynamicAccent(
fallbackAccent: Color,
fallbackOnAccent: Color = Color.White,
): DynamicAccent {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
return DynamicAccent(accent = fallbackAccent, onAccent = fallbackOnAccent)
}
val context = LocalContext.current
return remember(context) {
val scheme = dynamicDarkColorScheme(context)
DynamicAccent(accent = scheme.primary, onAccent = scheme.onPrimary)
}
}

/** A wallpaper-derived accent paired with the content color that reads on top of it. */
data class DynamicAccent(
val accent: Color,
val onAccent: Color,
)
Loading