1 /* 2 * 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.intentresolver.profiles; 18 19 import android.view.ViewGroup; 20 21 import com.android.intentresolver.emptystate.EmptyStateUiHelper; 22 23 import java.util.Optional; 24 import java.util.function.Supplier; 25 26 // TODO: `ChooserActivity` also has a per-profile record type. Maybe the "multi-profile pager" 27 // should be the owner of all per-profile data (especially now that the API is generic)? 28 class ProfileDescriptor<PageViewT, SinglePageAdapterT> { 29 final @MultiProfilePagerAdapter.ProfileType int mProfile; 30 final String mTabLabel; 31 final String mTabAccessibilityLabel; 32 final String mTabTag; 33 34 final ViewGroup mRootView; 35 final EmptyStateUiHelper mEmptyStateUi; 36 37 // TODO: post-refactoring, we may not need to retain these ivars directly (since they may 38 // be encapsulated within the `EmptyStateUiHelper`?). 39 private final ViewGroup mEmptyStateView; 40 41 private final SinglePageAdapterT mAdapter; 42 getAdapter()43 public SinglePageAdapterT getAdapter() { 44 return mAdapter; 45 } 46 getView()47 public PageViewT getView() { 48 return mView; 49 } 50 51 private final PageViewT mView; 52 ProfileDescriptor( @ultiProfilePagerAdapter.ProfileType int forProfile, String tabLabel, String tabAccessibilityLabel, String tabTag, ViewGroup rootView, SinglePageAdapterT adapter, Supplier<Optional<Integer>> containerBottomPaddingOverrideSupplier)53 ProfileDescriptor( 54 @MultiProfilePagerAdapter.ProfileType int forProfile, 55 String tabLabel, 56 String tabAccessibilityLabel, 57 String tabTag, 58 ViewGroup rootView, 59 SinglePageAdapterT adapter, 60 Supplier<Optional<Integer>> containerBottomPaddingOverrideSupplier) { 61 mProfile = forProfile; 62 mTabLabel = tabLabel; 63 mTabAccessibilityLabel = tabAccessibilityLabel; 64 mTabTag = tabTag; 65 mRootView = rootView; 66 mAdapter = adapter; 67 mEmptyStateView = rootView.findViewById(com.android.internal.R.id.resolver_empty_state); 68 mView = (PageViewT) rootView.findViewById(com.android.internal.R.id.resolver_list); 69 mEmptyStateUi = new EmptyStateUiHelper( 70 rootView, 71 com.android.internal.R.id.resolver_list, 72 containerBottomPaddingOverrideSupplier); 73 } 74 getEmptyStateView()75 protected ViewGroup getEmptyStateView() { 76 return mEmptyStateView; 77 } 78 setupContainerPadding()79 public void setupContainerPadding() { 80 mEmptyStateUi.setupContainerPadding(); 81 } 82 } 83