Add No Attestations when attestations DB is empty

This commit is contained in:
Mathieu Sanchez 2020-04-17 08:59:14 +02:00
parent 71cb112bbe
commit b95692bdf3
3 changed files with 23 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package fr.sanchezm.attestationsCovid19.ui.attestations
import android.view.View
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
@ -13,13 +14,23 @@ class AttestationsViewModel(attestationRepository: AttestationRepository) : View
private var _attestations = attestationRepository.getAttestations() as MutableLiveData<ArrayList<Attestation>>
private var _displayNoAttestation = MutableLiveData<Int>()
val attestations: LiveData<ArrayList<Attestation>> =
_attestations
val startActivity: LiveData<Event<Long>> =
_startActivity
val displayNoAttestation: LiveData<Int> =
_displayNoAttestation
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
}
}
}

View File

@ -29,6 +29,16 @@
app:layout_constraintStart_toStartOf="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
android:id="@+id/attestation_recycler_view"
android:layout_width="match_parent"

View File

@ -9,6 +9,7 @@
<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="attestation_generated">Attestation générer</string>
<string name="no_attestation">Aucune attestation, veuillez en générer une.</string>
<!-- Field for attestation -->
<string name="first_name">Prénom</string>