1 /* 2 * Copyright (C) 2022 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.people.data.repository 18 19 import android.app.people.PeopleSpaceTile 20 import com.android.systemui.dagger.SysUISingleton 21 import com.android.systemui.people.PeopleTileViewHelper 22 import com.android.systemui.people.data.model.PeopleTileModel 23 import com.android.systemui.people.widget.PeopleSpaceWidgetManager 24 import com.android.systemui.people.widget.PeopleTileKey 25 import javax.inject.Inject 26 27 /** A Repository to fetch the current tiles/conversations. */ 28 // TODO(b/238993727): Make the tiles API reactive. 29 interface PeopleTileRepository { 30 /* The current priority tiles. */ priorityTilesnull31 fun priorityTiles(): List<PeopleTileModel> 32 33 /* The current recent tiles. */ 34 fun recentTiles(): List<PeopleTileModel> 35 } 36 37 @SysUISingleton 38 class PeopleTileRepositoryImpl 39 @Inject 40 constructor( 41 private val peopleSpaceWidgetManager: PeopleSpaceWidgetManager, 42 ) : PeopleTileRepository { 43 override fun priorityTiles(): List<PeopleTileModel> { 44 return peopleSpaceWidgetManager.priorityTiles.map { it.toModel() } 45 } 46 47 override fun recentTiles(): List<PeopleTileModel> { 48 return peopleSpaceWidgetManager.recentTiles.map { it.toModel() } 49 } 50 51 private fun PeopleSpaceTile.toModel(): PeopleTileModel { 52 return PeopleTileModel( 53 PeopleTileKey(this), 54 userName.toString(), 55 userIcon, 56 PeopleTileViewHelper.getHasNewStory(this), 57 isImportantConversation, 58 PeopleTileViewHelper.isDndBlockingTileData(this), 59 ) 60 } 61 } 62