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

Commit 5957b1d6 authored by Nate Myren's avatar Nate Myren
Browse files

Update chip view when PrivacyItems update

If the user beings using a new privacy item while the chip is showing,
display the new item on the chip

Fixes: 187219110
Test: go to camera, start playing video while the chip is showing. It
should update to show the mic icon

Change-Id: I4e98375c70cb25e110824901e8738eab83564b3c
parent 327db785
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -32,6 +32,16 @@ interface StatusEvent {
    // Whether or not to force the status bar open and show a dot
    val forceVisible: Boolean
    val viewCreator: (context: Context) -> View

    // Update this event with values from another event.
    fun updateFromEvent(other: StatusEvent?) {
        // no op by default
    }

    // Whether or not this event should update its value from the provided. False by default
    fun shouldUpdateFromEvent(other: StatusEvent?): Boolean {
        return false
    }
}

class BatteryEvent : StatusEvent {
@@ -53,15 +63,30 @@ class PrivacyEvent : StatusEvent {
    override val priority = 100
    override val forceVisible = true
    var privacyItems: List<PrivacyItem> = listOf()
    private var privacyChip: OngoingPrivacyChip? = null

    override val viewCreator: (context: Context) -> View = { context ->
        val v = LayoutInflater.from(context)
                .inflate(R.layout.ongoing_privacy_chip, null) as OngoingPrivacyChip
        v.privacyList = privacyItems
        privacyChip = v
        v
    }

    override fun toString(): String {
        return javaClass.simpleName
    }

    override fun shouldUpdateFromEvent(other: StatusEvent?): Boolean {
        return other is PrivacyEvent && other.privacyItems != privacyItems
    }

    override fun updateFromEvent(other: StatusEvent?) {
        if (other !is PrivacyEvent) {
            return
        }

        privacyItems = other.privacyItems
        privacyChip?.privacyList = other.privacyItems
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -92,9 +92,6 @@ class SystemEventCoordinator @Inject constructor(
        var currentPrivacyItems = listOf<PrivacyItem>()

        override fun onPrivacyItemsChanged(privacyItems: List<PrivacyItem>) {
            if (privacyItems.isNotEmpty() && currentPrivacyItems.containsAll(privacyItems)) {
                return
            }
            currentPrivacyItems = privacyItems
            notifyListeners()
        }
+29 −3
Original line number Diff line number Diff line
@@ -98,7 +98,8 @@ class SystemStatusAnimationScheduler @Inject constructor(

        // Don't deal with threading for now (no need let's be honest)
        Assert.isMainThread()
        if (event.priority > scheduledEvent?.priority ?: -1) {
        if (event.priority > scheduledEvent?.priority ?: -1 ||
            scheduledEvent?.shouldUpdateFromEvent(event) == true) {
            if (DEBUG) {
                Log.d(TAG, "scheduling event $event")
            }
@@ -134,7 +135,20 @@ class SystemStatusAnimationScheduler @Inject constructor(
     * Clear the scheduled event (if any) and schedule a new one
     */
    private fun scheduleEvent(event: StatusEvent) {
        if (animationState == ANIMATING_OUT ||
            (animationState == SHOWING_PERSISTENT_DOT && event.forceVisible)) {
            // do not schedule an event or change the current one
            return
        }

        // If we are showing the chip, possibly update the current event, rather than replacing
        if (scheduledEvent?.shouldUpdateFromEvent(event) == true) {
            scheduledEvent?.updateFromEvent(event)
            return
        } else {
            scheduledEvent = event
        }

        if (scheduledEvent!!.forceVisible) {
            hasPersistentDot = true
        }
@@ -170,7 +184,13 @@ class SystemStatusAnimationScheduler @Inject constructor(

                val chipAnimator = ValueAnimator.ofFloat(1f, 0f)
                chipAnimator.duration = CHIP_ANIM_LENGTH
                chipAnimator.addListener(ChipAnimatorAdapter(IDLE, scheduledEvent!!.viewCreator))
                val endState = if (hasPersistentDot) {
                    SHOWING_PERSISTENT_DOT
                } else {
                    IDLE
                }
                chipAnimator.addListener(
                    ChipAnimatorAdapter(endState, scheduledEvent!!.viewCreator))
                chipAnimator.addUpdateListener(chipUpdateListener)

                val aSet2 = AnimatorSet()
@@ -207,6 +227,10 @@ class SystemStatusAnimationScheduler @Inject constructor(
            it.onHidePersistentDot()
        }

        if (animationState == SHOWING_PERSISTENT_DOT) {
            animationState = IDLE
        }

        if (anims.isNotEmpty()) {
            val aSet = AnimatorSet()
            aSet.playTogether(anims)
@@ -330,6 +354,8 @@ const val ANIMATING_IN = 1
const val RUNNING_CHIP_ANIM = 2
/** Chip is animating away and system is animating back */
const val ANIMATING_OUT = 3
/** Chip has animated away, and the persistent dot is showing */
const val SHOWING_PERSISTENT_DOT = 4

private const val TAG = "SystemStatusAnimationScheduler"
private const val DELAY: Long = 100