Don't make bottom sheet content scrollable per default

This commit is contained in:
MM20 2022-06-10 20:36:24 +02:00
parent 02d45a63fc
commit e565780015
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 226 additions and 205 deletions

View File

@ -4,6 +4,8 @@ import android.net.Uri
import android.text.format.DateUtils import android.text.format.DateUtils
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.* import androidx.compose.material.icons.rounded.*
import androidx.compose.material3.* import androidx.compose.material3.*
@ -74,147 +76,156 @@ fun RestoreBackupSheet(
} }
} else null } else null
) { ) {
when (state) { Box(
RestoreBackupState.Parsing -> { modifier = Modifier
Box( .fillMaxWidth()
modifier = Modifier .wrapContentHeight()
.fillMaxWidth() .verticalScroll(rememberScrollState())
.aspectRatio(1f), ) {
contentAlignment = Alignment.Center when (state) {
) { RestoreBackupState.Parsing -> {
CircularProgressIndicator( Box(
modifier = Modifier.size(48.dp) modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator(
modifier = Modifier.size(48.dp)
)
}
}
RestoreBackupState.InvalidFile -> {
LargeMessage(
modifier = Modifier.aspectRatio(1f),
icon = Icons.Rounded.ErrorOutline,
text = stringResource(id = R.string.restore_invalid_file)
) )
} }
} RestoreBackupState.Ready -> {
RestoreBackupState.InvalidFile -> { val metadata by viewModel.metadata.observeAsState(null)
LargeMessage(
modifier = Modifier.aspectRatio(1f),
icon = Icons.Rounded.ErrorOutline,
text = stringResource(id = R.string.restore_invalid_file)
)
}
RestoreBackupState.Ready -> {
val metadata by viewModel.metadata.observeAsState(null)
if (metadata != null) { if (metadata != null) {
Column { Column {
SmallMessage( SmallMessage(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.wrapContentHeight() .wrapContentHeight()
.padding(bottom = 16.dp), .padding(bottom = 16.dp),
icon = Icons.Rounded.Info, icon = Icons.Rounded.Info,
text = stringResource(
R.string.restore_meta,
DateUtils.formatDateTime(
LocalContext.current,
metadata!!.timestamp,
DateUtils.FORMAT_ABBREV_ALL or DateUtils.FORMAT_SHOW_TIME or DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_YEAR
),
metadata!!.deviceName,
stringResource(R.string.app_name) + " " + metadata!!.appVersionName,
)
)
if (compatibility == BackupCompatibility.Incompatible) {
LargeMessage(
modifier = Modifier.aspectRatio(1f),
icon = Icons.Rounded.ErrorOutline,
text = stringResource( text = stringResource(
id = R.string.restore_incompatible_file, R.string.restore_meta,
stringResource(R.string.app_name) DateUtils.formatDateTime(
LocalContext.current,
metadata!!.timestamp,
DateUtils.FORMAT_ABBREV_ALL or DateUtils.FORMAT_SHOW_TIME or DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_YEAR
),
metadata!!.deviceName,
stringResource(R.string.app_name) + " " + metadata!!.appVersionName,
) )
) )
} else { if (compatibility == BackupCompatibility.Incompatible) {
if (compatibility == BackupCompatibility.PartiallyCompatible) { LargeMessage(
SmallMessage( modifier = Modifier.aspectRatio(1f),
color = MaterialTheme.colorScheme.secondary, icon = Icons.Rounded.ErrorOutline,
modifier = Modifier text = stringResource(
.fillMaxWidth() id = R.string.restore_incompatible_file,
.padding(bottom = 16.dp),
icon = Icons.Rounded.Warning,
text =
stringResource(
R.string.restore_different_minor_version,
stringResource(R.string.app_name) stringResource(R.string.app_name)
) )
) )
} } else {
Text( if (compatibility == BackupCompatibility.PartiallyCompatible) {
stringResource(R.string.restore_select_components), SmallMessage(
style = MaterialTheme.typography.titleSmall, color = MaterialTheme.colorScheme.secondary,
modifier = Modifier.padding(top = 8.dp, bottom = 4.dp)
)
val components by viewModel.availableComponents.observeAsState(emptyList())
for (component in components) {
Row(
modifier = Modifier
.clickable {
viewModel.toggleComponent(
component
)
}
.padding(vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = when (component) {
BackupComponent.Favorites -> Icons.Rounded.Star
BackupComponent.Settings -> Icons.Rounded.Settings
BackupComponent.Websearches -> Icons.Rounded.TravelExplore
BackupComponent.Widgets -> Icons.Rounded.Widgets
},
contentDescription = null
)
Text(
text = stringResource(
when (component) {
BackupComponent.Favorites -> R.string.backup_component_favorites
BackupComponent.Settings -> R.string.backup_component_settings
BackupComponent.Websearches -> R.string.backup_component_websearches
BackupComponent.Widgets -> R.string.backup_component_widgets
}
),
style = MaterialTheme.typography.titleMedium,
modifier = Modifier modifier = Modifier
.weight(1f) .fillMaxWidth()
.padding(horizontal = 16.dp) .padding(bottom = 16.dp),
) icon = Icons.Rounded.Warning,
Checkbox( text =
checked = selectedComponents.contains( stringResource(
component R.string.restore_different_minor_version,
), stringResource(R.string.app_name)
onCheckedChange = { )
viewModel.toggleComponent(component)
}
) )
} }
Text(
stringResource(R.string.restore_select_components),
style = MaterialTheme.typography.titleSmall,
modifier = Modifier.padding(top = 8.dp, bottom = 4.dp)
)
val components by viewModel.availableComponents.observeAsState(
emptyList()
)
for (component in components) {
Row(
modifier = Modifier
.clickable {
viewModel.toggleComponent(
component
)
}
.padding(vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = when (component) {
BackupComponent.Favorites -> Icons.Rounded.Star
BackupComponent.Settings -> Icons.Rounded.Settings
BackupComponent.Websearches -> Icons.Rounded.TravelExplore
BackupComponent.Widgets -> Icons.Rounded.Widgets
},
contentDescription = null
)
Text(
text = stringResource(
when (component) {
BackupComponent.Favorites -> R.string.backup_component_favorites
BackupComponent.Settings -> R.string.backup_component_settings
BackupComponent.Websearches -> R.string.backup_component_websearches
BackupComponent.Widgets -> R.string.backup_component_widgets
}
),
style = MaterialTheme.typography.titleMedium,
modifier = Modifier
.weight(1f)
.padding(horizontal = 16.dp)
)
Checkbox(
checked = selectedComponents.contains(
component
),
onCheckedChange = {
viewModel.toggleComponent(component)
}
)
}
}
} }
} }
} }
} }
} RestoreBackupState.Restoring -> {
RestoreBackupState.Restoring -> { Box(
Box( modifier = Modifier
modifier = Modifier .fillMaxWidth()
.fillMaxWidth() .aspectRatio(1f),
.aspectRatio(1f), contentAlignment = Alignment.Center
contentAlignment = Alignment.Center ) {
) { CircularProgressIndicator(
CircularProgressIndicator( modifier = Modifier.size(48.dp)
modifier = Modifier.size(48.dp) )
}
}
RestoreBackupState.Restored -> {
LargeMessage(
modifier = Modifier.aspectRatio(1f),
icon = Icons.Rounded.CheckCircleOutline,
text = stringResource(
id = R.string.restore_complete
)
) )
} }
} }
RestoreBackupState.Restored -> {
LargeMessage(
modifier = Modifier.aspectRatio(1f),
icon = Icons.Rounded.CheckCircleOutline,
text = stringResource(
id = R.string.restore_complete
)
)
}
} }
} }
} }

