-
Notifications
You must be signed in to change notification settings - Fork 1
/
DndApplication.kt
54 lines (47 loc) · 1.7 KB
/
DndApplication.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.nimtome.app
import android.app.Application
import android.content.SharedPreferences
import androidx.room.Room
import com.nimtome.app.database.CharacterDatabase
import com.nimtome.app.database.SpellDatabase
import com.nimtome.app.ui.theme.ColorPalette
class DndApplication : Application() {
companion object {
lateinit var characterDatabase: CharacterDatabase
private set
lateinit var spellDatabase: SpellDatabase
private set
lateinit var sharedPreferences: SharedPreferences
private set
private const val SP_ID_MAIN = "com.nimtome.nimtome.main"
private const val SP_COLOR_THEME = "COLOR_THEME"
var colorPalette: ColorPalette
get() {
return ColorPalette.valueOf(
sharedPreferences
.getString(SP_COLOR_THEME, ColorPalette.Purple.name)
?: ColorPalette.Purple.name
)
}
set(value) {
with(sharedPreferences.edit()) {
putString(SP_COLOR_THEME, value.name)
apply()
}
}
}
override fun onCreate() {
spellDatabase = Room.databaseBuilder(
applicationContext,
SpellDatabase::class.java,
"spell_database",
).fallbackToDestructiveMigration().build()
characterDatabase = Room.databaseBuilder(
applicationContext,
CharacterDatabase::class.java,
"character_database",
).fallbackToDestructiveMigration().build()
sharedPreferences = getSharedPreferences(SP_ID_MAIN, MODE_PRIVATE)
super.onCreate()
}
}