Setting good date in attestation for toString method, adding save after ad attestation

This commit is contained in:
Mathieu Sanchez 2020-04-16 10:29:46 +02:00
parent 3c39066710
commit 9bbc364c11
3 changed files with 12 additions and 2 deletions

View File

@ -21,6 +21,7 @@ class AttestationDao(private val path: String) {
fun addAttestation(attestation: Attestation) {
_attestations.value?.add(attestation)
save()
}
init {

View File

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

View File

@ -113,7 +113,7 @@ class AddViewModel(
getProfileFromView(),
exitDate.value.toString(),
exitHour.value.toString(),
Date().time,
0,
getReasons()
)
}