2222
2323package ss.document.reader
2424
25+ import androidx.compose.animation.AnimatedVisibility
2526import androidx.compose.foundation.layout.Arrangement
2627import androidx.compose.foundation.layout.Column
28+ import androidx.compose.foundation.layout.FlowRow
2729import androidx.compose.foundation.layout.Row
2830import androidx.compose.foundation.layout.fillMaxWidth
2931import androidx.compose.foundation.layout.padding
3032import androidx.compose.foundation.layout.size
31- import androidx.compose.material3.SegmentedButton
32- import androidx.compose.material3.SegmentedButtonDefaults
33- import androidx.compose.material3.SingleChoiceSegmentedButtonRow
33+ import androidx.compose.material3.FilterChip
34+ import androidx.compose.material3.Icon
3435import androidx.compose.material3.Surface
3536import androidx.compose.material3.Text
3637import androidx.compose.runtime.Composable
@@ -40,12 +41,14 @@ import androidx.compose.runtime.remember
4041import androidx.compose.runtime.setValue
4142import androidx.compose.ui.Alignment
4243import androidx.compose.ui.Modifier
44+ import androidx.compose.ui.res.painterResource
4345import androidx.compose.ui.res.stringResource
4446import androidx.compose.ui.text.font.FontWeight
4547import androidx.compose.ui.tooling.preview.PreviewLightDark
4648import androidx.compose.ui.unit.dp
4749import app.ss.design.compose.extensions.haptics.LocalSsHapticFeedback
4850import app.ss.design.compose.theme.SsTheme
51+ import app.ss.design.compose.widget.divider.Divider
4952import app.ss.design.compose.widget.icon.IconBox
5053import app.ss.design.compose.widget.icon.ResIcon
5154import app.ss.design.compose.widget.material.LegacySlider
@@ -66,7 +69,7 @@ fun ReaderOptionsUi(state: State, modifier: Modifier = Modifier) {
6669 Column (
6770 modifier = modifier
6871 .fillMaxWidth()
69- .padding(bottom = 16 .dp), horizontalAlignment = Alignment .CenterHorizontally ,
72+ .padding(bottom = 16 .dp, top = 8 .dp ), horizontalAlignment = Alignment .CenterHorizontally ,
7073 verticalArrangement = Arrangement .spacedBy(12 .dp)
7174 ) {
7275 ReaderOptionsTheme (state.config.theme) {
@@ -96,28 +99,35 @@ private fun ReaderOptionsTheme(
9699 text = stringResource(L10nR .string.ss_settings_theme),
97100 modifier = Modifier
98101 .fillMaxWidth()
99- .padding(horizontal = 16 .dp, vertical = 8 .dp ),
102+ .padding(horizontal = 16 .dp),
100103 style = SsTheme .typography.titleMedium.copy(fontWeight = FontWeight .Bold )
101104 )
102105
103- SingleChoiceSegmentedButtonRow (
106+ FlowRow (
104107 modifier = modifier
105108 .fillMaxWidth()
106- .padding(horizontal = 16 .dp)
109+ .padding(horizontal = 16 .dp),
110+ horizontalArrangement = Arrangement .spacedBy(6 .dp, Alignment .Start ),
107111 ) {
108- ReaderStyle .Theme .entries.forEachIndexed { index, item ->
109- SegmentedButton (
110- selected = theme == item,
112+ ReaderStyle .Theme .entries.forEach { item ->
113+ val isSelected = theme == item
114+ FilterChip (
115+ selected = isSelected,
111116 onClick = { onSelected(item) },
112- shape = SegmentedButtonDefaults .itemShape(index = index, count = ReaderStyle .Typeface .entries.size)
113- ) {
114- Text (
115- text = stringResource(item.label()),
116- style = SsTheme .typography.titleMedium
117- )
118- }
117+ label = {
118+ Text (
119+ text = stringResource(item.label()),
120+ style = SsTheme .typography.titleMedium
121+ )
122+ },
123+ leadingIcon = {
124+ LeadingCheckIcon (isSelected)
125+ }
126+ )
119127 }
120128 }
129+
130+ Divider ()
121131}
122132
123133private fun ReaderStyle.Theme.label () = when (this ) {
@@ -137,30 +147,48 @@ private fun ReaderOptionsTypeface(
137147 text = stringResource(L10nR .string.ss_settings_typeface),
138148 modifier = Modifier
139149 .fillMaxWidth()
140- .padding(horizontal = 16 .dp, vertical = 8 .dp ),
150+ .padding(horizontal = 16 .dp),
141151 style = SsTheme .typography.titleMedium.copy(fontWeight = FontWeight .Bold )
142152 )
143153
144- SingleChoiceSegmentedButtonRow (
154+ FlowRow (
145155 modifier = modifier
146156 .fillMaxWidth()
147- .padding(horizontal = 16 .dp)
157+ .padding(horizontal = 16 .dp),
158+ horizontalArrangement = Arrangement .spacedBy(6 .dp, Alignment .Start ),
148159 ) {
149- ReaderStyle .Typeface .entries.forEachIndexed { index, item ->
150- SegmentedButton (
151- selected = typeface == item,
152- onClick = { onSelected(item) },
153- shape = SegmentedButtonDefaults .itemShape(index = index, count = ReaderStyle .Typeface .entries.size)
154- ) {
155- Text (
156- text = stringResource(item.label()),
157- style = SsTheme .typography.titleMedium.copy(
158- fontFamily = Styler .fontFamily(item)
160+ ReaderStyle .Typeface .entries.forEach { option ->
161+ val isSelected = typeface == option
162+ FilterChip (
163+ selected = isSelected,
164+ onClick = { onSelected(option) },
165+ label = {
166+ Text (
167+ text = stringResource(option.label()),
168+ style = SsTheme .typography.titleMedium.copy(
169+ fontFamily = Styler .fontFamily(option)
170+ )
159171 )
160- )
161- }
172+ },
173+ leadingIcon = {
174+ LeadingCheckIcon (isSelected)
175+ }
176+ )
162177 }
163178 }
179+
180+ Divider ()
181+ }
182+
183+ @Composable
184+ private fun LeadingCheckIcon (isSelected : Boolean , modifier : Modifier = Modifier ) {
185+ AnimatedVisibility (isSelected) {
186+ Icon (
187+ painter = painterResource(DocumentR .drawable.ic_check_small),
188+ contentDescription = null ,
189+ modifier = modifier,
190+ )
191+ }
164192}
165193
166194private fun ReaderStyle.Typeface.label () = when (this ) {
0 commit comments