Skip to content

Commit 7f85df8

Browse files
committed
refactor: enum: Parcelable
1 parent b53d206 commit 7f85df8

File tree

6 files changed

+37
-31
lines changed

6 files changed

+37
-31
lines changed

feature/bus/src/main/java/in/koreatech/bus/screen/timetable/composable/CityTimetableScreen.kt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import androidx.compose.material3.Text
1010
import androidx.compose.runtime.Composable
1111
import androidx.compose.runtime.LaunchedEffect
1212
import androidx.compose.runtime.getValue
13-
import androidx.compose.runtime.mutableIntStateOf
13+
import androidx.compose.runtime.mutableStateOf
1414
import androidx.compose.runtime.saveable.rememberSaveable
1515
import androidx.compose.runtime.setValue
1616
import androidx.compose.ui.Alignment
@@ -36,8 +36,8 @@ internal fun CityTimetableScreen(
3636
onDirectionChanged: (CommonDirectionType) -> Unit = {}
3737
) {
3838

39-
var selectedBusNumberTypeIndex by rememberSaveable { mutableIntStateOf(CityBusNumberType.N400.ordinal) }
40-
var selectedDirectionTypeIndex by rememberSaveable { mutableIntStateOf(CommonDirectionType.TO_BYEONGCHEON.ordinal) }
39+
var selectedBusNumberType by rememberSaveable { mutableStateOf(CityBusNumberType.N400) }
40+
var selectedDirectionType by rememberSaveable { mutableStateOf(CommonDirectionType.TO_BYEONGCHEON) }
4141
val context = LocalContext.current
4242

4343
Column(
@@ -59,11 +59,10 @@ internal fun CityTimetableScreen(
5959
modifier = Modifier.padding(start = 16.dp),
6060
titles = CityBusNumberType.entries.map { stringResource(it.titleRes) },
6161
onChipSelected = { title ->
62-
selectedBusNumberTypeIndex =
63-
CityBusNumberType.entries.find { context.getString(it.titleRes) == title }?.ordinal
64-
?: 0
62+
selectedBusNumberType =
63+
CityBusNumberType.entries.find { context.getString(it.titleRes) == title } ?: CityBusNumberType.N400
6564
},
66-
selectedChipIndexes = intArrayOf(selectedBusNumberTypeIndex)
65+
selectedChipIndexes = intArrayOf(selectedBusNumberType.ordinal)
6766
)
6867
}
6968
Row(
@@ -82,11 +81,10 @@ internal fun CityTimetableScreen(
8281
modifier = Modifier.padding(start = 16.dp),
8382
titles = CommonDirectionType.entries.map { stringResource(it.titleRes) },
8483
onChipSelected = { title ->
85-
selectedDirectionTypeIndex =
86-
CommonDirectionType.entries.find { context.getString(it.titleRes) == title }?.ordinal
87-
?: 0
84+
selectedDirectionType =
85+
CommonDirectionType.entries.find { context.getString(it.titleRes) == title } ?: CommonDirectionType.TO_BYEONGCHEON
8886
},
89-
selectedChipIndexes = intArrayOf(selectedDirectionTypeIndex)
87+
selectedChipIndexes = intArrayOf(selectedDirectionType.ordinal)
9088
)
9189
}
9290

@@ -96,12 +94,12 @@ internal fun CityTimetableScreen(
9694
)
9795
}
9896

