diff --git a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/repository/AttestationRepository.kt b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/repository/AttestationRepository.kt index e041ab1..24c030f 100644 --- a/app/src/main/java/fr/sanchezm/attestationsCovid19/data/repository/AttestationRepository.kt +++ b/app/src/main/java/fr/sanchezm/attestationsCovid19/data/repository/AttestationRepository.kt @@ -9,6 +9,12 @@ class AttestationRepository private constructor(private val attestationDao: Atte fun generateAttestation(attestation: Attestation) = PdfUtils.getInstance()?.fillForm(attestation) + fun getAttestations() = attestationDao.getAttestations() + + fun getAttestation(id: Int) = attestationDao.getAttestation(id) + + fun addAttestation(attestation: Attestation) = attestationDao.addAttestation(attestation) + companion object { @Volatile private var instance: AttestationRepository? = null diff --git a/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/add/AddViewModel.kt b/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/add/AddViewModel.kt index 9ec7cfb..82460b2 100644 --- a/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/add/AddViewModel.kt +++ b/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/add/AddViewModel.kt @@ -55,8 +55,10 @@ class AddViewModel( @SuppressLint("LongLogTag") fun onGenerateAttestationClick() { if (checkAllValue()) { + val attestation = getAttestation() profileRepository.insertProfile(getProfileFromView()) - attestationRepository.generateAttestation(getAttestation()) + attestationRepository.generateAttestation(attestation) + attestationRepository.addAttestation(attestation) _dataMessage.value = Event(R.string.attestation_generated) } else { _errorMessage.value = Event(R.string.error_cannot_create_attestation) diff --git a/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/attestations/AttestationsViewModel.kt b/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/attestations/AttestationsViewModel.kt index b6b5093..a491517 100644 --- a/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/attestations/AttestationsViewModel.kt +++ b/app/src/main/java/fr/sanchezm/attestationsCovid19/ui/attestations/AttestationsViewModel.kt @@ -1,12 +1,17 @@ package fr.sanchezm.attestationsCovid19.ui.attestations +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository class AttestationsViewModel(private val attestationRepository: AttestationRepository) : ViewModel() { -// private val _text = MutableLiveData().apply { -// value = "This is dashboard Fragment" -// } -// val text: LiveData = _text + val attestationName = MutableLiveData() + + fun onClick() { + } + + init { + attestationRepository.getAttestation(0) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_attestations.xml b/app/src/main/res/layout/fragment_attestations.xml index aa6a4f4..b7f0507 100644 --- a/app/src/main/res/layout/fragment_attestations.xml +++ b/app/src/main/res/layout/fragment_attestations.xml @@ -4,7 +4,6 @@ xmlns:tools="http://schemas.android.com/tools"> - @@ -15,19 +14,16 @@ android:layout_height="match_parent" tools:context=".ui.attestations.AttestationsFragment"> - + \ No newline at end of file