Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Srs progress loading button (EXPOSUREAPP-14322) #5710

Merged
merged 9 commits into from
Nov 16, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class SrsSymptomsCalendarFragment : Fragment(R.layout.fragment_submission_sympto

binding.toolbar.setNavigationOnClickListener { viewModel.onCancelConfirmed() }

viewModel.showLoadingIndicator.observe(viewLifecycleOwner) { binding.symptomButtonNext.isLoading = it }

viewModel.events.observe(viewLifecycleOwner) {
when (it) {
SrsSymptomsCalendarNavigation.ShowCloseDialog -> showCloseDialog { viewModel.goHome() }
Expand Down Expand Up @@ -114,7 +116,7 @@ class SrsSymptomsCalendarFragment : Fragment(R.layout.fragment_submission_sympto
}

symptomButtonNext.apply {
isEnabled = symptomStart != null
isActive = symptomStart != null
setOnClickListener { viewModel.onDone() }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SrsSymptomsCalendarViewModel @AssistedInject constructor(
val symptomStart = symptomStartInternal.asLiveData(context = dispatcherProvider.Default)

val events = SingleLiveEvent<SrsSymptomsCalendarNavigation>()
val showLoadingIndicator = SingleLiveEvent<Boolean>()

fun onCancelConfirmed() {
Timber.d("Canceled SRS submission")
Expand All @@ -47,6 +48,7 @@ class SrsSymptomsCalendarViewModel @AssistedInject constructor(
return
}
Timber.tag(TAG).d("onDone() clicked on calender screen.")
showLoadingIndicator.postValue(true)
submitSrs()
}

Expand All @@ -65,6 +67,8 @@ class SrsSymptomsCalendarViewModel @AssistedInject constructor(
events.postValue(SrsSymptomsCalendarNavigation.GoToThankYouScreen(submissionType))
} catch (e: Exception) {
events.postValue(SrsSymptomsCalendarNavigation.Error(e))
} finally {
showLoadingIndicator.postValue(false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class SrsSymptomsIntroductionFragment : Fragment(R.layout.fragment_submission_sy
updateButtons(it)
}

viewModel.showLoadingIndicator.observe(viewLifecycleOwner) { binding.symptomButtonNext.isLoading = it }

viewModel.events.observe(viewLifecycleOwner) {
when (it) {
SrsSymptomsIntroductionNavigation.ShowCloseDialog -> showCloseDialog { viewModel.goHome() }
Expand Down Expand Up @@ -105,8 +107,8 @@ class SrsSymptomsIntroductionFragment : Fragment(R.layout.fragment_submission_sy
}

binding.symptomButtonNext.apply {
isEnabled = symptomIndication != null
setText(
isActive = symptomIndication != null
defaultButton.setText(
when (symptomIndication) {
Symptoms.Indication.NEGATIVE -> R.string.submission_done_button_done
Symptoms.Indication.NO_INFORMATION -> R.string.submission_done_button_done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SrsSymptomsIntroductionViewModel @AssistedInject constructor(
) : CWAViewModel(dispatcherProvider) {

val events = SingleLiveEvent<SrsSymptomsIntroductionNavigation>()
val showLoadingIndicator = SingleLiveEvent<Boolean>()

private val symptomIndicationInternal = MutableStateFlow<Symptoms.Indication?>(null)
val symptomIndication = symptomIndicationInternal.asLiveData(context = dispatcherProvider.Default)
Expand All @@ -47,6 +48,7 @@ class SrsSymptomsIntroductionViewModel @AssistedInject constructor(
}

fun onWarningClicked() {
showLoadingIndicator.postValue(true)
when (symptomIndication.value) {
Symptoms.Indication.NEGATIVE -> {
submitSRS(Symptoms.Indication.NEGATIVE)
Expand Down Expand Up @@ -76,6 +78,8 @@ class SrsSymptomsIntroductionViewModel @AssistedInject constructor(
events.postValue(SrsSymptomsIntroductionNavigation.GoToThankYouScreen(submissionType))
} catch (e: Exception) {
events.postValue(SrsSymptomsIntroductionNavigation.Error(e))
} finally {
showLoadingIndicator.postValue(false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SubmissionSymptomCalendarFragment :
}

symptomButtonNext.apply {
isEnabled = symptomStart != null
isActive = symptomStart != null
setOnClickListener { viewModel.onDone() }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class SubmissionSymptomIntroductionFragment :
}

binding.symptomButtonNext.apply {
isEnabled = symptomIndication != null
setText(
isActive = symptomIndication != null
defaultButton.setText(
when (symptomIndication) {
Symptoms.Indication.NEGATIVE -> R.string.submission_done_button_done
Symptoms.Indication.NO_INFORMATION -> R.string.submission_done_button_done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,20 @@

</ScrollView>

<Button
<de.rki.coronawarnapp.ui.view.ProgressLoadingButton
android:id="@+id/symptom_button_next"
style="@style/buttonPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/spacing_normal"
android:layout_marginVertical="@dimen/spacing_small"
android:layout_marginBottom="@dimen/spacing_small"
android:text="@string/submission_done_button_done"
app:buttonText="@string/submission_done_button_done"
app:isLoading="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/scrollView" />
app:layout_constraintTop_toBottomOf="@id/scrollView"
app:loadingText="@string/start_validation_rule_check_loading_text" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,18 @@

</ScrollView>

<Button
<de.rki.coronawarnapp.ui.view.ProgressLoadingButton
android:id="@+id/symptom_button_next"
style="@style/buttonPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/spacing_normal"
android:layout_marginVertical="@dimen/spacing_small"
android:text="@string/submission_symptom_further_button"
app:buttonText="@string/submission_symptom_further_button"
app:isLoading="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/scrollView" />
app:layout_constraintTop_toBottomOf="@id/scrollView"
app:loadingText="@string/start_validation_rule_check_loading_text" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>