Skip to content

Commit

Permalink
feat: [ANDROAPP-5896] configurable event label (#3495)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmateos authored Feb 15, 2024
1 parent 2f3b422 commit 067dcac
Show file tree
Hide file tree
Showing 79 changed files with 217 additions and 624 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class EventInitialTest {
on { displayName() } doReturn PROGRAM_STAGE_NAME
on { executionDateLabel() } doReturn EXECUTION_DATE
on { generatedByEnrollmentDate() } doReturn true
on { uid() } doReturn "programStage"
}
private val catCombo: CategoryCombo = mock {
on { uid() } doReturn CAT_COMBO_UID
Expand Down Expand Up @@ -154,7 +155,7 @@ class EventInitialTest {
enrollmentStatus = enrollmentStatus,
)

private fun provideEventResourcesProvider() = EventDetailResourcesProvider(PROGRAM_UID, resourceManager)
private fun provideEventResourcesProvider() = EventDetailResourcesProvider(PROGRAM_UID, programStage.uid(), resourceManager)

private fun createOrUpdateEventDetails() = CreateOrUpdateEventDetails(
repository = eventDetailsRepository,
Expand Down
201 changes: 0 additions & 201 deletions app/src/main/java/org/dhis2/bindings/Bindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,207 +204,6 @@ public static void setEventIcon(ImageView view, Event event, Enrollment enrollme
}
}

@BindingAdapter(value = {"eventStatusText", "enrollmentStatus", "eventProgramStage", "eventProgram"})
public static void setEventText(TextView view, Event event, Enrollment enrollment, ProgramStage eventProgramStage, Program program) {
if (event != null) {
EventStatus status = event.status();
EnrollmentStatus enrollmentStatus = enrollment.status();
if (status == null)
status = EventStatus.ACTIVE;
if (enrollmentStatus == null)
enrollmentStatus = EnrollmentStatus.ACTIVE;


if (enrollmentStatus == EnrollmentStatus.ACTIVE) {
switch (status) {
case ACTIVE:
Date eventDate = event.eventDate();
if (eventProgramStage.periodType() != null && eventProgramStage.periodType().name().contains(PeriodType.Weekly.name()))
eventDate = DateUtils.getInstance().getNextPeriod(eventProgramStage.periodType(), eventDate, 0, true);
if (DateUtils.getInstance().isEventExpired(eventDate, null, event.status(), program.completeEventsExpiryDays(), eventProgramStage.periodType() != null ? eventProgramStage.periodType() : program.expiryPeriodType(), program.expiryDays())) {
view.setText(view.getContext().getString(R.string.event_expired));
} else {
view.setText(view.getContext().getString(R.string.event_open));
}
break;
case COMPLETED:
if (DateUtils.getInstance().isEventExpired(null, event.completedDate(), program.completeEventsExpiryDays())) {
view.setText(view.getContext().getString(R.string.event_expired));
} else {
view.setText(view.getContext().getString(R.string.event_completed));
}
break;
case SCHEDULE:
if (DateUtils.getInstance().isEventExpired(
event.dueDate(),
null,
status,
program.completeEventsExpiryDays(),
eventProgramStage.periodType() != null ? eventProgramStage.periodType() : program.expiryPeriodType(),
program.expiryDays())) {
view.setText(view.getContext().getString(R.string.event_expired));
} else {
view.setText(view.getContext().getString(R.string.event_schedule));
}
break;
case SKIPPED:
view.setText(view.getContext().getString(R.string.event_skipped));
break;
case OVERDUE:
view.setText(R.string.event_overdue);
break;
default:
view.setText(view.getContext().getString(R.string.read_only));
break;
}
} else if (enrollmentStatus == EnrollmentStatus.COMPLETED) {
view.setText(view.getContext().getString(R.string.program_completed));
} else { //EnrollmentStatus = CANCELLED
view.setText(view.getContext().getString(R.string.program_inactive));
}
}
}

@BindingAdapter(value = {"eventColor", "eventProgramStage", "eventProgram"})
public static void setEventColor(View view, Event event, ProgramStage programStage, Program program) {
if (event != null) {
int bgColor;
if (DateUtils.getInstance().isEventExpired(null, event.completedDate(), program.completeEventsExpiryDays())) {
bgColor = R.drawable.item_event_dark_gray_ripple;
} else if (event.status() != null) {
switch (event.status()) {
case ACTIVE:
Date eventDate = event.eventDate();
if (programStage.periodType() != null && programStage.periodType().name().contains(PeriodType.Weekly.name()))
eventDate = DateUtils.getInstance().getNextPeriod(programStage.periodType(), eventDate, 0, true);
if (DateUtils.getInstance().isEventExpired(eventDate, null, event.status(), program.completeEventsExpiryDays(), programStage.periodType() != null ? programStage.periodType() : program.expiryPeriodType(), program.expiryDays())) {
bgColor = R.drawable.item_event_dark_gray_ripple;
} else
bgColor = R.drawable.item_event_yellow_ripple;
break;
case COMPLETED:
if (DateUtils.getInstance().isEventExpired(null, event.completedDate(), program.completeEventsExpiryDays())) {
bgColor = R.drawable.item_event_dark_gray_ripple;
} else
bgColor = R.drawable.item_event_gray_ripple;
break;
case SCHEDULE:
if (DateUtils.getInstance().isEventExpired(
event.dueDate(),
null,
event.status(),
program.completeEventsExpiryDays(),
programStage.periodType() != null ? programStage.periodType() : program.expiryPeriodType(),
program.expiryDays())) {
bgColor = R.drawable.item_event_dark_gray_ripple;
} else
bgColor = R.drawable.item_event_green_ripple;
break;
case VISITED:
case SKIPPED:
default:
bgColor = R.drawable.item_event_red_ripple;
break;
}
} else {
bgColor = R.drawable.item_event_red_ripple;
}
view.setBackground(AppCompatResources.getDrawable(view.getContext(), bgColor));
}
}

@BindingAdapter("eventWithoutRegistrationStatusText")
public static void setEventWithoutRegistrationStatusText(TextView textView, ProgramEventViewModel event) {
switch (event.eventStatus()) {
case ACTIVE:
if (event.isExpired()) {
textView.setText(textView.getContext().getString(R.string.event_editing_expired));
} else {
textView.setText(textView.getContext().getString(R.string.event_open));
}
break;
case COMPLETED:
if (event.isExpired()) {
textView.setText(textView.getContext().getString(R.string.event_editing_expired));
} else {
textView.setText(textView.getContext().getString(R.string.event_completed));
}
break;
case SKIPPED:
textView.setText(textView.getContext().getString(R.string.event_editing_expired));
break;
default:
textView.setText(textView.getContext().getString(R.string.read_only));
break;
}
}



@BindingAdapter("stateText")
public static void setStateText(TextView textView, State state) {
switch (state) {
case TO_POST:
textView.setText(textView.getContext().getString(R.string.state_to_post));
break;
case TO_UPDATE:
textView.setText(textView.getContext().getString(R.string.state_to_update));
break;
case ERROR:
textView.setText(textView.getContext().getString(R.string.state_error));
break;
case SYNCED:
textView.setText(textView.getContext().getString(R.string.state_synced));
break;
default:
break;
}
}

@BindingAdapter("fromResBgColor")
public static void setFromResBgColor(View view, int color) {
String tintedColor;

ArrayList<Double> rgb = new ArrayList<>();
rgb.add(Color.red(color) / 255.0d);
rgb.add(Color.green(color) / 255.0d);
rgb.add(Color.blue(color) / 255.0d);

Double r = null;
Double g = null;
Double b = null;
for (Double c : rgb) {
if (c <= 0.03928d)
c = c / 12.92d;
else
c = Math.pow(((c + 0.055d) / 1.055d), 2.4d);

if (r == null)
r = c;
else if (g == null)
g = c;
else
b = c;
}

double L = 0.2126d * r + 0.7152d * g + 0.0722d * b;


if (L > 0.179d)
tintedColor = "#000000"; // bright colors - black font
else
tintedColor = "#FFFFFF"; // dark colors - white font

if (view instanceof TextView) {
((TextView) view).setTextColor(Color.parseColor(tintedColor));
}
if (view instanceof ImageView) {
Drawable drawable = ((ImageView) view).getDrawable();
if (drawable != null)
drawable.setColorFilter(Color.parseColor(tintedColor), PorterDuff.Mode.SRC_IN);
((ImageView) view).setImageDrawable(drawable);
}
}

@BindingAdapter("imageBackground")
public static void setImageBackground(ImageView imageView, Drawable drawable) {
Expand Down
Loading

0 comments on commit 067dcac

Please sign in to comment.