Skip to content

Commit

Permalink
refactor: [ANDROAPP-6170] Remove OpenYearMonthDayAgeCalendar UiEventType
Browse files Browse the repository at this point in the history
Signed-off-by: andresmr <[email protected]>
  • Loading branch information
andresmr committed May 28, 2024
1 parent 465f1c0 commit 69dffbb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
1 change: 0 additions & 1 deletion form/src/main/java/org/dhis2/form/model/UiEventType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.dhis2.form.model
enum class UiEventType {
DATE_TIME,
AGE_CALENDAR,
AGE_YEAR_MONTH_DAY,
ORG_UNIT,
REQUEST_CURRENT_LOCATION,
REQUEST_LOCATION_BY_MAP,
Expand Down
2 changes: 0 additions & 2 deletions form/src/main/java/org/dhis2/form/ui/FormView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,6 @@ class FormView : Fragment() {
private fun uiEventHandler(uiEvent: RecyclerViewUiEvents) {
when (uiEvent) {
is RecyclerViewUiEvents.OpenCustomCalendar -> showCustomCalendar(uiEvent)
is RecyclerViewUiEvents.OpenYearMonthDayAgeCalendar -> {}

is RecyclerViewUiEvents.OpenTimePicker -> showTimePicker(uiEvent)
is RecyclerViewUiEvents.ShowDescriptionLabelDialog -> showDescriptionLabelDialog(
uiEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import java.util.Date

sealed class RecyclerViewUiEvents {

data class OpenYearMonthDayAgeCalendar(
val uid: String,
val year: Int,
val month: Int,
val day: Int,
) : RecyclerViewUiEvents()

data class OpenCustomCalendar(
val uid: String,
val label: String,
Expand Down
30 changes: 14 additions & 16 deletions form/src/main/java/org/dhis2/form/ui/event/UiEventFactoryImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.dhis2.form.model.UiEventType.ADD_FILE
import org.dhis2.form.model.UiEventType.ADD_PICTURE
import org.dhis2.form.model.UiEventType.ADD_SIGNATURE
import org.dhis2.form.model.UiEventType.AGE_CALENDAR
import org.dhis2.form.model.UiEventType.AGE_YEAR_MONTH_DAY
import org.dhis2.form.model.UiEventType.COPY_TO_CLIPBOARD
import org.dhis2.form.model.UiEventType.DATE_TIME
import org.dhis2.form.model.UiEventType.EMAIL
Expand All @@ -27,7 +26,6 @@ import org.dhis2.form.model.UiRenderType
import org.hisp.dhis.android.core.common.FeatureType
import org.hisp.dhis.android.core.common.ValueType
import timber.log.Timber
import java.util.Calendar

class UiEventFactoryImpl(
val uid: String,
Expand All @@ -54,62 +52,64 @@ class UiEventFactoryImpl(
value?.let { DateUtils.oldUiDateFormat().parse(it) },
allowFutureDates ?: true,
)

ValueType.DATETIME -> RecyclerViewUiEvents.OpenCustomCalendar(
uid,
label,
value?.let { DateUtils.databaseDateFormatNoSeconds().parse(it) },
allowFutureDates ?: true,
isDateTime = true,
)

ValueType.TIME -> RecyclerViewUiEvents.OpenTimePicker(
uid,
label,
value?.let { DateUtils.timeFormat().parse(it) },
)

else -> null
}
}

AGE_CALENDAR -> RecyclerViewUiEvents.OpenCustomCalendar(
uid = uid,
label = label,
date = value?.toDate(),
allowFutureDates = allowFutureDates ?: false,
)
AGE_YEAR_MONTH_DAY -> {
val yearMonthDay = valueToYearMonthDay(value)
RecyclerViewUiEvents.OpenYearMonthDayAgeCalendar(
uid = uid,
year = yearMonthDay[0],
month = yearMonthDay[1],
day = yearMonthDay[2],
)
}

ORG_UNIT -> RecyclerViewUiEvents.OpenOrgUnitDialog(
uid,
label,
value,
fieldUiModel.orgUnitSelectorScope,
)

REQUEST_CURRENT_LOCATION -> RecyclerViewUiEvents.RequestCurrentLocation(
uid = uid,
)

REQUEST_LOCATION_BY_MAP -> RecyclerViewUiEvents.RequestLocationByMap(
uid = uid,
featureType = getFeatureType(renderingType),
value = value,
)

SHOW_DESCRIPTION -> RecyclerViewUiEvents.ShowDescriptionLabelDialog(
title = label,
message = description,
)

ADD_PICTURE -> RecyclerViewUiEvents.AddImage(uid)
SHOW_PICTURE -> RecyclerViewUiEvents.ShowImage(
label,
value ?: "",
)

COPY_TO_CLIPBOARD -> RecyclerViewUiEvents.CopyToClipboard(
value = value,
)

QR_CODE -> {
if (value.isNullOrEmpty() && fieldUiModel.editable) {
RecyclerViewUiEvents.ScanQRCode(
Expand All @@ -130,6 +130,7 @@ class UiEventFactoryImpl(
null
}
}

OPTION_SET -> RecyclerViewUiEvents.OpenOptionSetDialog(fieldUiModel)
ADD_SIGNATURE -> RecyclerViewUiEvents.AddSignature(uid, label)
ADD_FILE -> RecyclerViewUiEvents.OpenFileSelector(fieldUiModel)
Expand All @@ -140,11 +141,13 @@ class UiEventFactoryImpl(
value,
uid,
)

SHARE_IMAGE -> RecyclerViewUiEvents.OpenChooserIntent(
Intent.ACTION_SEND,
fieldUiModel.displayName,
uid,
)

else -> null
}
} catch (e: Exception) {
Expand All @@ -163,9 +166,4 @@ class UiEventFactoryImpl(
else -> FeatureType.NONE
}
}

private fun valueToYearMonthDay(value: String?) = value?.toDate()?.let {
Calendar.getInstance().time = it
DateUtils.getDifference(it, Calendar.getInstance().time)
} ?: intArrayOf(0, 0, 0)
}

0 comments on commit 69dffbb

Please sign in to comment.