diff --git a/tabletApp/features/roomInfo/src/commonMain/kotlin/band/effective/office/tablet/ui/mainScreen/mainScreen/MainComponent.kt b/tabletApp/features/roomInfo/src/commonMain/kotlin/band/effective/office/tablet/ui/mainScreen/mainScreen/MainComponent.kt
index 04eaafe202176a146ec0044b49d922b1d512f3d1..9da1e5ce1e37d4d22223531aad1c9f763b07bde8 100644
--- a/tabletApp/features/roomInfo/src/commonMain/kotlin/band/effective/office/tablet/ui/mainScreen/mainScreen/MainComponent.kt
+++ b/tabletApp/features/roomInfo/src/commonMain/kotlin/band/effective/office/tablet/ui/mainScreen/mainScreen/MainComponent.kt
@@ -94,7 +94,7 @@ class MainComponent(
event = modalWindows.event,
room = modalWindows.room,
onDelete = { slot ->
- slotComponent.sendIntent(SlotStore.Intent.Delete(slot, {
+ slotComponent.sendIntent(SlotStore.Intent.Delete(slot) {
CoroutineScope(Dispatchers.IO).launch {
(slot as? Slot.EventSlot)?.eventInfo?.apply {
deleteCachedEventUseCase(
@@ -104,12 +104,20 @@ class MainComponent(
cancelUseCase(this)
}
}
- }))
+ })
},
onCloseRequest = { closeModalWindow() },
onTempLoading = {
- slotComponent.sendIntent(SlotStore.Intent.Loading(Slot.LoadingEventSlot(start = it.startTime, finish = it.finishTime, it)))
+ slotComponent.sendIntent(
+ SlotStore.Intent.Loading(
+ Slot.LoadingEventSlot(
+ start = it.startTime,
+ finish = it.finishTime,
+ it
+ )
+ )
+ )
}
)
}
diff --git a/tabletApp/features/roomInfo/src/commonMain/kotlin/band/effective/office/tablet/ui/mainScreen/mainScreen/store/MainFactory.kt b/tabletApp/features/roomInfo/src/commonMain/kotlin/band/effective/office/tablet/ui/mainScreen/mainScreen/store/MainFactory.kt
index dd0a08bda2d03b277301bd09b971c8d7593587f9..31963559fe4be0398095666b5428e1eef7761758 100644
--- a/tabletApp/features/roomInfo/src/commonMain/kotlin/band/effective/office/tablet/ui/mainScreen/mainScreen/store/MainFactory.kt
+++ b/tabletApp/features/roomInfo/src/commonMain/kotlin/band/effective/office/tablet/ui/mainScreen/mainScreen/store/MainFactory.kt
@@ -1,7 +1,6 @@
package band.effective.office.tablet.ui.mainScreen.mainScreen.store
import android.os.Build
-import android.util.Log
import androidx.annotation.RequiresApi
import band.effective.office.network.model.Either
import band.effective.office.tablet.domain.model.ErrorWithData
@@ -138,7 +137,9 @@ class MainFactory(
override fun executeIntent(intent: MainStore.Intent, getState: () -> MainStore.State) {
when (intent) {
is MainStore.Intent.OnOpenFreeRoomModal ->
- navigate(MainComponent.ModalWindowsConfig.FreeRoom(getState().run { roomList[indexSelectRoom].currentEvent!! }))
+ navigate(MainComponent.ModalWindowsConfig.FreeRoom(
+ getState().run { roomList[indexSelectRoom].currentEvent!! }
+ ))
is MainStore.Intent.RebootRequest -> reboot(state = getState(), refresh = true)
is MainStore.Intent.OnChangeEventRequest -> navigate(
@@ -190,6 +191,12 @@ class MainFactory(
intent.updateInDays
)
}
+
+ val newDateWithoutTime = removeTimeFromCalendar(newDate.clone() as Calendar)
+ val currentDateWithoutTime = removeTimeFromCalendar(Calendar.getInstance())
+
+ if (newDateWithoutTime.before(currentDateWithoutTime)) return
+
dispatch(Message.UpdateDate(newDate))
updateDate(newDate)
}
@@ -201,6 +208,15 @@ class MainFactory(
}
}
+ private fun removeTimeFromCalendar(calendar: Calendar): Calendar {
+ return calendar.apply {
+ set(Calendar.HOUR_OF_DAY, 0)
+ set(Calendar.MINUTE, 0)
+ set(Calendar.SECOND, 0)
+ set(Calendar.MILLISECOND, 0)
+ }
+ }
+
fun reboot(
state: MainStore.State,
refresh: Boolean = false,
diff --git a/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/DateTimePickerModalView.kt b/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/DateTimePickerModalView.kt
index fa50fba9dc26cef0baf105289279cbd197ed424f..673074f931d57b03f61477d658f86337c300fb31 100644
--- a/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/DateTimePickerModalView.kt
+++ b/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/DateTimePickerModalView.kt
@@ -91,7 +91,7 @@ fun DateTimePickerModalView(
onChangeTime = {
dateTimePickerComponent.sendIntent(DateTimePickerStore.Intent.OnChangeTime(it))
},
- enableDateButton = stateDateTime.isEnabledButton
+ dateTimeButtonState = stateDateTime.dateTimeButtonState
)
}
@@ -104,7 +104,7 @@ fun DateTimePickerModalView(
onCloseRequest: () -> Unit,
onChangeDate: (LocalDate) -> Unit,
onChangeTime: (LocalTime) -> Unit,
- enableDateButton: Boolean
+ dateTimeButtonState: DateTimePickerStore.DateTimeButtonState
) {
Dialog(
onDismissRequest = onCloseRequest,
@@ -149,15 +149,16 @@ fun DateTimePickerModalView(
onClick = {
onCloseRequest()
},
- enabled = enableDateButton,
+ enabled = dateTimeButtonState.isEnabled,
colors = buttonColors(
containerColor = LocalCustomColorsPalette.current.pressedPrimaryButton
)
) {
Text(
- text = when (enableDateButton) {
- true -> SimpleDateFormat("dd MMMM HH:mm").format(currentDate.time)
- false -> MainRes.string.time_booked
+ text = when (dateTimeButtonState) {
+ is DateTimePickerStore.DateTimeButtonState.Enabled -> SimpleDateFormat("dd MMMM HH:mm").format(currentDate.time)
+ is DateTimePickerStore.DateTimeButtonState.TimeBooked -> MainRes.string.time_booked
+ is DateTimePickerStore.DateTimeButtonState.IncorrectDate -> MainRes.string.incorrect_date
},
style = header8,
color = LocalCustomColorsPalette.current.primaryTextAndIcon,
diff --git a/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/store/DateTimePickerStore.kt b/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/store/DateTimePickerStore.kt
index 8edcc939e9b6442ba35b21bbfa5d41c714c9b08f..91cddb9dfdfaa986b322459da680b0ab0ee7af2a 100644
--- a/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/store/DateTimePickerStore.kt
+++ b/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/store/DateTimePickerStore.kt
@@ -16,14 +16,21 @@ interface DateTimePickerStore :
data class State(
val currentDate: Calendar,
- val isEnabledButton: Boolean
+ val dateTimeButtonState: DateTimeButtonState
) {
companion object {
val default = State(
currentDate = Calendar.getInstance(),
- isEnabledButton = true
+ dateTimeButtonState = DateTimeButtonState.Enabled()
)
}
}
+
+ sealed interface DateTimeButtonState {
+ val isEnabled: Boolean
+ data class Enabled(override val isEnabled: Boolean = true) : DateTimeButtonState
+ data class TimeBooked(override val isEnabled: Boolean = false) : DateTimeButtonState
+ data class IncorrectDate(override val isEnabled: Boolean = false) : DateTimeButtonState
+ }
}
diff --git a/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/store/DateTimePickerStoreFactory.kt b/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/store/DateTimePickerStoreFactory.kt
index 5b15d3b403e5d90d163861526347340775a5ea1d..d196e77eaeb7c2854f3bd0732d8a735f83acea7e 100644
--- a/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/store/DateTimePickerStoreFactory.kt
+++ b/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/pickerDateTime/store/DateTimePickerStoreFactory.kt
@@ -41,7 +41,7 @@ class DateTimePickerStoreFactory(
private sealed interface Message {
data class UpdateDateTime(val newValue: Calendar) : Message
- data class EnableDateButton(val isEnabled: Boolean): Message
+ data class ChangeDateButtonState(val newState: DateTimePickerStore.DateTimeButtonState): Message
}
@RequiresApi(Build.VERSION_CODES.O)
@@ -83,12 +83,20 @@ class DateTimePickerStoreFactory(
set(Calendar.MONTH, month - 1)
set(Calendar.DAY_OF_MONTH, dayOfMonth)
}
+
+ if (newDate.before(Calendar.getInstance())) {
+ dispatch(Message.UpdateDateTime(newDate))
+ dispatch(Message.ChangeDateButtonState(DateTimePickerStore.DateTimeButtonState.IncorrectDate()))
+ return@launch
+ }
+
val finishDate = (newDate.clone() as Calendar).apply {
add(
Calendar.MINUTE,
duration
)
}
+
dispatch(Message.UpdateDateTime(newDate))
checkEnableDateButton(newDate, finishDate)
}
@@ -101,12 +109,20 @@ class DateTimePickerStoreFactory(
set(Calendar.HOUR_OF_DAY, hour)
set(Calendar.MINUTE, minute)
}
+
+ if (newDate.before(Calendar.getInstance())) {
+ dispatch(Message.UpdateDateTime(newDate))
+ dispatch(Message.ChangeDateButtonState(DateTimePickerStore.DateTimeButtonState.IncorrectDate()))
+ return@launch
+ }
+
val finishDate = (newDate.clone() as Calendar).apply {
add(
Calendar.MINUTE,
duration
)
}
+
dispatch(Message.UpdateDateTime(newDate))
checkEnableDateButton(newDate, finishDate)
}
@@ -120,10 +136,14 @@ class DateTimePickerStoreFactory(
room = room
).unbox({ it.saveData })?.filter { it.startTime != startDate } ?: listOf()
if (busyEvent.isNotEmpty()){
- dispatch(Message.EnableDateButton(false))
+ dispatch(Message.ChangeDateButtonState(
+ DateTimePickerStore.DateTimeButtonState.TimeBooked()
+ ))
}
- else{
- dispatch(Message.EnableDateButton(true))
+ else {
+ dispatch(Message.ChangeDateButtonState(
+ DateTimePickerStore.DateTimeButtonState.Enabled()
+ ))
}
}
@@ -133,7 +153,7 @@ class DateTimePickerStoreFactory(
override fun DateTimePickerStore.State.reduce(msg: Message): DateTimePickerStore.State =
when (msg) {
is Message.UpdateDateTime -> copy(currentDate = msg.newValue)
- is Message.EnableDateButton -> copy(isEnabledButton = msg.isEnabled)
+ is Message.ChangeDateButtonState -> copy(dateTimeButtonState = msg.newState)
}
}
}
\ No newline at end of file
diff --git a/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/updateEvent/UpdateEventView.kt b/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/updateEvent/UpdateEventView.kt
index aa5b195c71a63cd1b2446eecc5c01d367ca20be6..01f4b4b61e2092dfe7f1ac1781e13603176a3787 100644
--- a/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/updateEvent/UpdateEventView.kt
+++ b/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/updateEvent/UpdateEventView.kt
@@ -1,7 +1,6 @@
package band.effective.office.tablet.ui.updateEvent
import android.os.Build
-import android.util.Log
import androidx.annotation.RequiresApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
@@ -93,8 +92,8 @@ fun UpdateEventView(
component.sendIntent(UpdateEventStore.Intent.OnUpdateLength(-15))
},
onExpandedChange = { component.sendIntent(UpdateEventStore.Intent.OnExpandedChange) },
- onSelectOrganizer = {
- component.sendIntent(UpdateEventStore.Intent.OnSelectOrganizer(it))
+ onSelectOrganizer = { organizer ->
+ component.sendIntent(UpdateEventStore.Intent.OnSelectOrganizer(organizer))
},
selectData = state.date,
selectDuration = state.duration,
@@ -106,7 +105,7 @@ fun UpdateEventView(
},
onDeleteEvent = { component.sendIntent(UpdateEventStore.Intent.OnDeleteEvent) },
inputText = state.inputText,
- onInput = { component.sendIntent(UpdateEventStore.Intent.OnInput(it)) },
+ onInput = { input -> component.sendIntent(UpdateEventStore.Intent.OnInput(input)) },
isInputError = state.isInputError,
onDoneInput = { component.sendIntent(UpdateEventStore.Intent.OnDoneInput) },
isUpdateError = state.isErrorUpdate,
diff --git a/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/updateEvent/store/UpdateEventStoreFactory.kt b/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/updateEvent/store/UpdateEventStoreFactory.kt
index 1a314130ce9dca13d41ea616b38e318f2d3b1ddb..0c01ec26c1533fabe1ee2f05b8187cfad210ff04 100644
--- a/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/updateEvent/store/UpdateEventStoreFactory.kt
+++ b/tabletApp/features/selectRoom/src/commonMain/kotlin/band/effective/office/tablet/ui/updateEvent/store/UpdateEventStoreFactory.kt
@@ -1,6 +1,5 @@
package band.effective.office.tablet.ui.updateEvent.store
-import androidx.compose.ui.graphics.Color
import band.effective.office.network.model.Either
import band.effective.office.tablet.domain.model.EventInfo
import band.effective.office.tablet.domain.model.Organizer
@@ -118,9 +117,7 @@ class UpdateEventStoreFactory(
)
is UpdateEventStore.Intent.OnOpenSelectDateDialog -> dispatch(
- Message.ChangeShowSelectDateModal(
- true
- )
+ Message.ChangeShowSelectDateModal(true)
)
is UpdateEventStore.Intent.OnSetDate -> setDay(
@@ -134,7 +131,6 @@ class UpdateEventStoreFactory(
}
fun createEvent(state: UpdateEventStore.State) {
-
val event = EventInfo(
startTime = state.date,
organizer = state.selectOrganizer,
@@ -147,7 +143,6 @@ class UpdateEventStoreFactory(
id = ""
)
scope.launch {
-
if ((checkBookingUseCase.busyEvents(
event = event,
room = room
@@ -266,21 +261,15 @@ class UpdateEventStoreFactory(
)
)
dispatch(Message.BusyEvent(busyEvent.isNotEmpty()))
- checkEnableButton(state.isInputError, busyEvent.isNotEmpty() )
+ checkEnableButton(state.isInputError, busyEvent.isNotEmpty())
}
}
private fun checkEnableButton(
inputError: Boolean,
busyEvent: Boolean
- ){
- if(!inputError && !busyEvent) {
- dispatch(Message.EnableButton(isEnable = true))
- }
- else {
- dispatch(Message.EnableButton(isEnable = false))
- }
-
+ ) {
+ dispatch(Message.EnableButton(isEnable = !inputError && !busyEvent))
}
private fun today() = GregorianCalendar().apply {
diff --git a/tabletApp/features/selectRoom/src/commonMain/libres/strings/strings_ru.xml b/tabletApp/features/selectRoom/src/commonMain/libres/strings/strings_ru.xml
index c00f354d2763aa1dbac75f436fd9be9ff8d22add..aa87353cbd68bab68f72a593aace4ffcb0b511f0 100644
--- a/tabletApp/features/selectRoom/src/commonMain/libres/strings/strings_ru.xml
+++ b/tabletApp/features/selectRoom/src/commonMain/libres/strings/strings_ru.xml
@@ -22,4 +22,5 @@
Изменить
Удалить бронь
Это время уже занято
+ Бронировать в прошлое приложение пока не умеет
\ No newline at end of file