Skip to content

Commit

Permalink
Merge pull request #183 from Infomaniak/initProgress-color
Browse files Browse the repository at this point in the history
Send current textColor to `initProgress()` so it'll be able to restore it when progress is done
  • Loading branch information
tevincent authored May 24, 2024
2 parents f9990da + be700bd commit 3b4f976
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/com/infomaniak/lib/core/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import androidx.viewbinding.ViewBinding
import coil.ImageLoader
import coil.load
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
Expand Down Expand Up @@ -101,9 +102,20 @@ fun Context.showToast(title: Int, duration: Int = Toast.LENGTH_LONG) {
Toast.makeText(this, title, duration).show()
}

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

lifecycle.bindProgressButton(button = this)
attachTextChangeAnimator()

val params = color?.let {
TextChangeAnimatorParams().apply {
useCurrentTextColor = false
textColor = color
fadeInMills = 0L
fadeOutMills = 0L
}
}

attachTextChangeAnimator(params)
}

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

0 comments on commit 3b4f976

Please sign in to comment.