Skip to content

Commit 0f9684a

Browse files
committed
wear, fix scrollbar not showing in settings
1 parent 54e2b80 commit 0f9684a

File tree

9 files changed

+172
-74
lines changed

9 files changed

+172
-74
lines changed

buildSrc/src/main/kotlin/com/example/util/simpletimetracker/Versions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object Versions {
3232
const val navigationKtx = "2.3.5"
3333

3434
const val compose_version = "1.3.1"
35-
const val wear_compose_version = "1.1.0"
35+
const val wear_compose_version = "1.2.1"
3636
const val compose_icons = "1.6.1"
3737
const val wear_compose_tooling_preview = "1.0.0"
3838
const val horologist = "0.2.7"

wear/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ android {
5353
buildFeatures {
5454
compose = true
5555
viewBinding = true
56+
buildConfig = true
5657
}
5758

5859
composeOptions {

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
@@ -10,4 +10,5 @@ interface SettingsItemType {
1010
object AllowMultitasking : SettingsItemType
1111
object AllowMultitaskingHint : SettingsItemType
1212
object ShowCompactList : SettingsItemType
13+
object Version : SettingsItemType
1314
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package com.example.util.simpletimetracker.presentation.screens.settings
77

8+
import com.example.util.simpletimetracker.BuildConfig
89
import com.example.util.simpletimetracker.R
910
import com.example.util.simpletimetracker.data.WearResourceRepo
1011
import com.example.util.simpletimetracker.presentation.ui.components.SettingsItem
@@ -40,9 +41,23 @@ class SettingsViewDataMapper @Inject constructor(
4041
text = resourceRepo.getString(R.string.wear_settings_title_show_compact_list),
4142
checked = showCompactList,
4243
)
44+
items += SettingsItem.Version(
45+
type = SettingsItemType.Version,
46+
text = getAppVersion(),
47+
)
4348

4449
return SettingsListState.Content(
4550
items = items,
4651
)
4752
}
53+
54+
private fun getAppVersion(): String {
55+
val versionText = resourceRepo.getString(R.string.settings_version)
56+
val appVersion = "$versionText ${BuildConfig.VERSION_NAME}"
57+
return if (BuildConfig.DEBUG) {
58+
"$appVersion ${BuildConfig.BUILD_TYPE}"
59+
} else {
60+
appVersion
61+
}
62+
}
4863
}
Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,13 @@ import androidx.compose.ui.graphics.Color
1616
import androidx.compose.ui.text.font.FontWeight
1717
import androidx.compose.ui.tooling.preview.Preview
1818
import androidx.compose.ui.unit.dp
19-
import androidx.compose.ui.unit.sp
2019
import androidx.wear.compose.material.Checkbox
2120
import androidx.wear.compose.material.CheckboxDefaults
2221
import androidx.wear.compose.material.Text
2322
import androidx.wear.tooling.preview.devices.WearDevices
2423
import com.example.util.simpletimetracker.presentation.screens.settings.SettingsItemType
2524
import com.example.util.simpletimetracker.presentation.theme.ColorAccent
2625

27-
// TODO split into separate files
28-
sealed interface SettingsItem {
29-
val type: SettingsItemType
30-
31-
data class CheckBox(
32-
override val type: SettingsItemType,
33-
val text: String,
34-
val checked: Boolean,
35-
) : SettingsItem
36-
37-
data class Hint(
38-
override val type: SettingsItemType,
39-
val hint: String,
40-
) : SettingsItem
41-
}
42-
4326
@Composable
4427
fun SettingsCheckbox(
4528
state: SettingsItem.CheckBox,
@@ -75,25 +58,6 @@ fun SettingsCheckbox(
7558
}
7659
}
7760

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-
9761
@Preview(device = WearDevices.LARGE_ROUND)
9862
@Composable
9963
private fun SettingsCheckboxPreview() {
@@ -118,18 +82,6 @@ private fun SettingsCheckboxCheckedPreview() {
11882
)
11983
}
12084

121-
@Preview(device = WearDevices.LARGE_ROUND)
122-
@Composable
123-
private fun SettingsCheckboxHintPreview() {
124-
SettingsCheckbox(
125-
state = SettingsItem.CheckBox(
126-
type = SettingsItemType.ShowCompactList,
127-
text = "Check box",
128-
checked = false,
129-
),
130-
)
131-
}
132-
13385
@Preview(device = WearDevices.LARGE_ROUND)
13486
@Composable
13587
private fun SettingsCheckboxLongPreview() {
@@ -141,25 +93,3 @@ private fun SettingsCheckboxLongPreview() {
14193
),
14294
)
14395
}
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-
)
165-
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
package com.example.util.simpletimetracker.presentation.ui.components
7+
8+
import androidx.compose.foundation.layout.Column
9+
import androidx.compose.foundation.layout.fillMaxWidth
10+
import androidx.compose.foundation.layout.padding
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.ui.Modifier
13+
import androidx.compose.ui.text.font.FontWeight
14+
import androidx.compose.ui.tooling.preview.Preview
15+
import androidx.compose.ui.unit.dp
16+
import androidx.compose.ui.unit.sp
17+
import androidx.wear.compose.material.Text
18+
import androidx.wear.tooling.preview.devices.WearDevices
19+
import com.example.util.simpletimetracker.presentation.screens.settings.SettingsItemType
20+
21+
@Composable
22+
fun SettingsHint(
23+
state: SettingsItem.Hint,
24+
) {
25+
Column(
26+
Modifier
27+
.padding(bottom = 3.dp)
28+
.padding(horizontal = 4.dp)
29+
.fillMaxWidth(),
30+
) {
31+
Text(
32+
text = state.hint,
33+
fontWeight = FontWeight.Light,
34+
fontSize = 11.sp,
35+
lineHeight = 11.sp,
36+
)
37+
}
38+
}
39+
40+
@Preview(device = WearDevices.LARGE_ROUND)
41+
@Composable
42+
private fun SettingsHintPreview() {
43+
SettingsHint(
44+
state = SettingsItem.Hint(
45+
type = SettingsItemType.AllowMultitaskingHint,
46+
hint = "Check box hint",
47+
),
48+
)
49+
}
50+
51+
@Preview(device = WearDevices.LARGE_ROUND)
52+
@Composable
53+
private fun SettingsHintLongPreview() {
54+
SettingsHint(
55+
state = SettingsItem.Hint(
56+
type = SettingsItemType.AllowMultitaskingHint,
57+
hint = "Check box hint Check box hint Check box hint Check box hint Check box hint ",
58+
),
59+
)
60+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
package com.example.util.simpletimetracker.presentation.ui.components
7+
8+
import com.example.util.simpletimetracker.presentation.screens.settings.SettingsItemType
9+
10+
sealed interface SettingsItem {
11+
val type: SettingsItemType
12+
13+
data class CheckBox(
14+
override val type: SettingsItemType,
15+
val text: String,
16+
val checked: Boolean,
17+
) : SettingsItem
18+
19+
data class Hint(
20+
override val type: SettingsItemType,
21+
val hint: String,
22+
) : SettingsItem
23+
24+
data class Version(
25+
override val type: SettingsItemType,
26+
val text: String,
27+
) : SettingsItem
28+
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ private fun ScalingLazyListScope.renderContent(
113113
)
114114
}
115115
is SettingsItem.Hint -> {
116-
SettingsHint(
117-
state = item,
118-
)
116+
SettingsHint(item)
117+
}
118+
is SettingsItem.Version -> {
119+
SettingsVersion(item)
119120
}
120121
}
121122
}
@@ -143,6 +144,10 @@ private fun Content() {
143144
type = SettingsItemType.AllowMultitaskingHint,
144145
hint = "Hint",
145146
),
147+
SettingsItem.Version(
148+
type = SettingsItemType.Version,
149+
text = "Version 1.43",
150+
),
146151
)
147152
SettingsList(
148153
state = SettingsListState.Content(
@@ -168,6 +173,10 @@ private fun ContentLong() {
168173
type = SettingsItemType.AllowMultitaskingHint,
169174
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 ",
170175
),
176+
SettingsItem.Version(
177+
type = SettingsItemType.Version,
178+
text = "Version 1.43",
179+
),
171180
)
172181
SettingsList(
173182
state = SettingsListState.Content(
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
package com.example.util.simpletimetracker.presentation.ui.components
7+
8+
import androidx.compose.foundation.layout.Column
9+
import androidx.compose.foundation.layout.fillMaxWidth
10+
import androidx.compose.foundation.layout.padding
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.ui.Alignment
13+
import androidx.compose.ui.Modifier
14+
import androidx.compose.ui.text.font.FontWeight
15+
import androidx.compose.ui.text.style.TextAlign
16+
import androidx.compose.ui.tooling.preview.Preview
17+
import androidx.compose.ui.unit.dp
18+
import androidx.compose.ui.unit.sp
19+
import androidx.wear.compose.material.Text
20+
import androidx.wear.tooling.preview.devices.WearDevices
21+
import com.example.util.simpletimetracker.presentation.screens.settings.SettingsItemType
22+
23+
@Composable
24+
fun SettingsVersion(
25+
state: SettingsItem.Version,
26+
) {
27+
Column(
28+
Modifier
29+
.padding(top = 32.dp)
30+
.padding(horizontal = 4.dp)
31+
.fillMaxWidth(),
32+
) {
33+
Text(
34+
modifier = Modifier
35+
.align(Alignment.CenterHorizontally),
36+
text = state.text,
37+
fontWeight = FontWeight.Light,
38+
fontSize = 11.sp,
39+
lineHeight = 11.sp,
40+
textAlign = TextAlign.Center,
41+
)
42+
}
43+
}
44+
45+
@Preview(device = WearDevices.LARGE_ROUND)
46+
@Composable
47+
private fun SettingsVersionPreview() {
48+
SettingsVersion(
49+
state = SettingsItem.Version(
50+
type = SettingsItemType.Version,
51+
text = "Version 1.43",
52+
),
53+
)
54+
}

0 commit comments

Comments
 (0)