Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7fb3461a authored by Mill Chen's avatar Mill Chen
Browse files

Implement the renderers for conditional header and footer

Bug: 119593268
Bug: 113451905
Test: visual
Change-Id: I43d6ca8508f0ba49796004d679d6cbe37ddf4455
parent 59482597
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -33,13 +33,16 @@ public class ContextualCard {
    /**
     * Flags indicating the type of the ContextualCard.
     */
    @IntDef({CardType.DEFAULT, CardType.SLICE, CardType.LEGACY_SUGGESTION, CardType.CONDITIONAL})
    @IntDef({CardType.DEFAULT, CardType.SLICE, CardType.LEGACY_SUGGESTION, CardType.CONDITIONAL,
            CardType.CONDITIONAL_HEADER, CardType.CONDITIONAL_FOOTER})
    @Retention(RetentionPolicy.SOURCE)
    public @interface CardType {
        int DEFAULT = 0;
        int SLICE = 1;
        int LEGACY_SUGGESTION = 2;
        int CONDITIONAL = 3;
        int CONDITIONAL_HEADER = 4;
        int CONDITIONAL_FOOTER = 5;
    }

    private final Builder mBuilder;
+5 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ public class ConditionContextualCardController implements ContextualCardControll
    private final ConditionManager mConditionManager;

    private ContextualCardUpdateListener mListener;
    private boolean mIsExpanded;

    public ConditionContextualCardController(Context context) {
        mContext = context;
@@ -49,6 +50,10 @@ public class ConditionContextualCardController implements ContextualCardControll
        mConditionManager.startMonitoringStateChange();
    }

    public void setIsExpanded(boolean isExpanded) {
        mIsExpanded = isExpanded;
    }

    @Override
    public void setCardUpdateListener(ContextualCardUpdateListener listener) {
        mListener = listener;
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.settings.homepage.contextualcards.conditional;

import com.android.settings.homepage.contextualcards.ContextualCard;

/**
 * Data class representing a condition footer {@link ContextualCard}.
 *
 * Use this class for {@link ConditionFooterContextualCardRenderer} and
 * {@link ConditionContextualCardController}.
 */
public class ConditionFooterContextualCard extends ContextualCard {

    private ConditionFooterContextualCard(Builder builder) {
        super(builder);
    }

    @Override
    public int getCardType() {
        return CardType.CONDITIONAL_FOOTER;
    }

    public static class Builder extends ContextualCard.Builder {

        @Override
        public Builder setCardType(int cardType) {
            throw new IllegalArgumentException(
                    "Cannot change card type for " + getClass().getName());
        }

        public ConditionFooterContextualCard build() {
            return new ConditionFooterContextualCard(this);
        }
    }
}
 No newline at end of file
+79 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.settings.homepage.contextualcards.conditional;

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.homepage.contextualcards.ContextualCard;
import com.android.settings.homepage.contextualcards.ContextualCardRenderer;
import com.android.settings.homepage.contextualcards.ControllerRendererPool;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;

public class ConditionFooterContextualCardRenderer implements ContextualCardRenderer {
    public static final int VIEW_TYPE = R.layout.homepage_condition_footer;
    private static final String TAG = "ConditionFooterRenderer";

    private final Context mContext;
    private final ControllerRendererPool mControllerRendererPool;

    public ConditionFooterContextualCardRenderer(Context context,
            ControllerRendererPool controllerRendererPool) {
        mContext = context;
        mControllerRendererPool = controllerRendererPool;
    }

    @Override
    public int getViewType(boolean isHalfWidth) {
        return VIEW_TYPE;
    }

    @Override
    public RecyclerView.ViewHolder createViewHolder(View view) {
        return new ConditionFooterCardHolder(view);
    }

    @Override
    public void bindView(RecyclerView.ViewHolder holder, ContextualCard card) {
        final MetricsFeatureProvider metricsFeatureProvider = FeatureFactory.getFactory(
                mContext).getMetricsFeatureProvider();
        holder.itemView.setOnClickListener(v -> {
            metricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN,
                    MetricsProto.MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND,
                    SettingsEnums.SETTINGS_HOMEPAGE,
                    null /* key */,
                    0 /* false */);
            final ConditionContextualCardController controller =
                    mControllerRendererPool.getController(mContext,
                            ContextualCard.CardType.CONDITIONAL_FOOTER);
            controller.setIsExpanded(false);
            controller.onConditionsChanged();
        });
    }

    public static class ConditionFooterCardHolder extends RecyclerView.ViewHolder {
        public ConditionFooterCardHolder(View itemView) {
            super(itemView);
        }
    }
}
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.settings.homepage.contextualcards.conditional;

import com.android.settings.homepage.contextualcards.ContextualCard;

import java.util.List;

/**
 * Data class representing a condition header {@link ContextualCard}.
 *
 * Use this class to store additional attributes on top of {@link ContextualCard} for
 * {@link ConditionHeaderContextualCardRenderer} and {@link ConditionContextualCardController}.
 */
public class ConditionHeaderContextualCard extends ContextualCard {

    private final List<ContextualCard> mConditionalCards;

    private ConditionHeaderContextualCard(Builder builder) {
        super(builder);
        mConditionalCards = builder.mConditionalCards;
    }

    @Override
    public int getCardType() {
        return CardType.CONDITIONAL_HEADER;
    }

    public List<ContextualCard> getConditionalCards() {
        return mConditionalCards;
    }

    public static class Builder extends ContextualCard.Builder {

        private List<ContextualCard> mConditionalCards;

        public Builder setConditionalCards(List<ContextualCard> conditionalCards) {
            mConditionalCards = conditionalCards;
            return this;
        }

        @Override
        public Builder setCardType(int cardType) {
            throw new IllegalArgumentException(
                    "Cannot change card type for " + getClass().getName());
        }

        public ConditionHeaderContextualCard build() {
            return new ConditionHeaderContextualCard(this);
        }
    }
}
 No newline at end of file
Loading