Skip to content

Commit

Permalink
Merge pull request #201 from Infomaniak/show-progress-catching
Browse files Browse the repository at this point in the history
Prevent showing and hiding progress crashes
  • Loading branch information
sirambd committed Jun 27, 2024
2 parents 3d6d360 + 7dc52ca commit 11ab8f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class BugTrackerActivity : AppCompatActivity() {
} else if (descriptionTextInput.text.isNullOrBlank() || subjectTextInput.text.isNullOrBlank()) {
missingFieldsError.isVisible = true
} else {
showProgress()
showProgressCatching()
sendBugReport()
}
}
Expand All @@ -114,7 +114,7 @@ class BugTrackerActivity : AppCompatActivity() {
showToast(R.string.bugTrackerFormSubmitSuccess)
finish()
} else {
submitButton.hideProgress(R.string.bugTrackerSubmit)
submitButton.hideProgressCatching(R.string.bugTrackerSubmit)
showSnackbar(R.string.bugTrackerFormSubmitError)
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/com/infomaniak/lib/core/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ import coil.ImageLoader
import coil.load
import com.github.razir.progressbutton.*
import com.github.razir.progressbutton.DrawableButton.Companion.GRAVITY_CENTER
import com.github.razir.progressbutton.hideProgress
import com.google.android.material.button.MaterialButton
import com.infomaniak.lib.core.models.user.User
import com.infomaniak.lib.core.utils.CoilUtils.simpleImageLoader
Expand Down Expand Up @@ -120,17 +119,21 @@ fun MaterialButton.updateTextColor(color: Int?) {
initProgress(color = color)
}

fun MaterialButton.showProgress(color: Int? = null) {
fun MaterialButton.showProgressCatching(color: Int? = null) {
isClickable = false
showProgress {
progressColor = color ?: Color.WHITE
gravity = GRAVITY_CENTER
// showProgress stores references to views which crashes when the view is freed
runCatching {
showProgress {
progressColor = color ?: Color.WHITE
gravity = GRAVITY_CENTER
}
}
}

fun MaterialButton.hideProgress(@StringRes text: Int) {
fun MaterialButton.hideProgressCatching(@StringRes text: Int) {
isClickable = true
hideProgress(text)
// hideProgress stores references to views which crashes when the view is freed
runCatching { hideProgress(text) }
}

/**
Expand Down

0 comments on commit 11ab8f1

Please sign in to comment.