Skip to content

Commit 54e2b80

Browse files
committed
wear, fix content cutoff on increased font size
1 parent aacae9d commit 54e2b80

File tree

6 files changed

+94
-18
lines changed

6 files changed

+94
-18
lines changed

wear/src/main/java/com/example/util/simpletimetracker/presentation/screens/settings/SettingsItemType.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ package com.example.util.simpletimetracker.presentation.screens.settings
88
interface SettingsItemType {
99

1010
object AllowMultitasking : SettingsItemType
11+
object AllowMultitaskingHint : SettingsItemType
1112
object ShowCompactList : SettingsItemType
1213
}

wear/src/main/java/com/example/util/simpletimetracker/presentation/screens/settings/SettingsViewDataMapper.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ class SettingsViewDataMapper @Inject constructor(
2929
items += SettingsItem.CheckBox(
3030
type = SettingsItemType.AllowMultitasking,
3131
text = resourceRepo.getString(R.string.settings_allow_multitasking),
32-
hint = resourceRepo.getString(R.string.settings_allow_multitasking_hint),
3332
checked = wearSettings.allowMultitasking,
3433
)
35-
34+
items += SettingsItem.Hint(
35+
type = SettingsItemType.AllowMultitaskingHint,
36+
hint = resourceRepo.getString(R.string.settings_allow_multitasking_hint),
37+
)
3638
items += SettingsItem.CheckBox(
3739
type = SettingsItemType.ShowCompactList,
3840
text = resourceRepo.getString(R.string.wear_settings_title_show_compact_list),
39-
hint = "",
4041
checked = showCompactList,
4142
)
4243

wear/src/main/java/com/example/util/simpletimetracker/presentation/ui/components/SettingsItems.kt

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@ import androidx.wear.tooling.preview.devices.WearDevices
2424
import com.example.util.simpletimetracker.presentation.screens.settings.SettingsItemType
2525
import com.example.util.simpletimetracker.presentation.theme.ColorAccent
2626

27+
// TODO split into separate files
2728
sealed interface SettingsItem {
2829
val type: SettingsItemType
2930

3031
data class CheckBox(
3132
override val type: SettingsItemType,
3233
val text: String,
33-
val hint: String,
3434
val checked: Boolean,
3535
) : SettingsItem
36+
37+
data class Hint(
38+
override val type: SettingsItemType,
39+
val hint: String,
40+
) : SettingsItem
3641
}
3742

3843
@Composable
@@ -56,14 +61,6 @@ fun SettingsCheckbox(
5661
text = state.text,
5762
fontWeight = FontWeight.Medium,
5863
)
59-
if (state.hint.isNotEmpty()) {
60-
Text(
61-
text = state.hint,
62-
fontWeight = FontWeight.Light,
63-
fontSize = 11.sp,
64-
lineHeight = 11.sp,
65-
)
66-
}
6764
}
6865
Checkbox(
6966
modifier = Modifier,
@@ -78,14 +75,32 @@ fun SettingsCheckbox(
7875
}
7976
}
8077

78+
@Composable
79+
fun SettingsHint(
80+
state: SettingsItem.Hint,
81+
) {
82+
Column(
83+
Modifier
84+
.padding(bottom = 3.dp)
85+
.padding(horizontal = 4.dp)
86+
.fillMaxWidth(),
87+
) {
88+
Text(
89+
text = state.hint,
90+
fontWeight = FontWeight.Light,
91+
fontSize = 11.sp,
92+
lineHeight = 11.sp,
93+
)
94+
}
95+
}
96+
8197
@Preview(device = WearDevices.LARGE_ROUND)
8298
@Composable
8399
private fun SettingsCheckboxPreview() {
84100
SettingsCheckbox(
85101
state = SettingsItem.CheckBox(
86102
type = SettingsItemType.ShowCompactList,
87103
text = "Check box",
88-
hint = "",
89104
checked = false,
90105
),
91106
)
@@ -98,7 +113,6 @@ private fun SettingsCheckboxCheckedPreview() {
98113
state = SettingsItem.CheckBox(
99114
type = SettingsItemType.ShowCompactList,
100115
text = "Check box",
101-
hint = "Check box hint",
102116
checked = true,
103117
),
104118
)
@@ -111,7 +125,6 @@ private fun SettingsCheckboxHintPreview() {
111125
state = SettingsItem.CheckBox(
112126
type = SettingsItemType.ShowCompactList,
113127
text = "Check box",
114-
hint = "Check box hint",
115128
checked = false,
116129
),
117130
)
@@ -124,8 +137,29 @@ private fun SettingsCheckboxLongPreview() {
124137
state = SettingsItem.CheckBox(
125138
type = SettingsItemType.ShowCompactList,
126139
text = "Check box Check box Check box Check box Check box Check box Check box Check box ",
127-
hint = "Check box hint Check box hint Check box hint Check box hint Check box hint ",
128140
checked = false,
129141
),
130142
)
143+
}
144+
145+
@Preview(device = WearDevices.LARGE_ROUND)
146+
@Composable
147+
private fun SettingsHintPreview() {
148+
SettingsHint(
149+
state = SettingsItem.Hint(
150+
type = SettingsItemType.AllowMultitaskingHint,
151+
hint = "Check box hint",
152+
),
153+
)
154+
}
155+
156+
@Preview(device = WearDevices.LARGE_ROUND)
157+
@Composable
158+
private fun SettingsHintLongPreview() {
159+
SettingsHint(
160+
state = SettingsItem.Hint(
161+
type = SettingsItemType.AllowMultitaskingHint,
162+
hint = "Check box hint Check box hint Check box hint Check box hint Check box hint ",
163+
),
164+
)
131165
}

