Skip to content

Commit

Permalink
feat: [ANDROAPP-5896] configurable event label
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmateos committed Feb 12, 2024
1 parent 44bbb1f commit dc11a07
Show file tree
Hide file tree
Showing 57 changed files with 187 additions and 429 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(resourceManager)
private fun provideEventResourcesProvider() = EventDetailResourcesProvider(resourceManager, programStage.uid())

private fun createOrUpdateEventDetails() = CreateOrUpdateEventDetails(
repository = eventDetailsRepository,
Expand Down
88 changes: 0 additions & 88 deletions app/src/main/java/org/dhis2/bindings/Bindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,67 +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) {
Expand Down Expand Up @@ -313,33 +252,6 @@ public static void setEventColor(View view, Event event, ProgramStage programSta
}
}

@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.dhis2.commons.dialogs.AlertBottomDialog
import org.dhis2.commons.dialogs.CustomDialog
import org.dhis2.commons.dialogs.DialogClickListener
import org.dhis2.commons.popupmenu.AppMenuHelper
import org.dhis2.commons.resources.ResourceManager
import org.dhis2.commons.sync.SyncContext
import org.dhis2.databinding.ActivityEventCaptureBinding
import org.dhis2.ui.ErrorFieldList
Expand Down Expand Up @@ -58,7 +59,7 @@ class EventCaptureActivity :
EventCaptureContract.View,
MapButtonObservable,
EventDetailsComponentProvider {
private var binding: ActivityEventCaptureBinding? = null
private lateinit var binding: ActivityEventCaptureBinding

@JvmField
@Inject
Expand All @@ -74,6 +75,9 @@ class EventCaptureActivity :
private var isEventCompleted = false
private var eventMode: EventMode? = null

@Inject
lateinit var resourceManager: ResourceManager

@JvmField
var eventCaptureComponent: EventCaptureComponent? = null
var programUid: String? = null
Expand Down Expand Up @@ -119,6 +123,7 @@ class EventCaptureActivity :
this,
intent.getStringExtra(Constants.PROGRAM_UID),
intent.getStringExtra(Constants.EVENT_UID),
presenter?.programStage(),
pageConfigurator!!.displayAnalytics(),
pageConfigurator!!.displayRelationships(),
intent.getBooleanExtra(OPEN_ERROR_LOCATION, false),
Expand Down Expand Up @@ -297,9 +302,16 @@ class EventCaptureActivity :
}
}

override fun showSnackBar(messageId: Int) {
override fun showSnackBar(messageId: Int, programStage: String) {
val mySnackbar =
Snackbar.make(binding!!.root, messageId, BaseTransientBottomBar.LENGTH_SHORT)
Snackbar.make(
binding.root,
resourceManager.formatWithEventLabel(
messageId,
programStage,
),
BaseTransientBottomBar.LENGTH_SHORT,
)
mySnackbar.show()
}

Expand Down Expand Up @@ -369,30 +381,43 @@ class EventCaptureActivity :
}

private fun confirmDeleteEvent() {
CustomDialog(
this,
getString(R.string.delete_event),
getString(R.string.confirm_delete_event),
getString(R.string.delete),
getString(R.string.cancel),
0,
object : DialogClickListener {
override fun onPositive() {
analyticsHelper().setEvent(DELETE_EVENT, CLICK, DELETE_EVENT)
presenter!!.deleteEvent()
}
presenter?.programStage().let {
CustomDialog(
this,
resourceManager.formatWithEventLabel(
R.string.delete_event_label,
programStageUid = it,
),
resourceManager.formatWithEventLabel(
R.string.confirm_delete_event_label,
programStageUid = it,
),
getString(R.string.delete),
getString(R.string.cancel),
0,
object : DialogClickListener {
override fun onPositive() {
analyticsHelper().setEvent(DELETE_EVENT, CLICK, DELETE_EVENT)
presenter!!.deleteEvent()
}

override fun onNegative() {
// dismiss
}
},
).show()
override fun onNegative() {
// dismiss
}
},
).show()
}
}

