Skip to content

Commit

Permalink
Compose: restore edge-to-edge padding in AboutActivity.
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Jan 31, 2024
1 parent a45c697 commit 94878c8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.FilledTonalButton
Expand All @@ -38,6 +37,8 @@ import androidx.compose.ui.unit.dp
import com.battlelancer.seriesguide.R
import com.battlelancer.seriesguide.ui.theme.SeriesGuideTheme
import com.battlelancer.seriesguide.util.PackageTools
import com.battlelancer.seriesguide.util.ThemeUtils
import com.battlelancer.seriesguide.util.ThemeUtils.plus
import com.battlelancer.seriesguide.util.WebTools

/**
Expand All @@ -47,9 +48,7 @@ class AboutActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// FIXME How to do this?
// ThemeUtils.configureForEdgeToEdge(findViewById(R.id.rootLayoutAbout))
ThemeUtils.configureEdgeToEdge(window)

setContent {
SeriesGuideTheme {
Expand Down Expand Up @@ -121,63 +120,67 @@ class AboutActivity : ComponentActivity() {
}
) { scaffoldPadding ->
BoxWithConstraints(
modifier = Modifier
.padding(scaffoldPadding)
.fillMaxWidth()
modifier = Modifier.fillMaxWidth()
) {
val scrollAndPadding = Modifier
.verticalScroll(rememberScrollState())
.padding(defaultSpacerSize)
Column(
// if 600 dp or wider center align
modifier = if (maxWidth < 600.dp) {
scrollAndPadding
} else {
scrollAndPadding
// (Ab)using LazyColumn to easily add content padding that is not clipped
// for applying insets.
LazyColumn(
// if wider than 600 dp center align
modifier = if (maxWidth > 600.dp) {
Modifier
.width(600.dp)
.align(Alignment.Center)
}
} else {
Modifier
},
contentPadding = scaffoldPadding + PaddingValues(defaultSpacerSize)
) {
Text(
text = stringResource(id = R.string.app_name),
style = MaterialTheme.typography.headlineLarge
)
Text(
text = versionString,
style = MaterialTheme.typography.bodyLarge
)
FilledTonalButton(onClick = onOpenWebsite) {
Text(text = stringResource(id = R.string.website))
item {
Text(
text = stringResource(id = R.string.app_name),
style = MaterialTheme.typography.headlineLarge
)
Text(
text = versionString,
style = MaterialTheme.typography.bodyLarge
)
FilledTonalButton(onClick = onOpenWebsite) {
Text(text = stringResource(id = R.string.website))
}
FilledTonalButton(onClick = onOpenPrivacyPolicy) {
Text(text = stringResource(id = R.string.privacy_policy))
}
}
FilledTonalButton(onClick = onOpenPrivacyPolicy) {
Text(text = stringResource(id = R.string.privacy_policy))
item {
Text(
text = stringResource(id = R.string.about_open_source),
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(top = 16.dp)
)
FilledTonalButton(onClick = onOpenCredits) {
Text(text = stringResource(id = R.string.licences_and_credits))
}
Text(
text = stringResource(id = R.string.licence_themoviedb),
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(top = 16.dp)
)
FilledTonalButton(onClick = onOpenTmdbTerms) {
Text(text = stringResource(id = R.string.tmdb_terms))
}
FilledTonalButton(onClick = onOpenTmdbApiTerms) {
Text(text = stringResource(id = R.string.tmdb_api_terms))
}
}
Text(
text = stringResource(id = R.string.about_open_source),
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(top = 16.dp)
)
FilledTonalButton(onClick = onOpenCredits) {
Text(text = stringResource(id = R.string.licences_and_credits))
}
Text(
text = stringResource(id = R.string.licence_themoviedb),
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(top = 16.dp)
)
FilledTonalButton(onClick = onOpenTmdbTerms) {
Text(text = stringResource(id = R.string.tmdb_terms))
}
FilledTonalButton(onClick = onOpenTmdbApiTerms) {
Text(text = stringResource(id = R.string.tmdb_api_terms))
}
Text(
text = stringResource(id = R.string.licence_trakt),
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(top = 16.dp)
)
FilledTonalButton(onClick = onOpenTraktTerms) {
Text(text = stringResource(id = R.string.trakt_terms))
item {
Text(
text = stringResource(id = R.string.licence_trakt),
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(top = 16.dp)
)
FilledTonalButton(onClick = onOpenTraktTerms) {
Text(text = stringResource(id = R.string.trakt_terms))
}
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/battlelancer/seriesguide/util/ThemeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import android.view.Window
import androidx.annotation.AnyRes
import androidx.annotation.AttrRes
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import androidx.core.view.ViewCompat
Expand Down Expand Up @@ -352,4 +355,22 @@ object ThemeUtils {
}
}

// Easily add two [PaddingValues] if using a Modifier (with multiple padding calls) is not possible.
operator fun PaddingValues.plus(that: PaddingValues): PaddingValues = object : PaddingValues {
override fun calculateBottomPadding(): Dp =
this@plus.calculateBottomPadding() + that.calculateBottomPadding()

override fun calculateLeftPadding(layoutDirection: LayoutDirection): Dp =
this@plus.calculateLeftPadding(layoutDirection) + that.calculateLeftPadding(
layoutDirection
)

override fun calculateRightPadding(layoutDirection: LayoutDirection): Dp =
this@plus.calculateRightPadding(layoutDirection) + that.calculateRightPadding(
layoutDirection
)

override fun calculateTopPadding(): Dp =
this@plus.calculateTopPadding() + that.calculateTopPadding()
}
}

0 comments on commit 94878c8

Please sign in to comment.