wear/src/main/java/com/example/util/simpletimetracker/presentation/ui/components/SettingsList.kt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fun SettingsList(
4747
) {
4848
ScaffoldedScrollingColumn(
4949
startItemIndex = 0,
50+
spacedBy = 0.dp,
5051
) {
5152
when (state) {
5253
is SettingsListState.Loading -> item {
@@ -111,6 +112,11 @@ private fun ScalingLazyListScope.renderContent(
111112
onClick = onClick,
112113
)
113114
}
115+
is SettingsItem.Hint -> {
116+
SettingsHint(
117+
state = item,
118+
)
119+
}
114120
}
115121
}
116122
}
@@ -131,9 +137,37 @@ private fun Content() {
131137
SettingsItem.CheckBox(
132138
type = SettingsItemType.ShowCompactList,
133139
text = "Setting",
134-
hint = "",
135140
checked = true,
136141
),
142+
SettingsItem.Hint(
143+
type = SettingsItemType.AllowMultitaskingHint,
144+
hint = "Hint",
145+
),
146+
)
147+
SettingsList(
148+
state = SettingsListState.Content(
149+
items = items,
150+
),
151+
)
152+
}
153+
154+
@Preview(
155+
device = WearDevices.LARGE_ROUND,
156+
showSystemUi = true,
157+
fontScale = 1.5f,
158+
)
159+
@Composable
160+
private fun ContentLong() {
161+
val items = listOf(
162+
SettingsItem.CheckBox(
163+
type = SettingsItemType.ShowCompactList,
164+
text = "Setting Setting Setting Setting Setting",
165+
checked = true,
166+
),
167+
SettingsItem.Hint(
168+
type = SettingsItemType.AllowMultitaskingHint,
169+
hint = "Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint Hint ",
170+
),
137171
)
138172
SettingsList(
139173
state = SettingsListState.Content(

wear/src/main/java/com/example/util/simpletimetracker/presentation/ui/layout/ScaffoldedScrollingColumn.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
package com.example.util.simpletimetracker.presentation.ui.layout
77

88
import androidx.compose.runtime.Composable
9+
import androidx.compose.ui.unit.Dp
10+
import androidx.compose.ui.unit.dp
911
import androidx.wear.compose.material.ScalingLazyListScope
1012
import androidx.wear.compose.material.rememberScalingLazyListState
1113

1214
@Composable
1315
fun ScaffoldedScrollingColumn(
1416
startItemIndex: Int,
17+
spacedBy: Dp = 10.dp,
1518
content: ScalingLazyListScope.() -> Unit,
1619
) {
1720
val scrollState = rememberScalingLazyListState()
1821
Scaffolding(scrollState) {
1922
ScrollingColumn(
2023
startItemIndex = startItemIndex,
24+
spacedBy = spacedBy,
2125
scrollState = scrollState,
2226
content = content,
2327
)

wear/src/main/java/com/example/util/simpletimetracker/presentation/ui/layout/ScrollingColumn.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.fillMaxSize
1111
import androidx.compose.foundation.selection.selectableGroup
1212
import androidx.compose.runtime.Composable
1313
import androidx.compose.ui.Modifier
14+
import androidx.compose.ui.unit.Dp
1415
import androidx.compose.ui.unit.dp
1516
import androidx.wear.compose.material.AutoCenteringParams
1617
import androidx.wear.compose.material.MaterialTheme
@@ -27,6 +28,7 @@ import com.google.android.horologist.compose.rotaryinput.rotaryWithScroll
2728
@Composable
2829
fun ScrollingColumn(
2930
startItemIndex: Int,
31+
spacedBy: Dp,
3032
scrollState: ScalingLazyListState = rememberScalingLazyListState(),
3133
content: ScalingLazyListScope.() -> Unit,
3234
) {
@@ -41,7 +43,7 @@ fun ScrollingColumn(
4143
autoCentering = AutoCenteringParams(
4244
itemIndex = startItemIndex,
4345
),
44-
verticalArrangement = Arrangement.spacedBy(10.dp),
46+
verticalArrangement = Arrangement.spacedBy(spacedBy),
4547
state = scrollState,
4648
content = content,
4749
)

0 commit comments

Comments
 (0)