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 2 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
33 changes: 26 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 All @@ -77,6 +76,8 @@ import com.infomaniak.lib.core.utils.Utils.CAMEL_CASE_REGEX
import com.infomaniak.lib.core.utils.Utils.SNAKE_CASE_REGEX
import com.infomaniak.lib.core.utils.UtilsUi.generateInitialsAvatarDrawable
import com.infomaniak.lib.core.utils.UtilsUi.getBackgroundColorBasedOnId
import io.sentry.Sentry
import io.sentry.SentryLevel
import org.apache.commons.cli.MissingArgumentException
import java.io.Serializable
import kotlin.properties.ReadWriteProperty
Expand Down Expand Up @@ -120,17 +121,35 @@ fun MaterialButton.updateTextColor(color: Int?) {
initProgress(color = color)
}

fun MaterialButton.showProgress(color: Int? = null) {
fun MaterialButton.showProgressCatching(color: Int? = null) {
class ShowProgressException(cause: Throwable) : Exception("showProgressCatching failed to show progress", cause)

isClickable = false
showProgress {
progressColor = color ?: Color.WHITE
gravity = GRAVITY_CENTER
runCatching {
showProgress {
progressColor = color ?: Color.WHITE
gravity = GRAVITY_CENTER
}
}.onFailure { exception ->
Sentry.withScope { scope ->
scope.level = SentryLevel.INFO
Sentry.captureException(ShowProgressException(exception))
}
}
}

fun MaterialButton.hideProgress(@StringRes text: Int) {
fun MaterialButton.hideProgressCatching(@StringRes text: Int) {
class HideProgressException(cause: Throwable) : Exception("hideProgressCatching failed to hide progress", cause)

isClickable = true
hideProgress(text)
runCatching {
hideProgress(text)
}.onFailure { exception ->
Sentry.withScope { scope ->
scope.level = SentryLevel.INFO
Sentry.captureException(HideProgressException(exception))
}
}
}

/**
Expand Down
Loading