1 /* <lambda>null2 * Copyright (C) 2019 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.notification.stack 18 19 import android.annotation.ColorInt 20 import android.content.Context 21 import android.util.AttributeSet 22 import android.view.View 23 import android.view.ViewGroup 24 import android.widget.ImageView 25 import android.widget.TextView 26 import com.android.systemui.R 27 import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin 28 import com.android.systemui.statusbar.notification.people.DataListener 29 import com.android.systemui.statusbar.notification.people.PersonViewModel 30 import com.android.systemui.statusbar.notification.row.StackScrollerDecorView 31 32 class PeopleHubView(context: Context, attrs: AttributeSet) : 33 StackScrollerDecorView(context, attrs), SwipeableView { 34 35 private lateinit var contents: ViewGroup 36 private lateinit var label: TextView 37 38 lateinit var personViewAdapters: Sequence<DataListener<PersonViewModel?>> 39 private set 40 41 override fun onFinishInflate() { 42 contents = requireViewById(R.id.people_list) 43 label = requireViewById(R.id.header_label) 44 personViewAdapters = (0 until contents.childCount) 45 .asSequence() // so we can map 46 .mapNotNull { idx -> 47 // get all our people slots 48 (contents.getChildAt(idx) as? ImageView)?.let(::PersonDataListenerImpl) 49 } 50 .toList() // cache it 51 .asSequence() // but don't reveal it's a list 52 super.onFinishInflate() 53 setVisible(true /* nowVisible */, false /* animate */) 54 } 55 56 fun setTextColor(@ColorInt color: Int) = label.setTextColor(color) 57 58 override fun findContentView(): View = contents 59 override fun findSecondaryView(): View? = null 60 61 override fun hasFinishedInitialization(): Boolean = true 62 63 override fun createMenu(): NotificationMenuRowPlugin? = null 64 65 override fun resetTranslation() { 66 translationX = 0f 67 } 68 69 override fun setTranslation(translation: Float) { 70 if (canSwipe) { 71 super.setTranslation(translation) 72 } 73 } 74 75 var canSwipe: Boolean = false 76 set(value) { 77 if (field != value) { 78 if (field) { 79 resetTranslation() 80 } 81 field = value 82 } 83 } 84 85 override fun needsClippingToShelf(): Boolean = true 86 87 override fun applyContentTransformation(contentAlpha: Float, translationY: Float) { 88 super.applyContentTransformation(contentAlpha, translationY) 89 for (i in 0 until contents.childCount) { 90 val view = contents.getChildAt(i) 91 view.alpha = contentAlpha 92 view.translationY = translationY 93 } 94 } 95 96 private inner class PersonDataListenerImpl(val avatarView: ImageView) : 97 DataListener<PersonViewModel?> { 98 99 override fun onDataChanged(data: PersonViewModel?) { 100 avatarView.visibility = data?.let { View.VISIBLE } ?: View.GONE 101 avatarView.setImageDrawable(data?.icon) 102 avatarView.setOnClickListener { data?.onClick?.invoke() } 103 } 104 } 105 }