View File

@ -1,5 +1,6 @@
package de.mm20.launcher2.ui.component package de.mm20.launcher2.ui.component
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.animateDpAsState import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
@ -39,8 +40,6 @@ fun BottomSheetDialog(
dismissButton: @Composable (() -> Unit)? = null, dismissButton: @Composable (() -> Unit)? = null,
content: @Composable () -> Unit, content: @Composable () -> Unit,
) { ) {
val scrollState = rememberScrollState()
val swipeState = remember { val swipeState = remember {
SwipeableState( SwipeableState(
initialValue = SwipeState.Dismiss, initialValue = SwipeState.Dismiss,
@ -151,7 +150,7 @@ fun BottomSheetDialog(
}, },
resistance = null resistance = null
) )
//.animateContentSize() .animateContentSize()
.onSizeChanged { .onSizeChanged {
height = it.height.toFloat() height = it.height.toFloat()
} }
@ -172,7 +171,6 @@ fun BottomSheetDialog(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.wrapContentHeight() .wrapContentHeight()
.verticalScroll(scrollState)
.padding(horizontal = 24.dp, vertical = 8.dp), .padding(horizontal = 24.dp, vertical = 8.dp),
propagateMinConstraints = true, propagateMinConstraints = true,
contentAlignment = Alignment.Center contentAlignment = Alignment.Center

View File

@ -4,6 +4,8 @@ import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.* import androidx.compose.material.icons.rounded.*
import androidx.compose.material3.* import androidx.compose.material3.*
@ -47,7 +49,8 @@ fun CreateBackupSheet(
} }
) )
BottomSheetDialog(onDismissRequest = onDismissRequest, BottomSheetDialog(
onDismissRequest = onDismissRequest,
title = { title = {
Text( Text(
stringResource(id = R.string.preference_backup), stringResource(id = R.string.preference_backup),
@ -58,13 +61,13 @@ fun CreateBackupSheet(
Button( Button(
enabled = components.isNotEmpty(), enabled = components.isNotEmpty(),
onClick = { onClick = {
val fileName = "${ val fileName = "${
ZonedDateTime.now().format( ZonedDateTime.now().format(
DateTimeFormatter.ISO_INSTANT DateTimeFormatter.ISO_INSTANT
) )
}.kvaesitso" }.kvaesitso"
backupLauncher.launch(fileName) backupLauncher.launch(fileName)
}) { }) {
Text(stringResource(R.string.preference_backup)) Text(stringResource(R.string.preference_backup))
} }
} else if (state == CreateBackupState.BackedUp) { } else if (state == CreateBackupState.BackedUp) {
@ -75,81 +78,90 @@ fun CreateBackupSheet(
} }
} }
}, },
dismissButton = if (state == CreateBackupState.Ready) {{ dismissButton = if (state == CreateBackupState.Ready) {
OutlinedButton( {
onClick = onDismissRequest OutlinedButton(
) { onClick = onDismissRequest
Text(stringResource(android.R.string.cancel))
}
}} else null
) {
when (state) {
CreateBackupState.Ready -> {
Column {
Text(
stringResource(R.string.backup_select_components),
style = MaterialTheme.typography.titleSmall,
modifier = Modifier.padding(top = 8.dp, bottom = 4.dp)
)
BackupableComponent(
title = stringResource(R.string.backup_component_settings),
icon = Icons.Rounded.Settings,
checked = components.contains(BackupComponent.Settings),
onCheckedChange = {
viewModel.toggleComponent(BackupComponent.Settings)
}
)
BackupableComponent(
title = stringResource(R.string.backup_component_favorites),
icon = Icons.Rounded.Star,
checked = components.contains(BackupComponent.Favorites),
onCheckedChange = {
viewModel.toggleComponent(BackupComponent.Favorites)
}
)
BackupableComponent(
title = stringResource(R.string.backup_component_widgets),
icon = Icons.Rounded.Widgets,
checked = components.contains(BackupComponent.Widgets),
onCheckedChange = {
viewModel.toggleComponent(BackupComponent.Widgets)
}
)
BackupableComponent(
title = stringResource(R.string.backup_component_websearches),
icon = Icons.Rounded.TravelExplore,
checked = components.contains(BackupComponent.Websearches),
onCheckedChange = {
viewModel.toggleComponent(BackupComponent.Websearches)
}
)
SmallMessage(
modifier = Modifier.padding(top = 8.dp),
icon = Icons.Rounded.Warning,
text = stringResource(R.string.backup_not_included)
)
}
}
CreateBackupState.BackingUp -> {
Box(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f),
contentAlignment = Alignment.Center
) { ) {
CircularProgressIndicator( Text(stringResource(android.R.string.cancel))
modifier = Modifier.size(48.dp)
)
} }
} }
CreateBackupState.BackedUp -> { } else null
LargeMessage( ) {
modifier = Modifier.aspectRatio(1f), Box(
icon = Icons.Rounded.CheckCircleOutline, modifier = Modifier
text = stringResource( .fillMaxWidth()
id = R.string.backup_complete .wrapContentHeight()
.verticalScroll(rememberScrollState())
) {
when (state) {
CreateBackupState.Ready -> {
Column {
Text(
stringResource(R.string.backup_select_components),
style = MaterialTheme.typography.titleSmall,
modifier = Modifier.padding(top = 8.dp, bottom = 4.dp)
)
BackupableComponent(
title = stringResource(R.string.backup_component_settings),
icon = Icons.Rounded.Settings,
checked = components.contains(BackupComponent.Settings),
onCheckedChange = {
viewModel.toggleComponent(BackupComponent.Settings)
}
)
BackupableComponent(
title = stringResource(R.string.backup_component_favorites),
icon = Icons.Rounded.Star,
checked = components.contains(BackupComponent.Favorites),
onCheckedChange = {
viewModel.toggleComponent(BackupComponent.Favorites)
}
)
BackupableComponent(
title = stringResource(R.string.backup_component_widgets),
icon = Icons.Rounded.Widgets,
checked = components.contains(BackupComponent.Widgets),
onCheckedChange = {
viewModel.toggleComponent(BackupComponent.Widgets)
}
)
BackupableComponent(
title = stringResource(R.string.backup_component_websearches),
icon = Icons.Rounded.TravelExplore,
checked = components.contains(BackupComponent.Websearches),
onCheckedChange = {
viewModel.toggleComponent(BackupComponent.Websearches)
}
)
SmallMessage(
modifier = Modifier.padding(top = 8.dp),
icon = Icons.Rounded.Warning,
text = stringResource(R.string.backup_not_included)
)
}
}
CreateBackupState.BackingUp -> {
Box(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator(
modifier = Modifier.size(48.dp)
)
}
}
CreateBackupState.BackedUp -> {
LargeMessage(
modifier = Modifier.aspectRatio(1f),
icon = Icons.Rounded.CheckCircleOutline,
text = stringResource(
id = R.string.backup_complete
)
) )
) }
} }
} }
} }