Starting my attestations page
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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<String>().apply {
 | 
			
		||||
//        value = "This is dashboard Fragment"
 | 
			
		||||
//    }
 | 
			
		||||
//    val text: LiveData<String> = _text
 | 
			
		||||
    val attestationName = MutableLiveData<String>()
 | 
			
		||||
 | 
			
		||||
    fun onClick() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    init {
 | 
			
		||||
        attestationRepository.getAttestation(0)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -4,7 +4,6 @@
 | 
			
		||||
    xmlns:tools="http://schemas.android.com/tools">
 | 
			
		||||
 | 
			
		||||
    <data>
 | 
			
		||||
 | 
			
		||||
        <variable
 | 
			
		||||
            name="viewModel"
 | 
			
		||||
            type="fr.sanchezm.attestationsCovid19.ui.attestations.AttestationsViewModel" />
 | 
			
		||||
@@ -15,19 +14,16 @@
 | 
			
		||||
        android:layout_height="match_parent"
 | 
			
		||||
        tools:context=".ui.attestations.AttestationsFragment">
 | 
			
		||||
 | 
			
		||||
        <TextView
 | 
			
		||||
            android:id="@+id/text_dashboard"
 | 
			
		||||
            android:layout_width="match_parent"
 | 
			
		||||
        <com.google.android.material.button.MaterialButton
 | 
			
		||||
            android:layout_width="wrap_content"
 | 
			
		||||
            android:layout_height="wrap_content"
 | 
			
		||||
            android:layout_marginStart="8dp"
 | 
			
		||||
            android:layout_marginTop="8dp"
 | 
			
		||||
            android:layout_marginEnd="8dp"
 | 
			
		||||
            android:textAlignment="center"
 | 
			
		||||
            android:textSize="20sp"
 | 
			
		||||
            android:onClick="@{() -> viewModel.onClick()}"
 | 
			
		||||
            android:text="@{viewModel.attestationName}"
 | 
			
		||||
            app:layout_constraintBottom_toBottomOf="parent"
 | 
			
		||||
            app:layout_constraintEnd_toEndOf="parent"
 | 
			
		||||
            app:layout_constraintStart_toStartOf="parent"
 | 
			
		||||
            app:layout_constraintTop_toTopOf="parent" />
 | 
			
		||||
 | 
			
		||||
    </androidx.constraintlayout.widget.ConstraintLayout>
 | 
			
		||||
 | 
			
		||||
</layout>
 | 
			
		||||
		Reference in New Issue
	
	Block a user