Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent showing and hiding progress crashes #201

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading