| /* |
| * Copyright (C) 2019 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.systemui.statusbar.notification.stack |
| |
| import android.content.Context |
| import android.util.AttributeSet |
| import android.view.View |
| import android.view.ViewGroup |
| import android.widget.ImageView |
| import android.widget.LinearLayout |
| import android.widget.TextView |
| import com.android.systemui.R |
| import com.android.systemui.statusbar.notification.people.PersonViewModel |
| import com.android.systemui.statusbar.notification.people.DataListener |
| import com.android.systemui.statusbar.notification.row.ActivatableNotificationView |
| |
| class PeopleHubView(context: Context, attrs: AttributeSet) : |
| ActivatableNotificationView(context, attrs) { |
| |
| private lateinit var contents: ViewGroup |
| private lateinit var personControllers: List<PersonDataListenerImpl> |
| val personViewAdapters: Sequence<DataListener<PersonViewModel?>> |
| get() = personControllers.asSequence() |
| |
| override fun onFinishInflate() { |
| super.onFinishInflate() |
| contents = requireViewById(R.id.people_list) |
| personControllers = (0 until contents.childCount) |
| .asSequence() |
| .mapNotNull { idx -> |
| (contents.getChildAt(idx) as? LinearLayout)?.let(::PersonDataListenerImpl) |
| } |
| .toList() |
| } |
| |
| override fun getContentView(): View = contents |
| |
| private inner class PersonDataListenerImpl(val viewGroup: ViewGroup) : |
| DataListener<PersonViewModel?> { |
| |
| val nameView = viewGroup.requireViewById<TextView>(R.id.person_name) |
| val avatarView = viewGroup.requireViewById<ImageView>(R.id.person_icon) |
| |
| override fun onDataChanged(data: PersonViewModel?) { |
| viewGroup.visibility = data?.let { View.VISIBLE } ?: View.INVISIBLE |
| nameView.text = data?.name |
| avatarView.setImageDrawable(data?.icon) |
| viewGroup.setOnClickListener { data?.onClick?.invoke() } |
| } |
| } |
| } |