From ff11a6a1f99c66d51abb90dd7f5707cfb63c9a81 Mon Sep 17 00:00:00 2001 From: "Jack Boswell (boswelja)" Date: Wed, 3 Jan 2024 20:37:27 +1300 Subject: [PATCH] Migrate to Paddings --- .../animite/features/MainActivity.kt | 9 ++--- .../imashnake/animite/features/home/Home.kt | 18 ++++----- .../animite/features/media/MediaPage.kt | 38 +++++++++---------- .../features/searchbar/SearchFrontDrop.kt | 18 ++++----- .../animite/features/ui/MediaSmall.kt | 8 ++-- .../animite/profile/ProfileScreen.kt | 4 +- .../imashnake/animite/rslash/RSlashScreen.kt | 4 +- 7 files changed, 49 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/com/imashnake/animite/features/MainActivity.kt b/app/src/main/java/com/imashnake/animite/features/MainActivity.kt index 9eecd220..31453bca 100644 --- a/app/src/main/java/com/imashnake/animite/features/MainActivity.kt +++ b/app/src/main/java/com/imashnake/animite/features/MainActivity.kt @@ -24,10 +24,9 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.dimensionResource import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController -import com.imashnake.animite.core.R as coreR +import com.imashnake.animite.core.ui.LocalPaddings import com.imashnake.animite.features.destinations.MediaPageDestination import com.imashnake.animite.features.media.MediaPageArgs import com.imashnake.animite.features.navigationbar.NavigationBar @@ -107,9 +106,9 @@ fun MainScreen(modifier: Modifier = Modifier) { modifier = Modifier .align(Alignment.BottomEnd) .padding( - start = dimensionResource(coreR.dimen.large_padding), - end = dimensionResource(coreR.dimen.large_padding), - bottom = dimensionResource(coreR.dimen.large_padding) + start = LocalPaddings.current.large, + end = LocalPaddings.current.large, + bottom = LocalPaddings.current.large ) ) diff --git a/app/src/main/java/com/imashnake/animite/features/home/Home.kt b/app/src/main/java/com/imashnake/animite/features/home/Home.kt index 193cf900..556f3ab2 100644 --- a/app/src/main/java/com/imashnake/animite/features/home/Home.kt +++ b/app/src/main/java/com/imashnake/animite/features/home/Home.kt @@ -58,8 +58,8 @@ import com.imashnake.animite.features.ui.MediaSmall import com.imashnake.animite.features.ui.MediaSmallRow import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.navigation.DestinationsNavigator -import com.imashnake.animite.core.R as coreR import com.imashnake.animite.R +import com.imashnake.animite.core.ui.LocalPaddings @Destination @Composable @@ -130,8 +130,8 @@ fun Home( style = MaterialTheme.typography.displayMedium, modifier = Modifier .padding( - start = dimensionResource(coreR.dimen.large_padding), - bottom = dimensionResource(coreR.dimen.medium_padding) + start = LocalPaddings.current.large, + bottom = LocalPaddings.current.medium ) .landscapeCutoutPadding() .weight(1f, fill = false), @@ -141,8 +141,8 @@ fun Home( MediaTypeSelector( modifier = Modifier .padding( - end = dimensionResource(coreR.dimen.large_padding), - bottom = dimensionResource(coreR.dimen.medium_padding) + end = LocalPaddings.current.large, + bottom = LocalPaddings.current.medium ) .landscapeCutoutPadding(), selectedOption = homeMediaType, @@ -157,10 +157,10 @@ fun Home( Column( modifier = Modifier .background(MaterialTheme.colorScheme.background) - .padding(vertical = dimensionResource(coreR.dimen.large_padding)) + .padding(vertical = LocalPaddings.current.large) // TODO: Move this one out of Home when we can pass modifiers in. .padding(bottom = dimensionResource(R.dimen.navigation_bar_height)), - verticalArrangement = Arrangement.spacedBy(dimensionResource(coreR.dimen.large_padding)) + verticalArrangement = Arrangement.spacedBy(LocalPaddings.current.large) ) { HomeRow( list = trendingList.data.orEmpty(), @@ -261,11 +261,11 @@ fun HomeRow( text = title, style = MaterialTheme.typography.titleMedium, modifier = Modifier - .padding(start = dimensionResource(coreR.dimen.large_padding)) + .padding(start = LocalPaddings.current.large) .landscapeCutoutPadding() ) - Spacer(Modifier.size(dimensionResource(coreR.dimen.medium_padding))) + Spacer(Modifier.size(LocalPaddings.current.medium)) MediaSmallRow( mediaList = list, diff --git a/app/src/main/java/com/imashnake/animite/features/media/MediaPage.kt b/app/src/main/java/com/imashnake/animite/features/media/MediaPage.kt index 69e70685..83f2b692 100644 --- a/app/src/main/java/com/imashnake/animite/features/media/MediaPage.kt +++ b/app/src/main/java/com/imashnake/animite/features/media/MediaPage.kt @@ -66,11 +66,11 @@ import androidx.core.text.HtmlCompat import androidx.hilt.navigation.compose.hiltViewModel import coil.compose.AsyncImage import coil.request.ImageRequest -import com.imashnake.animite.core.R as coreR import com.imashnake.animite.R import com.imashnake.animite.api.anilist.sanitize.media.Media import com.imashnake.animite.core.extensions.bannerParallax import com.imashnake.animite.core.extensions.landscapeCutoutPadding +import com.imashnake.animite.core.ui.LocalPaddings import com.imashnake.animite.core.ui.NestedScrollableContent import com.imashnake.animite.core.ui.TranslucentStatusBarLayout import com.imashnake.animite.dev.internal.Constants @@ -114,9 +114,9 @@ fun MediaPage( .fillMaxHeight() .padding(top = bannerHeight) .background(MaterialTheme.colorScheme.background) - .padding(bottom = dimensionResource(coreR.dimen.large_padding)) + .padding(bottom = LocalPaddings.current.large) .navigationBarsPadding(), - verticalArrangement = Arrangement.spacedBy(dimensionResource(coreR.dimen.large_padding)) + verticalArrangement = Arrangement.spacedBy(LocalPaddings.current.large) ) { MediaDetails( title = media.title.orEmpty(), @@ -124,11 +124,11 @@ fun MediaPage( // TODO Can we do something about this Modifier chain? modifier = Modifier .padding( - start = dimensionResource(coreR.dimen.large_padding) + start = LocalPaddings.current.large + dimensionResource(R.dimen.media_card_width) - + dimensionResource(coreR.dimen.large_padding), - top = dimensionResource(coreR.dimen.medium_padding), - end = dimensionResource(coreR.dimen.large_padding) + + LocalPaddings.current.large, + top = LocalPaddings.current.medium, + end = LocalPaddings.current.large ) .landscapeCutoutPadding() .height( @@ -138,7 +138,7 @@ fun MediaPage( + dimensionResource(R.dimen.media_card_top_padding) + dimensionResource(R.dimen.media_card_height) - dimensionResource(R.dimen.banner_height) - - dimensionResource(coreR.dimen.medium_padding) + - LocalPaddings.current.medium ) .fillMaxSize() ) @@ -148,7 +148,7 @@ fun MediaPage( rankings = media.ranks, modifier = Modifier .fillMaxWidth() - .padding(horizontal = dimensionResource(coreR.dimen.large_padding)) + .padding(horizontal = LocalPaddings.current.large) .landscapeCutoutPadding() ) } @@ -157,13 +157,13 @@ fun MediaPage( MediaGenres( genres = media.genres, contentPadding = PaddingValues( - start = dimensionResource(coreR.dimen.large_padding) + if ( + start = LocalPaddings.current.large + if ( LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE ) { WindowInsets.displayCutout.asPaddingValues() .calculateLeftPadding(LayoutDirection.Ltr) } else 0.dp, - end = dimensionResource(coreR.dimen.large_padding) + end = LocalPaddings.current.large ), color = Color(media.color ?: (0xFF152232).toInt()), ) @@ -172,7 +172,7 @@ fun MediaPage( if (!media.characters.isNullOrEmpty()) { MediaCharacters( characters = media.characters, - contentPadding = PaddingValues(horizontal = dimensionResource(coreR.dimen.large_padding)) + contentPadding = PaddingValues(horizontal = LocalPaddings.current.large) ) } @@ -180,7 +180,7 @@ fun MediaPage( MediaTrailer( trailer = media.trailer, modifier = Modifier - .padding(horizontal = dimensionResource(coreR.dimen.large_padding)) + .padding(horizontal = LocalPaddings.current.large) .landscapeCutoutPadding() ) } @@ -191,8 +191,8 @@ fun MediaPage( .statusBarsPadding() .padding( top = dimensionResource(R.dimen.media_card_top_padding), - start = dimensionResource(coreR.dimen.large_padding), - end = dimensionResource(coreR.dimen.large_padding) + start = LocalPaddings.current.large, + end = LocalPaddings.current.large ) .landscapeCutoutPadding() ) { @@ -330,7 +330,7 @@ fun MediaGenres( ) { LazyRow( horizontalArrangement = Arrangement.spacedBy( - dimensionResource(coreR.dimen.medium_padding) + LocalPaddings.current.medium ), contentPadding = contentPadding, modifier = modifier @@ -343,7 +343,7 @@ fun MediaGenres( color = MaterialTheme.colorScheme.onBackground, style = MaterialTheme.typography.labelMedium, modifier = Modifier.padding( - vertical = dimensionResource(coreR.dimen.small_padding) + vertical = LocalPaddings.current.small ) ) }, @@ -374,7 +374,7 @@ fun MediaCharacters( .landscapeCutoutPadding() ) - Spacer(Modifier.size(dimensionResource(coreR.dimen.medium_padding))) + Spacer(Modifier.size(LocalPaddings.current.medium)) MediaSmallRow( mediaList = characters @@ -401,7 +401,7 @@ fun MediaTrailer( style = MaterialTheme.typography.titleMedium ) - Spacer(Modifier.size(dimensionResource(coreR.dimen.medium_padding))) + Spacer(Modifier.size(LocalPaddings.current.medium)) val context = LocalContext.current Box( diff --git a/app/src/main/java/com/imashnake/animite/features/searchbar/SearchFrontDrop.kt b/app/src/main/java/com/imashnake/animite/features/searchbar/SearchFrontDrop.kt index 1ad8cadb..5da9982d 100644 --- a/app/src/main/java/com/imashnake/animite/features/searchbar/SearchFrontDrop.kt +++ b/app/src/main/java/com/imashnake/animite/features/searchbar/SearchFrontDrop.kt @@ -46,11 +46,11 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel -import com.imashnake.animite.core.R as coreR import com.imashnake.animite.R import com.imashnake.animite.api.anilist.sanitize.search.Search import com.imashnake.animite.api.anilist.type.MediaType import com.imashnake.animite.core.extensions.landscapeCutoutPadding +import com.imashnake.animite.core.ui.LocalPaddings import com.imashnake.animite.dev.internal.Constants import com.imashnake.animite.features.ui.MediaSmall @@ -136,17 +136,17 @@ fun SearchList( LazyColumn( modifier = modifier, contentPadding = PaddingValues( - start = dimensionResource(coreR.dimen.large_padding), - end = dimensionResource(coreR.dimen.large_padding), - top = dimensionResource(coreR.dimen.large_padding) + start = LocalPaddings.current.large, + end = LocalPaddings.current.large, + top = LocalPaddings.current.large + WindowInsets.statusBars.asPaddingValues().calculateTopPadding(), bottom = dimensionResource(R.dimen.search_bar_height) - + dimensionResource(coreR.dimen.large_padding) - + dimensionResource(coreR.dimen.large_padding) + + LocalPaddings.current.large + + LocalPaddings.current.large + dimensionResource(R.dimen.navigation_bar_height) + WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding() ), - verticalArrangement = Arrangement.spacedBy(dimensionResource(coreR.dimen.small_padding)) + verticalArrangement = Arrangement.spacedBy(LocalPaddings.current.small) ) { items(searchList.size, key = { searchList[it].id }) { index -> SearchItem( @@ -176,7 +176,7 @@ private fun SearchItem( modifier = Modifier.width(dimensionResource(R.dimen.character_card_width)) ) - Column(Modifier.padding(horizontal = dimensionResource(coreR.dimen.small_padding))) { + Column(Modifier.padding(horizontal = LocalPaddings.current.small)) { Text( text = item.title.orEmpty(), color = MaterialTheme.colorScheme.onBackground, @@ -193,7 +193,7 @@ private fun SearchItem( ) } - Spacer(Modifier.size(dimensionResource(coreR.dimen.medium_padding))) + Spacer(Modifier.size(LocalPaddings.current.medium)) Text( text = item.studios.joinToString(), diff --git a/app/src/main/java/com/imashnake/animite/features/ui/MediaSmall.kt b/app/src/main/java/com/imashnake/animite/features/ui/MediaSmall.kt index 81c7846b..288e7cb7 100644 --- a/app/src/main/java/com/imashnake/animite/features/ui/MediaSmall.kt +++ b/app/src/main/java/com/imashnake/animite/features/ui/MediaSmall.kt @@ -36,8 +36,8 @@ import coil.request.ImageRequest import com.imashnake.animite.api.anilist.MediaListQuery import com.imashnake.animite.api.anilist.type.MediaType import com.imashnake.animite.dev.internal.Constants.CROSSFADE_DURATION -import com.imashnake.animite.core.R as coreR import com.imashnake.animite.R +import com.imashnake.animite.core.ui.LocalPaddings /** * A [LazyRow] of [MediaSmall]s. @@ -50,14 +50,14 @@ fun MediaSmallRow( content: @Composable (T) -> Unit ) { LazyRow( - horizontalArrangement = Arrangement.spacedBy(dimensionResource(coreR.dimen.small_padding)), + horizontalArrangement = Arrangement.spacedBy(LocalPaddings.current.small), contentPadding = PaddingValues( - start = dimensionResource(coreR.dimen.large_padding) + if ( + start = LocalPaddings.current.large + if ( LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE ) { WindowInsets.displayCutout.asPaddingValues().calculateLeftPadding(LayoutDirection.Ltr) } else 0.dp, - end = dimensionResource(coreR.dimen.large_padding) + end = LocalPaddings.current.large ) ) { items(mediaList) { media -> diff --git a/profile/src/main/kotlin/com/imashnake/animite/profile/ProfileScreen.kt b/profile/src/main/kotlin/com/imashnake/animite/profile/ProfileScreen.kt index abb48424..749cbcc5 100644 --- a/profile/src/main/kotlin/com/imashnake/animite/profile/ProfileScreen.kt +++ b/profile/src/main/kotlin/com/imashnake/animite/profile/ProfileScreen.kt @@ -10,9 +10,9 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.stringResource import com.imashnake.animite.core.R as coreR +import com.imashnake.animite.core.ui.LocalPaddings import com.imashnake.animite.core.ui.ProgressIndicator import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootNavGraph @@ -30,7 +30,7 @@ fun ProfileScreen() { Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy( - dimensionResource(coreR.dimen.tiny_padding) + LocalPaddings.current.tiny ) ) { Text( diff --git a/rslash/src/main/kotlin/com/imashnake/animite/rslash/RSlashScreen.kt b/rslash/src/main/kotlin/com/imashnake/animite/rslash/RSlashScreen.kt index 39ec3bb6..cd764e9c 100644 --- a/rslash/src/main/kotlin/com/imashnake/animite/rslash/RSlashScreen.kt +++ b/rslash/src/main/kotlin/com/imashnake/animite/rslash/RSlashScreen.kt @@ -10,8 +10,8 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.stringResource +import com.imashnake.animite.core.ui.LocalPaddings import com.imashnake.animite.core.R as coreR import com.imashnake.animite.core.ui.ProgressIndicator import com.ramcosta.composedestinations.annotation.Destination @@ -30,7 +30,7 @@ fun RSlashScreen() { Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy( - dimensionResource(coreR.dimen.tiny_padding) + LocalPaddings.current.tiny ) ) { Text(