Skip to content

Commit

Permalink
Fix #8 background colour on the details screens
Browse files Browse the repository at this point in the history
  • Loading branch information
herrbert74 committed Oct 29, 2024
1 parent ee6e604 commit ff7a26c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun MovieDetailScreen(
val darkVibrantColor = extractColorsFromBitmap(
bitmap = bitmap,
isDarkMode = context.isDarkMode
)["dark"] ?: bgDim.toString()
)["muted"] ?: bgDim.toString()
color2 = Color(parseColor(darkVibrantColor))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package com.zsoltbertalan.flickslate.shared.compose.util
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import androidx.compose.ui.graphics.toArgb
import androidx.palette.graphics.Palette
import coil.ImageLoader
import coil.request.ImageRequest
import coil.request.SuccessResult
import com.zsoltbertalan.flickslate.shared.compose.design.FlickSlateDarkColorScheme
import com.zsoltbertalan.flickslate.shared.compose.design.FlickSlateLightColorScheme

suspend fun convertImageUrlToBitmap(
imageUrl: String,
Expand All @@ -30,19 +33,22 @@ fun extractColorsFromBitmap(bitmap: Bitmap, isDarkMode: Boolean): Map<String, St

return mapOf(
"vibrant" to parseColorSwatch(
color = if (isDarkMode) palette.darkVibrantSwatch else palette.lightVibrantSwatch
color = if (isDarkMode) palette.darkVibrantSwatch else palette.lightVibrantSwatch,
isDarkMode = isDarkMode
),
"dark" to parseColorSwatch(
color = if (isDarkMode) palette.darkMutedSwatch else palette.lightMutedSwatch
"muted" to parseColorSwatch(
color = if (isDarkMode) palette.darkMutedSwatch else palette.lightMutedSwatch,
isDarkMode = isDarkMode
),
)
}

private fun parseColorSwatch(color: Palette.Swatch?): String {
private fun parseColorSwatch(color: Palette.Swatch?, isDarkMode: Boolean): String {
return if (color != null) {
val parsedColor = Integer.toHexString(color.rgb)
return "#$parsedColor"
} else {
"#000000"
if(isDarkMode) "#${Integer.toHexString(FlickSlateDarkColorScheme.surface.toArgb())}"
else "#${Integer.toHexString(FlickSlateLightColorScheme.surface.toArgb())}"
}
}

0 comments on commit ff7a26c

Please sign in to comment.