diff --git a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/dao/AttestationDao.kt b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/dao/AttestationDao.kt index 8ea0a27..eef5377 100644 --- a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/dao/AttestationDao.kt +++ b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/dao/AttestationDao.kt @@ -21,6 +21,7 @@ class AttestationDao(private val path: String) { fun addAttestation(attestation: Attestation) { _attestations.value?.add(attestation) + save() } init { diff --git a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/entity/Attestation.kt b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/entity/Attestation.kt index fb5181f..e9d0380 100644 --- a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/entity/Attestation.kt +++ b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/db/entity/Attestation.kt @@ -1,5 +1,8 @@ package fr.sanchezm.attestationsCovid19.data.db.entity +import java.text.SimpleDateFormat +import java.util.* + //@Entity(tableName = "attestation") data class Attestation( val profile: Profile, @@ -8,11 +11,17 @@ data class Attestation( var createAt: Long, val reasons: List ) { + private val pattern = "dd/MM/yyyy 'a' HH:mm" + override fun toString(): String { val motifs = StringBuilder() repeat(reasons.size) { motifs.append(getMotifText(it), "-") }.also { motifs.dropLast(1) } - return "Cree le: $createAt; $profile; Sortie: $exitDate a $exitHour; Motifs: $motifs" + return "Cree le: ${getDate(createAt)}; $profile; Sortie: $exitDate a $exitHour; Motifs: $motifs" + } + + private fun getDate(dateTime: Long): String { + return SimpleDateFormat(pattern, Locale.FRANCE).format(Date(dateTime)) } private fun getMotifText(i: Int): String { diff --git a/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/add/AddViewModel.kt b/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/add/AddViewModel.kt index 82460b2..bde8727 100644 --- a/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/add/AddViewModel.kt +++ b/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/add/AddViewModel.kt @@ -113,7 +113,7 @@ class AddViewModel( getProfileFromView(), exitDate.value.toString(), exitHour.value.toString(), - Date().time, + 0, getReasons() ) }