|
@@ -1,6 +1,7 @@
|
|
-package com.flacksta.chef.journeygpstracker
|
|
|
|
|
|
+package com.flacksta.chef.journeygpstracker.database
|
|
|
|
|
|
import android.content.Context
|
|
import android.content.Context
|
|
|
|
+import android.util.Log
|
|
import androidx.room.Database
|
|
import androidx.room.Database
|
|
import androidx.room.Room
|
|
import androidx.room.Room
|
|
import androidx.room.RoomDatabase
|
|
import androidx.room.RoomDatabase
|
|
@@ -12,16 +13,19 @@ import kotlinx.coroutines.launch
|
|
@Database(entities = [GpsData::class], version = 1, exportSchema = false)
|
|
@Database(entities = [GpsData::class], version = 1, exportSchema = false)
|
|
public abstract class GpsPosRoomDatabase : RoomDatabase() {
|
|
public abstract class GpsPosRoomDatabase : RoomDatabase() {
|
|
|
|
|
|
|
|
+
|
|
abstract fun gpsDataDao(): GpsDataDao
|
|
abstract fun gpsDataDao(): GpsDataDao
|
|
|
|
|
|
companion object {
|
|
companion object {
|
|
@Volatile
|
|
@Volatile
|
|
private var INSTANCE: GpsPosRoomDatabase? = null
|
|
private var INSTANCE: GpsPosRoomDatabase? = null
|
|
|
|
+ private const val mTag:String = "GpsPosRoomDatabase"
|
|
|
|
|
|
fun getDatabase(
|
|
fun getDatabase(
|
|
context: Context,
|
|
context: Context,
|
|
scope: CoroutineScope
|
|
scope: CoroutineScope
|
|
): GpsPosRoomDatabase {
|
|
): GpsPosRoomDatabase {
|
|
|
|
+ Log.i(mTag,"getDatabase()")
|
|
// if the INSTANCE is not null, then return it,
|
|
// if the INSTANCE is not null, then return it,
|
|
// if it is, then create the database
|
|
// if it is, then create the database
|
|
return INSTANCE ?: synchronized(this) {
|
|
return INSTANCE ?: synchronized(this) {
|
|
@@ -60,10 +64,10 @@ public abstract class GpsPosRoomDatabase : RoomDatabase() {
|
|
}
|
|
}
|
|
|
|
|
|
suspend fun populateDatabase(gpsDataDao: GpsDataDao) {
|
|
suspend fun populateDatabase(gpsDataDao: GpsDataDao) {
|
|
- // Start the app with a clean database every time.
|
|
|
|
- // Not needed if you only populate on creation.
|
|
|
|
|
|
+ Log.i(mTag,"populateDatabase()")
|
|
gpsDataDao.deleteAll()
|
|
gpsDataDao.deleteAll()
|
|
-
|
|
|
|
|
|
+ var d = GpsData(0,0,0.0,0.0,2.0)
|
|
|
|
+ gpsDataDao.insert(d)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|