Merge "Update chip view when PrivacyItems update" into sc-dev
This commit is contained in:
@@ -32,6 +32,16 @@ interface StatusEvent {
|
|||||||
// Whether or not to force the status bar open and show a dot
|
// Whether or not to force the status bar open and show a dot
|
||||||
val forceVisible: Boolean
|
val forceVisible: Boolean
|
||||||
val viewCreator: (context: Context) -> View
|
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 {
|
class BatteryEvent : StatusEvent {
|
||||||
@@ -53,15 +63,30 @@ class PrivacyEvent : StatusEvent {
|
|||||||
override val priority = 100
|
override val priority = 100
|
||||||
override val forceVisible = true
|
override val forceVisible = true
|
||||||
var privacyItems: List<PrivacyItem> = listOf()
|
var privacyItems: List<PrivacyItem> = listOf()
|
||||||
|
private var privacyChip: OngoingPrivacyChip? = null
|
||||||
|
|
||||||
override val viewCreator: (context: Context) -> View = { context ->
|
override val viewCreator: (context: Context) -> View = { context ->
|
||||||
val v = LayoutInflater.from(context)
|
val v = LayoutInflater.from(context)
|
||||||
.inflate(R.layout.ongoing_privacy_chip, null) as OngoingPrivacyChip
|
.inflate(R.layout.ongoing_privacy_chip, null) as OngoingPrivacyChip
|
||||||
v.privacyList = privacyItems
|
v.privacyList = privacyItems
|
||||||
|
privacyChip = v
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return javaClass.simpleName
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,9 +92,6 @@ class SystemEventCoordinator @Inject constructor(
|
|||||||
var currentPrivacyItems = listOf<PrivacyItem>()
|
var currentPrivacyItems = listOf<PrivacyItem>()
|
||||||
|
|
||||||
override fun onPrivacyItemsChanged(privacyItems: List<PrivacyItem>) {
|
override fun onPrivacyItemsChanged(privacyItems: List<PrivacyItem>) {
|
||||||
if (privacyItems.isNotEmpty() && currentPrivacyItems.containsAll(privacyItems)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
currentPrivacyItems = privacyItems
|
currentPrivacyItems = privacyItems
|
||||||
notifyListeners()
|
notifyListeners()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,8 @@ class SystemStatusAnimationScheduler @Inject constructor(
|
|||||||
|
|
||||||
// Don't deal with threading for now (no need let's be honest)
|
// Don't deal with threading for now (no need let's be honest)
|
||||||
Assert.isMainThread()
|
Assert.isMainThread()
|
||||||
if (event.priority > scheduledEvent?.priority ?: -1) {
|
if (event.priority > scheduledEvent?.priority ?: -1 ||
|
||||||
|
scheduledEvent?.shouldUpdateFromEvent(event) == true) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "scheduling event $event")
|
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
|
* Clear the scheduled event (if any) and schedule a new one
|
||||||
*/
|
*/
|
||||||
private fun scheduleEvent(event: StatusEvent) {
|
private fun scheduleEvent(event: StatusEvent) {
|
||||||
scheduledEvent = event
|
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) {
|
if (scheduledEvent!!.forceVisible) {
|
||||||
hasPersistentDot = true
|
hasPersistentDot = true
|
||||||
}
|
}
|
||||||
@@ -170,7 +184,13 @@ class SystemStatusAnimationScheduler @Inject constructor(
|
|||||||
|
|
||||||
val chipAnimator = ValueAnimator.ofFloat(1f, 0f)
|
val chipAnimator = ValueAnimator.ofFloat(1f, 0f)
|
||||||
chipAnimator.duration = CHIP_ANIM_LENGTH
|
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)
|
chipAnimator.addUpdateListener(chipUpdateListener)
|
||||||
|
|
||||||
val aSet2 = AnimatorSet()
|
val aSet2 = AnimatorSet()
|
||||||
@@ -207,6 +227,10 @@ class SystemStatusAnimationScheduler @Inject constructor(
|
|||||||
it.onHidePersistentDot()
|
it.onHidePersistentDot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (animationState == SHOWING_PERSISTENT_DOT) {
|
||||||
|
animationState = IDLE
|
||||||
|
}
|
||||||
|
|
||||||
if (anims.isNotEmpty()) {
|
if (anims.isNotEmpty()) {
|
||||||
val aSet = AnimatorSet()
|
val aSet = AnimatorSet()
|
||||||
aSet.playTogether(anims)
|
aSet.playTogether(anims)
|
||||||
@@ -330,6 +354,8 @@ const val ANIMATING_IN = 1
|
|||||||
const val RUNNING_CHIP_ANIM = 2
|
const val RUNNING_CHIP_ANIM = 2
|
||||||
/** Chip is animating away and system is animating back */
|
/** Chip is animating away and system is animating back */
|
||||||
const val ANIMATING_OUT = 3
|
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 TAG = "SystemStatusAnimationScheduler"
|
||||||
private const val DELAY: Long = 100
|
private const val DELAY: Long = 100
|
||||||
|
|||||||
Reference in New Issue
Block a user