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

Commit bd1d0c57 authored by Matt Casey's avatar Matt Casey Committed by Automerger Merge Worker
Browse files

Merge "Add badge to work profile screenshots in shelf UI" into 24D1-dev am: 12c947f9

parents ecde3e18 12c947f9
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