Skip to content

Commit

Permalink
prevent empty task (which would lead to an exception)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathisdt committed Dec 9, 2023
1 parent f246ce1 commit a5bf498
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,15 @@ protected void onCreate(Bundle savedInstanceState) {
OffsetDateTime startDateTime = getCurrentlySetDateTime();
OffsetDateTime endDateTime = getCurrentlySetEndDateTime();
if (startDateTime == null || endDateTime == null) {
// TODO: Would be better to disable save button, if date/time is not selected
showMsgDateTimeNotSelected();
return;
}

Task selectedTask = (Task) task.getSelectedItem();
if (selectedTask == null) {
showMsgTaskNotSelected();
return;
}
Integer taskId = selectedTask.getId();
String textString = text.getText().toString();

Expand All @@ -161,15 +164,17 @@ protected void onCreate(Bundle savedInstanceState) {

OffsetDateTime dateTime = getCurrentlySetDateTime();
if (dateTime == null) {
// TODO: Would be better to disable save button, if date/time is not selected
showMsgDateTimeNotSelected();
return;
}

Task selectedTask = (Task) task.getSelectedItem();
Integer taskId = ((typeEnum == TypeEnum.CLOCK_OUT || selectedTask == null) ? null :
selectedTask.getId());
String textString = (typeEnum == TypeEnum.CLOCK_OUT ? null : text.getText().toString());
if (typeEnum == TypeEnum.CLOCK_IN && selectedTask == null) {
showMsgTaskNotSelected();
return;
}
Integer taskId = (typeEnum != TypeEnum.CLOCK_IN ? null : selectedTask.getId());
String textString = (typeEnum != TypeEnum.CLOCK_IN ? null : text.getText().toString());

if (newEvent) {
Logger.debug("saving new event: {} @ {}", typeEnum.name(), dateTime);
Expand Down Expand Up @@ -401,4 +406,8 @@ private void showMsgDateTimeNotSelected() {
Toast.makeText(this, R.string.errorDateOrTimeNotSelected, Toast.LENGTH_LONG).show();
}

private void showMsgTaskNotSelected() {
Toast.makeText(this, R.string.errorTaskNotSelected, Toast.LENGTH_LONG).show();
}

}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
<string name="storagePermissionsRequestTitle">Storage Permission</string>
<string name="storagePermissionsRequestText">It\'s recommended to let this app write a daily backup of your data to your device or to your SD card (if present).\n\nIf you want that, please allow it in the following dialog.\n\nIf you don\'t see any permission dialog, please just wait some minutes (Android imposes a rate limit on permission requests) or manually grant the permission in Android\'s settings for this app.</string>
<string name="errorDateOrTimeNotSelected">Date or time not selected</string>
<string name="errorTaskNotSelected">No task selected</string>
<string name="documentTreePermissionsRequestTitle">Storage Permission</string>
<string name="documentTreePermissionsRequestTextOnStart">This app needs a little space on your device to save a daily backup of your data and the reports you generate.\n\nPlease choose a directory in the following dialog, e.g. \"Documents\". Of course, you\'re also welcome to create a custom directory.\n\nIf you don\'t want that now, no daily backups will be created and you can\'t generate any reports (you\'ll be asked again if you try).</string>
<string name="documentTreePermissionsRequestTextOnUserAction">This feature needs to access your device\'s storage.\n\nPlease choose a directory in the following dialog, e.g. \"Documents\". Of course, you\'re also welcome to create a custom directory.\n\nIf you don\'t want that now, the feature will not be available.</string>
Expand Down

0 comments on commit a5bf498

Please sign in to comment.