Skip to content

Commit 092428a

Browse files
committed
refactor: reorganize profile settings and extract shared components
- Extract `ToggleSettingCard` into a standalone component to improve reusability across different settings sections. - Move clipboard detection and "seen" history settings from the Appearance section to the Others section. - Relocate `ClearSeenHistoryCard` to `Others.kt` to align with the updated settings structure. - Replace custom `VerticalSpacer` with standard `Spacer(Modifier.height(...))` for consistency across the profile module. - Update visibility modifiers for `ThemeModeOption` and `ThemeColorCard` to facilitate better internal access.
1 parent e3a3a88 commit 092428a

3 files changed

Lines changed: 151 additions & 131 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package zed.rainxch.profile.presentation.components
2+
3+
import androidx.compose.foundation.interaction.MutableInteractionSource
4+
import androidx.compose.foundation.layout.Arrangement
5+
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.Row
7+
import androidx.compose.foundation.layout.Spacer
8+
import androidx.compose.foundation.layout.fillMaxWidth
9+
import androidx.compose.foundation.layout.height
10+
import androidx.compose.foundation.layout.padding
11+
import androidx.compose.foundation.selection.toggleable
12+
import androidx.compose.material3.MaterialTheme
13+
import androidx.compose.material3.Switch
14+
import androidx.compose.material3.Text
15+
import androidx.compose.material3.ripple
16+
import androidx.compose.runtime.Composable
17+
import androidx.compose.runtime.remember
18+
import androidx.compose.ui.Alignment
19+
import androidx.compose.ui.Modifier
20+
import androidx.compose.ui.semantics.Role
21+
import androidx.compose.ui.text.font.FontWeight
22+
import androidx.compose.ui.unit.dp
23+
import zed.rainxch.core.presentation.components.ExpressiveCard
24+
25+
@Composable
26+
fun ToggleSettingCard(
27+
title: String,
28+
description: String,
29+
checked: Boolean,
30+
onCheckedChange: (Boolean) -> Unit,
31+
) {
32+
ExpressiveCard {
33+
Row(
34+
modifier =
35+
Modifier
36+
.fillMaxWidth()
37+
.toggleable(
38+
value = checked,
39+
onValueChange = onCheckedChange,
40+
role = Role.Switch,
41+
interactionSource = remember { MutableInteractionSource() },
42+
indication = ripple(),
43+
).padding(16.dp),
44+
horizontalArrangement = Arrangement.SpaceBetween,
45+
verticalAlignment = Alignment.CenterVertically,
46+
) {
47+
Column(
48+
modifier =
49+
Modifier
50+
.weight(1f)
51+
.padding(end = 16.dp),
52+
) {
53+
Text(
54+
text = title,
55+
style = MaterialTheme.typography.titleMedium,
56+
color = MaterialTheme.colorScheme.onSurface,
57+
fontWeight = FontWeight.SemiBold,
58+
)
59+
60+
Spacer(Modifier.height(4.dp))
61+
62+
Text(
63+
text = description,
64+
style = MaterialTheme.typography.bodyMedium,
65+
color = MaterialTheme.colorScheme.onSurfaceVariant,
66+
)
67+
}
68+
69+
Switch(
70+
checked = checked,
71+
onCheckedChange = null,
72+
)
73+
}
74+
}
75+
}

feature/profile/presentation/src/commonMain/kotlin/zed/rainxch/profile/presentation/components/sections/Appearance.kt

Lines changed: 9 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import zed.rainxch.githubstore.core.presentation.res.*
6363
import zed.rainxch.profile.presentation.ProfileAction
6464
import zed.rainxch.profile.presentation.ProfileState
6565
import zed.rainxch.profile.presentation.components.SectionHeader
66+
import zed.rainxch.profile.presentation.components.ToggleSettingCard
6667

