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

Commit 39cfbb80 authored by Miranda Kephart's avatar Miranda Kephart
Browse files

Add badge to work profile screenshots in shelf UI

Bug: 339373904
Test: manual (visual change)
Flag: ACONFIG com.android.systemui.screenshot_shelf_ui2 TEAMFOOD
Change-Id: I2968b23b08c28850b48ecb3f86f0f872e001a872
parent 1ada6e0b
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.view.WindowInsets
import android.view.WindowManager
import android.window.OnBackInvokedCallback
import android.window.OnBackInvokedDispatcher
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.animation.doOnEnd
import androidx.core.animation.doOnStart
import com.android.internal.logging.UiEventLogger
@@ -69,7 +70,17 @@ constructor(
    override var callbacks: ScreenshotView.ScreenshotViewCallback? = null
    override var screenshot: ScreenshotData? = null
        set(value) {
            viewModel.setScreenshotBitmap(value?.bitmap)
            value?.let {
                viewModel.setScreenshotBitmap(it.bitmap)
                val badgeBg =
                    AppCompatResources.getDrawable(context, R.drawable.overlay_badge_background)
                val user = it.userHandle
                if (badgeBg != null && user != null) {
                    viewModel.setScreenshotBadge(
                        context.packageManager.getUserBadgedIcon(badgeBg, user)
                    )
                }
            }
            field = value
        }

+7 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ object ScreenshotShelfViewBinder {
        dismissButton.setOnClickListener {
            onDismissalRequested(ScreenshotEvent.SCREENSHOT_EXPLICIT_DISMISSAL, null)
        }
        val badgeView = view.requireViewById<ImageView>(R.id.screenshot_badge)

        // use immediate dispatcher to ensure screenshot bitmap is set before animation
        view.repeatWhenAttached(Dispatchers.Main.immediate) {
@@ -86,6 +87,12 @@ object ScreenshotShelfViewBinder {
                            }
                        }
                    }
                    launch {
                        viewModel.badge.collect { badge ->
                            badgeView.setImageDrawable(badge)
                            badgeView.visibility = if (badge != null) View.VISIBLE else View.GONE
                        }
                    }
                    launch {
                        viewModel.previewAction.collect { onClick ->
                            previewView.setOnClickListener { onClick?.invoke() }
+8 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.screenshot.ui.viewmodel

import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.util.Log
import android.view.accessibility.AccessibilityManager
import kotlinx.coroutines.flow.MutableStateFlow
@@ -25,6 +26,8 @@ import kotlinx.coroutines.flow.StateFlow
class ScreenshotViewModel(private val accessibilityManager: AccessibilityManager) {
    private val _preview = MutableStateFlow<Bitmap?>(null)
    val preview: StateFlow<Bitmap?> = _preview
    private val _badge = MutableStateFlow<Drawable?>(null)
    val badge: StateFlow<Drawable?> = _badge
    private val _previewAction = MutableStateFlow<(() -> Unit)?>(null)
    val previewAction: StateFlow<(() -> Unit)?> = _previewAction
    private val _actions = MutableStateFlow(emptyList<ActionButtonViewModel>())
@@ -39,6 +42,10 @@ class ScreenshotViewModel(private val accessibilityManager: AccessibilityManager
        _preview.value = bitmap
    }

    fun setScreenshotBadge(badge: Drawable?) {
        _badge.value = badge
    }

    fun setPreviewAction(onClick: () -> Unit) {
        _previewAction.value = onClick
    }
@@ -109,6 +116,7 @@ class ScreenshotViewModel(private val accessibilityManager: AccessibilityManager

    fun reset() {
        _preview.value = null
        _badge.value = null
        _previewAction.value = null
        _actions.value = listOf()
        _animationState.value = AnimationState.NOT_STARTED