avoid creating multiple db instances

This commit is contained in:
tibbi 2017-06-03 16:41:39 +02:00
parent 130b4fe1e3
commit 3288435662
1 changed files with 5 additions and 1 deletions

View File

@ -56,12 +56,16 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
private val DB_VERSION = 11 private val DB_VERSION = 11
val DB_NAME = "events.db" val DB_NAME = "events.db"
val REGULAR_EVENT_TYPE_ID = 1 val REGULAR_EVENT_TYPE_ID = 1
var dbInstance: DBHelper? = null
private var mEventsListener: EventUpdateListener? = null private var mEventsListener: EventUpdateListener? = null
fun newInstance(context: Context, callback: EventUpdateListener? = null): DBHelper { fun newInstance(context: Context, callback: EventUpdateListener? = null): DBHelper {
mEventsListener = callback mEventsListener = callback
return DBHelper(context) if (dbInstance == null)
dbInstance = DBHelper(context)
return dbInstance!!
} }
} }