From e152b50cd5738538187047b8c142061403c3baf4 Mon Sep 17 00:00:00 2001 From: maulidkategile Date: Thu, 19 Oct 2023 13:28:15 +0300 Subject: [PATCH] make a dialog not dismissable if form errors available for improved ux --- ...ectChildForGroupSessionDialogFragment.java | 36 +++++++++++-------- opensrp-chw/src/kk/res/values-sw/strings.xml | 2 ++ opensrp-chw/src/kk/res/values/strings.xml | 2 ++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/opensrp-chw/src/kk/java/org/smartregister/chw/fragment/SelectChildForGroupSessionDialogFragment.java b/opensrp-chw/src/kk/java/org/smartregister/chw/fragment/SelectChildForGroupSessionDialogFragment.java index 9d1462b5f..59636e793 100644 --- a/opensrp-chw/src/kk/java/org/smartregister/chw/fragment/SelectChildForGroupSessionDialogFragment.java +++ b/opensrp-chw/src/kk/java/org/smartregister/chw/fragment/SelectChildForGroupSessionDialogFragment.java @@ -148,19 +148,7 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { selected_group_lv_adapter.setSelectedPosition(position); }); - builder.setPositiveButton(R.string.ok, (dialog, which) -> { - if (selectedPosition1 == -1) { - Toast.makeText(requireContext(), "Caregiver information missing", Toast.LENGTH_SHORT).show(); - dialogDismissListener.onFailure(); - dialog.dismiss(); - }else if (selectedPosition2 == -1 && childrenDividedIntoGroups) { - Toast.makeText(requireContext(), "Child missing the group", Toast.LENGTH_SHORT).show(); - dialogDismissListener.onFailure(); - dialog.dismiss(); - }else { - handleSuccess(dialog); - } - }); + builder.setPositiveButton(R.string.ok, null); builder.setNegativeButton(R.string.cancel, (dialog, which) -> { dialogDismissListener.onFailure(); @@ -170,6 +158,27 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { return builder.create(); } + @Override + public void onResume() { + AlertDialog dialog = (AlertDialog) getDialog(); + assert dialog != null; + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() + { + @Override + public void onClick(View v) + { + if (selectedPosition1 == -1) { + dialogValidationFail(dialog, getString(R.string.came_with_pc_lv)); + }else if (selectedPosition2 == -1 && childrenDividedIntoGroups) { + dialogValidationFail(dialog, getString(R.string.selected_group_lv)); + }else { + handleSuccess(dialog); + } + } + }); + super.onResume(); + } + void handleSuccess(DialogInterface dialogInterface){ String otherCompanion = who_came_with_the_child_lv_other.getText().toString(); if(selectedPosition1 == 0){ @@ -212,7 +221,6 @@ void handleSuccess(DialogInterface dialogInterface){ void dialogValidationFail(DialogInterface dialogInterface,String message){ Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show(); dialogDismissListener.onFailure(); - dialogInterface.dismiss(); } void dialogValidationSuccess(DialogInterface dialogInterface){ diff --git a/opensrp-chw/src/kk/res/values-sw/strings.xml b/opensrp-chw/src/kk/res/values-sw/strings.xml index 794943ae3..e27fcaeb2 100644 --- a/opensrp-chw/src/kk/res/values-sw/strings.xml +++ b/opensrp-chw/src/kk/res/values-sw/strings.xml @@ -212,4 +212,6 @@ Tafadhari jaza mtu mwingine ambae alikuja kwa niaba ya mlezi wa mtoto Tafadhari chagua walezi/watu wengine waliohudhuria Tafadhari jaza mlezi/mtu mwingine aliyehudhuria + Tafadhari bainisha kama mtoto amekuja na mlezi wake + Tafadhari chagua kundi la mototo \ No newline at end of file diff --git a/opensrp-chw/src/kk/res/values/strings.xml b/opensrp-chw/src/kk/res/values/strings.xml index ba08c1e64..f928c8263 100644 --- a/opensrp-chw/src/kk/res/values/strings.xml +++ b/opensrp-chw/src/kk/res/values/strings.xml @@ -231,4 +231,6 @@ Other caregiver representative missing The companions of caregiver missing Other companion of caregiver missing + Caregiver information missing + Child missing the group \ No newline at end of file