do not allow enabling an alarm if no days are selected

This commit is contained in:
tibbi 2018-03-06 10:31:30 +01:00
parent ce033cf6fa
commit 9e106e5a83
5 changed files with 15 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import com.simplemobiletools.clock.models.Alarm
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.getSelectedDaysString
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.views.MyRecyclerView
import kotlinx.android.synthetic.main.item_alarm.view.*
import java.util.*
@ -81,7 +82,12 @@ class AlarmsAdapter(activity: SimpleActivity, var alarms: ArrayList<Alarm>, val
alarm_switch.isChecked = alarm.isEnabled
alarm_switch.setColors(textColor, adjustedPrimaryColor, backgroundColor)
alarm_switch.setOnClickListener {
toggleAlarmInterface.alarmToggled(alarm.id, alarm_switch.isChecked)
if (alarm.days > 0) {
toggleAlarmInterface.alarmToggled(alarm.id, alarm_switch.isChecked)
} else {
activity.toast(R.string.no_days_selected)
alarm_switch.isChecked = false
}
}
}
}

View File

@ -92,6 +92,11 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
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 (!activity.dbHelper.updateAlarm(alarm)) {
activity.toast(R.string.unknown_error_occurred)
}

View File

@ -4,6 +4,7 @@
<string name="time_zone">Fuso horário</string>
<string name="vibrate">Vibrate</string>
<string name="label">Label</string>
<string name="no_days_selected">No days selected</string>
<!-- Settings -->
<string name="clock_tab">Relógio</string>

View File

@ -4,6 +4,7 @@
<string name="time_zone">Časové pásmo</string>
<string name="vibrate">Vibrovanie</string>
<string name="label">Štítok</string>
<string name="no_days_selected">Neboli označené žiadne dni</string>
<!-- Settings -->
<string name="clock_tab">Okno s časom</string>

View File

@ -4,6 +4,7 @@
<string name="time_zone">Time zone</string>
<string name="vibrate">Vibrate</string>
<string name="label">Label</string>
<string name="no_days_selected">No days selected</string>
<!-- Settings -->
<string name="clock_tab">Clock tab</string>