cancel active alarms before deleting
This commit is contained in:
parent
02ea628762
commit
a20e1ce8f9
|
@ -64,16 +64,14 @@ class AlarmsAdapter(activity: SimpleActivity, var alarms: ArrayList<Alarm>, val
|
||||||
|
|
||||||
private fun deleteItems() {
|
private fun deleteItems() {
|
||||||
val alarmsToRemove = ArrayList<Alarm>()
|
val alarmsToRemove = ArrayList<Alarm>()
|
||||||
val alarmIDs = ArrayList<String>()
|
|
||||||
selectedPositions.sortedDescending().forEach {
|
selectedPositions.sortedDescending().forEach {
|
||||||
val alarm = alarms[it]
|
val alarm = alarms[it]
|
||||||
alarmIDs.add(alarm.id.toString())
|
|
||||||
alarmsToRemove.add(alarm)
|
alarmsToRemove.add(alarm)
|
||||||
}
|
}
|
||||||
|
|
||||||
alarms.removeAll(alarmsToRemove)
|
alarms.removeAll(alarmsToRemove)
|
||||||
removeSelectedItems()
|
removeSelectedItems()
|
||||||
activity.dbHelper.deleteAlarms(alarmIDs)
|
activity.dbHelper.deleteAlarms(alarmsToRemove)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupView(view: View, alarm: Alarm) {
|
private fun setupView(view: View, alarm: Alarm) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.database.Cursor
|
||||||
import android.database.sqlite.SQLiteDatabase
|
import android.database.sqlite.SQLiteDatabase
|
||||||
import android.database.sqlite.SQLiteOpenHelper
|
import android.database.sqlite.SQLiteOpenHelper
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
|
import com.simplemobiletools.clock.extensions.cancelAlarmClock
|
||||||
import com.simplemobiletools.clock.extensions.createNewAlarm
|
import com.simplemobiletools.clock.extensions.createNewAlarm
|
||||||
import com.simplemobiletools.clock.models.Alarm
|
import com.simplemobiletools.clock.models.Alarm
|
||||||
import com.simplemobiletools.commons.extensions.getIntValue
|
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
|
return mDb.update(ALARMS_TABLE_NAME, values, selection, selectionArgs) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteAlarms(ids: ArrayList<String>) {
|
fun deleteAlarms(alarms: ArrayList<Alarm>) {
|
||||||
val args = TextUtils.join(", ", ids)
|
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)"
|
val selection = "$ALARMS_TABLE_NAME.$COL_ID IN ($args)"
|
||||||
mDb.delete(ALARMS_TABLE_NAME, selection, null)
|
mDb.delete(ALARMS_TABLE_NAME, selection, null)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue