Don't make bottom sheet content scrollable per default
This commit is contained in:
parent
02d45a63fc
commit
e565780015
@ -4,6 +4,8 @@ import android.net.Uri
|
||||
import android.text.format.DateUtils
|
||||
import androidx.compose.foundation.clickable
|
||||
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.rounded.*
|
||||
import androidx.compose.material3.*
|
||||
@ -74,147 +76,156 @@ fun RestoreBackupSheet(
|
||||
}
|
||||
} else null
|
||||
) {
|
||||
when (state) {
|
||||
RestoreBackupState.Parsing -> {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(1f),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(48.dp)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
when (state) {
|
||||
RestoreBackupState.Parsing -> {
|
||||
Box(
|
||||
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.InvalidFile -> {
|
||||
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)
|
||||
RestoreBackupState.Ready -> {
|
||||
val metadata by viewModel.metadata.observeAsState(null)
|
||||
|
||||
if (metadata != null) {
|
||||
Column {
|
||||
SmallMessage(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.padding(bottom = 16.dp),
|
||||
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,
|
||||
if (metadata != null) {
|
||||
Column {
|
||||
SmallMessage(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.padding(bottom = 16.dp),
|
||||
icon = Icons.Rounded.Info,
|
||||
text = stringResource(
|
||||
id = R.string.restore_incompatible_file,
|
||||
stringResource(R.string.app_name)
|
||||
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,
|
||||
)
|
||||
)
|
||||
} else {
|
||||
if (compatibility == BackupCompatibility.PartiallyCompatible) {
|
||||
SmallMessage(
|
||||
color = MaterialTheme.colorScheme.secondary,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 16.dp),
|
||||
icon = Icons.Rounded.Warning,
|
||||
text =
|
||||
stringResource(
|
||||
R.string.restore_different_minor_version,
|
||||
if (compatibility == BackupCompatibility.Incompatible) {
|
||||
LargeMessage(
|
||||
modifier = Modifier.aspectRatio(1f),
|
||||
icon = Icons.Rounded.ErrorOutline,
|
||||
text = stringResource(
|
||||
id = R.string.restore_incompatible_file,
|
||||
stringResource(R.string.app_name)
|
||||
)
|
||||
)
|
||||
}
|
||||
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,
|
||||
} else {
|
||||
if (compatibility == BackupCompatibility.PartiallyCompatible) {
|
||||
SmallMessage(
|
||||
color = MaterialTheme.colorScheme.secondary,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(horizontal = 16.dp)
|
||||
)
|
||||
Checkbox(
|
||||
checked = selectedComponents.contains(
|
||||
component
|
||||
),
|
||||
onCheckedChange = {
|
||||
viewModel.toggleComponent(component)
|
||||
}
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 16.dp),
|
||||
icon = Icons.Rounded.Warning,
|
||||
text =
|
||||
stringResource(
|
||||
R.string.restore_different_minor_version,
|
||||
stringResource(R.string.app_name)
|
||||
)
|
||||
)
|
||||
}
|
||||
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 -> {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(1f),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(48.dp)
|
||||
RestoreBackupState.Restoring -> {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(1f),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator(
|
||||
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
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package de.mm20.launcher2.ui.component
|
||||
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.animateDpAsState
|
||||
import androidx.compose.foundation.gestures.Orientation
|
||||
import androidx.compose.foundation.layout.*
|
||||
@ -39,8 +40,6 @@ fun BottomSheetDialog(
|
||||
dismissButton: @Composable (() -> Unit)? = null,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
val swipeState = remember {
|
||||
SwipeableState(
|
||||
initialValue = SwipeState.Dismiss,
|
||||
@ -151,7 +150,7 @@ fun BottomSheetDialog(
|
||||
},
|
||||
resistance = null
|
||||
)
|
||||
//.animateContentSize()
|
||||
.animateContentSize()
|
||||
.onSizeChanged {
|
||||
height = it.height.toFloat()
|
||||
}
|
||||
@ -172,7 +171,6 @@ fun BottomSheetDialog(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.verticalScroll(scrollState)
|
||||
.padding(horizontal = 24.dp, vertical = 8.dp),
|
||||
propagateMinConstraints = true,
|
||||
contentAlignment = Alignment.Center
|
||||
|
||||
@ -4,6 +4,8 @@ import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.clickable
|
||||
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.rounded.*
|
||||
import androidx.compose.material3.*
|
||||
@ -47,7 +49,8 @@ fun CreateBackupSheet(
|
||||
}
|
||||
)
|
||||
|
||||
BottomSheetDialog(onDismissRequest = onDismissRequest,
|
||||
BottomSheetDialog(
|
||||
onDismissRequest = onDismissRequest,
|
||||
title = {
|
||||
Text(
|
||||
stringResource(id = R.string.preference_backup),
|
||||
@ -58,13 +61,13 @@ fun CreateBackupSheet(
|
||||
Button(
|
||||
enabled = components.isNotEmpty(),
|
||||
onClick = {
|
||||
val fileName = "${
|
||||
ZonedDateTime.now().format(
|
||||
DateTimeFormatter.ISO_INSTANT
|
||||
)
|
||||
}.kvaesitso"
|
||||
backupLauncher.launch(fileName)
|
||||
}) {
|
||||
val fileName = "${
|
||||
ZonedDateTime.now().format(
|
||||
DateTimeFormatter.ISO_INSTANT
|
||||
)
|
||||
}.kvaesitso"
|
||||
backupLauncher.launch(fileName)
|
||||
}) {
|
||||
Text(stringResource(R.string.preference_backup))
|
||||
}
|
||||
} else if (state == CreateBackupState.BackedUp) {
|
||||
@ -75,81 +78,90 @@ fun CreateBackupSheet(
|
||||
}
|
||||
}
|
||||
},
|
||||
dismissButton = if (state == CreateBackupState.Ready) {{
|
||||
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
|
||||
dismissButton = if (state == CreateBackupState.Ready) {
|
||||
{
|
||||
OutlinedButton(
|
||||
onClick = onDismissRequest
|
||||
) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(48.dp)
|
||||
)
|
||||
Text(stringResource(android.R.string.cancel))
|
||||
}
|
||||
}
|
||||
CreateBackupState.BackedUp -> {
|
||||
LargeMessage(
|
||||
modifier = Modifier.aspectRatio(1f),
|
||||
icon = Icons.Rounded.CheckCircleOutline,
|
||||
text = stringResource(
|
||||
id = R.string.backup_complete
|
||||
} else null
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.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
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user