Setting good date in attestation for toString method, adding save after ad attestation
This commit is contained in:
parent
3c39066710
commit
9bbc364c11
@ -21,6 +21,7 @@ class AttestationDao(private val path: String) {
|
||||
|
||||
fun addAttestation(attestation: Attestation) {
|
||||
_attestations.value?.add(attestation)
|
||||
save()
|
||||
}
|
||||
|
||||
init {
|
||||
|
@ -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 {
|
||||
|
@ -113,7 +113,7 @@ class AddViewModel(
|
||||
getProfileFromView(),
|
||||
exitDate.value.toString(),
|
||||
exitHour.value.toString(),
|
||||
Date().time,
|
||||
0,
|
||||
getReasons()
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user