Starting my attestations page
This commit is contained in:
parent
5ce2bb2fe4
commit
3c39066710
@ -9,6 +9,12 @@ class AttestationRepository private constructor(private val attestationDao: Atte
|
|||||||
fun generateAttestation(attestation: Attestation) =
|
fun generateAttestation(attestation: Attestation) =
|
||||||
PdfUtils.getInstance()?.fillForm(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 {
|
companion object {
|
||||||
@Volatile
|
@Volatile
|
||||||
private var instance: AttestationRepository? = null
|
private var instance: AttestationRepository? = null
|
||||||
|
@ -55,8 +55,10 @@ class AddViewModel(
|
|||||||
@SuppressLint("LongLogTag")
|
@SuppressLint("LongLogTag")
|
||||||
fun onGenerateAttestationClick() {
|
fun onGenerateAttestationClick() {
|
||||||
if (checkAllValue()) {
|
if (checkAllValue()) {
|
||||||
|
val attestation = getAttestation()
|
||||||
profileRepository.insertProfile(getProfileFromView())
|
profileRepository.insertProfile(getProfileFromView())
|
||||||
attestationRepository.generateAttestation(getAttestation())
|
attestationRepository.generateAttestation(attestation)
|
||||||
|
attestationRepository.addAttestation(attestation)
|
||||||
_dataMessage.value = Event(R.string.attestation_generated)
|
_dataMessage.value = Event(R.string.attestation_generated)
|
||||||
} else {
|
} else {
|
||||||
_errorMessage.value = Event(R.string.error_cannot_create_attestation)
|
_errorMessage.value = Event(R.string.error_cannot_create_attestation)
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package fr.sanchezm.attestationsCovid19.ui.attestations
|
package fr.sanchezm.attestationsCovid19.ui.attestations
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
import fr.sanchezm.attestationsCovid19.data.repository.AttestationRepository
|
||||||
|
|
||||||
class AttestationsViewModel(private val attestationRepository: AttestationRepository) : ViewModel() {
|
class AttestationsViewModel(private val attestationRepository: AttestationRepository) : ViewModel() {
|
||||||
|
|
||||||
// private val _text = MutableLiveData<String>().apply {
|
val attestationName = MutableLiveData<String>()
|
||||||
// value = "This is dashboard Fragment"
|
|
||||||
// }
|
fun onClick() {
|
||||||
// val text: LiveData<String> = _text
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
attestationRepository.getAttestation(0)
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,7 +4,6 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
<variable
|
<variable
|
||||||
name="viewModel"
|
name="viewModel"
|
||||||
type="fr.sanchezm.attestationsCovid19.ui.attestations.AttestationsViewModel" />
|
type="fr.sanchezm.attestationsCovid19.ui.attestations.AttestationsViewModel" />
|
||||||
@ -15,19 +14,16 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".ui.attestations.AttestationsFragment">
|
tools:context=".ui.attestations.AttestationsFragment">
|
||||||
|
|
||||||
<TextView
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/text_dashboard"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:onClick="@{() -> viewModel.onClick()}"
|
||||||
android:layout_marginTop="8dp"
|
android:text="@{viewModel.attestationName}"
|
||||||
android:layout_marginEnd="8dp"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:textSize="20sp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</layout>
|
</layout>
|
Loading…
Reference in New Issue
Block a user