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

Add fun updateTextColor() to clean listeners when updating TextColor #184

Merged
merged 1 commit into from
May 24, 2024
Merged
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
14 changes: 8 additions & 6 deletions src/main/java/com/infomaniak/lib/core/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
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.TextChangeAnimatorParams
import com.github.razir.progressbutton.attachTextChangeAnimator
import com.github.razir.progressbutton.bindProgressButton
import com.github.razir.progressbutton.hideProgress
import com.github.razir.progressbutton.showProgress
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 @@ -102,9 +99,9 @@ fun Context.showToast(title: Int, duration: Int = Toast.LENGTH_LONG) {
Toast.makeText(this, title, duration).show()
}

fun MaterialButton.initProgress(lifecycle: LifecycleOwner, color: Int? = null) {
fun MaterialButton.initProgress(lifecycle: LifecycleOwner? = null, color: Int? = null) {

lifecycle.bindProgressButton(button = this)
lifecycle?.bindProgressButton(button = this)

val params = color?.let {
TextChangeAnimatorParams().apply {
Expand All @@ -118,6 +115,11 @@ fun MaterialButton.initProgress(lifecycle: LifecycleOwner, color: Int? = null) {
attachTextChangeAnimator(params)
}

fun MaterialButton.updateTextColor(color: Int?) {
detachTextChangeAnimator()
initProgress(color = color)
}

fun MaterialButton.showProgress(color: Int? = null) {
isClickable = false
showProgress {
Expand Down
Loading