Skip to content

Commit

Permalink
[ANDROAPP-5894] Adapt enrollment label to be configurable from server (
Browse files Browse the repository at this point in the history
…#3493)

Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan authored Feb 14, 2024
1 parent dc60ddf commit 039ffb7
Show file tree
Hide file tree
Showing 83 changed files with 263 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class EventInitialTest {
enrollmentStatus = enrollmentStatus,
)

private fun provideEventResourcesProvider() = EventDetailResourcesProvider(resourceManager)
private fun provideEventResourcesProvider() = EventDetailResourcesProvider(PROGRAM_UID, resourceManager)

private fun createOrUpdateEventDetails() = CreateOrUpdateEventDetails(
repository = eventDetailsRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.dhis2.usescases.flow.searchFlow

import android.content.Intent
import androidx.compose.ui.text.capitalize
import androidx.compose.ui.text.intl.Locale
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.dhis2.R
Expand All @@ -27,6 +29,7 @@ class SearchFlowTest : BaseTest() {
setDatePicker()
val registerTEIDetails = createRegisterTEI()
val enrollmentStatus = context.getString(R.string.filters_title_enrollment_status)
.format(context.resources.getQuantityString(R.plurals.enrollment, 1).capitalize(Locale.current))
val filterCounter = "1"
val filterTotalCount = "2"
prepareWomanProgrammeIntentAndLaunchActivity(rule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.dhis2.usescases.searchte
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.text.capitalize
import androidx.compose.ui.text.intl.Locale
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.IdlingResourceTimeoutException
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand Down Expand Up @@ -145,6 +147,7 @@ class SearchTETest : BaseTest() {
@Test
fun shouldSuccessfullyFilterByEnrollmentStatusActive() {
val enrollmentStatusFilter = context.getString(R.string.filters_title_enrollment_status)
.format(context.resources.getQuantityString(R.plurals.enrollment, 1).capitalize(Locale.current))
val totalFilterCount = "2"
val filterCount = "1"

Expand Down Expand Up @@ -310,6 +313,7 @@ class SearchTETest : BaseTest() {
val lastName = "Jones"
val namePosition = 0
val enrollmentStatus = context.getString(R.string.filters_title_enrollment_status)
.format(context.resources.getQuantityString(R.plurals.enrollment, 1).capitalize(Locale.current))
val totalCount = "2"
val totalFilterCount = "1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,12 @@ class TeiDashboardRobot : BaseRobot() {
}

fun clickOnMenuProgramEnrollments() {
onView(withText(R.string.program_selector)).perform(click())
with(InstrumentationRegistry.getInstrumentation().targetContext){
val programSelectorLabel = getString(R.string.program_selector_V2)
val enrollmentLabel = resources.getQuantityString(R.plurals.enrollment,2)
val itemLabel = programSelectorLabel.format(enrollmentLabel)
onView(withText(itemLabel)).perform(click())
}
}

fun clickOnCreateNewEvent() {
Expand Down Expand Up @@ -376,7 +381,12 @@ class TeiDashboardRobot : BaseRobot() {
}

fun clickOnMenuDeleteEnrollment() {
onView(withText(R.string.dashboard_menu_delete_enrollment)).perform(click())
with(InstrumentationRegistry.getInstrumentation().targetContext){
val deleteEnrollmentLabel = getString(R.string.dashboard_menu_delete_enrollment_V2)
val enrollmentLabel = resources.getQuantityString(R.plurals.enrollment,1)
val itemLabel = deleteEnrollmentLabel.format(enrollmentLabel)
onView(withText(itemLabel)).perform(click())
}
}

fun clickOnGroupByStage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.dhis2.commons.data.TeiAttributesInfo
import org.dhis2.commons.dialogs.imagedetail.ImageDetailActivity
import org.dhis2.commons.featureconfig.data.FeatureConfigRepository
import org.dhis2.commons.featureconfig.model.Feature
import org.dhis2.commons.resources.ResourceManager
import org.dhis2.databinding.EnrollmentActivityBinding
import org.dhis2.form.data.GeometryController
import org.dhis2.form.data.GeometryParserImpl
Expand Down Expand Up @@ -51,6 +52,9 @@ class EnrollmentActivity : ActivityGlobalAbstract(), EnrollmentView {
private var forRelationship: Boolean = false
private lateinit var formView: FormView

@Inject
lateinit var resourceManager: ResourceManager

@Inject
lateinit var presenter: EnrollmentPresenterImpl

Expand Down Expand Up @@ -343,7 +347,11 @@ class EnrollmentActivity : ActivityGlobalAbstract(), EnrollmentView {
binding.title.visibility = View.VISIBLE
binding.teiDataHeader.root.visibility = View.GONE
binding.title.text =
String.format(getString(R.string.enroll_in), presenter.getProgram()?.displayName())
resourceManager.formatWithEnrollmentLabel(
programUid = presenter.getProgram()?.uid()!!,
R.string.new_enrollment,
1,
)
}
}

Expand Down
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(programUid, resourceManager)
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.dhis2.commons.resources.ResourceManager
import org.hisp.dhis.android.core.event.EventNonEditableReason

class EventDetailResourcesProvider(
private val programUid: String,
private val resourceManager: ResourceManager,
) {
fun provideDueDate() = resourceManager.getString(R.string.due_date)
Expand All @@ -24,7 +25,11 @@ class EventDetailResourcesProvider(
EventNonEditableReason.NO_CATEGORY_COMBO_ACCESS ->
resourceManager.getString(R.string.edition_no_catcombo_access)
EventNonEditableReason.ENROLLMENT_IS_NOT_OPEN ->
resourceManager.getString(R.string.edition_enrollment_is_no_open)
resourceManager.formatWithEnrollmentLabel(
programUid,
R.string.edition_enrollment_is_no_open_V2,
1,
)
EventNonEditableReason.ORGUNIT_IS_NOT_IN_CAPTURE_SCOPE ->
resourceManager.getString(R.string.edition_orgunit_capture_scope)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ public void couldNotDownload(String typeName) {
@Override
public void showBreakTheGlass(String teiUid, String enrollmentUid) {
new BreakTheGlassBottomDialog()
.setProgram(presenter.getProgram().uid())
.setPositiveButton(reason -> {
viewModel.onDownloadTei(teiUid, enrollmentUid, reason);
return Unit.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,23 @@ EnrollmentUiDataHelper enrollmentUiDataHelper(Context context) {

@Provides
@PerActivity
SearchSortingValueSetter searchSortingValueSetter(Context context, D2 d2, EnrollmentUiDataHelper enrollmentUiDataHelper) {
SearchSortingValueSetter searchSortingValueSetter(
Context context,
D2 d2,
EnrollmentUiDataHelper enrollmentUiDataHelper,
ResourceManager resourceManager) {
String unknownLabel = context.getString(R.string.unknownValue);
String eventDateLabel = context.getString(R.string.most_recent_event_date);
String enrollmentStatusLabel = context.getString(R.string.filters_title_enrollment_status);
String enrollmentDateDefaultLabel = context.getString(R.string.enrollment_date);
String enrollmentStatusLabel = resourceManager.formatWithEnrollmentLabel(
initialProgram,
R.string.filters_title_enrollment_status,
1,
false);
String enrollmentDateDefaultLabel = resourceManager.formatWithEnrollmentLabel(
initialProgram,
R.string.enrollment_date_V2,
1,
false);
String uiDateFormat = DateUtils.SIMPLE_DATE_FORMAT;
return new SearchSortingValueSetter(d2,
unknownLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class TEICardMapper(
enrolledPrograms = searchTEIModel.programInfo,
)
checkEnrollmentStatus(
programUid = searchTEIModel.selectedEnrollment.program()!!,
list = list,
status = searchTEIModel.selectedEnrollment?.status(),
)
Expand Down Expand Up @@ -175,35 +176,46 @@ class TEICardMapper(
}

private fun checkEnrollmentStatus(
programUid: String,
list: MutableList<AdditionalInfoItem>,
status: EnrollmentStatus?,
) {
val item = when (status) {
EnrollmentStatus.COMPLETED -> {
val label = resourceManager.formatWithEnrollmentLabel(
programUid,
R.string.enrollment_completed_V2,
1,
)
AdditionalInfoItem(
icon = {
Icon(
imageVector = Icons.Outlined.Check,
contentDescription = resourceManager.getString(R.string.enrollment_completed),
contentDescription = label,
tint = AdditionalInfoItemColor.SUCCESS.color,
)
},
value = resourceManager.getString(R.string.enrollment_completed),
value = label,
isConstantItem = true,
color = AdditionalInfoItemColor.SUCCESS.color,
)
}

EnrollmentStatus.CANCELLED -> {
val label = resourceManager.formatWithEnrollmentLabel(
programUid,
R.string.enrollment_cancelled_V2,
1,
)
AdditionalInfoItem(
icon = {
Icon(
imageVector = Icons.Outlined.Close,
contentDescription = resourceManager.getString(R.string.enrollment_cancelled),
contentDescription = label,
tint = AdditionalInfoItemColor.DISABLED.color,
)
},
value = resourceManager.getString(R.string.enrollment_cancelled),
value = label,
isConstantItem = true,
color = AdditionalInfoItemColor.DISABLED.color,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.dhis2.commons.filters.FilterManager
import org.dhis2.commons.filters.Filters
import org.dhis2.commons.network.NetworkUtils
import org.dhis2.commons.popupmenu.AppMenuHelper
import org.dhis2.commons.resources.ResourceManager
import org.dhis2.commons.sync.OnDismissListener
import org.dhis2.commons.sync.SyncContext
import org.dhis2.databinding.ActivityDashboardMobileBinding
Expand Down Expand Up @@ -83,6 +84,9 @@ class TeiDashboardMobileActivity :
@Inject
lateinit var networkUtils: NetworkUtils

@Inject
lateinit var resourceManager: ResourceManager

lateinit var programModel: DashboardProgramModel
var teiUid: String? = null
var programUid: String? = null
Expand Down Expand Up @@ -157,7 +161,8 @@ class TeiDashboardMobileActivity :
super.onCreate(savedInstanceState)
groupByStage = MutableLiveData(presenter.programGrouping)
currentEnrollment = MutableLiveData()
dashboardViewModel = ViewModelProvider(this, viewModelFactory)[DashboardViewModel::class.java]
dashboardViewModel =
ViewModelProvider(this, viewModelFactory)[DashboardViewModel::class.java]
binding = DataBindingUtil.setContentView(this, R.layout.activity_dashboard_mobile)
showLoadingProgress(true)
binding.presenter = presenter
Expand Down Expand Up @@ -290,7 +295,10 @@ class TeiDashboardMobileActivity :
android.R.anim.fade_in,
android.R.anim.fade_out,
)
startActivity(intent(context, teiUid, programUid, enrollmentUid), activityOptions.toBundle())
startActivity(
intent(context, teiUid, programUid, enrollmentUid),
activityOptions.toBundle(),
)
finish()
}
}
Expand Down Expand Up @@ -578,6 +586,20 @@ class TeiDashboardMobileActivity :
deleteEnrollmentItem.isVisible = presenter.checkIfEnrollmentCanBeDeleted(enrollmentUid)

if (enrollmentUid != null) {
popupMenu.menu.findItem(R.id.deleteEnrollment).let { deleteEnrollmentItem ->
deleteEnrollmentItem.title = resourceManager.formatWithEnrollmentLabel(
programUid!!,
R.string.dashboard_menu_delete_enrollment_V2,
1,
)
}
popupMenu.menu.findItem(R.id.programSelector).let { programSelectorItem ->
programSelectorItem.title = resourceManager.formatWithEnrollmentLabel(
programUid!!,
R.string.program_selector_V2,
2,
)
}
val status = presenter.getEnrollmentStatus(enrollmentUid)
if (status == EnrollmentStatus.COMPLETED) {
popupMenu.menu.findItem(R.id.complete).isVisible = false
Expand Down Expand Up @@ -611,14 +633,17 @@ class TeiDashboardMobileActivity :
EnrollmentStatus.COMPLETED,
)
}

R.id.activate -> dashboardViewModel.updateEnrollmentStatus(
programModel,
EnrollmentStatus.ACTIVE,
)

R.id.deactivate -> dashboardViewModel.updateEnrollmentStatus(
programModel,
EnrollmentStatus.CANCELLED,
)

R.id.share -> startQRActivity()
}
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ class InfoBarMapper(
InfoBarType.FOLLOW_UP -> resourceManager.getString(R.string.marked_follow_up)
InfoBarType.ENROLLMENT_STATUS -> {
if (item.currentEnrollmentStatus == EnrollmentStatus.COMPLETED) {
resourceManager.getString(R.string.enrollment_completed)
resourceManager.formatWithEnrollmentLabel(
item.currentProgram.uid(),
R.string.enrollment_completed_V2,
1,
)
} else {
resourceManager.getString(R.string.enrollment_cancelled)
resourceManager.formatWithEnrollmentLabel(
item.currentProgram.uid(),
R.string.enrollment_cancelled_V2,
1,
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class TeiDashboardCardMapper(
}
}.also { list ->
addEnrollmentDate(
item.currentProgram.uid(),
list,
item.currentProgram.enrollmentDateLabel(),
item.currentEnrollment.enrollmentDate(),
Expand Down Expand Up @@ -211,13 +212,20 @@ class TeiDashboardCardMapper(
}

private fun addEnrollmentDate(
programUid: String,
list: MutableList<AdditionalInfoItem>,
programLabel: String?,
enrollmentDate: Date?,
) {
list.add(
AdditionalInfoItem(
key = "${programLabel ?: resourceManager.getString(R.string.enrollment_date)}:",
key = "${
programLabel ?: resourceManager.formatWithEnrollmentLabel(
programUid,
R.string.enrollment_date_V2,
1,
)
}:",
value = enrollmentDate.toUi() ?: "",
isConstantItem = true,
),
Expand Down
33 changes: 0 additions & 33 deletions app/src/main/java/org/dhis2/utils/D2EditionMapper.kt

This file was deleted.

Loading

0 comments on commit 039ffb7

Please sign in to comment.