Skip to content

Commit

Permalink
Merge pull request #1943 from Infomaniak/show-progress-catching
Browse files Browse the repository at this point in the history
Prevent showing and hiding progress crashes by using showProgressCatching() and hideProgressCatching()
  • Loading branch information
sirambd committed Jun 27, 2024
2 parents 8e458a0 + 54e3cbf commit 3359d8d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.google.android.material.button.MaterialButton
import com.infomaniak.lib.core.utils.Utils
import com.infomaniak.lib.core.utils.hideProgress
import com.infomaniak.lib.core.utils.hideProgressCatching
import com.infomaniak.lib.core.utils.initProgress
import com.infomaniak.lib.core.utils.showProgress
import com.infomaniak.lib.core.utils.showProgressCatching
import com.infomaniak.mail.R

abstract class BaseAlertDialog(activityContext: Context) : DefaultLifecycleObserver {
Expand All @@ -45,12 +45,12 @@ abstract class BaseAlertDialog(activityContext: Context) : DefaultLifecycleObser
fun startLoading() {
alertDialog.setCancelable(false)
negativeButton.isEnabled = false
Utils.createRefreshTimer(onTimerFinish = positiveButton::showProgress).start()
Utils.createRefreshTimer(onTimerFinish = positiveButton::showProgressCatching).start()
}

fun resetLoadingAndDismiss() = with(alertDialog) {
if (isShowing) {
positiveButton.hideProgress(R.string.buttonCreate)
positiveButton.hideProgressCatching(R.string.buttonCreate)
negativeButton.isEnabled = true
setCancelable(true)
dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class LoginFragment : Fragment() {

private fun resetLoginButtons() = with(binding) {
connectButtonProgressTimer.cancel()
connectButton.hideProgress(RCore.string.connect)
connectButton.hideProgressCatching(RCore.string.connect)
signInButton.isEnabled = true
}

Expand All @@ -198,7 +198,7 @@ class LoginFragment : Fragment() {
}

private fun startProgress() {
binding.connectButton.showProgress(getCurrentOnPrimary())
binding.connectButton.showProgressCatching(getCurrentOnPrimary())
}

private fun getCurrentOnPrimary(): Int? = introViewModel.updatedAccentColor.value?.first?.getOnPrimary(requireContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class InvalidPasswordFragment : Fragment() {
passwordInputLayout.error = getString(error)
passwordInput.text = null
updatePasswordButtonProgressTimer.cancel()
confirmButton.hideProgress(R.string.buttonConfirm)
confirmButton.hideProgressCatching(R.string.buttonConfirm)
}

invalidPasswordViewModel.detachMailboxResult.observe(viewLifecycleOwner) { error ->
Expand Down Expand Up @@ -142,6 +142,6 @@ class InvalidPasswordFragment : Fragment() {
}

private fun startProgress() {
binding.confirmButton.showProgress()
binding.confirmButton.showProgressCatching()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class RestoreEmailsBottomSheetDialog : BottomSheetDialogFragment() {
val formattedDate = formattedDates?.get(date) ?: date
restoreEmailViewModel.restoreEmails(formattedDate).observe(viewLifecycleOwner) { apiResponse ->
restoreEmailsButtonProgressTimer.cancel()
binding.restoreMailsButton.hideProgress(R.string.buttonConfirmRestoreEmails)
binding.restoreMailsButton.hideProgressCatching(R.string.buttonConfirmRestoreEmails)
showSnackbar(if (apiResponse.isSuccess()) R.string.snackbarRestorationLaunched else apiResponse.translatedError)
findNavController().popBackStack()
}
Expand All @@ -126,6 +126,6 @@ class RestoreEmailsBottomSheetDialog : BottomSheetDialogFragment() {
}

private fun startProgress() {
binding.restoreMailsButton.showProgress()
binding.restoreMailsButton.showProgressCatching()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ class AttachMailboxFragment : Fragment() {

passwordInput.text = null
attachMailboxButtonProgressTimer.cancel()
attachMailboxButton.hideProgress(R.string.buttonAttachMailbox)
attachMailboxButton.hideProgressCatching(R.string.buttonAttachMailbox)
}
}

private fun startProgress() {
binding.attachMailboxButton.showProgress()
binding.attachMailboxButton.showProgressCatching()
}
}

0 comments on commit 3359d8d

Please sign in to comment.