fix: onboarding screens invalid layout and reseting
This commit is contained in:
1 parent
a292bddbe8
commit
0f1db0fb22
6 files changed
+147
-100
No files matched your search
@@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -39,12 +40,20 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
// Track if DataStore has loaded at least once
|
||||
// This prevents the loading screen from showing again if the composable is recomposed
|
||||
val appSettings by settingsViewModel.appSettings.collectAsStateWithLifecycle()
|
||||
val appSettingsState by settingsViewModel.appSettings.collectAsStateWithLifecycle()
|
||||
|
||||
// Remember if we've ever loaded settings to prevent losing NavigationGraph during recreation
|
||||
var settingsLoadedOnce by rememberSaveable { mutableStateOf(false) }
|
||||
val currentSettings = appSettingsState
|
||||
|
||||
if (currentSettings != null) {
|
||||
settingsLoadedOnce = true
|
||||
}
|
||||
|
||||
|
||||
PaperizeTheme(
|
||||
darkMode = appSettings?.darkMode ?: false,
|
||||
dynamicTheming = appSettings?.dynamicTheming ?: false
|
||||
darkMode = currentSettings?.darkMode ?: false,
|
||||
dynamicTheming = currentSettings?.dynamicTheming ?: false
|
||||
) {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
@@ -52,11 +61,10 @@ class MainActivity : ComponentActivity() {
|
||||
) {
|
||||
// Only render navigation once DataStore has loaded
|
||||
// After first load, always show navigation even during updates
|
||||
val currentSettings = appSettings
|
||||
if (currentSettings != null) {
|
||||
if (settingsLoadedOnce) {
|
||||
NavigationGraph(
|
||||
startDestination = if (currentSettings.firstLaunch) StartupRoute else HomeRoute,
|
||||
animate = currentSettings.animate,
|
||||
startDestination = if (currentSettings?.firstLaunch != false) StartupRoute else HomeRoute,
|
||||
animate = currentSettings?.animate ?: true,
|
||||
onFirstLaunchComplete = {
|
||||
settingsViewModel.updateFirstLaunch(false)
|
||||
}
|
||||
|
||||
+3
@@ -67,6 +67,9 @@ fun NavigationGraph(
|
||||
navController.navigate(WallpaperModeSelectionRoute) {
|
||||
popUpTo<StartupRoute> { inclusive = true }
|
||||
}
|
||||
},
|
||||
onPrivacyClick = {
|
||||
navController.navigate(PrivacyRoute)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
+92
-75
@@ -5,13 +5,16 @@ import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
@@ -50,87 +53,101 @@ fun OnboardingLayout(
|
||||
visible = true
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.padding(AppSpacing.extraLarge)
|
||||
) {
|
||||
BoxWithConstraints(modifier = modifier.fillMaxSize()) {
|
||||
val maxHeight = maxHeight
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
.fillMaxSize()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(AppSpacing.extraLarge),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
AnimatedVisibility(
|
||||
visible = visible,
|
||||
enter = fadeIn(animationSpec = tween(500)) +
|
||||
slideInVertically(
|
||||
animationSpec = tween(500),
|
||||
initialOffsetY = { 50 }
|
||||
)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(120.dp) // Larger container for the icon background
|
||||
.background(
|
||||
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.5f),
|
||||
shape = CircleShape
|
||||
),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
iconContent()
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(AppSpacing.extraLarge))
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = visible,
|
||||
enter = fadeIn(animationSpec = tween(500, delayMillis = 100)) +
|
||||
slideInVertically(
|
||||
animationSpec = tween(500, delayMillis = 100),
|
||||
initialOffsetY = { 50 }
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.headlineLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
fontWeight = FontWeight.Bold,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(AppSpacing.large))
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = visible,
|
||||
enter = fadeIn(animationSpec = tween(500, delayMillis = 200)) +
|
||||
slideInVertically(
|
||||
animationSpec = tween(500, delayMillis = 200),
|
||||
initialOffsetY = { 50 }
|
||||
)
|
||||
) {
|
||||
content()
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(AppSpacing.medium))
|
||||
|
||||
// Actions pinned to bottom
|
||||
AnimatedVisibility(
|
||||
visible = visible,
|
||||
enter = fadeIn(animationSpec = tween(500, delayMillis = 300)) +
|
||||
slideInVertically(
|
||||
animationSpec = tween(500, delayMillis = 300),
|
||||
initialOffsetY = { 100 }
|
||||
)
|
||||
verticalArrangement = Arrangement.Top // Top here, centering happens in inner Column
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(AppSpacing.medium)
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(min = maxHeight - (AppSpacing.extraLarge * 2)),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
actions()
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
AnimatedVisibility(
|
||||
visible = visible,
|
||||
enter = fadeIn(animationSpec = tween(500)) +
|
||||
slideInVertically(
|
||||
animationSpec = tween(500),
|
||||
initialOffsetY = { 50 }
|
||||
)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(120.dp) // Larger container for the icon background
|
||||
.background(
|
||||
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.5f),
|
||||
shape = CircleShape
|
||||
),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
iconContent()
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(AppSpacing.extraLarge))
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = visible,
|
||||
enter = fadeIn(animationSpec = tween(500, delayMillis = 100)) +
|
||||
slideInVertically(
|
||||
animationSpec = tween(500, delayMillis = 100),
|
||||
initialOffsetY = { 50 }
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.headlineLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
fontWeight = FontWeight.Bold,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(AppSpacing.large))
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = visible,
|
||||
enter = fadeIn(animationSpec = tween(500, delayMillis = 200)) +
|
||||
slideInVertically(
|
||||
animationSpec = tween(500, delayMillis = 200),
|
||||
initialOffsetY = { 50 }
|
||||
)
|
||||
) {
|
||||
content()
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(AppSpacing.extraLarge))
|
||||
|
||||
// Actions now part of the scrollable content to handle small heights (landscape)
|
||||
AnimatedVisibility(
|
||||
visible = visible,
|
||||
enter = fadeIn(animationSpec = tween(500, delayMillis = 300)) +
|
||||
slideInVertically(
|
||||
animationSpec = tween(500, delayMillis = 300),
|
||||
initialOffsetY = { 100 }
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(AppSpacing.medium)
|
||||
) {
|
||||
actions()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ fun PrivacyScreen(
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(R.string.privacy_screen)) },
|
||||
title = { Text(stringResource(R.string.privacy_policy)) },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onNavigateBack) {
|
||||
Icon(
|
||||
|
||||
+36
-16
@@ -6,16 +6,21 @@ import androidx.appcompat.content.res.AppCompatResources
|
||||
import com.anthonyla.paperize.presentation.components.OnboardingLayout
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -38,6 +43,7 @@ import com.anthonyla.paperize.presentation.theme.AppSpacing
|
||||
@Composable
|
||||
fun StartupScreen(
|
||||
onAgree: () -> Unit,
|
||||
onPrivacyClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
@@ -78,7 +84,9 @@ fun StartupScreen(
|
||||
|
||||
// Cleaner privacy notice
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { onPrivacyClick() },
|
||||
shape = MaterialTheme.shapes.large,
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f)
|
||||
@@ -88,24 +96,36 @@ fun StartupScreen(
|
||||
color = MaterialTheme.colorScheme.outlineVariant
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(AppSpacing.large)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(AppSpacing.large),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.privacy_notice),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = stringResource(R.string.privacy_notice),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(AppSpacing.small))
|
||||
Spacer(modifier = Modifier.height(AppSpacing.small))
|
||||
|
||||
Text(
|
||||
text = stringResource(
|
||||
R.string.please_read_and_agree_to_the_following_privacy_notice_to_use_the_app
|
||||
),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
Text(
|
||||
text = stringResource(
|
||||
R.string.please_read_and_agree_to_the_following_privacy_notice_to_use_the_app
|
||||
),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(start = AppSpacing.small)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
<string name="continue_button">I\'m In</string>
|
||||
<string name="allow">Allow</string>
|
||||
<string name="privacy_policy">Privacy Policy</string>
|
||||
<string name="privacy_screen">Privacy Screen</string>
|
||||
<string name="reset_to_default">Reset to default</string>
|
||||
<string name="reset_all_data">Reset all data</string>
|
||||
<string name="are_you_sure_you_want_to_reset_all_settings_and_data_to_default">Are you sure you want to reset all settings and data to default?</string>
|
||||
|
||||
Reference in new issue
Block a user