create the database holding alarms

This commit is contained in:
tibbi 2018-03-03 23:41:21 +01:00
parent 0e4744a0d2
commit 91bd5a6d4a
4 changed files with 56 additions and 4 deletions

View file

@ -2,15 +2,14 @@ package com.simplemobiletools.clock.extensions
import android.content.Context
import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.helpers.Config
import com.simplemobiletools.clock.helpers.EDITED_TIME_ZONE_SEPARATOR
import com.simplemobiletools.clock.helpers.getAllTimeZones
import com.simplemobiletools.clock.helpers.getDefaultTimeZoneTitle
import com.simplemobiletools.clock.helpers.*
import com.simplemobiletools.clock.models.MyTimeZone
import java.util.*
val Context.config: Config get() = Config.newInstance(applicationContext)
val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext)
fun Context.getFormattedDate(calendar: Calendar): String {
val dayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 5) % 7 // make sure index 0 means monday
val dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH)

View file

@ -11,6 +11,14 @@ const val EDITED_TIME_ZONE_TITLES = "edited_time_zone_titles"
const val TABS_COUNT = 3
const val EDITED_TIME_ZONE_SEPARATOR = ":"
const val MONDAY_BIT = 1
const val TUESDAY_BIT = 2
const val WEDNESDAY_BIT = 4
const val THURSDAY_BIT = 8
const val FRIDAY_BIT = 16
const val SATURDAY_BIT = 32
const val SUNDAY_BIT = 64
fun getDefaultTimeZoneTitle(id: Int) = getAllTimeZones().firstOrNull { it.id == id }?.title ?: ""
fun getAllTimeZones() = arrayListOf(

View file

@ -0,0 +1,42 @@
package com.simplemobiletools.clock.helpers
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.util.Log
class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
private val ALARMS_TABLE_NAME = "contacts"
private val COL_ID = "id"
private val COL_TIME_IN_MINUTES = "time_in_minutes"
private val COL_DAYS = "days"
private val COL_IS_ENABLED = "is_enabled"
private val COL_VIBRATE = "vibrate"
private val COL_SOUND_URI = "sound_uri"
private val COL_LABEL = "label"
private val mDb = writableDatabase
companion object {
private const val DB_VERSION = 1
const val DB_NAME = "alarms.db"
var dbInstance: DBHelper? = null
fun newInstance(context: Context): DBHelper {
if (dbInstance == null)
dbInstance = DBHelper(context)
return dbInstance!!
}
}
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")
}
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
}
}

View file

@ -0,0 +1,3 @@
package com.simplemobiletools.clock.models
data class Alarm(val timeInMinutes: Int, var days: Int, val isEnabled: Boolean, val vibrate: Boolean, val soundUri: String, val label: String)