create some initial alarms for weekdays and the weekend

This commit is contained in:
tibbi 2018-03-04 00:08:17 +01:00
parent 7c498b90dc
commit 4f9624a232

View File

@ -1,9 +1,10 @@
package com.simplemobiletools.clock.helpers
import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.util.Log
import com.simplemobiletools.clock.models.Alarm
class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
private val ALARMS_TABLE_NAME = "contacts"
@ -33,10 +34,34 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
override fun onCreate(db: SQLiteDatabase) {
db.execSQL("CREATE TABLE $ALARMS_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TIME_IN_MINUTES INTEGER, $COL_DAYS INTEGER, " +
"$COL_IS_ENABLED INTEGER, $COL_VIBRATE INTEGER, $COL_SOUND_URI TEXT, $COL_LABEL TEXT)")
Log.e("DEBUG", "creating")
insertInitialAlarms(db)
}
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {}
private fun insertInitialAlarms(db: SQLiteDatabase) {
val weekDays = MONDAY_BIT or TUESDAY_BIT or WEDNESDAY_BIT or THURSDAY_BIT or FRIDAY_BIT
val weekDaysAlarm = Alarm(420, weekDays, false, false, "", "")
insertAlarm(weekDaysAlarm, db)
val weekEnd = SATURDAY_BIT or SUNDAY_BIT
val weekEndAlarm = Alarm(540, weekEnd, false, false, "", "")
insertAlarm(weekEndAlarm, db)
}
private fun insertAlarm(alarm: Alarm, db: SQLiteDatabase) {
val values = fillAlarmContentValues(alarm)
db.insert(ALARMS_TABLE_NAME, null, values)
}
private fun fillAlarmContentValues(alarm: Alarm): ContentValues {
return ContentValues().apply {
put(COL_TIME_IN_MINUTES, alarm.timeInMinutes)
put(COL_DAYS, alarm.days)
put(COL_IS_ENABLED, alarm.isEnabled)
put(COL_VIBRATE, alarm.vibrate)
put(COL_SOUND_URI, alarm.soundUri)
put(COL_LABEL, alarm.label)
}
}
}