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.mediaprojection.appselector.view 18 19 import android.view.LayoutInflater 20 import android.view.View 21 import android.view.ViewGroup 22 import androidx.recyclerview.widget.RecyclerView 23 import com.android.systemui.res.R 24 import com.android.systemui.mediaprojection.appselector.data.RecentTask 25 import dagger.assisted.Assisted 26 import dagger.assisted.AssistedFactory 27 import dagger.assisted.AssistedInject 28 29 class RecentTasksAdapter 30 @AssistedInject 31 constructor( 32 @Assisted private val items: List<RecentTask>, 33 @Assisted private val listener: RecentTaskClickListener, 34 private val viewHolderFactory: RecentTaskViewHolder.Factory 35 ) : RecyclerView.Adapter<RecentTaskViewHolder>() { 36 onCreateViewHoldernull37 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecentTaskViewHolder { 38 val taskItem = 39 LayoutInflater.from(parent.context) 40 .inflate(R.layout.media_projection_task_item, parent, false) as ViewGroup 41 42 return viewHolderFactory.create(taskItem) 43 } 44 onBindViewHoldernull45 override fun onBindViewHolder(holder: RecentTaskViewHolder, position: Int) { 46 val task = items[position] 47 holder.bind(task, onClick = { 48 listener.onRecentAppClicked(task, holder.itemView) 49 }) 50 } 51 getItemCountnull52 override fun getItemCount(): Int = items.size 53 54 override fun onViewRecycled(holder: RecentTaskViewHolder) { 55 holder.onRecycled() 56 } 57 58 interface RecentTaskClickListener { onRecentAppClickednull59 fun onRecentAppClicked(task: RecentTask, view: View) 60 } 61 62 @AssistedFactory 63 fun interface Factory { 64 fun create(items: List<RecentTask>, listener: RecentTaskClickListener): RecentTasksAdapter 65 } 66 } 67