6768
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
6869
fun LazyListScope.appearanceSection(
@@ -74,7 +75,7 @@ fun LazyListScope.appearanceSection(
7475
text = stringResource(Res.string.section_appearance),
7576
)
7677

77-
VerticalSpacer(8.dp)
78+
Spacer(Modifier.height(8.dp))
7879

7980
ThemeSelectionCard(
8081
isDarkTheme = state.isDarkTheme,
@@ -83,7 +84,7 @@ fun LazyListScope.appearanceSection(
8384
},
8485
)
8586

86-
VerticalSpacer(12.dp)
87+
Spacer(Modifier.height(12.dp))
8788

8889
ThemeColorCard(
8990
selectedThemeColor = state.selectedThemeColor,
@@ -92,7 +93,7 @@ fun LazyListScope.appearanceSection(
9293
},
9394
)
9495

95-
VerticalSpacer(16.dp)
96+
Spacer(Modifier.height(16.dp))
9697

9798
if (state.isDarkTheme == true || (state.isDarkTheme == null && isSystemInDarkTheme())) {
9899
ToggleSettingCard(
@@ -104,7 +105,7 @@ fun LazyListScope.appearanceSection(
104105
},
105106
)
106107

107-
VerticalSpacer(8.dp)
108+
Spacer(Modifier.height(8.dp))
108109
}
109110

110111
ToggleSettingCard(
@@ -124,7 +125,7 @@ fun LazyListScope.appearanceSection(
124125
},
125126
)
126127

127-
VerticalSpacer(8.dp)
128+
Spacer(Modifier.height(8.dp))
128129

129130
ToggleSettingCard(
130131
title = stringResource(Res.string.liquid_glass_option_title),
@@ -134,44 +135,9 @@ fun LazyListScope.appearanceSection(
134135
onAction(ProfileAction.OnLiquidGlassEnabledChange(enabled))
135136
},
136137
)
137-
138-
VerticalSpacer(8.dp)
139-
140-
ToggleSettingCard(
141-
title = stringResource(Res.string.auto_detect_clipboard_links),
142-
description = stringResource(Res.string.auto_detect_clipboard_description),
143-
checked = state.autoDetectClipboardLinks,
144-
onCheckedChange = { enabled ->
145-
onAction(ProfileAction.OnAutoDetectClipboardToggled(enabled))
146-
},
147-
)
148-
149-
VerticalSpacer(8.dp)
150-
151-
ToggleSettingCard(
152-
title = stringResource(Res.string.hide_seen_title),
153-
description = stringResource(Res.string.hide_seen_description),
154-
checked = state.isHideSeenEnabled,
155-
onCheckedChange = { enabled ->
156-
onAction(ProfileAction.OnHideSeenToggled(enabled))
157-
},
158-
)
159-
160-
VerticalSpacer(8.dp)
161-
162-
ClearSeenHistoryCard(
163-
onClick = {
164-
onAction(ProfileAction.OnClearSeenRepos)
165-
},
166-
)
167138
}
168139
}
169140

