do not allow confirming the Edit Alarm dialog with no days selected

This commit is contained in:
tibbi 2018-03-13 17:51:52 +01:00
parent 711c230ac1
commit 7d862313ec
1 changed files with 23 additions and 21 deletions

View File

@ -77,10 +77,31 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
}
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this)
activity.setupDialogStuff(view, this) {
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (alarm.days == 0) {
activity.toast(R.string.no_days_selected)
return@setOnClickListener
}
alarm.label = view.edit_alarm_label.value
if (alarm.id == 0) {
if (!activity.dbHelper.insertAlarm(alarm)) {
activity.toast(R.string.unknown_error_occurred)
}
} else {
if (!activity.dbHelper.updateAlarm(alarm)) {
activity.toast(R.string.unknown_error_occurred)
}
}
callback()
dismiss()
}
}
}
}
@ -93,25 +114,6 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
view.edit_alarm_time.text = activity.getFormattedTime(alarm.timeInMinutes * 60, false, true)
}
private fun dialogConfirmed() {
alarm.label = view.edit_alarm_label.value
if (alarm.days == 0) {
activity.toast(R.string.no_days_selected)
alarm.isEnabled = false
}
if (alarm.id == 0) {
if (!activity.dbHelper.insertAlarm(alarm)) {
activity.toast(R.string.unknown_error_occurred)
}
} else {
if (!activity.dbHelper.updateAlarm(alarm)) {
activity.toast(R.string.unknown_error_occurred)
}
}
callback()
}
private fun getProperDayDrawable(selected: Boolean): Drawable {
val drawableId = if (selected) R.drawable.circle_background_filled else R.drawable.circle_background_stroke
val drawable = activity.resources.getDrawable(drawableId)