Skip to content

Commit

Permalink
Update Headline Background Blur Effect.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Jun 1, 2024
1 parent f467151 commit c2e702c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.offset
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
Expand All @@ -20,7 +21,7 @@ import coil.compose.AsyncImage
import coil.request.CachePolicy
import coil.request.ImageRequest
import com.m3u.core.architecture.preferences.hiltPreferences
import com.m3u.material.ktx.BlurTransformation
import com.m3u.material.transformation.BlurTransformation
import com.m3u.ui.helper.LocalHelper
import com.m3u.ui.helper.Metadata
import com.m3u.ui.helper.useRailNav
Expand All @@ -31,6 +32,7 @@ fun HeadlineBackground(modifier: Modifier = Modifier) {
val context = LocalContext.current
val configuration = LocalConfiguration.current
val helper = LocalHelper.current
val colorScheme = MaterialTheme.colorScheme

val preferences = hiltPreferences()

Expand All @@ -46,15 +48,15 @@ fun HeadlineBackground(modifier: Modifier = Modifier) {
targetValue = lerp(
start = if (useDarkTheme) Color.Black.copy(0.56f)
else Color.White.copy(0.56f),
stop = Color.Transparent,
stop = colorScheme.surface,
fraction = fraction
),
label = "scaffold-main-content-mask-color"
)

if (!preferences.noPictureMode) {
AsyncImage(
model = remember(url) {
model = remember(url, colorScheme.background) {
ImageRequest.Builder(context)
.data(url)
.crossfade(800)
Expand All @@ -78,7 +80,12 @@ fun HeadlineBackground(modifier: Modifier = Modifier) {
.drawWithContent {
drawContent()
if (url.isNotEmpty()) {
drawRect(color = currentMaskColor, size = size)
drawRect(
color = currentMaskColor,
// size = size.copy(
// height = size.height * 0.95f
// )
)
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ internal fun PlaylistGallery(

val state = rememberLazyGridState()
val viewportStartOffset by remember {
derivedStateOf { state.layoutInfo.visibleItemsInfo.firstOrNull()?.offset?.y ?: 0 }
derivedStateOf {
if (state.firstVisibleItemIndex == 0) state.firstVisibleItemScrollOffset
else -Int.MAX_VALUE
}
}
val currentHazeColor by animateColorAsState(
targetValue = lerp(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.m3u.material.ktx
package com.m3u.material.transformation

import android.content.Context
import android.graphics.Bitmap
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.m3u.material.transformation

import android.graphics.Bitmap
import android.graphics.Paint
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.core.graphics.applyCanvas
import androidx.core.graphics.createBitmap
import coil.size.Size
import coil.size.pxOrElse
import coil.transform.Transformation

class ColorCombineTransformation(
private val color: Color
) : Transformation {
override val cacheKey: String = "${ColorCombineTransformation::class.java.name}_$color"

@Suppress("USELESS_ELVIS")
override suspend fun transform(input: Bitmap, size: Size): Bitmap {
val bitmapPainter = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
val colorPainter = Paint().apply {
setColor(this@ColorCombineTransformation.color.toArgb())
setColor(android.graphics.Color.RED)
}
val width = input.width
val height = input.height
return createBitmap(
width = width,
height = height,
config = input.config ?: Bitmap.Config.ARGB_8888
).applyCanvas {
drawBitmap(
input,
0f,
0f,
bitmapPainter
)
drawRect(
0f,
size.height.pxOrElse { height } * 0.85f,
size.width.pxOrElse { width }.toFloat(),
height.toFloat(),
colorPainter
)
}
}
}

0 comments on commit c2e702c

Please sign in to comment.