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

Refactor: optimize date handling, streamline room update logic, and improve Xcode configuration

- Replaced `first` with `minByOrNull` for safer event list start time handling.
- Refactored `UpdateUseCase` to remove redundant `Clock` and `TimeZone` usage, simplifying time management logic.
- Consolidated redundant code and improved readability in `MainComponent` by modularizing state updates and event listeners.
- Updated `currentInstant` logic in `LocalDateTimeUtils` for better consistency with `LocalDateTime` utilities.
- Removed fixed button width in `BusyRoomInfoComponent` for more flexible UI design.
- Simplified `iosApp.xcscheme` by removing unused configurations and streamlining build settings.
владелец bf6326f5
...@@ -69,7 +69,7 @@ open class SelectRoomUseCase( ...@@ -69,7 +69,7 @@ open class SelectRoomUseCase(
if (eventList.isEmpty()) return true if (eventList.isEmpty()) return true
val target = currentInstant + duration.minutes val target = currentInstant + duration.minutes
val firstEventStart = eventList.first().startTime.asInstant val firstEventStart = eventList.minByOrNull { it.startTime }!!.startTime.asInstant
return target < firstEventStart return target < firstEventStart
} }
} }
\ No newline at end of file
package band.effective.office.tablet.core.domain.useCase package band.effective.office.tablet.core.domain.useCase
import band.effective.office.tablet.core.domain.unbox import band.effective.office.tablet.core.domain.unbox
import kotlinx.datetime.Clock import band.effective.office.tablet.core.domain.util.asInstant
import kotlin.time.Duration import band.effective.office.tablet.core.domain.util.currentInstant
import kotlin.time.Duration.Companion.minutes import io.github.aakira.napier.Napier
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.datetime.TimeZone import kotlin.time.Duration
import kotlinx.datetime.toInstant import kotlin.time.Duration.Companion.minutes
/** Timer for update when start/finish event in room */ /** Timer for update when start/finish event in room */
class UpdateUseCase( class UpdateUseCase(
private val timerUseCase: TimerUseCase, private val timerUseCase: TimerUseCase,
private val roomInfoUseCase: RoomInfoUseCase, private val roomInfoUseCase: RoomInfoUseCase,
) { ) {
private val timeZone: TimeZone = TimeZone.currentSystemDefault()
private val clock: Clock = Clock.System
/** Flow for update when start/finish event in room */ /** Flow for update when start/finish event in room */
fun updateFlow() = flow { fun updateFlow() = flow {
while (true) { while (true) {
val roomInfo = roomInfoUseCase.getCurrentRooms().unbox( val roomsInfoList = roomInfoUseCase.getCurrentRooms().unbox(
errorHandler = { it.saveData } errorHandler = { it.saveData }
) ?: emptyList() ) ?: emptyList()
if (roomInfo.isNotEmpty()) { if (roomsInfoList.isNotEmpty()) {
val now = clock.now()
val timeToStartNextEvent = roomInfo val timeToStartNextEvent = roomsInfoList
.flatMap { it.eventList } .flatMap { it.eventList }
.minByOrNull { it.startTime } .minByOrNull { it.startTime }
?.let { event -> ?.let { event ->
val eventInstant = event.startTime.toInstant(timeZone) val eventInstant = event.startTime.asInstant
(eventInstant - now).coerceAtLeast(Duration.ZERO) eventInstant - currentInstant
} ?: 1.minutes } ?: 1.minutes
val timeToFinishCurrentEvent = roomInfo val timeToFinishCurrentEvent = roomsInfoList
.mapNotNull { it.currentEvent } .mapNotNull { it.currentEvent }
.minByOrNull { it.startTime } .minByOrNull { it.startTime }
?.let { event -> ?.let { event ->
val finishInstant = event.finishTime.toInstant(timeZone) val finishInstant = event.finishTime.asInstant
(finishInstant - now).coerceAtLeast(Duration.ZERO) finishInstant - currentInstant
} ?: 1.minutes } ?: 1.minutes
val minDelay = min(timeToStartNextEvent, timeToFinishCurrentEvent) val minDelay = min(timeToStartNextEvent, timeToFinishCurrentEvent)
......
...@@ -14,7 +14,7 @@ val defaultTimeZone = TimeZone.currentSystemDefault() ...@@ -14,7 +14,7 @@ val defaultTimeZone = TimeZone.currentSystemDefault()
val currentLocalDateTime: LocalDateTime get() = Clock.System.now().toLocalDateTime(defaultTimeZone) val currentLocalDateTime: LocalDateTime get() = Clock.System.now().toLocalDateTime(defaultTimeZone)
val currentLocalDate: LocalDate get() = Clock.System.now().toLocalDateTime(defaultTimeZone).date val currentLocalDate: LocalDate get() = Clock.System.now().toLocalDateTime(defaultTimeZone).date
val currentInstant: Instant get() = Instant.fromEpochMilliseconds(Clock.System.now().toEpochMilliseconds()) val currentInstant: Instant get() = Clock.System.now().toLocalDateTime(defaultTimeZone).asInstant
fun roundUpToNextQuarter(dateTime: LocalDateTime): LocalDateTime { fun roundUpToNextQuarter(dateTime: LocalDateTime): LocalDateTime {
val minutes = dateTime.minute val minutes = dateTime.minute
......
...@@ -78,7 +78,6 @@ fun BusyRoomInfoComponent( ...@@ -78,7 +78,6 @@ fun BusyRoomInfoComponent(
modifier = Modifier modifier = Modifier
.clip(shape = RoundedCornerShape(40.dp)) .clip(shape = RoundedCornerShape(40.dp))
.height(45.dp) .height(45.dp)
.width(150.dp)
.background(color = backgroundColor) .background(color = backgroundColor)
.border( .border(
width = 3.dp, width = 3.dp,
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
version = "1.7"> version = "1.3">
<BuildAction <BuildAction>
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries> <BuildActionEntries>
<BuildActionEntry <BuildActionEntry
buildForTesting = "YES" buildForRunning = "YES">
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "A93A953629CC810C00F8E227" BlueprintIdentifier = "A93A953629CC810C00F8E227"
...@@ -21,25 +15,11 @@ ...@@ -21,25 +15,11 @@
</BuildActionEntry> </BuildActionEntry>
</BuildActionEntries> </BuildActionEntries>
</BuildAction> </BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" buildConfiguration = "Debug"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"> allowLocationSimulation = "YES">
<BuildableProductRunnable <BuildableProductRunnable>
runnableDebuggingMode = "0">
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "A93A953629CC810C00F8E227" BlueprintIdentifier = "A93A953629CC810C00F8E227"
...@@ -53,18 +33,4 @@ ...@@ -53,18 +33,4 @@
referenceType = "1"> referenceType = "1">
</LocationScenarioReference> </LocationScenarioReference>
</LaunchAction> </LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme> </Scheme>
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать