Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class SchedulerImpl(
workManager.cancelAllWorkByTag(DATA_SYNC_WORK)
}

override fun dataSyncWorker() {
TODO("Not yet implemented")
}

private fun getScheduleWorkTag(scheduleId: Uuid) = "SCHEDULE_${scheduleId.value}"

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.middlepoint.morestuff.shared.ui.screen

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

@Composable
actual fun SetSystemBarsColor(
statusBarColor: Color,
navigationBarColor: Color,
darkIcons: Boolean?
) {
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package io.middlepoint.morestuff.shared.data.middleware

import io.middlepoint.morestuff.shared.domain.redux.state.AppState
import io.middlepoint.morestuff.shared.domain.redux.Middleware
import io.middlepoint.morestuff.shared.domain.redux.action.NotificationAction
import io.middlepoint.morestuff.shared.domain.redux.action.NotificationAction.*
import io.middlepoint.morestuff.shared.domain.redux.action.NotificationAction.RemoveScheduleNotificationAction
import io.middlepoint.morestuff.shared.domain.redux.action.NotificationAction.ShowReminderNotificationAction
import io.middlepoint.morestuff.shared.domain.redux.action.NotificationAction.ShowReviewNotification
import io.middlepoint.morestuff.shared.domain.redux.action.NotificationAction.UserResponseAction
import io.middlepoint.morestuff.shared.domain.redux.action.ScheduleAction
import io.middlepoint.morestuff.shared.domain.redux.action.TaskAction
import io.middlepoint.morestuff.shared.domain.redux.state.AppState
import io.middlepoint.morestuff.shared.domain.redux.store.Action
import io.middlepoint.morestuff.shared.domain.redux.store.Dispatch
import io.middlepoint.morestuff.shared.domain.redux.store.Next
import io.middlepoint.morestuff.shared.domain.redux.store.NoOp
import io.middlepoint.morestuff.shared.domain.service.Notifier
import io.middlepoint.morestuff.shared.domain.service.logger
import io.middlepoint.morestuff.shared.domain.usecase.task.ClearTaskNotificationsUseCase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -44,6 +45,7 @@ class NotificationMiddleware(
}

is UserResponseAction -> with(action) {
logger.i { "Received user response for scheduleId=$scheduleId, replyType=$replyType" }
notifier.clearScheduleNotification(scheduleId)
dispatch(ScheduleAction.ScheduleReplyAction(scheduleId, replyType))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import io.middlepoint.morestuff.shared.domain.redux.store.Dispatch
import io.middlepoint.morestuff.shared.domain.redux.store.Next
import io.middlepoint.morestuff.shared.domain.redux.store.NoOp
import io.middlepoint.morestuff.shared.domain.service.TimeManager
import io.middlepoint.morestuff.shared.domain.service.logger
import io.middlepoint.morestuff.shared.domain.usecase.schedule.CancelActiveScheduleUseCase
import io.middlepoint.morestuff.shared.domain.usecase.schedule.CreateOneTimeScheduleUseCase
import io.middlepoint.morestuff.shared.domain.usecase.schedule.CreateScheduleUseCase
import io.middlepoint.morestuff.shared.domain.usecase.schedule.GetScheduleUseCase
import io.middlepoint.morestuff.shared.domain.usecase.schedule.ScheduleAtTimeUseCase
import io.middlepoint.morestuff.shared.domain.usecase.schedule.ScheduleUserReplyUseCase
import io.middlepoint.morestuff.shared.domain.usecase.schedule.ScheduleWorkUseCase
import io.middlepoint.morestuff.shared.domain.usecase.schedule.SetScheduleFulfilledUseCase
import io.middlepoint.morestuff.shared.domain.usecase.task.GetTaskUseCase
Expand All @@ -41,7 +43,8 @@ class ScheduleMiddleware(
private val createOneTimeScheduleUseCase: CreateOneTimeScheduleUseCase,
private val cancelActiveScheduleUseCase: CancelActiveScheduleUseCase,
private val setScheduleFulfilledUseCase: SetScheduleFulfilledUseCase,
private val getTaskUseCase: GetTaskUseCase
private val getTaskUseCase: GetTaskUseCase,
private val scheduleUserReplyUseCase: ScheduleUserReplyUseCase
) : Middleware<AppState> {

val timeManager: TimeManager = TimeManagerImpl()
Expand Down Expand Up @@ -88,9 +91,27 @@ class ScheduleMiddleware(
}

is ScheduleAction.ScheduleReplyAction -> {
scheduleUserReply(scope, action.scheduleId, action.replyType, dispatch)
logger.i { "⏳ ScheduleReplyAction: scheduleId=${action.scheduleId}, replyType=${action.replyType}" }

scope.launch {
val result = scheduleUserReplyUseCase(action.scheduleId, action.replyType)

result.onRight { actionResult ->
if (actionResult != null) {
logger.i { "🚀 Ejecutando acción resultante del use case: $actionResult" }
dispatch(actionResult)
} else {
logger.i { "⚠️ No se generó ninguna acción (null)" }
}
}

result.onLeft { failure ->
logger.e { "❌ Error al ejecutar ScheduleUserReplyUseCase: $failure" }
}
}
}


is ScheduleCreatedAction -> {
scope.launch {
action.schedule.scheduledAt.let { time ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ import io.middlepoint.morestuff.shared.domain.usecase.schedule.GetScheduleImpl
import io.middlepoint.morestuff.shared.domain.usecase.schedule.GetScheduleUseCase
import io.middlepoint.morestuff.shared.domain.usecase.schedule.ScheduleAtTimeUseCase
import io.middlepoint.morestuff.shared.domain.usecase.schedule.ScheduleAtTimeUseCaseImpl
import io.middlepoint.morestuff.shared.domain.usecase.schedule.ScheduleUserReplyUseCase
import io.middlepoint.morestuff.shared.domain.usecase.schedule.ScheduleUserReplyUseCaseImpl

import io.middlepoint.morestuff.shared.domain.usecase.schedule.ScheduleWorkUseCase
import io.middlepoint.morestuff.shared.domain.usecase.schedule.ScheduleWorkUseCaseImpl
import io.middlepoint.morestuff.shared.domain.usecase.schedule.SetScheduleFulfilledUseCase
Expand Down Expand Up @@ -278,6 +281,7 @@ val scheduleUseCases = module {
factoryOf(::SetScheduleFulfilledUseCaseImpl) bind SetScheduleFulfilledUseCase::class
factoryOf(::ScheduleAtTimeUseCaseImpl) bind ScheduleAtTimeUseCase::class
factoryOf(::ScheduleWorkUseCaseImpl) bind ScheduleWorkUseCase::class
factoryOf(::ScheduleUserReplyUseCaseImpl) bind ScheduleUserReplyUseCase::class
}

val messageUseCases = module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package io.middlepoint.morestuff.shared.domain.service
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import co.touchlab.kermit.Logger
import io.middlepoint.morestuff.shared.domain.enums.ReplyType
import io.middlepoint.morestuff.shared.domain.model.Shareable
import io.middlepoint.morestuff.shared.domain.model.Uuid
import io.middlepoint.morestuff.shared.domain.nav.Screen
import io.middlepoint.morestuff.shared.domain.redux.AppStore
import io.middlepoint.morestuff.shared.domain.redux.action.ScheduleAction
import io.middlepoint.morestuff.shared.domain.usecase.schedule.CancelActiveScheduleUseCase
import kotlinx.coroutines.launch
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

Expand All @@ -21,6 +24,9 @@ class NavigationHelper: ViewModel(), KoinComponent {
val navigation = MutableSharedFlow<Screen>()
val code = MutableSharedFlow<String>()
private val cancelActiveScheduleUseCase: CancelActiveScheduleUseCase by inject()
private val scheduler: Scheduler by inject()
private val store: AppStore by inject()



fun shareText(message: String) {
Expand Down Expand Up @@ -80,6 +86,20 @@ class NavigationHelper: ViewModel(), KoinComponent {
}
}

fun triggerDataSyncSchedule() {
logger.d { "Calling scheduleDataSyncWorker from NavigationHelper" }
scheduler.dataSyncWorker()
}


fun replyToSchedule(scheduleId: Uuid, replyTypeString: String) {
viewModelScope.launch {
val replyType = ReplyType.valueOf(replyTypeString.uppercase())
logger.d { "Dispatching ScheduleReplyAction with id: $scheduleId and type: $replyType" }
store.dispatch(ScheduleAction.ScheduleReplyAction(scheduleId, replyType))
}
}



}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ interface Scheduler {
fun scheduleDataSyncWorker()
fun cancelSchedule(scheduleId: Uuid)
fun cancelPlannedPriorityUpdate()
fun dataSyncWorker()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.middlepoint.morestuff.shared.domain.usecase.schedule

import arrow.core.Either
import io.middlepoint.morestuff.shared.domain.enums.ReplyType
import io.middlepoint.morestuff.shared.domain.model.Failure
import io.middlepoint.morestuff.shared.domain.model.Uuid
import io.middlepoint.morestuff.shared.domain.redux.action.ScheduleAction
import io.middlepoint.morestuff.shared.domain.redux.action.TaskAction
import io.middlepoint.morestuff.shared.domain.redux.store.Action
import io.middlepoint.morestuff.shared.domain.service.TimeManager
import io.middlepoint.morestuff.shared.domain.service.logger

interface ScheduleUserReplyUseCase {
suspend operator fun invoke(scheduleId: Uuid, replyType: ReplyType): Either<Failure, Action?>
}

class ScheduleUserReplyUseCaseImpl(
private val getScheduleUseCase: GetScheduleUseCase,
private val timeManager: TimeManager,

) : ScheduleUserReplyUseCase {

override suspend fun invoke(scheduleId: Uuid, replyType: ReplyType): Either<Failure, Action?> {
logger.i { "🟡 Invocando ScheduleUserReplyUseCase con scheduleId=$scheduleId y replyType=$replyType" }

return getScheduleUseCase(scheduleId).map { schedule ->
logger.i { "🟢 Schedule obtenido: taskId=${schedule.taskId}, type=${schedule.scheduleType}" }

when (replyType) {
ReplyType.LATER -> {
logger.i { "⏳ ReplyType.LATER: no se genera ninguna acción" }
null
}

ReplyType.TOMORROW -> {
val tomorrowTime = timeManager.tomorrowLocalDateTime(12)
logger.i { "📅 ReplyType.TOMORROW: reprogramando para mañana a las 12:00 => $tomorrowTime" }
ScheduleAction.RescheduleTaskAction(
schedule.taskId,
schedule.scheduleType,
tomorrowTime
)
}

ReplyType.SNOOZE -> {
val snoozeTime = timeManager.todayLocalDateTimeByAdding(hour = 1, minute = 0)
logger.i { "🔁 ReplyType.SNOOZE: reprogramando para dentro de 1h => $snoozeTime" }
ScheduleAction.RescheduleTaskAction(
schedule.taskId,
schedule.scheduleType,
snoozeTime
)
}

ReplyType.DONE -> {
logger.i { "✅ ReplyType.DONE: marcando como completada taskId=${schedule.taskId}" }
TaskAction.CompleteTasksAction(listOf(schedule.taskId), true)
}
}
}.also {
logger.i { "✅ Acción generada: $it" }
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.middlepoint.morestuff.shared.ui.screen

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

@Composable
expect fun SetSystemBarsColor(
statusBarColor: Color,
navigationBarColor: Color,
darkIcons: Boolean?
)
Loading
Loading