Skip to content

Commit

Permalink
Finish landscape support for clock view
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkeppeler committed Feb 5, 2023
1 parent ba5b059 commit e5d303c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
17 changes: 13 additions & 4 deletions clock/src/main/java/com/maxkeppeler/sheets/clock/ClockView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,6 +61,7 @@ fun ClockView(
FrameBase(
header = header,
config = config,
contentHorizontalAlignment = Alignment.CenterHorizontally,
content = {
PortraitTimeValueComponent(
modifier = Modifier
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ 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

/**
* The general configuration for the clock dialog.
* @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()
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,9 +38,9 @@ import com.maxkeppeler.sheets.clock.utils.Constants
@Composable
internal fun KeyboardComponent(
modifier: Modifier,
orientation: LibOrientation,
config: ClockConfig,
keys: List<String>,
orientation: Orientation = Orientation.Vertical,
disabledKeys: List<String>,
onEnterValue: (Int) -> Unit,
onPrevAction: () -> Unit,
Expand All @@ -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,
Expand Down

0 comments on commit e5d303c

Please sign in to comment.