Skip to content

Commit

Permalink
Migrate to Paddings
Browse files Browse the repository at this point in the history
  • Loading branch information
boswelja committed Jan 3, 2024
1 parent c9d8319 commit ff11a6a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
)

Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/imashnake/animite/features/home/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
38 changes: 19 additions & 19 deletions app/src/main/java/com/imashnake/animite/features/media/MediaPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,21 +114,21 @@ 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(),
description = media.description.orEmpty(),
// 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(
Expand All @@ -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()
)
Expand All @@ -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()
)
}
Expand All @@ -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()),
)
Expand All @@ -172,15 +172,15 @@ fun MediaPage(
if (!media.characters.isNullOrEmpty()) {
MediaCharacters(
characters = media.characters,
contentPadding = PaddingValues(horizontal = dimensionResource(coreR.dimen.large_padding))
contentPadding = PaddingValues(horizontal = LocalPaddings.current.large)
)
}

if (media.trailer != null) {
MediaTrailer(
trailer = media.trailer,
modifier = Modifier
.padding(horizontal = dimensionResource(coreR.dimen.large_padding))
.padding(horizontal = LocalPaddings.current.large)
.landscapeCutoutPadding()
)
}
Expand All @@ -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()
) {
Expand Down Expand Up @@ -330,7 +330,7 @@ fun MediaGenres(
) {
LazyRow(
horizontalArrangement = Arrangement.spacedBy(
dimensionResource(coreR.dimen.medium_padding)
LocalPaddings.current.medium
),
contentPadding = contentPadding,
modifier = modifier
Expand All @@ -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
)
)
},
Expand Down Expand Up @@ -374,7 +374,7 @@ fun MediaCharacters(
.landscapeCutoutPadding()
)

Spacer(Modifier.size(dimensionResource(coreR.dimen.medium_padding)))
Spacer(Modifier.size(LocalPaddings.current.medium))

MediaSmallRow(
mediaList = characters
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -50,14 +50,14 @@ fun <T> 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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,7 +30,7 @@ fun ProfileScreen() {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
dimensionResource(coreR.dimen.tiny_padding)
LocalPaddings.current.tiny
)
) {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,7 +30,7 @@ fun RSlashScreen() {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(
dimensionResource(coreR.dimen.tiny_padding)
LocalPaddings.current.tiny
)
) {
Text(
Expand Down

0 comments on commit ff11a6a

Please sign in to comment.