Add No Attestations when attestations DB is empty
This commit is contained in:
parent
71cb112bbe
commit
b95692bdf3
@ -1,5 +1,6 @@
|
|||||||
package fr.sanchezm.attestationsCovid19.ui.attestations
|
package fr.sanchezm.attestationsCovid19.ui.attestations
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
@ -13,13 +14,23 @@ class AttestationsViewModel(attestationRepository: AttestationRepository) : View
|
|||||||
|
|
||||||
private var _attestations = attestationRepository.getAttestations() as MutableLiveData<ArrayList<Attestation>>
|
private var _attestations = attestationRepository.getAttestations() as MutableLiveData<ArrayList<Attestation>>
|
||||||
|
|
||||||
|
private var _displayNoAttestation = MutableLiveData<Int>()
|
||||||
|
|
||||||
val attestations: LiveData<ArrayList<Attestation>> =
|
val attestations: LiveData<ArrayList<Attestation>> =
|
||||||
_attestations
|
_attestations
|
||||||
|
|
||||||
val startActivity: LiveData<Event<Long>> =
|
val startActivity: LiveData<Event<Long>> =
|
||||||
_startActivity
|
_startActivity
|
||||||
|
|
||||||
|
val displayNoAttestation: LiveData<Int> =
|
||||||
|
_displayNoAttestation
|
||||||
|
|
||||||
init {
|
init {
|
||||||
_attestations = attestationRepository.getAttestations() as MutableLiveData<ArrayList<Attestation>>
|
if (_attestations.value == null || _attestations.value?.size == 0) {
|
||||||
|
_displayNoAttestation.value = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
_displayNoAttestation.value = View.GONE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -29,6 +29,16 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:text="@string/no_attestation"
|
||||||
|
android:visibility="@{viewModel.displayNoAttestation}"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/title" />
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/attestation_recycler_view"
|
android:id="@+id/attestation_recycler_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
<string name="attestation_subtitle">#RestonsChezNous</string>
|
<string name="attestation_subtitle">#RestonsChezNous</string>
|
||||||
<string name="error_cannot_create_attestation">Erreur lors de la génération de l\'attestation, tout les champs ne sont pas compléter</string>
|
<string name="error_cannot_create_attestation">Erreur lors de la génération de l\'attestation, tout les champs ne sont pas compléter</string>
|
||||||
<string name="attestation_generated">Attestation générer</string>
|
<string name="attestation_generated">Attestation générer</string>
|
||||||
|
<string name="no_attestation">Aucune attestation, veuillez en générer une.</string>
|
||||||
|
|
||||||
<!-- Field for attestation -->
|
<!-- Field for attestation -->
|
||||||
<string name="first_name">Prénom</string>
|
<string name="first_name">Prénom</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user