Skip to content

Commit

Permalink
Show the same period format label on input and bottomsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdyrod committed Feb 27, 2025
1 parent b186a6a commit ad3f0c4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;

public class DataSetInitialActivity extends ActivityGlobalAbstract implements DataSetInitialContract.View {

Expand Down Expand Up @@ -150,11 +151,17 @@ private void checkPeriodIsValidForOrgUnit(OrganisationUnit selectedOrgUnit) {
public void showPeriodSelector(PeriodType periodType, Integer openFuturePeriods) {
DataSetPeriodDialog dialog =
new DataSetPeriodDialog(getDataSetUid(), periodType, selectedPeriod, openFuturePeriods);
dialog.setOnDateSelectedListener(date -> {
dialog.setOnDateSelectedListener((date, periodName) -> {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
selectedPeriod = calendar.getTime();
binding.dataSetPeriodEditText.setText(periodUtils.getPeriodUIString(periodType, date, Locale.getDefault()));
String periodLabel = "";
if (periodType == PeriodType.Daily) {
periodLabel = periodUtils.getPeriodUIString(periodType, date, Locale.getDefault());
} else {
periodLabel = periodName;
}
binding.dataSetPeriodEditText.setText(periodLabel);
checkCatOptionsAreValidForOrgUnit(selectedPeriod);
checkActionVisivbility();
return Unit.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DataSetPeriodDialog(
private val openFuturePeriods: Int,
) : BottomSheetDialogFragment() {

lateinit var onDateSelectedListener: (Date) -> Unit
lateinit var onDateSelectedListener: (Date, String) -> Unit

val viewModel by viewModel<DatasetPeriodViewModel>()

Expand Down Expand Up @@ -84,7 +84,7 @@ class DataSetPeriodDialog(
onCancel = { dismiss() },
onConfirm = { date ->
date.selectedDateMillis?.let {
onDateSelectedListener(Date(it))
onDateSelectedListener(Date(it), "")
}
dismiss()
},
Expand All @@ -111,8 +111,8 @@ class DataSetPeriodDialog(
PeriodSelectorContent(
periods = periods,
scrollState = scrollState,
) { selectedDate ->
onDateSelectedListener(selectedDate)
) { selectedDate, periodName ->
onDateSelectedListener(selectedDate, periodName)
dismiss()
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class ScheduledEventActivity : ActivityGlobalAbstract(), ScheduledEventContract.
PeriodSelectorContent(
periods = periods,
scrollState = scrollState,
) { selectedPeriod ->
) { selectedPeriod, _ ->
presenter.setDueDate(selectedPeriod)
bottomSheetDialog.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class EventDetailsFragment : FragmentGlobalAbstract() {
PeriodSelectorContent(
periods = periods,
scrollState = scrollState,
) { selectedDate ->
) { selectedDate, _ ->
viewModel.setUpEventReportDate(selectedDate)
bottomSheetDialog.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class SchedulingDialog : BottomSheetDialogFragment() {
PeriodSelectorContent(
periods = periods,
scrollState = scrollState,
) { selectedDate ->
) { selectedDate, _ ->
viewModel.setUpEventReportDate(selectedDate)
bottomSheetDialog.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import java.util.Date
fun PeriodSelectorContent(
periods: LazyPagingItems<Period>,
scrollState: LazyListState,
onPeriodSelected: (Date) -> Unit,
onPeriodSelected: (Date, String) -> Unit,
) {
LazyColumn(
modifier = Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -64,7 +64,9 @@ fun PeriodSelectorContent(
selected = period?.selected == true,
enabled = period?.enabled == true,
) {
period?.startDate?.let(onPeriodSelected)
period?.startDate?.let {
onPeriodSelected(it, period.name)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion form/src/main/java/org/dhis2/form/ui/FormView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class FormView : Fragment() {
PeriodSelectorContent(
periods = periods,
scrollState = scrollState,
) { selectedDate ->
) { selectedDate, _ ->
val dateString = DateUtils.oldUiDateFormat().format(selectedDate)
intentHandler(
FormIntent.OnSave(
Expand Down

0 comments on commit ad3f0c4

Please sign in to comment.