|
2 | 2 |
|
3 | 3 | import android.app.ProgressDialog; |
4 | 4 | import android.app.TimePickerDialog; |
| 5 | +import android.content.DialogInterface; |
5 | 6 | import android.content.Intent; |
6 | 7 | import android.content.SharedPreferences; |
7 | 8 | import android.os.AsyncTask; |
|
19 | 20 | import androidx.constraintlayout.widget.ConstraintLayout; |
20 | 21 | import androidx.constraintlayout.widget.ConstraintSet; |
21 | 22 |
|
| 23 | +import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
22 | 24 | import com.google.android.material.textfield.TextInputEditText; |
23 | 25 | import com.poupa.attestationdeplacement.generator.Attestation; |
24 | 26 | import com.poupa.attestationdeplacement.generator.AttestationDeplacementDerogatoireGenerator; |
@@ -171,13 +173,97 @@ public void onClick(View v) { |
171 | 173 | * @param v |
172 | 174 | */ |
173 | 175 | public void startGenerate(View v) { |
174 | | - new Thread(new Runnable() { |
175 | | - @Override |
176 | | - public void run() { |
177 | | - final GeneratePdfTask task = new GeneratePdfTask(); |
178 | | - task.execute(); |
179 | | - } |
180 | | - }).start(); |
| 176 | + boolean valid = checkFields(); |
| 177 | + |
| 178 | + if (valid) { |
| 179 | + new Thread(new Runnable() { |
| 180 | + @Override |
| 181 | + public void run() { |
| 182 | + final GeneratePdfTask task = new GeneratePdfTask(); |
| 183 | + task.execute(); |
| 184 | + } |
| 185 | + }).start(); |
| 186 | + } |
| 187 | + } |
| 188 | + |
| 189 | + public boolean checkFields() { |
| 190 | + if (surnameInput.getText().toString().isEmpty()) { |
| 191 | + displayAlertDialog(getString(R.string.surname_missing)); |
| 192 | + return false; |
| 193 | + } |
| 194 | + |
| 195 | + if (lastNameInput.getText().toString().isEmpty()) { |
| 196 | + displayAlertDialog(getString(R.string.lastname_missing)); |
| 197 | + return false; |
| 198 | + } |
| 199 | + |
| 200 | + if (birthDateInput.getText().toString().equals("JJ/MM/AAAA")) { |
| 201 | + displayAlertDialog(getString(R.string.birthdate_missing)); |
| 202 | + return false; |
| 203 | + } |
| 204 | + |
| 205 | + if (birthPlaceInput.getText().toString().isEmpty()) { |
| 206 | + displayAlertDialog(getString(R.string.birthplace_missing)); |
| 207 | + return false; |
| 208 | + } |
| 209 | + |
| 210 | + if (addressInput.getText().toString().isEmpty()) { |
| 211 | + displayAlertDialog(getString(R.string.address_missing)); |
| 212 | + return false; |
| 213 | + } |
| 214 | + |
| 215 | + if (cityInput.getText().toString().isEmpty()) { |
| 216 | + displayAlertDialog(getString(R.string.city_missing)); |
| 217 | + return false; |
| 218 | + } |
| 219 | + |
| 220 | + if (postalCodeInput.getText().toString().isEmpty()) { |
| 221 | + displayAlertDialog(getString(R.string.postal_code_missing)); |
| 222 | + return false; |
| 223 | + } |
| 224 | + |
| 225 | + if (travelDateInput.getText().toString().isEmpty()) { |
| 226 | + displayAlertDialog(getString(R.string.travel_date_missing)); |
| 227 | + return false; |
| 228 | + } |
| 229 | + |
| 230 | + if (travelHourInput.getText().toString().isEmpty()) { |
| 231 | + displayAlertDialog(getString(R.string.travel_hour_missing)); |
| 232 | + return false; |
| 233 | + } |
| 234 | + |
| 235 | + if (! ((CheckBox) findViewById(R.id.reason1)).isChecked() && |
| 236 | + ! ((CheckBox) findViewById(R.id.reason2)).isChecked() && |
| 237 | + ! ((CheckBox) findViewById(R.id.reason3)).isChecked() && |
| 238 | + ! ((CheckBox) findViewById(R.id.reason4)).isChecked() && |
| 239 | + ! ((CheckBox) findViewById(R.id.reason5)).isChecked() && |
| 240 | + ! ((CheckBox) findViewById(R.id.reason6)).isChecked() && |
| 241 | + ! ((CheckBox) findViewById(R.id.reason7)).isChecked() && |
| 242 | + ! ((CheckBox) findViewById(R.id.reason8)).isChecked() && |
| 243 | + ! ((CheckBox) findViewById(R.id.reason9)).isChecked() |
| 244 | + ) { |
| 245 | + displayAlertDialog(getString(R.string.reaon_missing)); |
| 246 | + return false; |
| 247 | + } |
| 248 | + |
| 249 | + return true; |
| 250 | + } |
| 251 | + |
| 252 | + private void displayAlertDialog(String text) { |
| 253 | + new MaterialAlertDialogBuilder(this) |
| 254 | + .setTitle(R.string.warning) |
| 255 | + .setMessage(text) |
| 256 | + .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { |
| 257 | + public void onClick(DialogInterface dialog, int which) { |
| 258 | + dialog.dismiss(); |
| 259 | + } |
| 260 | + }) |
| 261 | + .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { |
| 262 | + public void onClick(DialogInterface dialog, int which) { |
| 263 | + dialog.dismiss(); |
| 264 | + } |
| 265 | + }) |
| 266 | + .show(); |
181 | 267 | } |
182 | 268 |
|
183 | 269 | private class GeneratePdfTask extends AsyncTask<Void, Void, Void> { |
|
0 commit comments