Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New postpone screen #139

Merged
merged 4 commits into from
Oct 18, 2024
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 @@ -9,6 +9,7 @@ object DateTimeFormatters {
val shortDayOfWeekFormatter = DateTimeFormatter.ofPattern("E")
val dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
val monthFormatter = DateTimeFormatter.ofPattern("MMMM yyyy")
val dateWithMonthFormatter = DateTimeFormatter.ofPattern("d MMM")

fun LocalTime.formatTime(locale: Locale): String =
DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(locale).format(this)
Expand Down
8 changes: 6 additions & 2 deletions core/ui/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<string name="notification_reminder_postpone">Posponer</string>
<string name="agenda_mark_as_done">Marcar como hecho</string>
<string name="agenda_mark_as_undone">Marcar como no hecho</string>
<string name="postpone_task_fifteen_minutes">15 minutos</string>
<string name="postpone_task_thirty_minutes">30 minutos</string>
<string name="postpone_task_one_hour">1 hora</string>
<string name="postpone_task_tonight">Esta noche</string>
<string name="postpone_task_tomorrow_morning">Mañana por la mañana</string>
Expand Down Expand Up @@ -81,7 +81,7 @@
<string name="create_task_schedule_exact_reminder_permission_missing_description">Para utilizar la función de recordatorios, necesitamos el permiso para alarmas exactas. Sin él, los recordatorios no funcionarán</string>
<string name="create_task_schedule_exact_reminder_permission_missing_dismiss">Lo entiendo</string>
<string name="create_task_schedule_exact_reminder_permission_missing_confirm">Ir a Ajustes</string>
<string name="postpone_task_title">" ¿No es el momento? Decide cuándo"</string>
<string name="postpone_task_title">Posponer tarea</string>
<string name="create_task_notification_permission_rationale_title">El permiso de notificaciones es necesario</string>
<string name="create_task_notification_permission_rationale_description">"Para utilizar la función de recordatorios, necesitamos el permiso de notificaciones. Sin él, los recordatorios no funcionarán "</string>
<string name="create_task_notification_permission_rationale_dismiss">No gracias</string>
Expand All @@ -99,4 +99,8 @@
<string name="update_recurring_task_dialog_this">Esta tarea</string>
<string name="update_recurring_task_dialog_this_and_future">Esta tarea y las posteriores</string>
<string name="task_detail_task_name_placeholder">Título de la tarea</string>
<string name="postpone_task_three_hours">3 horas</string>
<string name="postpone_task_custom">Escoge fecha y hora</string>
<string name="postpone_task_custom_date">Día</string>
<string name="postpone_task_custom_time">Hora</string>
</resources>
10 changes: 7 additions & 3 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@
<string name="notification_reminder_postpone">Postpone</string>

<!-- Postpone task picker -->
<string name="postpone_task_title">Not now? Pick when</string>
<string name="postpone_task_fifteen_minutes">15 minutes</string>
<string name="postpone_task_one_hour">1 hour</string>
<string name="postpone_task_title">Reschedule task</string>
<string name="postpone_task_thirty_minutes">In 30 minutes</string>
<string name="postpone_task_one_hour">In 1 hour</string>
<string name="postpone_task_three_hours">In 3 hours</string>
<string name="postpone_task_tonight">Tonight</string>
<string name="postpone_task_tomorrow_morning">Tomorrow morning</string>
<string name="postpone_task_next_weekend">Next weekend</string>
<string name="postpone_task_next_week">Next week</string>
<string name="postpone_task_custom">Pick a date &amp; time</string>
<string name="postpone_task_custom_date">Date</string>
<string name="postpone_task_custom_time">Time</string>

<!-- Settings -->
<string name="settings">Settings</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
package com.costular.atomtasks.postponetask.domain

import com.costular.atomtasks.core.usecase.UseCase
import java.time.LocalDate
import javax.inject.Inject

class GetPostponeChoiceListUseCase @Inject constructor(): UseCase<Unit, List<PostponeChoice>> {
override suspend fun invoke(params: Unit): List<PostponeChoice> = listOf(
PostponeChoice.FifteenMinutes,
PostponeChoice.OneHour,
PostponeChoice.Tonight,
PostponeChoice.TomorrowMorning,
PostponeChoice.NextWeek,
)
class GetPostponeChoiceListUseCase @Inject constructor(
private val postponeChoiceCalculator: PostponeChoiceCalculator,
) : UseCase<Unit, List<PostponeChoice>> {

override suspend fun invoke(params: Unit): List<PostponeChoice> {
return Choices.map { PostponeChoice(it, postponeChoiceCalculator.calculatePostpone(it)) }
.filter {
it.postponeChoiceType != PostponeChoiceType.Tonight ||
(it.postponeChoiceType == PostponeChoiceType.Tonight &&
it.postponeDateTime?.toLocalDate() == LocalDate.now())
}
}

companion object {
internal val Choices = listOf(
PostponeChoiceType.ThirtyMinutes,
PostponeChoiceType.OneHour,
PostponeChoiceType.ThreeHours,
PostponeChoiceType.Tonight,
PostponeChoiceType.TomorrowMorning,
PostponeChoiceType.NextWeek,
PostponeChoiceType.Custom,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package com.costular.atomtasks.postponetask.domain

sealed interface PostponeChoice {
import java.time.LocalDateTime

data object FifteenMinutes : PostponeChoice

data object OneHour : PostponeChoice

data object Tonight : PostponeChoice

data object TomorrowMorning : PostponeChoice

data object NextWeekend : PostponeChoice

data object NextWeek : PostponeChoice
}
data class PostponeChoice(
val postponeChoiceType: PostponeChoiceType,
val postponeDateTime: LocalDateTime?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ import java.time.LocalDate
import java.time.LocalDateTime

interface PostponeChoiceCalculator {
fun calculatePostpone(postponeChoice: PostponeChoice): LocalDateTime
fun calculatePostpone(postponeChoiceType: PostponeChoiceType): LocalDateTime?
}

@Suppress("MagicNumber")
class DefaultPostponeChoiceCalculator(
private val clock: Clock,
) : PostponeChoiceCalculator {
override fun calculatePostpone(postponeChoice: PostponeChoice): LocalDateTime {
return when (postponeChoice) {
PostponeChoice.FifteenMinutes -> {
now().plusMinutes(15)
override fun calculatePostpone(postponeChoiceType: PostponeChoiceType): LocalDateTime? {
return when (postponeChoiceType) {
PostponeChoiceType.ThirtyMinutes -> {
now().plusMinutes(30)
}

PostponeChoice.OneHour -> {
PostponeChoiceType.OneHour -> {
now().plusHours(1)
}

PostponeChoice.Tonight -> {
PostponeChoiceType.ThreeHours -> {
now().plusHours(3)
}

PostponeChoiceType.Tonight -> {
val tonigth = today().atTime(PredefinedTimes.Night)
if (tonigth.isBefore(LocalDateTime.now(clock))) {
tonigth.plusDays(1)
Expand All @@ -34,17 +38,21 @@ class DefaultPostponeChoiceCalculator(
}
}

PostponeChoice.TomorrowMorning -> {
PostponeChoiceType.TomorrowMorning -> {
today().plusDays(1).atTime(PredefinedTimes.Morning)
}

PostponeChoice.NextWeekend -> {
PostponeChoiceType.NextWeekend -> {
today().findNextWeekend().atTime(PredefinedTimes.Morning)
}

PostponeChoice.NextWeek -> {
PostponeChoiceType.NextWeek -> {
today().findNextWeek().atTime(PredefinedTimes.Morning)
}

PostponeChoiceType.Custom -> {
null
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.costular.atomtasks.postponetask.domain

sealed interface PostponeChoiceType {

data object ThirtyMinutes : PostponeChoiceType

data object OneHour : PostponeChoiceType

data object ThreeHours: PostponeChoiceType

data object Tonight : PostponeChoiceType

data object TomorrowMorning : PostponeChoiceType

data object NextWeekend : PostponeChoiceType

data object NextWeek : PostponeChoiceType

data object Custom : PostponeChoiceType
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.costular.atomtasks.postponetask.ui

import com.costular.atomtasks.analytics.TrackingEvent
import java.time.LocalDate
import java.time.LocalTime

data class PostponeDefaultOptionClicked(val option: String) : TrackingEvent(
name = "postpone_default_clicked",
attributes = mapOf("option" to option)
)

data object PostponeCustomOptionClicked : TrackingEvent(name = "postpone_custom_clicked")

data object PostponeCustomDatePickerOpened :
TrackingEvent(name = "postpone_custom_date_picker_opened")

data object PostponeCustomTimePickerOpened :
TrackingEvent(name = "postpone_custom_time_picker_opened")

data class PostponeCustomRescheduled(
val date: LocalDate,
val time: LocalTime,
) : TrackingEvent(
name = "postpone_custom_rescheduled",
attributes = mapOf(
"date" to date.toString(),
"time" to time.toString(),
)
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.costular.atomtasks.postponetask.ui

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand All @@ -28,12 +26,6 @@ class PostponeTaskActivity : ComponentActivity() {
}

companion object {
fun buildIntent(context: Context, taskId: Long): Intent {
return Intent(context, PostponeTaskActivity::class.java).apply {
putExtra(ParamTaskId, taskId)
}
}

private const val ParamTaskId = "postpone_param_task_id"
}
}
Loading
Loading