1 /* <lambda>null2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.statusbar.chips.ui.viewmodel 18 19 import android.view.View 20 import com.android.internal.logging.InstanceId 21 import com.android.systemui.animation.DialogCuj 22 import com.android.systemui.animation.DialogTransitionAnimator 23 import com.android.systemui.animation.Expandable 24 import com.android.systemui.log.LogBuffer 25 import com.android.systemui.log.core.LogLevel 26 import com.android.systemui.res.R 27 import com.android.systemui.statusbar.chips.StatusBarChipsLog 28 import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel 29 import com.android.systemui.statusbar.chips.ui.view.ChipBackgroundContainer 30 import com.android.systemui.statusbar.chips.uievents.StatusBarChipsUiEventLogger 31 import com.android.systemui.statusbar.phone.SystemUIDialog 32 import com.android.systemui.statusbar.phone.ongoingcall.StatusBarChipsModernization 33 import kotlinx.coroutines.flow.StateFlow 34 35 /** 36 * Interface for a view model that knows the display requirements for a single type of ongoing 37 * activity chip. 38 */ 39 interface OngoingActivityChipViewModel { 40 /** A flow modeling the chip that should be shown (or not shown). */ 41 val chip: StateFlow<OngoingActivityChipModel> 42 43 companion object { 44 /** Creates a chip click listener that launches a dialog created by [dialogDelegate]. */ 45 fun createDialogLaunchOnClickListener( 46 dialogDelegate: SystemUIDialog.Delegate, 47 dialogTransitionAnimator: DialogTransitionAnimator, 48 cuj: DialogCuj, 49 instanceId: InstanceId, 50 uiEventLogger: StatusBarChipsUiEventLogger, 51 @StatusBarChipsLog logger: LogBuffer, 52 tag: String, 53 ): View.OnClickListener { 54 return View.OnClickListener { view -> 55 StatusBarChipsModernization.assertInLegacyMode() 56 57 logger.log(tag, LogLevel.INFO, {}, { "Chip clicked" }) 58 uiEventLogger.logChipTapToShow(instanceId) 59 60 val dialog = dialogDelegate.createDialog() 61 val launchableView = 62 view.requireViewById<ChipBackgroundContainer>( 63 R.id.ongoing_activity_chip_background 64 ) 65 dialogTransitionAnimator.showFromView(dialog, launchableView, cuj) 66 } 67 } 68 69 /** 70 * Creates a chip click callback with an [Expandable] parameter that launches a dialog 71 * created by [dialogDelegate]. 72 */ 73 fun createDialogLaunchOnClickCallback( 74 dialogDelegate: SystemUIDialog.Delegate, 75 dialogTransitionAnimator: DialogTransitionAnimator, 76 cuj: DialogCuj, 77 instanceId: InstanceId, 78 uiEventLogger: StatusBarChipsUiEventLogger, 79 @StatusBarChipsLog logger: LogBuffer, 80 tag: String, 81 ): (Expandable) -> Unit { 82 return { expandable -> 83 StatusBarChipsModernization.unsafeAssertInNewMode() 84 85 logger.log(tag, LogLevel.INFO, {}, { "Chip clicked" }) 86 uiEventLogger.logChipTapToShow(instanceId) 87 88 val dialog = dialogDelegate.createDialog() 89 90 val controller = expandable.dialogTransitionController(cuj) 91 if (controller != null) { 92 dialogTransitionAnimator.show(dialog, controller) 93 } 94 } 95 } 96 } 97 } 98