From 54a57b65ab704a999f45ccab9741d6cba0a12911 Mon Sep 17 00:00:00 2001 From: Mathieu Sanchez Date: Sat, 2 May 2020 14:41:39 +0200 Subject: [PATCH] Add profiles gestion --- .../attestationsCovid19/data/db/dao/ProfileDao.kt | 10 +++++++++- .../attestationsCovid19/data/db/entity/Config.kt | 3 ++- .../data/repository/ProfileRepository.kt | 5 ++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/dao/ProfileDao.kt b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/dao/ProfileDao.kt index 7f1e4ac..def5506 100644 --- a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/dao/ProfileDao.kt +++ b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/dao/ProfileDao.kt @@ -21,10 +21,18 @@ class ProfileDao(private val path: String, private val configRepository: ConfigR fun getProfiles(): LiveData> = _profile as LiveData> - fun addProfile(profile: Profile) { + fun getProfile(id: Int): Profile? = + _profile.value?.get(id) + + fun getProfileId(profile: Profile): Int? = + _profile.value?.indexOf(profile) + + fun addProfile(profile: Profile): Int { _profile.value?.add(profile) _profile.value = _profile.value save() + + return _profile.value?.indexOf(profile)!! } init { diff --git a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/entity/Config.kt b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/entity/Config.kt index aa0344d..e7d8e50 100644 --- a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/entity/Config.kt +++ b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/entity/Config.kt @@ -3,5 +3,6 @@ package fr.sanchezm.attestationsCovid19.data.db.entity data class Config( var dbVersion: Int, var versionName: String, - var versionCode: Int + var versionCode: Int, + var selectProfileId: Int ) \ No newline at end of file diff --git a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/repository/ProfileRepository.kt b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/repository/ProfileRepository.kt index 8b45668..9d8c682 100644 --- a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/repository/ProfileRepository.kt +++ b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/repository/ProfileRepository.kt @@ -9,7 +9,10 @@ class ProfileRepository private constructor(private val profileDao: ProfileDao) fun getProfiles(): LiveData> = profileDao.getProfiles() - fun insertProfile(profile: Profile) = + fun getProfile(id: Int): Profile? = + profileDao.getProfile(id) + + fun insertProfile(profile: Profile): Int = profileDao.addProfile(profile) companion object {