Add preference to remove space above clock widget

This commit is contained in:
MM20
2022-09-03 15:42:32 +02:00
parent 372913e5f1
commit 56e08ab02c
7 changed files with 48 additions and 9 deletions
+2
View File
@@ -519,6 +519,8 @@
<string name="preference_clockwidget_layout">Layout</string> <string name="preference_clockwidget_layout">Layout</string>
<string name="preference_clockwidget_layout_vertical">Default</string> <string name="preference_clockwidget_layout_vertical">Default</string>
<string name="preference_clockwidget_layout_horizontal">Compact</string> <string name="preference_clockwidget_layout_horizontal">Compact</string>
<string name="preference_clock_widget_fill_height">Fill screen height</string>
<string name="preference_clock_widget_fill_height_summary">Insert extra space above the clock to fill the entire screen height</string>
<string name="preference_clock_widget_style">Style</string> <string name="preference_clock_widget_style">Style</string>
<string name="preference_clock_widget_style_summary">Select a clock</string> <string name="preference_clock_widget_style_summary">Select a clock</string>
<string name="preference_clockwidget_date_part">Date</string> <string name="preference_clockwidget_date_part">Date</string>
@@ -50,4 +50,6 @@ class LauncherScaffoldVM : ViewModel(), KoinComponent {
} }
val wallpaperBlur = dataStore.data.map { it.appearance.blurWallpaper }.asLiveData() val wallpaperBlur = dataStore.data.map { it.appearance.blurWallpaper }.asLiveData()
val fillClockHeight = dataStore.data.map { it.clockWidget.fillHeight }.asLiveData()
} }
@@ -87,12 +87,15 @@ fun PagerScaffold(
} }
} }
} }
val fillClockHeight by viewModel.fillClockHeight.observeAsState(true)
val showNavBarScrim by remember { val showNavBarScrim by remember {
derivedStateOf { derivedStateOf {
if (isSearchOpen) { if (isSearchOpen) {
!isSearchAtStart !isSearchAtStart
} else { } else {
widgetsScrollState.value > 0 && widgetsScrollState.value < widgetsScrollState.maxValue (widgetsScrollState.value > 0 || !fillClockHeight) && widgetsScrollState.value < widgetsScrollState.maxValue
} }
} }
} }
@@ -274,12 +277,16 @@ fun PagerScaffold(
val editModePadding by animateDpAsState(if (isWidgetEditMode) 56.dp else 0.dp) val editModePadding by animateDpAsState(if (isWidgetEditMode) 56.dp else 0.dp)
val clockPadding by animateDpAsState( val clockPadding by animateDpAsState(
if (isWidgetsScrollZero) 64.dp + insets.calculateBottomPadding() else 0.dp if (isWidgetsScrollZero && fillClockHeight) 64.dp + insets.calculateBottomPadding() else 0.dp
) )
val clockHeight by remember { val clockHeight by remember {
derivedStateOf { derivedStateOf {
height - (64.dp + insets.calculateTopPadding() + insets.calculateBottomPadding() - clockPadding) if (fillClockHeight){
height - (64.dp + insets.calculateTopPadding() + insets.calculateBottomPadding() - clockPadding)
} else {
null
}
} }
} }
@@ -347,7 +354,7 @@ fun PagerScaffold(
derivedStateOf { derivedStateOf {
when { when {
swipeableState.direction != 0f -> SearchBarLevel.Raised swipeableState.direction != 0f -> SearchBarLevel.Raised
!isSearchOpen && isWidgetsScrollZero -> SearchBarLevel.Resting !isSearchOpen && isWidgetsScrollZero && fillClockHeight -> SearchBarLevel.Resting
isSearchOpen && isSearchAtStart -> SearchBarLevel.Active isSearchOpen && isSearchAtStart -> SearchBarLevel.Active
else -> SearchBarLevel.Raised else -> SearchBarLevel.Raised
} }
@@ -88,6 +88,8 @@ fun PullDownScaffold(
} }
} }
val fillClockHeight by viewModel.fillClockHeight.observeAsState(true)
val showStatusBarScrim by remember { val showStatusBarScrim by remember {
derivedStateOf { derivedStateOf {
if (isSearchOpen) { if (isSearchOpen) {
@@ -102,7 +104,7 @@ fun PullDownScaffold(
if (isSearchOpen) { if (isSearchOpen) {
!isSearchAtEnd !isSearchAtEnd
} else { } else {
widgetsScrollState.value > 0 && widgetsScrollState.value < widgetsScrollState.maxValue (widgetsScrollState.value > 0 || !fillClockHeight) && widgetsScrollState.value < widgetsScrollState.maxValue
} }
} }
} }
@@ -295,11 +297,15 @@ fun PullDownScaffold(
) )
val editModePadding by animateDpAsState(if (isWidgetEditMode) 56.dp else 0.dp) val editModePadding by animateDpAsState(if (isWidgetEditMode) 56.dp else 0.dp)
val clockPadding by animateDpAsState( val clockPadding by animateDpAsState(
if (isWidgetsAtStart) insets.calculateBottomPadding() else 0.dp if (isWidgetsAtStart && fillClockHeight) insets.calculateBottomPadding() else 0.dp
) )
val clockHeight by remember { val clockHeight by remember {
derivedStateOf { derivedStateOf {
height - (insets.calculateTopPadding() + insets.calculateBottomPadding() - clockPadding) if (fillClockHeight) {
height - (insets.calculateTopPadding() + insets.calculateBottomPadding() - clockPadding + 56.dp)
} else {
null
}
} }
} }
WidgetColumn( WidgetColumn(
@@ -316,6 +322,7 @@ fun PullDownScaffold(
.verticalScroll(widgetsScrollState) .verticalScroll(widgetsScrollState)
.windowInsetsPadding(WindowInsets.safeDrawing) .windowInsetsPadding(WindowInsets.safeDrawing)
.padding(8.dp) .padding(8.dp)
.padding(top = 56.dp)
.padding(top = editModePadding), .padding(top = editModePadding),
clockHeight = { clockHeight }, clockHeight = { clockHeight },
clockBottomPadding = { clockPadding }, clockBottomPadding = { clockPadding },
@@ -38,6 +38,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import de.mm20.launcher2.ui.launcher.widgets.clock.ClockWidget import de.mm20.launcher2.ui.launcher.widgets.clock.ClockWidget
import de.mm20.launcher2.ui.R import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.ktx.animateTo import de.mm20.launcher2.ui.ktx.animateTo
import de.mm20.launcher2.ui.ktx.conditional
import de.mm20.launcher2.ui.launcher.widgets.picker.PickAppWidgetActivity import de.mm20.launcher2.ui.launcher.widgets.picker.PickAppWidgetActivity
import de.mm20.launcher2.widgets.ExternalWidget import de.mm20.launcher2.widgets.ExternalWidget
import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.awaitCancellation
@@ -46,7 +47,7 @@ import kotlinx.coroutines.launch
@Composable @Composable
fun WidgetColumn( fun WidgetColumn(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
clockHeight: () -> Dp = { 0.dp }, clockHeight: () -> Dp? = { null },
clockBottomPadding: () -> Dp = { 0.dp }, clockBottomPadding: () -> Dp = { 0.dp },
editMode: Boolean = false, editMode: Boolean = false,
onEditModeChange: (Boolean) -> Unit, onEditModeChange: (Boolean) -> Unit,
@@ -90,7 +91,7 @@ fun WidgetColumn(
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(clockHeight()) .then(clockHeight()?.let { Modifier.height(it) } ?: Modifier)
.padding(bottom = clockBottomPadding()), .padding(bottom = clockBottomPadding()),
contentAlignment = Alignment.BottomCenter contentAlignment = Alignment.BottomCenter
) { ) {
@@ -52,6 +52,13 @@ fun ClockWidgetSettingsScreen() {
viewModel.setClockStyle(it) viewModel.setClockStyle(it)
} }
) )
val fillHeight by viewModel.fillHeight.observeAsState()
SwitchPreference(
title = stringResource(R.string.preference_clock_widget_fill_height),
summary = stringResource(R.string.preference_clock_widget_fill_height_summary),
value = fillHeight == true,
onValueChanged = { viewModel.setFillHeight(it) }
)
} }
} }
item { item {
@@ -38,6 +38,19 @@ class ClockWidgetSettingsScreenVM : ViewModel(), KoinComponent {
} }
} }
val fillHeight = dataStore.data.map { it.clockWidget.fillHeight }.asLiveData()
fun setFillHeight(fillHeight: Boolean) {
viewModelScope.launch {
dataStore.updateData {
it.toBuilder()
.setClockWidget(
it.clockWidget.toBuilder()
.setFillHeight(fillHeight)
).build()
}
}
}
val datePart = dataStore.data.map { it.clockWidget.datePart }.asLiveData() val datePart = dataStore.data.map { it.clockWidget.datePart }.asLiveData()
fun setDatePart(datePart: Boolean) { fun setDatePart(datePart: Boolean) {
viewModelScope.launch { viewModelScope.launch {