99-
LaunchedEffect(selectedBusNumberTypeIndex) {
100-
onBusNumberChanged(CityBusNumberType.entries[selectedBusNumberTypeIndex])
97+
LaunchedEffect(selectedBusNumberType) {
98+
onBusNumberChanged(selectedBusNumberType)
10199
}
102100

103-
LaunchedEffect(selectedDirectionTypeIndex) {
104-
onDirectionChanged(CommonDirectionType.entries[selectedDirectionTypeIndex])
101+
LaunchedEffect(selectedDirectionType) {
102+
onDirectionChanged(selectedDirectionType)
105103
}
106104
}
107105

feature/bus/src/main/java/in/koreatech/bus/screen/timetable/composable/ExpressTimetableScreen.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import androidx.compose.material3.Text
1010
import androidx.compose.runtime.Composable
1111
import androidx.compose.runtime.LaunchedEffect
1212
import androidx.compose.runtime.getValue
13-
import androidx.compose.runtime.mutableIntStateOf
13+
import androidx.compose.runtime.mutableStateOf
1414
import androidx.compose.runtime.saveable.rememberSaveable
1515
import androidx.compose.runtime.setValue
1616
import androidx.compose.ui.Alignment
@@ -19,8 +19,8 @@ import androidx.compose.ui.platform.LocalContext
1919
import androidx.compose.ui.res.stringResource
2020
import androidx.compose.ui.tooling.preview.Preview
2121
import androidx.compose.ui.unit.dp
22-
import `in`.koreatech.bus.screen.timetable.type.DaytimeType
2322
import `in`.koreatech.bus.screen.timetable.type.CommonDirectionType
23+
import `in`.koreatech.bus.screen.timetable.type.DaytimeType
2424
import `in`.koreatech.bus.viewstate.ArrivalViewState
2525
import `in`.koreatech.bus.viewstate.CommonTimetableViewState
2626
import `in`.koreatech.koin.core.designsystem.component.chip.TextChipGroup
@@ -34,7 +34,7 @@ internal fun ExpressTimetableScreen(
3434
onDirectionChanged: (CommonDirectionType) -> Unit = {}
3535
) {
3636

37-
var selectedDirectionTypeIndex by rememberSaveable { mutableIntStateOf(CommonDirectionType.TO_BYEONGCHEON.ordinal) }
37+
var selectedDirectionType by rememberSaveable { mutableStateOf(CommonDirectionType.TO_BYEONGCHEON) }
3838
val context = LocalContext.current
3939

4040
Column(
@@ -56,11 +56,10 @@ internal fun ExpressTimetableScreen(
5656
modifier = Modifier.padding(start = 16.dp),
5757
titles = CommonDirectionType.entries.map { stringResource(it.titleRes) },
5858
onChipSelected = { title ->
59-
selectedDirectionTypeIndex =
60-
CommonDirectionType.entries.find { context.getString(it.titleRes) == title }?.ordinal
61-
?: 0
59+
selectedDirectionType =
60+
CommonDirectionType.entries.find { context.getString(it.titleRes) == title } ?: CommonDirectionType.TO_BYEONGCHEON
6261
},
63-
selectedChipIndexes = intArrayOf(selectedDirectionTypeIndex)
62+
selectedChipIndexes = intArrayOf(selectedDirectionType.ordinal)
6463
)
6564
}
6665

@@ -70,8 +69,8 @@ internal fun ExpressTimetableScreen(
7069
)
7170
}
7271

73-
LaunchedEffect(selectedDirectionTypeIndex) {
74-
onDirectionChanged(CommonDirectionType.entries[selectedDirectionTypeIndex])
72+
LaunchedEffect(selectedDirectionType) {
73+
onDirectionChanged(selectedDirectionType)
7574
}
7675
}
7776

feature/bus/src/main/java/in/koreatech/bus/screen/timetable/composable/ShuttleTimetableScreen.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import androidx.compose.material3.Icon
1414
import androidx.compose.material3.Text
1515
import androidx.compose.runtime.Composable
1616
import androidx.compose.runtime.getValue
17-
import androidx.compose.runtime.mutableIntStateOf
17+
import androidx.compose.runtime.mutableStateOf
1818
import androidx.compose.runtime.saveable.rememberSaveable
1919
import androidx.compose.runtime.setValue
2020
import androidx.compose.ui.Alignment
@@ -40,7 +40,7 @@ internal fun ShuttleTimetableScreen(
4040
regions: ImmutableList<ShuttleRegionViewState>
4141
) {
4242

43-
var selectedRouteTypeIndex by rememberSaveable { mutableIntStateOf(ShuttleBusRouteType.ALL.ordinal) }
43+
var selectedRouteType by rememberSaveable { mutableStateOf(ShuttleBusRouteType.ALL) }
4444
val context = LocalContext.current
4545

4646
Column(
@@ -50,9 +50,9 @@ internal fun ShuttleTimetableScreen(
5050
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp, horizontal = 24.dp),
5151
titles = ShuttleBusRouteType.entries.map { stringResource(it.titleRes) },
5252
onChipSelected = { title ->
53-
selectedRouteTypeIndex = ShuttleBusRouteType.entries.find { context.getString(it.titleRes) == title }?.ordinal ?: 0
53+
selectedRouteType = ShuttleBusRouteType.entries.find { context.getString(it.titleRes) == title } ?: ShuttleBusRouteType.ALL
5454
},
55-
selectedChipIndexes = intArrayOf(selectedRouteTypeIndex)
55+
selectedChipIndexes = intArrayOf(selectedRouteType.ordinal)
5656
)
5757
regions.forEach {
5858
ShuttleRegionView(
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package `in`.koreatech.bus.screen.timetable.type
22

3+
import android.os.Parcelable
34
import androidx.annotation.StringRes
45
import `in`.koreatech.koin.feature.bus.R
6+
import kotlinx.parcelize.Parcelize
57

8+
@Parcelize
69
enum class CityBusNumberType(
710
@StringRes val titleRes: Int
8-
) {
11+
) : Parcelable {
912
N400(R.string.n400), N405(R.string.n405), N495(R.string.n495)
1013
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package `in`.koreatech.bus.screen.timetable.type
22

3+
import android.os.Parcelable
34
import androidx.annotation.StringRes
45
import `in`.koreatech.koin.feature.bus.R
6+
import kotlinx.parcelize.Parcelize
57

8+
@Parcelize
69
enum class CommonDirectionType(
710
@StringRes val titleRes: Int
8-
) {
11+
) : Parcelable {
912
TO_BYEONGCHEON(R.string.to_byeongcheon),
1013
TO_CHEONAN(R.string.to_cheonan),
1114
}

feature/bus/src/main/java/in/koreatech/bus/screen/timetable/type/ShuttleBusRouteType.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package `in`.koreatech.bus.screen.timetable.type
22

3+
import android.os.Parcelable
34
import androidx.annotation.StringRes
45
import `in`.koreatech.koin.feature.bus.R
6+
import kotlinx.parcelize.Parcelize
57

8+
@Parcelize
69
enum class ShuttleBusRouteType(
710
@StringRes val titleRes: Int,
811
@StringRes val simpleTitleRes: Int
9-
) {
12+
) : Parcelable {
1013
ALL(R.string.all_routes, 0),
1114
WEEKDAY(R.string.weekday_routes, R.string.weekday_routes_simple),
1215
WEEKEND(R.string.weekend_routes, R.string.weekend_routes_simple),

0 commit comments

Comments
 (0)