1 /*
2  * Copyright (C) 2018 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.settings.homepage.contextualcards.conditional;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.view.View;
22 
23 import androidx.annotation.LayoutRes;
24 import androidx.recyclerview.widget.RecyclerView;
25 
26 import com.android.settings.R;
27 import com.android.settings.homepage.contextualcards.ContextualCard;
28 import com.android.settings.homepage.contextualcards.ContextualCardRenderer;
29 import com.android.settings.homepage.contextualcards.ControllerRendererPool;
30 import com.android.settings.overlay.FeatureFactory;
31 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
32 
33 public class ConditionFooterContextualCardRenderer implements ContextualCardRenderer {
34     public static final int VIEW_TYPE = R.layout.conditional_card_footer;
35     private static final String TAG = "ConditionFooterRenderer";
36 
37     private final Context mContext;
38     private final ControllerRendererPool mControllerRendererPool;
39 
ConditionFooterContextualCardRenderer(Context context, ControllerRendererPool controllerRendererPool)40     public ConditionFooterContextualCardRenderer(Context context,
41             ControllerRendererPool controllerRendererPool) {
42         mContext = context;
43         mControllerRendererPool = controllerRendererPool;
44     }
45 
46     @Override
createViewHolder(View view, @LayoutRes int viewType)47     public RecyclerView.ViewHolder createViewHolder(View view, @LayoutRes int viewType) {
48         return new ConditionFooterCardHolder(view);
49     }
50 
51     @Override
bindView(RecyclerView.ViewHolder holder, ContextualCard card)52     public void bindView(RecyclerView.ViewHolder holder, ContextualCard card) {
53         final MetricsFeatureProvider metricsFeatureProvider =
54                 FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
55         holder.itemView.setOnClickListener(v -> {
56             metricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN,
57                     SettingsEnums.ACTION_SETTINGS_CONDITION_EXPAND,
58                     SettingsEnums.SETTINGS_HOMEPAGE,
59                     null /* key */,
60                     0 /* false */);
61             final ConditionContextualCardController controller =
62                     mControllerRendererPool.getController(mContext,
63                             ContextualCard.CardType.CONDITIONAL_FOOTER);
64             controller.setIsExpanded(false);
65             controller.onConditionsChanged();
66         });
67     }
68 
69     public static class ConditionFooterCardHolder extends RecyclerView.ViewHolder {
ConditionFooterCardHolder(View itemView)70         public ConditionFooterCardHolder(View itemView) {
71             super(itemView);
72         }
73     }
74 }
75