forked from upstream-mirrors/quik
a82ab5fc15
Co-authored-by: octoshrimpy <7097172+octoshrimpy@users.noreply.github.com>
28 lines
759 B
Kotlin
28 lines
759 B
Kotlin
package dev.octoshrimpy.quik.realm
|
|
|
|
import android.content.Context
|
|
import io.realm.Realm
|
|
import io.realm.RealmConfiguration
|
|
import dev.octoshrimpy.quik.repository.migrations.AppRealmMigration
|
|
|
|
object RealmConfig {
|
|
|
|
@Volatile
|
|
private var config: RealmConfiguration? = null
|
|
|
|
private fun getConfig(): RealmConfiguration {
|
|
return config ?: synchronized(this) {
|
|
config ?: RealmConfiguration.Builder()
|
|
.compactOnLaunch()
|
|
.schemaVersion(AppRealmMigration.SCHEMA_VERSION)
|
|
.migration(AppRealmMigration())
|
|
.build().also { config = it }
|
|
}
|
|
}
|
|
|
|
fun init(context: Context) {
|
|
Realm.init(context)
|
|
Realm.setDefaultConfiguration(getConfig())
|
|
}
|
|
}
|