some cleanup

This commit is contained in:
Owen LeJeune
2023-07-11 14:32:34 -04:00
parent 0c2689c329
commit 85cdbc80cd
3 changed files with 47 additions and 10 deletions

View File

@@ -0,0 +1,41 @@
package com.owenlejeune.tvtime.extensions
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.TileMode
fun Modifier.shimmerBackground(shape: Shape = RectangleShape): Modifier = composed {
val transition = rememberInfiniteTransition()
val translateAnimation by transition.animateFloat(
initialValue = 0f,
targetValue = 400f,
animationSpec = infiniteRepeatable(
tween(durationMillis = 1500, easing = LinearOutSlowInEasing),
RepeatMode.Restart
),
)
val shimmerColors = listOf(
Color.LightGray.copy(alpha = 0.9f),
Color.LightGray.copy(alpha = 0.4f),
)
val brush = Brush.linearGradient(
colors = shimmerColors,
start = Offset(translateAnimation, translateAnimation),
end = Offset(translateAnimation + 100f, translateAnimation + 100f),
tileMode = TileMode.Mirror,
)
return@composed this.then(background(brush, shape))
}

View File

@@ -1,7 +1,6 @@
package com.owenlejeune.tvtime.ui.components package com.owenlejeune.tvtime.ui.components
import android.util.Log import android.util.Log
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.focusable import androidx.compose.foundation.focusable
@@ -16,7 +15,6 @@ import androidx.compose.material.icons.filled.Movie
import androidx.compose.material.icons.filled.Person import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.Card import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
@@ -39,16 +37,14 @@ import androidx.paging.compose.LazyPagingItems
import coil.compose.AsyncImage import coil.compose.AsyncImage
import coil.request.CachePolicy import coil.request.CachePolicy
import coil.request.ImageRequest import coil.request.ImageRequest
import com.owenlejeune.tvtime.api.LoadingState
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.HomePagePerson import com.owenlejeune.tvtime.api.tmdb.api.v3.model.HomePagePerson
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.Person
import com.owenlejeune.tvtime.api.tmdb.api.v3.model.TmdbItem import com.owenlejeune.tvtime.api.tmdb.api.v3.model.TmdbItem
import com.owenlejeune.tvtime.extensions.header import com.owenlejeune.tvtime.extensions.header
import com.owenlejeune.tvtime.extensions.lazyPagingItems import com.owenlejeune.tvtime.extensions.lazyPagingItems
import com.owenlejeune.tvtime.extensions.listItems import com.owenlejeune.tvtime.extensions.shimmerBackground
import com.owenlejeune.tvtime.preferences.AppPreferences import com.owenlejeune.tvtime.preferences.AppPreferences
import com.owenlejeune.tvtime.ui.viewmodel.ConfigurationViewModel
import com.owenlejeune.tvtime.utils.TmdbUtils import com.owenlejeune.tvtime.utils.TmdbUtils
import org.koin.androidx.compose.koinViewModel
import org.koin.java.KoinJavaComponent.get import org.koin.java.KoinJavaComponent.get
private val POSTER_WIDTH = 120.dp private val POSTER_WIDTH = 120.dp
@@ -58,7 +54,7 @@ private val POSTER_HEIGHT = 180.dp
fun PagingPosterGrid( fun PagingPosterGrid(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
lazyPagingItems: LazyPagingItems<TmdbItem>?, lazyPagingItems: LazyPagingItems<TmdbItem>?,
header: @Composable (LazyGridItemScope.() -> Unit)? = null, headerContent: @Composable (LazyGridItemScope.() -> Unit)? = null,
onClick: (id: Int) -> Unit = {} onClick: (id: Int) -> Unit = {}
) { ) {
lazyPagingItems?.let { lazyPagingItems?.let {
@@ -68,8 +64,8 @@ fun PagingPosterGrid(
contentPadding = PaddingValues(8.dp), contentPadding = PaddingValues(8.dp),
horizontalArrangement = Arrangement.SpaceBetween horizontalArrangement = Arrangement.SpaceBetween
) { ) {
header?.let { headerContent?.let {
header(header) header(headerContent)
} }
lazyPagingItems( lazyPagingItems(
lazyPagingItems = lazyPagingItems, lazyPagingItems = lazyPagingItems,

View File

@@ -101,7 +101,7 @@ fun MediaTabTrendingContent(
PagingPosterGrid( PagingPosterGrid(
lazyPagingItems = mediaListItems, lazyPagingItems = mediaListItems,
header = { headerContent = {
val options = listOf(TimeWindow.DAY, TimeWindow.WEEK) val options = listOf(TimeWindow.DAY, TimeWindow.WEEK)
val context = LocalContext.current val context = LocalContext.current