JourneyGpsTrackerApplication.kt 870 B

1234567891011121314151617181920212223242526272829
  1. package com.flacksta.chef.journeygpstracker
  2. import android.app.Application
  3. import android.util.Log
  4. import com.flacksta.chef.journeygpstracker.database.GpsData
  5. import com.flacksta.chef.journeygpstracker.database.GpsPosRepository
  6. import com.flacksta.chef.journeygpstracker.database.GpsPosRoomDatabase
  7. import kotlinx.coroutines.*
  8. class JourneyGpsTrackerApplication : Application() {
  9. val applicationScope = CoroutineScope(SupervisorJob())
  10. val database by lazy { GpsPosRoomDatabase.getDatabase(this, applicationScope) }
  11. val repository by lazy { GpsPosRepository(database.gpsDataDao()) }
  12. override fun onCreate() {
  13. super.onCreate()
  14. Log.i("JourneyGpsTrackerApplication","onCreate()")
  15. initStuff()
  16. }
  17. fun initStuff() = runBlocking { // this: CoroutineScope
  18. launch {
  19. repository.deleteAll()
  20. }
  21. }
  22. }