170-
@Composable
171-
private fun VerticalSpacer(height: Dp) {
172-
Spacer(Modifier.height(height))
173-
}
174-
175141
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
176142
@Composable
177143
private fun ThemeSelectionCard(
@@ -216,7 +182,7 @@ private fun ThemeSelectionCard(
216182

217183
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
218184
@Composable
219-
private fun ThemeModeOption(
185+
fun ThemeModeOption(
220186
icon: ImageVector,
221187
label: String,
222188
isSelected: Boolean,
@@ -275,7 +241,7 @@ private fun ThemeModeOption(
275241

276242
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
277243
@Composable
278-
private fun ThemeColorCard(
244+
fun ThemeColorCard(
279245
selectedThemeColor: AppTheme,
280246
onThemeColorSelected: (AppTheme) -> Unit,
281247
) {
@@ -290,7 +256,7 @@ private fun ThemeColorCard(
290256
fontWeight = FontWeight.SemiBold,
291257
)
292258

293-
VerticalSpacer(12.dp)
259+
Spacer(Modifier.height(12.dp))
294260

295261
LazyRow(
296262
modifier = Modifier.fillMaxWidth(),
@@ -398,91 +364,3 @@ private fun ThemeColorOption(
398364
)
399365
}
400366
}
401-
402-
@Composable
403-
private fun ToggleSettingCard(
404-
title: String,
405-
description: String,
406-
checked: Boolean,
407-
onCheckedChange: (Boolean) -> Unit,
408-
) {
409-
ExpressiveCard {
410-
Row(
411-
modifier =
412-
Modifier
413-
.fillMaxWidth()
414-
.toggleable(
415-
value = checked,
416-
onValueChange = onCheckedChange,
417-
role = Role.Switch,
418-
interactionSource = remember { MutableInteractionSource() },
419-
indication = ripple(),
420-
).padding(16.dp),
421-
horizontalArrangement = Arrangement.SpaceBetween,
422-
verticalAlignment = Alignment.CenterVertically,
423-
) {
424-
Column(
425-
modifier =
426-
Modifier
427-
.weight(1f)
428-
.padding(end = 16.dp),
429-
) {
430-
Text(
431-
text = title,
432-
style = MaterialTheme.typography.titleMedium,
433-
color = MaterialTheme.colorScheme.onSurface,
434-
fontWeight = FontWeight.SemiBold,
435-
)
436-
437-
VerticalSpacer(4.dp)
438-
439-
Text(
440-
text = description,
441-
style = MaterialTheme.typography.bodyMedium,
442-
color = MaterialTheme.colorScheme.onSurfaceVariant,
443-
)
444-
}
445-
446-
Switch(
447-
checked = checked,
448-
onCheckedChange = null,
449-
)
450-
}
451-
}
452-
}
453-
454-
@Composable
455-
private fun ClearSeenHistoryCard(
456-
onClick: () -> Unit,
457-
) {
458-
ExpressiveCard {
459-
Row(
460-
modifier =
461-
Modifier
462-
.fillMaxWidth()
463-
.clickable(onClick = onClick)
464-
.padding(16.dp),
465-
horizontalArrangement = Arrangement.SpaceBetween,
466-
verticalAlignment = Alignment.CenterVertically,
467-
) {
468-
Column(
469-
modifier = Modifier.weight(1f),
470-
) {
471-
Text(
472-
text = stringResource(Res.string.clear_seen_history),
473-
style = MaterialTheme.typography.titleMedium,
474-
color = MaterialTheme.colorScheme.onSurface,
475-
fontWeight = FontWeight.SemiBold,
476-
)
477-
478-
VerticalSpacer(4.dp)
479-
480-
Text(
481-
text = stringResource(Res.string.clear_seen_history_description),
482-
style = MaterialTheme.typography.bodyMedium,
483-
color = MaterialTheme.colorScheme.onSurfaceVariant,
484-
)
485-
}
486-
}
487-
}
488-
}

feature/profile/presentation/src/commonMain/kotlin/zed/rainxch/profile/presentation/components/sections/Others.kt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package zed.rainxch.profile.presentation.components.sections
22

33
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.clickable
45
import androidx.compose.foundation.layout.Arrangement
56
import androidx.compose.foundation.layout.Column
67
import androidx.compose.foundation.layout.Row
@@ -19,6 +20,7 @@ import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
1920
import androidx.compose.material3.Icon
2021
import androidx.compose.material3.MaterialTheme
2122
import androidx.compose.material3.Text
23+
import androidx.compose.runtime.Composable
2224
import androidx.compose.ui.Alignment
2325
import androidx.compose.ui.Modifier
2426
import androidx.compose.ui.draw.clip
@@ -30,6 +32,7 @@ import zed.rainxch.githubstore.core.presentation.res.*
3032
import zed.rainxch.profile.presentation.ProfileAction
3133
import zed.rainxch.profile.presentation.ProfileState
3234
import zed.rainxch.profile.presentation.components.SectionHeader
35+
import zed.rainxch.profile.presentation.components.ToggleSettingCard
3336

3437
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
3538
fun LazyListScope.othersSection(
@@ -100,5 +103,69 @@ fun LazyListScope.othersSection(
100103
}
101104
}
102105
}
106+
107+
Spacer(Modifier.height(16.dp))
108+
109+
ToggleSettingCard(
110+
title = stringResource(Res.string.auto_detect_clipboard_links),
111+
description = stringResource(Res.string.auto_detect_clipboard_description),
112+
checked = state.autoDetectClipboardLinks,
113+
onCheckedChange = { enabled ->
114+
onAction(ProfileAction.OnAutoDetectClipboardToggled(enabled))
115+
},
116+
)
117+
118+
Spacer(Modifier.height(16.dp))
119+
120+
ToggleSettingCard(
121+
title = stringResource(Res.string.hide_seen_title),
122+
description = stringResource(Res.string.hide_seen_description),
123+
checked = state.isHideSeenEnabled,
124+
onCheckedChange = { enabled ->
125+
onAction(ProfileAction.OnHideSeenToggled(enabled))
126+
},
127+
)
128+
129+
Spacer(Modifier.height(8.dp))
130+
131+
ClearSeenHistoryCard(
132+
onClick = {
133+
onAction(ProfileAction.OnClearSeenRepos)
134+
},
135+
)
136+
}
137+
}
138+
139+
@Composable
140+
private fun ClearSeenHistoryCard(onClick: () -> Unit) {
141+
ExpressiveCard {
142+
Row(
143+
modifier =
144+
Modifier
145+
.fillMaxWidth()
146+
.clickable(onClick = onClick)
147+
.padding(16.dp),
148+
horizontalArrangement = Arrangement.SpaceBetween,
149+
verticalAlignment = Alignment.CenterVertically,
150+
) {
151+
Column(
152+
modifier = Modifier.weight(1f),
153+
) {
154+
Text(
155+
text = stringResource(Res.string.clear_seen_history),
156+
style = MaterialTheme.typography.titleMedium,
157+
color = MaterialTheme.colorScheme.onSurface,
158+
fontWeight = FontWeight.SemiBold,
159+
)
160+
161+
Spacer(Modifier.height(4.dp))
162+
163+
Text(
164+
text = stringResource(Res.string.clear_seen_history_description),
165+
style = MaterialTheme.typography.bodyMedium,
166+
color = MaterialTheme.colorScheme.onSurfaceVariant,
167+
)
168+
}
169+
}
103170
}
104171
}

0 commit comments

Comments
 (0)