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 b91901a9..fa41508f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/adapters/AlarmsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/adapters/AlarmsAdapter.kt @@ -6,6 +6,7 @@ import android.view.ViewGroup import com.simplemobiletools.clock.R import com.simplemobiletools.clock.activities.SimpleActivity import com.simplemobiletools.clock.extensions.config +import com.simplemobiletools.clock.extensions.dbHelper import com.simplemobiletools.clock.extensions.formatAlarmTime import com.simplemobiletools.clock.interfaces.ToggleAlarmInterface import com.simplemobiletools.clock.models.Alarm @@ -64,13 +65,16 @@ 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) } 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 1604c7f2..a8e1609d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/DBHelper.kt @@ -5,6 +5,7 @@ import android.content.Context import android.database.Cursor import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper +import android.text.TextUtils import com.simplemobiletools.clock.extensions.createNewAlarm import com.simplemobiletools.clock.models.Alarm import com.simplemobiletools.commons.extensions.getIntValue @@ -76,6 +77,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) + val selection = "$ALARMS_TABLE_NAME.$COL_ID IN ($args)" + mDb.delete(ALARMS_TABLE_NAME, selection, null) + } + fun getAlarmWithId(id: Int) = getAlarms().firstOrNull { it.id == id } private fun fillAlarmContentValues(alarm: Alarm): ContentValues {