Add profiles gestion

This commit is contained in:
Mathieu Sanchez 2020-05-02 14:41:39 +02:00
parent 5f373a19d7
commit 54a57b65ab
3 changed files with 15 additions and 3 deletions

View File

@ -21,10 +21,18 @@ class ProfileDao(private val path: String, private val configRepository: ConfigR
fun getProfiles(): LiveData<List<Profile>> =
_profile as LiveData<List<Profile>>
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 {

View File

@ -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
)

View File

@ -9,7 +9,10 @@ class ProfileRepository private constructor(private val profileDao: ProfileDao)
fun getProfiles(): LiveData<List<Profile>> =
profileDao.getProfiles()
fun insertProfile(profile: Profile) =
fun getProfile(id: Int): Profile? =
profileDao.getProfile(id)
fun insertProfile(profile: Profile): Int =
profileDao.addProfile(profile)
companion object {