diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/adapters/AlarmsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/clock/adapters/AlarmsAdapter.kt index 7e393c6..19a05a9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/adapters/AlarmsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/adapters/AlarmsAdapter.kt @@ -64,16 +64,14 @@ class AlarmsAdapter(activity: SimpleActivity, var alarms: ArrayList, val private fun deleteItems() { val alarmsToRemove = ArrayList() - val alarmIDs = ArrayList() selectedPositions.sortedDescending().forEach { val alarm = alarms[it] - alarmIDs.add(alarm.id.toString()) alarmsToRemove.add(alarm) } alarms.removeAll(alarmsToRemove) removeSelectedItems() - activity.dbHelper.deleteAlarms(alarmIDs) + activity.dbHelper.deleteAlarms(alarmsToRemove) } private fun setupView(view: View, alarm: Alarm) { diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/DBHelper.kt index 1fe25e9..9e6be86 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/DBHelper.kt @@ -6,6 +6,7 @@ import android.database.Cursor import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper import android.text.TextUtils +import com.simplemobiletools.clock.extensions.cancelAlarmClock import com.simplemobiletools.clock.extensions.createNewAlarm import com.simplemobiletools.clock.models.Alarm import com.simplemobiletools.commons.extensions.getIntValue @@ -77,8 +78,12 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont return mDb.update(ALARMS_TABLE_NAME, values, selection, selectionArgs) == 1 } - fun deleteAlarms(ids: ArrayList) { - val args = TextUtils.join(", ", ids) + fun deleteAlarms(alarms: ArrayList) { + alarms.filter { it.isEnabled }.forEach { + context.cancelAlarmClock(it) + } + + val args = TextUtils.join(", ", alarms.map { it.id.toString() }) val selection = "$ALARMS_TABLE_NAME.$COL_ID IN ($args)" mDb.delete(ALARMS_TABLE_NAME, selection, null) }