override fun showEventIntegrityAlert() {
MaterialAlertDialogBuilder(this, R.style.DhisMaterialDialog)
.setTitle(R.string.conflict)
.setMessage(R.string.event_date_in_future_message)
.setMessage(
resourceManager.formatWithEventLabel(
R.string.event_label_date_in_future_message,
programStageUid = presenter?.programStage(),
),
)
.setPositiveButton(
R.string.change_event_date,
) { _, _ -> binding!!.navigationBar.selectItemAt(0) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void showCompleteActions(

void SaveAndFinish();

void showSnackBar(int messageId);
void showSnackBar(int messageId, String programStage);

void attemptToSkip();

Expand Down Expand Up @@ -100,6 +100,8 @@ void attemptFinish(boolean canComplete,
boolean getCompletionPercentageVisibility();

void emitAction(@NotNull EventCaptureAction onBack);

String programStage();
}

public interface EventCaptureRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhis2.usescases.eventsWithoutRegistration.eventCapture;

import static org.dhis2.commons.Constants.PROGRAM_STAGE_UID;
import static org.dhis2.usescases.teiDashboard.dashboardfragments.indicators.IndicatorsFragmentKt.VISUALIZATION_TYPE;
import static org.dhis2.commons.Constants.PROGRAM_UID;

Expand Down Expand Up @@ -31,6 +32,7 @@ public class EventCapturePagerAdapter extends FragmentStateAdapter {
private final String programUid;
private final String eventUid;
private final List<EventPageType> pages;
private final String programStage;
private EventCaptureFormFragment formFragment;

private final boolean shouldOpenErrorSection;
Expand All @@ -46,6 +48,7 @@ private enum EventPageType {
public EventCapturePagerAdapter(FragmentActivity fragmentActivity,
String programUid,
String eventUid,
String programStage,
boolean displayAnalyticScreen,
boolean displayRelationshipScreen,
boolean openErrorSection
Expand All @@ -54,6 +57,7 @@ public EventCapturePagerAdapter(FragmentActivity fragmentActivity,
super(fragmentActivity);
this.programUid = programUid;
this.eventUid = eventUid;
this.programStage = programStage;
this.shouldOpenErrorSection = openErrorSection;
pages = new ArrayList<>();
pages.add(EventPageType.DETAILS);
Expand Down Expand Up @@ -93,6 +97,7 @@ public Fragment createFragment(int position) {
Bundle bundle = new Bundle();
bundle.putString(Constants.EVENT_UID, eventUid);
bundle.putString(PROGRAM_UID, programUid);
bundle.putString(PROGRAM_STAGE_UID, programStage);
EventDetailsFragment eventDetailsFragment = new EventDetailsFragment();
eventDetailsFragment.setArguments(bundle);
eventDetailsFragment.setOnEventReopened(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class EventCapturePresenterImpl(
schedulerProvider,
{ result ->
if (result) {
view.showSnackBar(R.string.event_was_deleted)
view.showSnackBar(R.string.event_label_was_deleted, programStage())
}
},
Timber::e,
Expand All @@ -200,7 +200,7 @@ class EventCapturePresenterImpl(
eventCaptureRepository.updateEventStatus(EventStatus.SKIPPED)
.defaultSubscribe(
schedulerProvider,
{ view.showSnackBar(R.string.event_was_skipped) },
{ view.showSnackBar(R.string.event_label_was_skipped, programStage()) },
Timber::e,
view::finishDataEntry,
),
Expand Down Expand Up @@ -268,4 +268,6 @@ class EventCapturePresenterImpl(

private val eventStatus: EventStatus
get() = eventCaptureRepository.eventStatus().blockingFirst()

override fun programStage(): String = eventCaptureRepository.programStage().blockingFirst()
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class EventDetailsModule(
fun provideEventDetailResourceProvider(
resourceManager: ResourceManager,
): EventDetailResourcesProvider {
return EventDetailResourcesProvider(resourceManager)
return EventDetailResourcesProvider(resourceManager, programStageUid)
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import org.hisp.dhis.android.core.event.EventNonEditableReason

class EventDetailResourcesProvider(
private val resourceManager: ResourceManager,
private val programStage: String?,
) {
fun provideDueDate() = resourceManager.getString(R.string.due_date)

fun provideEventDate() = resourceManager.getString(R.string.event_date)
fun provideEventDate() = resourceManager.formatWithEventLabel(
R.string.event_label_date,
programStage,
)

fun provideEditionStatus(reason: EventNonEditableReason): String {
return when (reason) {
Expand All @@ -36,9 +40,15 @@ class EventDetailResourcesProvider(

fun provideButtonCheck() = resourceManager.getString(R.string.check_event)

fun provideEventCreatedMessage() = resourceManager.getString(R.string.event_updated)
fun provideEventCreatedMessage() = resourceManager.formatWithEventLabel(
R.string.event_label_updated,
programStage,
)

fun provideEventCreationError() = resourceManager.getString(R.string.failed_insert_event)
fun provideEventCreationError() = resourceManager.formatWithEventLabel(
R.string.failed_insert_event_label,
programStage,
)

fun provideReOpened() = resourceManager.getString(R.string.re_opened)
}
Loading

0 comments on commit dc11a07

Please sign in to comment.