From 6687a19c4709281e0f622b622e92a3260bf55ed5 Mon Sep 17 00:00:00 2001 From: Ho Bing Xuan Date: Thu, 2 Jul 2020 21:01:47 +0800 Subject: [PATCH] Fixes #31 --- app/src/main/java/com/izho/saveentry/data/Database.kt | 5 ++++- .../com/izho/saveentry/viewmodel/CheckInOrOutViewModel.kt | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/izho/saveentry/data/Database.kt b/app/src/main/java/com/izho/saveentry/data/Database.kt index 9a19c16..b2cd1bb 100644 --- a/app/src/main/java/com/izho/saveentry/data/Database.kt +++ b/app/src/main/java/com/izho/saveentry/data/Database.kt @@ -9,7 +9,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase @Dao interface AppDao { - @Insert(onConflict = OnConflictStrategy.REPLACE) + @Insert(onConflict = OnConflictStrategy.IGNORE) suspend fun insertLocation(location: Location): Long @Insert(onConflict = OnConflictStrategy.REPLACE) @@ -53,6 +53,9 @@ interface AppDao { @Query("SELECT * FROM visit WHERE check_out_at IS NULL AND location_id = :locationId") fun getActiveVisitWithLocationId(locationId:String) : LiveData> + + @Query("UPDATE location SET organization = :organization, venue_name = :venueName WHERE location_id = :location_id") + fun updateLocationNames(venueName:String, organization:String, location_id:String) } @Database(entities = [Location::class, Visit::class], version = 3) diff --git a/app/src/main/java/com/izho/saveentry/viewmodel/CheckInOrOutViewModel.kt b/app/src/main/java/com/izho/saveentry/viewmodel/CheckInOrOutViewModel.kt index c1fccb5..fba8343 100644 --- a/app/src/main/java/com/izho/saveentry/viewmodel/CheckInOrOutViewModel.kt +++ b/app/src/main/java/com/izho/saveentry/viewmodel/CheckInOrOutViewModel.kt @@ -101,6 +101,7 @@ class CheckInOrOutViewModel(app: Application, info?.let { _currentLocation.postValue( Location(locationId, info.entityName, info.venueName, url)) + database.dao.updateLocationNames(info.venueName, info.entityName, locationId) } } } catch (e:Throwable) {