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) {
|
fun addAttestation(attestation: Attestation) {
|
||||||
_attestations.value?.add(attestation)
|
_attestations.value?.add(attestation)
|
||||||
|
save()
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package fr.sanchezm.attestationsCovid19.data.db.entity
|
package fr.sanchezm.attestationsCovid19.data.db.entity
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
//@Entity(tableName = "attestation")
|
//@Entity(tableName = "attestation")
|
||||||
data class Attestation(
|
data class Attestation(
|
||||||
val profile: Profile,
|
val profile: Profile,
|
||||||
@ -8,11 +11,17 @@ data class Attestation(
|
|||||||
var createAt: Long,
|
var createAt: Long,
|
||||||
val reasons: List<Int>
|
val reasons: List<Int>
|
||||||
) {
|
) {
|
||||||
|
private val pattern = "dd/MM/yyyy 'a' HH:mm"
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
val motifs = StringBuilder()
|
val motifs = StringBuilder()
|
||||||
|
|
||||||
repeat(reasons.size) { motifs.append(getMotifText(it), "-") }.also { motifs.dropLast(1) }
|
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 {
|
private fun getMotifText(i: Int): String {
|
||||||
|
@ -113,7 +113,7 @@ class AddViewModel(
|
|||||||
getProfileFromView(),
|
getProfileFromView(),
|
||||||
exitDate.value.toString(),
|
exitDate.value.toString(),
|
||||||
exitHour.value.toString(),
|
exitHour.value.toString(),
|
||||||
Date().time,
|
0,
|
||||||
getReasons()
|
getReasons()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user