|
10 | 10 | import android.database.Cursor; |
11 | 11 | import android.inputmethodservice.Keyboard; |
12 | 12 | import android.os.Bundle; |
| 13 | +import android.text.Editable; |
13 | 14 | import android.text.InputType; |
| 15 | +import android.text.TextWatcher; |
14 | 16 | import android.view.Menu; |
15 | 17 | import android.view.MenuInflater; |
16 | 18 | import android.view.MenuItem; |
@@ -93,7 +95,7 @@ public static Intent newIntent(@NonNull Context context, @NonNull String claimUU |
93 | 95 | RadioButton rbEmergency, rbReferral, rbOther, rbPositive, rbNegative; |
94 | 96 | ImageButton btnScan; |
95 | 97 | LinearLayout llFagepFields; |
96 | | - TextInputLayout ettClaimPrefix, ettGuaranteeNo; |
| 98 | + TextInputLayout ettClaimPrefix, ettGuaranteeNo, ettClaimCode; |
97 | 99 |
|
98 | 100 | @Override |
99 | 101 | protected void onCreate(Bundle savedInstanceState) { |
@@ -140,6 +142,10 @@ protected void onCreate(Bundle savedInstanceState) { |
140 | 142 | etVisitType = findViewById(R.id.etVisitType); |
141 | 143 | ettClaimPrefix = findViewById(R.id.ettClaimPrefix); |
142 | 144 | ettGuaranteeNo = findViewById(R.id.ettGuaranteeNo); |
| 145 | + View claimCodeParent = (View) etClaimCode.getParent(); |
| 146 | + if (claimCodeParent instanceof TextInputLayout) { |
| 147 | + ettClaimCode = (TextInputLayout) claimCodeParent; |
| 148 | + } |
143 | 149 |
|
144 | 150 | String[] visitTypes = getResources().getStringArray(R.array.visitType); |
145 | 151 | ArrayAdapter<String> visitTypeAdapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, visitTypes); |
@@ -170,6 +176,25 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon |
170 | 176 | rgVisitType.setVisibility(View.GONE); |
171 | 177 | ettGuaranteeNo.setVisibility(View.GONE); |
172 | 178 |
|
| 179 | + TextWatcher claimCodeUniquenessWatcher = new TextWatcher() { |
| 180 | + @Override |
| 181 | + public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 182 | + // no-op |
| 183 | + } |
| 184 | + |
| 185 | + @Override |
| 186 | + public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 187 | + // no-op |
| 188 | + } |
| 189 | + |
| 190 | + @Override |
| 191 | + public void afterTextChanged(Editable s) { |
| 192 | + validateLocalClaimCodeUniqueness(); |
| 193 | + } |
| 194 | + }; |
| 195 | + etClaimCode.addTextChangedListener(claimCodeUniquenessWatcher); |
| 196 | + etClaimPrefix.addTextChangedListener(claimCodeUniquenessWatcher); |
| 197 | + |
173 | 198 | tvItemTotal.setText("0"); |
174 | 199 | tvServiceTotal.setText("0"); |
175 | 200 |
|
@@ -842,6 +867,10 @@ private boolean isValidData() { |
842 | 867 | return false; |
843 | 868 | } |
844 | 869 |
|
| 870 | + if (!validateLocalClaimCodeUniqueness()) { |
| 871 | + return false; |
| 872 | + } |
| 873 | + |
845 | 874 | // if (rgVisitType.getCheckedRadioButtonId() == -1) { |
846 | 875 | // showValidationDialog(rgVisitType, getResources().getString(R.string.MissingVisitType)); |
847 | 876 | // return false; |
@@ -970,4 +999,47 @@ private boolean saveClaim() { |
970 | 999 | return true; |
971 | 1000 | } |
972 | 1001 |
|
| 1002 | + private boolean validateLocalClaimCodeUniqueness() { |
| 1003 | + if (getIntent().hasExtra(EXTRA_CLAIM_UUID)) { |
| 1004 | + if (ettClaimCode != null) { |
| 1005 | + ettClaimCode.setError(null); |
| 1006 | + ettClaimCode.setErrorEnabled(false); |
| 1007 | + } else { |
| 1008 | + etClaimCode.setError(null); |
| 1009 | + } |
| 1010 | + return true; |
| 1011 | + } |
| 1012 | + |
| 1013 | + String finalCode = etClaimPrefix.getText().toString() + etClaimCode.getText().toString(); |
| 1014 | + if (finalCode.trim().isEmpty()) { |
| 1015 | + if (ettClaimCode != null) { |
| 1016 | + ettClaimCode.setError(null); |
| 1017 | + ettClaimCode.setErrorEnabled(false); |
| 1018 | + } else { |
| 1019 | + etClaimCode.setError(null); |
| 1020 | + } |
| 1021 | + return true; |
| 1022 | + } |
| 1023 | + |
| 1024 | + boolean exists = sqlHandler.existsClaimCode(finalCode); |
| 1025 | + if (exists) { |
| 1026 | + String errorMessage = getResources().getString(R.string.ClaimNumberExist); |
| 1027 | + if (ettClaimCode != null) { |
| 1028 | + ettClaimCode.setErrorEnabled(true); |
| 1029 | + ettClaimCode.setError(errorMessage); |
| 1030 | + } else { |
| 1031 | + etClaimCode.setError(errorMessage); |
| 1032 | + } |
| 1033 | + return false; |
| 1034 | + } |
| 1035 | + |
| 1036 | + if (ettClaimCode != null) { |
| 1037 | + ettClaimCode.setError(null); |
| 1038 | + ettClaimCode.setErrorEnabled(false); |
| 1039 | + } else { |
| 1040 | + etClaimCode.setError(null); |
| 1041 | + } |
| 1042 | + return true; |
| 1043 | + } |
| 1044 | + |
973 | 1045 | } |
0 commit comments