From e5d303c2c3e459de802801c726c0a3f2a1e1d67a Mon Sep 17 00:00:00 2001 From: Maximilian Keppeler Date: Sun, 5 Feb 2023 14:06:55 +0100 Subject: [PATCH] Finish landscape support for clock view --- .../com/maxkeppeler/sheets/clock/ClockView.kt | 17 +++++++--- .../sheets/clock/models/ClockConfig.kt | 7 ++-- .../sheets/clock/views/KeyItemComponent.kt | 32 +++++++++++-------- .../sheets/clock/views/KeyboardComponent.kt | 8 +++-- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/clock/src/main/java/com/maxkeppeler/sheets/clock/ClockView.kt b/clock/src/main/java/com/maxkeppeler/sheets/clock/ClockView.kt index 376b7fde..9e754538 100644 --- a/clock/src/main/java/com/maxkeppeler/sheets/clock/ClockView.kt +++ b/clock/src/main/java/com/maxkeppeler/sheets/clock/ClockView.kt @@ -17,17 +17,19 @@ package com.maxkeppeler.sheets.clock -import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.layout.* import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.unit.dp import com.maxkeppeker.sheets.core.models.base.Header +import com.maxkeppeker.sheets.core.models.base.LibOrientation import com.maxkeppeker.sheets.core.models.base.SheetState import com.maxkeppeker.sheets.core.models.base.StateHandler +import com.maxkeppeker.sheets.core.utils.BaseConstants import com.maxkeppeker.sheets.core.views.ButtonsComponent import com.maxkeppeker.sheets.core.views.base.FrameBase import com.maxkeppeler.sheets.clock.models.ClockConfig @@ -59,6 +61,7 @@ fun ClockView( FrameBase( header = header, config = config, + contentHorizontalAlignment = Alignment.CenterHorizontally, content = { PortraitTimeValueComponent( modifier = Modifier @@ -73,7 +76,10 @@ fun ClockView( onAm = clockState::onChange12HourFormatValue, ) KeyboardComponent( - modifier = Modifier.weight(1f, false), + modifier = Modifier + .sizeIn(maxHeight = BaseConstants.KEYBOARD_HEIGHT_MAX) + .aspectRatio(BaseConstants.KEYBOARD_RATIO), + orientation = LibOrientation.PORTRAIT, config = config, keys = clockState.keys, disabledKeys = clockState.disabledKeys, @@ -98,8 +104,11 @@ fun ClockView( ) Spacer(modifier = Modifier.width(16.dp)) KeyboardComponent( - modifier = Modifier.weight(1f, true), - orientation = Orientation.Horizontal, + modifier = Modifier + .weight(1f, true) + .sizeIn(maxHeight = BaseConstants.KEYBOARD_HEIGHT_MAX) + .aspectRatio(BaseConstants.KEYBOARD_RATIO), + orientation = LibOrientation.LANDSCAPE, config = config, keys = clockState.keys, disabledKeys = clockState.disabledKeys, diff --git a/clock/src/main/java/com/maxkeppeler/sheets/clock/models/ClockConfig.kt b/clock/src/main/java/com/maxkeppeler/sheets/clock/models/ClockConfig.kt index af961e9b..9e94bfc0 100644 --- a/clock/src/main/java/com/maxkeppeler/sheets/clock/models/ClockConfig.kt +++ b/clock/src/main/java/com/maxkeppeler/sheets/clock/models/ClockConfig.kt @@ -17,7 +17,8 @@ package com.maxkeppeler.sheets.clock.models import com.maxkeppeker.sheets.core.icons.LibIcons import com.maxkeppeker.sheets.core.models.base.BaseConfigs -import com.maxkeppeker.sheets.core.utils.BaseConstants.DEFAULT_ICON_STYLE +import com.maxkeppeker.sheets.core.models.base.LibOrientation +import com.maxkeppeker.sheets.core.utils.BaseConstants import java.time.LocalTime /** @@ -25,9 +26,11 @@ import java.time.LocalTime * @param defaultTime The default time. * @param is24HourFormat If the 24HourFormat is enabled. * @param icons The style of icons that are used for dialog/ view-specific icons. + * @param orientation The orientation of the view or null for auto orientation. */ data class ClockConfig( val defaultTime: LocalTime? = null, val is24HourFormat: Boolean? = null, - override val icons: LibIcons = DEFAULT_ICON_STYLE, + override val icons: LibIcons = BaseConstants.DEFAULT_ICON_STYLE, + override val orientation: LibOrientation? = BaseConstants.DEFAULT_LIB_LAYOUT, ) : BaseConfigs() \ No newline at end of file diff --git a/clock/src/main/java/com/maxkeppeler/sheets/clock/views/KeyItemComponent.kt b/clock/src/main/java/com/maxkeppeler/sheets/clock/views/KeyItemComponent.kt index 9d5eb913..091f3553 100644 --- a/clock/src/main/java/com/maxkeppeler/sheets/clock/views/KeyItemComponent.kt +++ b/clock/src/main/java/com/maxkeppeler/sheets/clock/views/KeyItemComponent.kt @@ -20,7 +20,6 @@ import androidx.compose.animation.core.tween import androidx.compose.foundation.LocalIndication import androidx.compose.foundation.background import androidx.compose.foundation.clickable -import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.collectIsPressedAsState import androidx.compose.foundation.layout.* @@ -39,7 +38,7 @@ import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.unit.dp +import com.maxkeppeker.sheets.core.models.base.LibOrientation import com.maxkeppeker.sheets.core.utils.TestTags import com.maxkeppeker.sheets.core.utils.testTags import com.maxkeppeler.sheets.clock.R @@ -50,6 +49,7 @@ import com.maxkeppeler.sheets.core.R as RC /** * The item component of the keyboard. * @param config The general configuration for the dialog view. + * @param orientation The orientation of the view. * @param key The key that the component represents. * @param disabled Whenever the current key is disabled. * @param onEnterValue The listener that is invoked when a value was clicked. @@ -59,9 +59,9 @@ import com.maxkeppeler.sheets.core.R as RC @Composable internal fun KeyItemComponent( config: ClockConfig, + orientation: LibOrientation, key: String, disabled: Boolean = false, - orientation: Orientation = Orientation.Vertical, onEnterValue: (Int) -> Unit, onPrevAction: () -> Unit, onNextAction: () -> Unit, @@ -87,7 +87,6 @@ internal fun KeyItemComponent( modifier = Modifier .testTags(TestTags.KEYBOARD_KEY, key) .aspectRatio(1f, true) - .sizeIn(minHeight = 35.dp, minWidth = 35.dp, maxWidth = 42.dp, maxHeight = 42.dp) .alpha(if (disabled) Constants.KEYBOARD_ALPHA_ITEM_DISABLED else Constants.KEYBOARD_ALPHA_ITEM_ENABLED) .clip(RoundedCornerShape(animatedCornerRadius.value)) .background( @@ -109,9 +108,18 @@ internal fun KeyItemComponent( verticalAlignment = Alignment.CenterVertically ) { if (isActionNext || isActionPrev) { - val size = dimensionResource(RC.dimen.scd_size_175) + val maxSize = dimensionResource(RC.dimen.scd_size_150) + val minSize = dimensionResource(RC.dimen.scd_size_100) Icon( - modifier = Modifier.size(size), + modifier = Modifier + .padding(dimensionResource(RC.dimen.scd_small_100)) + .sizeIn( + maxWidth = maxSize, + maxHeight = maxSize, + minWidth = minSize, + minHeight = minSize + ) + .fillMaxSize(), imageVector = if (isActionNext) config.icons.ChevronRight else config.icons.ChevronLeft, contentDescription = stringResource(if (isActionNext) R.string.scd_clock_dialog_next_value else R.string.scd_clock_dialog_previous_value), tint = MaterialTheme.colorScheme.secondary @@ -120,13 +128,11 @@ internal fun KeyItemComponent( Box(contentAlignment = Alignment.Center) { Text( text = key, - style = when(orientation) { - Orientation.Vertical -> MaterialTheme.typography.headlineLarge.copy( - fontWeight = FontWeight.Bold - ) - Orientation.Horizontal -> MaterialTheme.typography.headlineSmall.copy( - fontWeight = FontWeight.Bold - ) + style = with(MaterialTheme.typography) { + when (orientation) { + LibOrientation.PORTRAIT -> headlineLarge.copy(fontWeight = FontWeight.Bold) + LibOrientation.LANDSCAPE -> titleMedium.copy(fontWeight = FontWeight.Bold) + } }, textAlign = TextAlign.Center, ) diff --git a/clock/src/main/java/com/maxkeppeler/sheets/clock/views/KeyboardComponent.kt b/clock/src/main/java/com/maxkeppeler/sheets/clock/views/KeyboardComponent.kt index 0df0c8fe..b90243a0 100644 --- a/clock/src/main/java/com/maxkeppeler/sheets/clock/views/KeyboardComponent.kt +++ b/clock/src/main/java/com/maxkeppeler/sheets/clock/views/KeyboardComponent.kt @@ -16,16 +16,18 @@ package com.maxkeppeler.sheets.clock.views -import androidx.compose.foundation.gestures.Orientation import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp +import com.maxkeppeker.sheets.core.models.base.LibOrientation import com.maxkeppeker.sheets.core.views.Grid import com.maxkeppeler.sheets.clock.models.ClockConfig import com.maxkeppeler.sheets.clock.utils.Constants /** * The keyboard component that is used to input the clock time. + * @param modifier The modifier that is applied to this component. + * @param orientation The orientation of the view. * @param config The general configuration for the dialog view. * @param keys A list of keys that will be displayed. * @param disabledKeys A list of the keys that are displayed. @@ -36,9 +38,9 @@ import com.maxkeppeler.sheets.clock.utils.Constants @Composable internal fun KeyboardComponent( modifier: Modifier, + orientation: LibOrientation, config: ClockConfig, keys: List, - orientation: Orientation = Orientation.Vertical, disabledKeys: List, onEnterValue: (Int) -> Unit, onPrevAction: () -> Unit, @@ -54,8 +56,8 @@ internal fun KeyboardComponent( val disabled = disabledKeys.contains(key) KeyItemComponent( config = config, - key = key, orientation = orientation, + key = key, disabled = disabled, onNextAction = onNextAction, onPrevAction = onPrevAction,