Skip to content

Commit

Permalink
refactor: enum: Parcelable
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirFir committed Nov 7, 2024
1 parent b53d206 commit 7f85df8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
Expand All @@ -36,8 +36,8 @@ internal fun CityTimetableScreen(
onDirectionChanged: (CommonDirectionType) -> Unit = {}
) {

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

Column(
Expand All @@ -59,11 +59,10 @@ internal fun CityTimetableScreen(
modifier = Modifier.padding(start = 16.dp),
titles = CityBusNumberType.entries.map { stringResource(it.titleRes) },
onChipSelected = { title ->
selectedBusNumberTypeIndex =
CityBusNumberType.entries.find { context.getString(it.titleRes) == title }?.ordinal
?: 0
selectedBusNumberType =
CityBusNumberType.entries.find { context.getString(it.titleRes) == title } ?: CityBusNumberType.N400
},
selectedChipIndexes = intArrayOf(selectedBusNumberTypeIndex)
selectedChipIndexes = intArrayOf(selectedBusNumberType.ordinal)
)
}
Row(
Expand All @@ -82,11 +81,10 @@ internal fun CityTimetableScreen(
modifier = Modifier.padding(start = 16.dp),
titles = CommonDirectionType.entries.map { stringResource(it.titleRes) },
onChipSelected = { title ->
selectedDirectionTypeIndex =
CommonDirectionType.entries.find { context.getString(it.titleRes) == title }?.ordinal
?: 0
selectedDirectionType =
CommonDirectionType.entries.find { context.getString(it.titleRes) == title } ?: CommonDirectionType.TO_BYEONGCHEON
},
selectedChipIndexes = intArrayOf(selectedDirectionTypeIndex)
selectedChipIndexes = intArrayOf(selectedDirectionType.ordinal)
)
}

Expand All @@ -96,12 +94,12 @@ internal fun CityTimetableScreen(
)
}

LaunchedEffect(selectedBusNumberTypeIndex) {
onBusNumberChanged(CityBusNumberType.entries[selectedBusNumberTypeIndex])
LaunchedEffect(selectedBusNumberType) {
onBusNumberChanged(selectedBusNumberType)
}

LaunchedEffect(selectedDirectionTypeIndex) {
onDirectionChanged(CommonDirectionType.entries[selectedDirectionTypeIndex])
LaunchedEffect(selectedDirectionType) {
onDirectionChanged(selectedDirectionType)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
Expand All @@ -19,8 +19,8 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import `in`.koreatech.bus.screen.timetable.type.DaytimeType
import `in`.koreatech.bus.screen.timetable.type.CommonDirectionType
import `in`.koreatech.bus.screen.timetable.type.DaytimeType
import `in`.koreatech.bus.viewstate.ArrivalViewState
import `in`.koreatech.bus.viewstate.CommonTimetableViewState
import `in`.koreatech.koin.core.designsystem.component.chip.TextChipGroup
Expand All @@ -34,7 +34,7 @@ internal fun ExpressTimetableScreen(
onDirectionChanged: (CommonDirectionType) -> Unit = {}
) {

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

Column(
Expand All @@ -56,11 +56,10 @@ internal fun ExpressTimetableScreen(
modifier = Modifier.padding(start = 16.dp),
titles = CommonDirectionType.entries.map { stringResource(it.titleRes) },
onChipSelected = { title ->
selectedDirectionTypeIndex =
CommonDirectionType.entries.find { context.getString(it.titleRes) == title }?.ordinal
?: 0
selectedDirectionType =
CommonDirectionType.entries.find { context.getString(it.titleRes) == title } ?: CommonDirectionType.TO_BYEONGCHEON
},
selectedChipIndexes = intArrayOf(selectedDirectionTypeIndex)
selectedChipIndexes = intArrayOf(selectedDirectionType.ordinal)
)
}

Expand All @@ -70,8 +69,8 @@ internal fun ExpressTimetableScreen(
)
}

LaunchedEffect(selectedDirectionTypeIndex) {
onDirectionChanged(CommonDirectionType.entries[selectedDirectionTypeIndex])
LaunchedEffect(selectedDirectionType) {
onDirectionChanged(selectedDirectionType)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
Expand All @@ -40,7 +40,7 @@ internal fun ShuttleTimetableScreen(
regions: ImmutableList<ShuttleRegionViewState>
) {

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

Column(
Expand All @@ -50,9 +50,9 @@ internal fun ShuttleTimetableScreen(
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp, horizontal = 24.dp),
titles = ShuttleBusRouteType.entries.map { stringResource(it.titleRes) },
onChipSelected = { title ->
selectedRouteTypeIndex = ShuttleBusRouteType.entries.find { context.getString(it.titleRes) == title }?.ordinal ?: 0
selectedRouteType = ShuttleBusRouteType.entries.find { context.getString(it.titleRes) == title } ?: ShuttleBusRouteType.ALL
},
selectedChipIndexes = intArrayOf(selectedRouteTypeIndex)
selectedChipIndexes = intArrayOf(selectedRouteType.ordinal)
)
regions.forEach {
ShuttleRegionView(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package `in`.koreatech.bus.screen.timetable.type

import android.os.Parcelable
import androidx.annotation.StringRes
import `in`.koreatech.koin.feature.bus.R
import kotlinx.parcelize.Parcelize

@Parcelize
enum class CityBusNumberType(
@StringRes val titleRes: Int
) {
) : Parcelable {
N400(R.string.n400), N405(R.string.n405), N495(R.string.n495)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package `in`.koreatech.bus.screen.timetable.type

import android.os.Parcelable
import androidx.annotation.StringRes
import `in`.koreatech.koin.feature.bus.R
import kotlinx.parcelize.Parcelize

@Parcelize
enum class CommonDirectionType(
@StringRes val titleRes: Int
) {
) : Parcelable {
TO_BYEONGCHEON(R.string.to_byeongcheon),
TO_CHEONAN(R.string.to_cheonan),
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package `in`.koreatech.bus.screen.timetable.type

import android.os.Parcelable
import androidx.annotation.StringRes
import `in`.koreatech.koin.feature.bus.R
import kotlinx.parcelize.Parcelize

@Parcelize
enum class ShuttleBusRouteType(
@StringRes val titleRes: Int,
@StringRes val simpleTitleRes: Int
) {
) : Parcelable {
ALL(R.string.all_routes, 0),
WEEKDAY(R.string.weekday_routes, R.string.weekday_routes_simple),
WEEKEND(R.string.weekend_routes, R.string.weekend_routes_simple),
Expand Down

0 comments on commit 7f85df8

Please sign in to comment.