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
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
7 changed files with 48 additions and 9 deletions

View File

@ -519,6 +519,8 @@
<string name="preference_clockwidget_layout">Layout</string>
<string name="preference_clockwidget_layout_vertical">Default</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_summary">Select a clock</string>
<string name="preference_clockwidget_date_part">Date</string>

View File

@ -50,4 +50,6 @@ class LauncherScaffoldVM : ViewModel(), KoinComponent {
}
val wallpaperBlur = dataStore.data.map { it.appearance.blurWallpaper }.asLiveData()
val fillClockHeight = dataStore.data.map { it.clockWidget.fillHeight }.asLiveData()
}

View File

@ -87,12 +87,15 @@ fun PagerScaffold(
}
}
}
val fillClockHeight by viewModel.fillClockHeight.observeAsState(true)
val showNavBarScrim by remember {
derivedStateOf {
if (isSearchOpen) {
!isSearchAtStart
} 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 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 {
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 {
when {
swipeableState.direction != 0f -> SearchBarLevel.Raised
!isSearchOpen && isWidgetsScrollZero -> SearchBarLevel.Resting
!isSearchOpen && isWidgetsScrollZero && fillClockHeight -> SearchBarLevel.Resting
isSearchOpen && isSearchAtStart -> SearchBarLevel.Active
else -> SearchBarLevel.Raised
}

View File

@ -88,6 +88,8 @@ fun PullDownScaffold(
}
}
val fillClockHeight by viewModel.fillClockHeight.observeAsState(true)
val showStatusBarScrim by remember {
derivedStateOf {
if (isSearchOpen) {
@ -102,7 +104,7 @@ fun PullDownScaffold(
if (isSearchOpen) {
!isSearchAtEnd
} 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 clockPadding by animateDpAsState(
if (isWidgetsAtStart) insets.calculateBottomPadding() else 0.dp
if (isWidgetsAtStart && fillClockHeight) insets.calculateBottomPadding() else 0.dp
)
val clockHeight by remember {
derivedStateOf {
height - (insets.calculateTopPadding() + insets.calculateBottomPadding() - clockPadding)
if (fillClockHeight) {
height - (insets.calculateTopPadding() + insets.calculateBottomPadding() - clockPadding + 56.dp)
} else {
null
}
}
}
WidgetColumn(
@ -316,6 +322,7 @@ fun PullDownScaffold(
.verticalScroll(widgetsScrollState)
.windowInsetsPadding(WindowInsets.safeDrawing)
.padding(8.dp)
.padding(top = 56.dp)
.padding(top = editModePadding),
clockHeight = { clockHeight },
clockBottomPadding = { clockPadding },

View File

@ -38,6 +38,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import de.mm20.launcher2.ui.launcher.widgets.clock.ClockWidget
import de.mm20.launcher2.ui.R
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.widgets.ExternalWidget
import kotlinx.coroutines.awaitCancellation
@ -46,7 +47,7 @@ import kotlinx.coroutines.launch
@Composable
fun WidgetColumn(
modifier: Modifier = Modifier,
clockHeight: () -> Dp = { 0.dp },
clockHeight: () -> Dp? = { null },
clockBottomPadding: () -> Dp = { 0.dp },
editMode: Boolean = false,
onEditModeChange: (Boolean) -> Unit,
@ -90,7 +91,7 @@ fun WidgetColumn(
Box(
modifier = Modifier
.fillMaxWidth()
.height(clockHeight())
.then(clockHeight()?.let { Modifier.height(it) } ?: Modifier)
.padding(bottom = clockBottomPadding()),
contentAlignment = Alignment.BottomCenter
) {

View File

@ -52,6 +52,13 @@ fun ClockWidgetSettingsScreen() {
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 {

View File

@ -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()
fun setDatePart(datePart: Boolean) {
viewModelScope.launch {