110110
111111@ RuntimePermissions
112112public class AddEditPatientFragment extends ACBaseFragment <AddEditPatientContract .Presenter > implements AddEditPatientContract .View , CameraOrGalleryPickerDialog .onInputSelected {
113-
114113 AlertDialog alertDialog ;
115114 private FragmentPatientInfoBinding binding ;
116115 private LocalDate birthDate ;
@@ -170,8 +169,8 @@ public void setErrorsVisibility(boolean givenNameError,
170169
171170 dateTimeFormatter = DateTimeFormat .forPattern (DateUtils .DEFAULT_DATE_FORMAT );
172171 String minimumDate = DateTime .now ().minusYears (
173- ApplicationConstants .RegisterPatientRequirements .MAX_PATIENT_AGE )
174- .toString (dateTimeFormatter );
172+ ApplicationConstants .RegisterPatientRequirements .MAX_PATIENT_AGE )
173+ .toString (dateTimeFormatter );
175174 String maximumDate = DateTime .now ().toString (dateTimeFormatter );
176175 if (binding .unidentifiedCheckbox .isChecked ()) {
177176 binding .dobError .setText (getString (R .string .dob_error_for_unidentified ));
@@ -209,21 +208,20 @@ private Patient updatePatientWithData(Patient patient) {
209208
210209 List <PersonAddress > addresses = new ArrayList <>();
211210 patient .setAddresses (addresses );
212-
213211 } else {
214212 // Validate address
215213 if (ViewUtils .isEmpty (binding .addressOne )
216- && ViewUtils .isEmpty (binding .addressTwo )
217- && ViewUtils .isEmpty (binding .cityAutoComplete )
218- && ViewUtils .isEmpty (binding .postalCode )
219- && ViewUtils .isCountryCodePickerEmpty (binding .countryCodeSpinner )
220- && ViewUtils .isEmpty (binding .stateAutoComplete )) {
214+ && ViewUtils .isEmpty (binding .addressTwo )
215+ && ViewUtils .isEmpty (binding .cityAutoComplete )
216+ && ViewUtils .isEmpty (binding .postalCode )
217+ && ViewUtils .isCountryCodePickerEmpty (binding .countryCodeSpinner )
218+ && ViewUtils .isEmpty (binding .stateAutoComplete )) {
221219
222220 binding .addressError .setText (R .string .atleastone );
223221 binding .textInputLayoutAddress .setErrorEnabled (true );
224222 binding .textInputLayoutAddress .setError (getString (R .string .atleastone ));
225223 } else if (!ViewUtils .validateText (ViewUtils .getInput (binding .addressOne ), ViewUtils .ILLEGAL_ADDRESS_CHARACTERS )
226- || !ViewUtils .validateText (ViewUtils .getInput (binding .addressTwo ), ViewUtils .ILLEGAL_ADDRESS_CHARACTERS )) {
224+ || !ViewUtils .validateText (ViewUtils .getInput (binding .addressTwo ), ViewUtils .ILLEGAL_ADDRESS_CHARACTERS )) {
227225
228226 binding .addressError .setText (getString (R .string .addr_invalid_error ));
229227 binding .textInputLayoutAddress .setErrorEnabled (true );
@@ -312,7 +310,7 @@ private Patient updatePatientWithData(Patient patient) {
312310 String unvalidatedDate = binding .dobEditText .getText ().toString ().trim ();
313311
314312 DateTime minDateOfBirth = DateTime .now ().minusYears (
315- ApplicationConstants .RegisterPatientRequirements .MAX_PATIENT_AGE );
313+ ApplicationConstants .RegisterPatientRequirements .MAX_PATIENT_AGE );
316314 DateTime maxDateOfBirth = DateTime .now ();
317315
318316 if (DateUtils .validateDate (unvalidatedDate , minDateOfBirth , maxDateOfBirth )) {
@@ -404,16 +402,16 @@ public void showUpgradeRegistrationModuleInfo() {
404402 @ Override
405403 public boolean areFieldsNotEmpty () {
406404 return (!ViewUtils .isEmpty (binding .firstName ) ||
407- (!ViewUtils .isEmpty (binding .middlename )) ||
408- (!ViewUtils .isEmpty (binding .surname )) ||
409- (!ViewUtils .isEmpty (binding .dobEditText )) ||
410- (!ViewUtils .isEmpty (binding .estimatedYear )) ||
411- (!ViewUtils .isEmpty (binding .addressOne )) ||
412- (!ViewUtils .isEmpty (binding .addressTwo )) ||
413- (!ViewUtils .isEmpty (binding .cityAutoComplete )) ||
414- (!ViewUtils .isEmpty (binding .stateAutoComplete )) ||
415- (!ViewUtils .isCountryCodePickerEmpty (binding .countryCodeSpinner )) ||
416- (!ViewUtils .isEmpty (binding .postalCode )));
405+ (!ViewUtils .isEmpty (binding .middlename )) ||
406+ (!ViewUtils .isEmpty (binding .surname )) ||
407+ (!ViewUtils .isEmpty (binding .dobEditText )) ||
408+ (!ViewUtils .isEmpty (binding .estimatedYear )) ||
409+ (!ViewUtils .isEmpty (binding .addressOne )) ||
410+ (!ViewUtils .isEmpty (binding .addressTwo )) ||
411+ (!ViewUtils .isEmpty (binding .cityAutoComplete )) ||
412+ (!ViewUtils .isEmpty (binding .stateAutoComplete )) ||
413+ (!ViewUtils .isCountryCodePickerEmpty (binding .countryCodeSpinner )) ||
414+ (!ViewUtils .isEmpty (binding .postalCode )));
417415 }
418416
419417 @ Override
@@ -489,7 +487,7 @@ private void fillFields(final Patient patient) {
489487 if (StringUtils .notNull (patient .getBirthdate ()) || StringUtils .notEmpty (patient .getBirthdate ())) {
490488 bdt = DateUtils .convertTimeString (patient .getBirthdate ());
491489 binding .dobEditText .setText (DateUtils .convertTime (DateUtils .convertTime (bdt .toString (), DateUtils .OPEN_MRS_REQUEST_FORMAT ),
492- DateUtils .DEFAULT_DATE_FORMAT ));
490+ DateUtils .DEFAULT_DATE_FORMAT ));
493491 }
494492
495493 if ((StringValue .MALE ).equals (patient .getGender ())) {
@@ -528,7 +526,7 @@ private void addSuggestionsToCities() {
528526 if (resourceId != 0 ) {
529527 String [] states = getContext ().getResources ().getStringArray (resourceId );
530528 ArrayAdapter <String > state_adapter = new ArrayAdapter <>(getContext (),
531- android .R .layout .simple_dropdown_item_1line , states );
529+ android .R .layout .simple_dropdown_item_1line , states );
532530 binding .stateAutoComplete .setAdapter (state_adapter );
533531 }
534532 }
@@ -596,8 +594,9 @@ public void afterTextChanged(Editable s) {
596594
597595 binding .capturePhoto .setOnClickListener (view -> {
598596 boolean showRemoveButton = true ;
599- if (patientPhoto == null )
597+ if (patientPhoto == null ) {
600598 showRemoveButton = false ;
599+ }
601600 CameraOrGalleryPickerDialog cameraOrGalleryPickerDialog = new CameraOrGalleryPickerDialog (showRemoveButton );
602601 cameraOrGalleryPickerDialog .setTargetFragment (AddEditPatientFragment .this , 1000 );
603602 cameraOrGalleryPickerDialog .show (getFragmentManager (), "tag" );
@@ -637,11 +636,11 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
637636 AutocompleteSessionToken token = AutocompleteSessionToken .newInstance ();
638637
639638 FindAutocompletePredictionsRequest request = FindAutocompletePredictionsRequest .builder ()
640- .setCountry (binding .countryCodeSpinner .getSelectedCountryNameCode ().toLowerCase ())
641- .setTypeFilter (TypeFilter .CITIES )
642- .setSessionToken (token )
643- .setQuery (binding .cityAutoComplete .getText ().toString ())
644- .build ();
639+ .setCountry (binding .countryCodeSpinner .getSelectedCountryNameCode ().toLowerCase ())
640+ .setTypeFilter (TypeFilter .CITIES )
641+ .setSessionToken (token )
642+ .setQuery (binding .cityAutoComplete .getText ().toString ())
643+ .build ();
645644
646645 placesClient .findAutocompletePredictions (request ).addOnSuccessListener (response -> {
647646 binding .cityProgressBar .setVisibility (View .GONE );
@@ -734,10 +733,11 @@ public void performFunction(int position) {
734733 }
735734
736735 Intent i ;
737- if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .KITKAT )
736+ if (android .os .Build .VERSION .SDK_INT >= android .os .Build .VERSION_CODES .KITKAT ) {
738737 i = new Intent (Intent .ACTION_OPEN_DOCUMENT );
739- else
738+ } else {
740739 i = new Intent (Intent .ACTION_GET_CONTENT );
740+ }
741741 i .addCategory (Intent .CATEGORY_OPENABLE );
742742 i .setType ("image/*" );
743743 startActivityForResult (i , ApplicationConstants .RequestCodes .GALLERY_IMAGE_REQUEST );
@@ -762,22 +762,22 @@ public void capturePhoto() {
762762 @ OnShowRationale ({Manifest .permission .CAMERA , Manifest .permission .WRITE_EXTERNAL_STORAGE })
763763 public void showRationaleForCamera (final PermissionRequest request ) {
764764 new AlertDialog .Builder (getActivity ())
765- .setMessage (R .string .permission_camera_rationale )
766- .setPositiveButton (R .string .button_allow , (dialog , which ) -> request .proceed ())
767- .setNegativeButton (R .string .button_deny , (dialog , button ) -> request .cancel ())
768- .show ();
765+ .setMessage (R .string .permission_camera_rationale )
766+ .setPositiveButton (R .string .button_allow , (dialog , which ) -> request .proceed ())
767+ .setNegativeButton (R .string .button_deny , (dialog , button ) -> request .cancel ())
768+ .show ();
769769 }
770770
771771 @ OnPermissionDenied ({Manifest .permission .CAMERA , Manifest .permission .WRITE_EXTERNAL_STORAGE })
772772 public void showDeniedForCamera () {
773773 createSnackbarLong (R .string .permission_camera_denied )
774- .show ();
774+ .show ();
775775 }
776776
777777 @ OnNeverAskAgain ({Manifest .permission .CAMERA , Manifest .permission .WRITE_EXTERNAL_STORAGE })
778778 public void showNeverAskForCamera () {
779779 createSnackbarLong (R .string .permission_camera_neverask )
780- .show ();
780+ .show ();
781781 }
782782
783783 private Snackbar createSnackbarLong (int stringId ) {
@@ -823,8 +823,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
823823
824824 private void openCropActivity (Uri sourceUri , Uri destinationUri ) {
825825 UCrop .of (sourceUri , destinationUri )
826- .withAspectRatio (ApplicationConstants .ASPECT_RATIO_FOR_CROPPING , ApplicationConstants .ASPECT_RATIO_FOR_CROPPING )
827- .start (getActivity (), AddEditPatientFragment .this );
826+ .withAspectRatio (ApplicationConstants .ASPECT_RATIO_FOR_CROPPING , ApplicationConstants .ASPECT_RATIO_FOR_CROPPING )
827+ .start (getActivity (), AddEditPatientFragment .this );
828828 }
829829
830830 private String getUniqueImageFileName () {
@@ -879,11 +879,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
879879 break ;
880880 case R .id .actionReset :
881881 new AlertDialog .Builder (getActivity ())
882- .setTitle (R .string .dialog_title_reset_patient )
883- .setMessage (R .string .reset_dialog_message )
884- .setPositiveButton (R .string .dialog_button_ok , (DialogInterface dialogInterface , int i ) -> resetAction ())
885- .setNegativeButton (R .string .dialog_button_cancel , null )
886- .show ();
882+ .setTitle (R .string .dialog_title_reset_patient )
883+ .setMessage (R .string .reset_dialog_message )
884+ .setPositiveButton (R .string .dialog_button_ok , (DialogInterface dialogInterface , int i ) -> resetAction ())
885+ .setNegativeButton (R .string .dialog_button_cancel , null )
886+ .show ();
887887 break ;
888888 default :
889889 // Do nothing
@@ -899,15 +899,15 @@ private void submitAction() {
899899 alertDialogBuilder .setTitle (R .string .mark_patient_deceased );
900900 // set dialog message
901901 alertDialogBuilder
902- .setMessage (R .string .mark_patient_deceased_notice )
903- .setCancelable (false )
904- .setPositiveButton (R .string .mark_patient_deceased_proceed , (dialog , id ) -> {
905- dialog .cancel ();
906- mPresenter .confirmUpdate (updatePatient (updatedPatient ));
907- })
908- .setNegativeButton (R .string .dialog_button_cancel , (dialog , id ) -> {
909- alertDialog .cancel ();
910- });
902+ .setMessage (R .string .mark_patient_deceased_notice )
903+ .setCancelable (false )
904+ .setPositiveButton (R .string .mark_patient_deceased_proceed , (dialog , id ) -> {
905+ dialog .cancel ();
906+ mPresenter .confirmUpdate (updatePatient (updatedPatient ));
907+ })
908+ .setNegativeButton (R .string .dialog_button_cancel , (dialog , id ) -> {
909+ alertDialog .cancel ();
910+ });
911911 alertDialog = alertDialogBuilder .create ();
912912 alertDialog .show ();
913913 } else {
0 commit comments