Коммит 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(
if (eventList.isEmpty()) return true
val target = currentInstant + duration.minutes
val firstEventStart = eventList.first().startTime.asInstant
val firstEventStart = eventList.minByOrNull { it.startTime }!!.startTime.asInstant
return target < firstEventStart
}
}
\ Нет новой строки в конце файла
package band.effective.office.tablet.core.domain.useCase
import band.effective.office.tablet.core.domain.unbox
import kotlinx.datetime.Clock
import kotlin.time.Duration
import kotlin.time.Duration.Companion.minutes
import band.effective.office.tablet.core.domain.util.asInstant
import band.effective.office.tablet.core.domain.util.currentInstant
import io.github.aakira.napier.Napier
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toInstant
import kotlin.time.Duration
import kotlin.time.Duration.Companion.minutes
/** Timer for update when start/finish event in room */
class UpdateUseCase(
private val timerUseCase: TimerUseCase,
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 */
fun updateFlow() = flow {
while (true) {
val roomInfo = roomInfoUseCase.getCurrentRooms().unbox(
val roomsInfoList = roomInfoUseCase.getCurrentRooms().unbox(
errorHandler = { it.saveData }
) ?: emptyList()
if (roomInfo.isNotEmpty()) {
val now = clock.now()
if (roomsInfoList.isNotEmpty()) {
val timeToStartNextEvent = roomInfo
val timeToStartNextEvent = roomsInfoList
.flatMap { it.eventList }
.minByOrNull { it.startTime }
?.let { event ->
val eventInstant = event.startTime.toInstant(timeZone)
(eventInstant - now).coerceAtLeast(Duration.ZERO)
val eventInstant = event.startTime.asInstant
eventInstant - currentInstant
} ?: 1.minutes
val timeToFinishCurrentEvent = roomInfo
val timeToFinishCurrentEvent = roomsInfoList
.mapNotNull { it.currentEvent }
.minByOrNull { it.startTime }
?.let { event ->
val finishInstant = event.finishTime.toInstant(timeZone)
(finishInstant - now).coerceAtLeast(Duration.ZERO)
val finishInstant = event.finishTime.asInstant
finishInstant - currentInstant
} ?: 1.minutes
val minDelay = min(timeToStartNextEvent, timeToFinishCurrentEvent)
......
......@@ -14,7 +14,7 @@ val defaultTimeZone = TimeZone.currentSystemDefault()
val currentLocalDateTime: LocalDateTime get() = Clock.System.now().toLocalDateTime(defaultTimeZone)
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 {
val minutes = dateTime.minute
......
......@@ -78,7 +78,6 @@ fun BusyRoomInfoComponent(
modifier = Modifier
.clip(shape = RoundedCornerShape(40.dp))
.height(45.dp)
.width(150.dp)
.background(color = backgroundColor)
.border(
width = 3.dp,
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
version = "1.3">
<BuildAction>
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
buildForRunning = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A93A953629CC810C00F8E227"
......@@ -21,25 +15,11 @@
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
buildConfiguration = "Debug"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A93A953629CC810C00F8E227"
......@@ -53,18 +33,4 @@
referenceType = "1">
</LocationScenarioReference>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать