Коммит 3e138bae создал по автору Radch-enko's avatar Radch-enko
Просмотр файлов

Refactor: simplify settings initialization and remove redundant navigation logic

- Integrated `CheckSettingsUseCase` in `RootComponent` for settings validation during initialization.
- Removed `onSettings` callback and associated navigation logic in `MainComponent`.
- Updated `RoomsResult` to calculate room index based on settings.
- Eliminated `isSettings` state and redundant settings handling in `State` and `MainScreen`.
- Improved `SettingsManager` initialization to prevent redundant assignments.
владелец a5e9ce5d
...@@ -3,6 +3,7 @@ package band.effective.office.tablet.root ...@@ -3,6 +3,7 @@ package band.effective.office.tablet.root
import band.effective.office.tablet.core.domain.model.EventInfo import band.effective.office.tablet.core.domain.model.EventInfo
import band.effective.office.tablet.core.domain.model.RoomInfo import band.effective.office.tablet.core.domain.model.RoomInfo
import band.effective.office.tablet.core.domain.model.Slot import band.effective.office.tablet.core.domain.model.Slot
import band.effective.office.tablet.core.domain.useCase.CheckSettingsUseCase
import band.effective.office.tablet.core.domain.useCase.ResourceDisposerUseCase import band.effective.office.tablet.core.domain.useCase.ResourceDisposerUseCase
import band.effective.office.tablet.core.ui.common.ModalWindow import band.effective.office.tablet.core.ui.common.ModalWindow
import band.effective.office.tablet.feature.bookingEditor.presentation.BookingEditorComponent import band.effective.office.tablet.feature.bookingEditor.presentation.BookingEditorComponent
...@@ -18,7 +19,6 @@ import com.arkivanov.decompose.router.slot.dismiss ...@@ -18,7 +19,6 @@ import com.arkivanov.decompose.router.slot.dismiss
import com.arkivanov.decompose.router.stack.ChildStack import com.arkivanov.decompose.router.stack.ChildStack
import com.arkivanov.decompose.router.stack.StackNavigation import com.arkivanov.decompose.router.stack.StackNavigation
import com.arkivanov.decompose.router.stack.childStack import com.arkivanov.decompose.router.stack.childStack
import com.arkivanov.decompose.router.stack.push
import com.arkivanov.decompose.router.stack.replaceAll import com.arkivanov.decompose.router.stack.replaceAll
import com.arkivanov.decompose.value.Value import com.arkivanov.decompose.value.Value
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
...@@ -33,6 +33,7 @@ class RootComponent( ...@@ -33,6 +33,7 @@ class RootComponent(
private val modalNavigation = SlotNavigation<ModalWindowsConfig>() private val modalNavigation = SlotNavigation<ModalWindowsConfig>()
private val resourceDisposerUseCase: ResourceDisposerUseCase by inject() private val resourceDisposerUseCase: ResourceDisposerUseCase by inject()
private val checkSettingsUseCase: CheckSettingsUseCase by inject()
val modalWindowSlot = childSlot( val modalWindowSlot = childSlot(
source = modalNavigation, source = modalNavigation,
...@@ -42,7 +43,11 @@ class RootComponent( ...@@ -42,7 +43,11 @@ class RootComponent(
val childStack: Value<ChildStack<*, Child>> = childStack( val childStack: Value<ChildStack<*, Child>> = childStack(
source = navigation, source = navigation,
initialConfiguration = Config.Main, initialConfiguration = if (checkSettingsUseCase().isEmpty()) {
Config.Settings
} else {
Config.Main
},
handleBackButton = true, handleBackButton = true,
serializer = kotlinx.serialization.serializer<Config>(), serializer = kotlinx.serialization.serializer<Config>(),
childFactory = ::createChild, childFactory = ::createChild,
...@@ -60,7 +65,6 @@ class RootComponent( ...@@ -60,7 +65,6 @@ class RootComponent(
Child.MainChild( Child.MainChild(
MainComponent( MainComponent(
componentContext = componentContext, componentContext = componentContext,
onSettings = { navigation.push(Config.Settings) },
onFastBooking = ::handleFastBookingIntent, onFastBooking = ::handleFastBookingIntent,
onOpenFreeRoomModal = ::handleFreeRoomIntent, onOpenFreeRoomModal = ::handleFreeRoomIntent,
openBookingDialog = ::openBookingDialog, openBookingDialog = ::openBookingDialog,
......
...@@ -10,7 +10,9 @@ class SettingsManager(private val settings: Settings) { ...@@ -10,7 +10,9 @@ class SettingsManager(private val settings: Settings) {
private var currentInstance: SettingsManager? = null private var currentInstance: SettingsManager? = null
fun init(settings: Settings) { fun init(settings: Settings) {
currentInstance = SettingsManager(settings) if(currentInstance == null) {
currentInstance = SettingsManager(settings)
}
} }
fun current(): SettingsManager { fun current(): SettingsManager {
......
...@@ -48,7 +48,6 @@ import org.koin.core.component.inject ...@@ -48,7 +48,6 @@ import org.koin.core.component.inject
@OptIn(ExperimentalTime::class) @OptIn(ExperimentalTime::class)
class MainComponent( class MainComponent(
private val componentContext: ComponentContext, private val componentContext: ComponentContext,
val onSettings: () -> Unit,
val onFastBooking: (minDuration: Int, selectedRoom: RoomInfo, rooms: List<RoomInfo>) -> Unit, val onFastBooking: (minDuration: Int, selectedRoom: RoomInfo, rooms: List<RoomInfo>) -> Unit,
val onOpenFreeRoomModal: (currentEvent: EventInfo, roomName: String) -> Unit, val onOpenFreeRoomModal: (currentEvent: EventInfo, roomName: String) -> Unit,
private val openBookingDialog: (event: EventInfo, room: String) -> Unit, private val openBookingDialog: (event: EventInfo, room: String) -> Unit,
...@@ -91,11 +90,6 @@ class MainComponent( ...@@ -91,11 +90,6 @@ class MainComponent(
* Initializes the component, checking settings and setting up timers and event listeners. * Initializes the component, checking settings and setting up timers and event listeners.
*/ */
private fun initializeComponent() { private fun initializeComponent() {
// Check if settings are configured
if (checkSettingsUseCase().isEmpty()) {
onSettings()
}
// Load initial room data // Load initial room data
loadRooms() loadRooms()
...@@ -322,11 +316,17 @@ class MainComponent( ...@@ -322,11 +316,17 @@ class MainComponent(
indexSelectRoom = 0 indexSelectRoom = 0
) )
is Either.Success<List<RoomInfo>> -> RoomsResult( is Either.Success<List<RoomInfo>> -> {
isSuccess = true, val selectedRoomName = checkSettingsUseCase()
roomList = result.data, val roomIndex =
indexSelectRoom = state.value.indexSelectRoom, result.data.indexOfFirst { it.name == selectedRoomName }
) .coerceAtLeast(0)
RoomsResult(
isSuccess = true,
roomList = result.data,
indexSelectRoom = roomIndex,
)
}
else -> RoomsResult( else -> RoomsResult(
isSuccess = false, isSuccess = false,
......
...@@ -43,10 +43,6 @@ fun MainScreen(component: MainComponent) { ...@@ -43,10 +43,6 @@ fun MainScreen(component: MainComponent) {
onOpenDateTimePickerModalRequest = {}, // TODO onOpenDateTimePickerModalRequest = {}, // TODO
) )
} }
state.isSettings -> {
component.onSettings()
}
} }
} }
} }
...@@ -10,7 +10,6 @@ data class State( ...@@ -10,7 +10,6 @@ data class State(
val isError: Boolean, val isError: Boolean,
val isDisconnect: Boolean, val isDisconnect: Boolean,
val updatedEvent: Any, val updatedEvent: Any,
val isSettings: Boolean,
val roomList: List<RoomInfo>, val roomList: List<RoomInfo>,
val indexSelectRoom: Int, val indexSelectRoom: Int,
val timeToNextEvent: Int, val timeToNextEvent: Int,
...@@ -24,7 +23,6 @@ data class State( ...@@ -24,7 +23,6 @@ data class State(
isData = false, isData = false,
isError = false, isError = false,
isDisconnect = false, isDisconnect = false,
isSettings = false,
updatedEvent = Any(), updatedEvent = Any(),
roomList = listOf(), roomList = listOf(),
indexSelectRoom = 0, indexSelectRoom = 0,
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать