Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 02c401b4 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

AccountActivity: animate progress bar becoming invisible (bitfireAT/davx5#366)



* [WIP] Animate invisibility

* Reordered for cleaner look

Signed-off-by: default avatarArnau Mora <arnyminerz@proton.me>

* Fixed animation

Signed-off-by: default avatarArnau Mora <arnyminerz@proton.me>

* Reduced animation time for going to visible to 0

Signed-off-by: default avatarArnau Mora <arnyminerz@proton.me>

* Remove logging

---------

Signed-off-by: default avatarArnau Mora <arnyminerz@proton.me>
Co-authored-by: default avatarArnau Mora <arnyminerz@proton.me>
parent 48327e44
Loading
Loading
Loading
Loading
+22 −12
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@

package at.bitfire.davdroid.ui.account

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.app.Application
import android.content.*
import android.os.Bundle
@@ -98,18 +100,26 @@ abstract class CollectionsFragment: Fragment(), SwipeRefreshLayout.OnRefreshList
        binding.swipeRefresh.setOnRefreshListener(this)

        val updateProgress = Observer<Boolean> {
            binding.progress.apply {
                val isVisible = model.isSyncActive.value == true || model.isSyncPending.value == true

                if (model.isSyncActive.value == true) {
                binding.progress.isIndeterminate = true
                binding.progress.alpha = 1.0f
                binding.progress.visibility = View.VISIBLE
            } else {
                if (model.isSyncPending.value == true) {
                    binding.progress.visibility = View.VISIBLE
                    binding.progress.alpha = 0.2f
                    binding.progress.isIndeterminate = false
                    binding.progress.progress = 100
                } else
                    binding.progress.visibility = View.INVISIBLE
                    isIndeterminate = true
                } else if (model.isSyncPending.value == true) {
                    isIndeterminate = false
                    progress = 100
                }

                animate()
                    .alpha(if (isVisible) 1f else 0f)
                    // go to VISIBLE instantly, take 500 ms for INVISIBLE
                    .setDuration(if (isVisible) 0 else 500)
                    .setListener(object : AnimatorListenerAdapter() {
                        override fun onAnimationEnd(animation: Animator) {
                            super.onAnimationEnd(animation)
                            visibility = if (isVisible) View.VISIBLE else View.INVISIBLE
                        }
                    })
            }
        }
        model.isSyncPending.observe(viewLifecycleOwner, updateProgress)