Skip to content

Commit

Permalink
Add safe drawing padding (edge-to-edge)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc2822 committed Dec 12, 2024
1 parent 5a43f1d commit e69ce55
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
9 changes: 8 additions & 1 deletion lib/src/main/java/at/bitfire/cert4android/Cert4Android.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
package at.bitfire.cert4android

import android.util.Log
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import java.util.logging.Level
import java.util.logging.Logger

Expand All @@ -28,7 +31,11 @@ object Cert4Android {
// theme

var theme: @Composable (content: @Composable () -> Unit) -> Unit = { content ->
MaterialTheme(content = content)
MaterialTheme {
Box(Modifier.safeDrawingPadding()) {
content()
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -42,6 +43,8 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.ByteArrayInputStream
import java.security.cert.CertificateFactory
import java.security.cert.CertificateParsingException
Expand All @@ -50,8 +53,6 @@ import java.security.spec.MGF1ParameterSpec.SHA1
import java.security.spec.MGF1ParameterSpec.SHA256
import java.text.DateFormat
import java.util.logging.Level
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class TrustCertificateActivity : ComponentActivity() {

Expand All @@ -74,11 +75,15 @@ class TrustCertificateActivity : ComponentActivity() {
processIntent(newIntent)
}

enableEdgeToEdge()

setContent {
MainLayout(
onRegisterDecision = { trusted -> model.registerDecision(trusted) },
onFinish = { finish() }
)
Cert4Android.theme {
MainLayout(
onRegisterDecision = { trusted -> model.registerDecision(trusted) },
onFinish = { finish() }
)
}
}
}

Expand Down Expand Up @@ -124,37 +129,35 @@ class TrustCertificateActivity : ComponentActivity() {
backPressedCounter = newBackPressedCounter
}

Cert4Android.theme {
Scaffold(
snackbarHost = { SnackbarHost(snackbarHostState) },
modifier = Modifier.padding(16.dp)
) { paddingValues ->
Column(
Scaffold(
snackbarHost = { SnackbarHost(snackbarHostState) },
modifier = Modifier.padding(16.dp)
) { paddingValues ->
Column(
modifier = Modifier
.padding(paddingValues)
.verticalScroll(rememberScrollState()),
) {
Text(
text = stringResource(R.string.trust_certificate_unknown_certificate_found),
style = MaterialTheme.typography.bodySmall,
modifier = Modifier
.padding(paddingValues)
.verticalScroll(rememberScrollState()),
) {
Text(
text = stringResource(R.string.trust_certificate_unknown_certificate_found),
style = MaterialTheme.typography.bodySmall,
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 16.dp)
)
.fillMaxWidth()
.padding(bottom = 16.dp)
)

CertificateCard(
uiState = uiState,
onRegisterDecision = onRegisterDecision
)
CertificateCard(
uiState = uiState,
onRegisterDecision = onRegisterDecision
)

Text(
text = stringResource(R.string.trust_certificate_reset_info),
style = MaterialTheme.typography.bodySmall,
modifier = Modifier
.fillMaxWidth()
.padding(top = 16.dp),
)
}
Text(
text = stringResource(R.string.trust_certificate_reset_info),
style = MaterialTheme.typography.bodySmall,
modifier = Modifier
.fillMaxWidth()
.padding(top = 16.dp),
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MainActivity : ComponentActivity() {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.POST_NOTIFICATIONS), 0)

setContent {
MaterialTheme {
Cert4Android.theme {
Column(Modifier
.padding(8.dp)
.verticalScroll(rememberScrollState())) {
Expand Down

0 comments on commit e69ce55

Please sign in to comment.