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.text.TextUtils; 20 21 import com.android.settings.homepage.contextualcards.ContextualCard; 22 23 import java.util.List; 24 import java.util.Objects; 25 26 /** 27 * Data class representing a condition header {@link ContextualCard}. 28 * 29 * Use this class to store additional attributes on top of {@link ContextualCard} for 30 * {@link ConditionHeaderContextualCardRenderer} and {@link ConditionContextualCardController}. 31 */ 32 public class ConditionHeaderContextualCard extends ContextualCard { 33 34 private final List<ContextualCard> mConditionalCards; 35 ConditionHeaderContextualCard(Builder builder)36 private ConditionHeaderContextualCard(Builder builder) { 37 super(builder); 38 mConditionalCards = builder.mConditionalCards; 39 } 40 41 @Override getCardType()42 public int getCardType() { 43 return CardType.CONDITIONAL_HEADER; 44 } 45 getConditionalCards()46 public List<ContextualCard> getConditionalCards() { 47 return mConditionalCards; 48 } 49 50 @Override hashCode()51 public int hashCode() { 52 return Objects.hash(getName(), mConditionalCards); 53 } 54 55 @Override equals(Object obj)56 public boolean equals(Object obj) { 57 if (this == obj) { 58 return true; 59 } 60 if (!(obj instanceof ConditionHeaderContextualCard)) { 61 return false; 62 } 63 final ConditionHeaderContextualCard that = (ConditionHeaderContextualCard) obj; 64 65 return TextUtils.equals(getName(), that.getName()) && mConditionalCards.equals( 66 that.mConditionalCards); 67 } 68 69 public static class Builder extends ContextualCard.Builder { 70 71 private List<ContextualCard> mConditionalCards; 72 setConditionalCards(List<ContextualCard> conditionalCards)73 public Builder setConditionalCards(List<ContextualCard> conditionalCards) { 74 mConditionalCards = conditionalCards; 75 return this; 76 } 77 78 @Override setCardType(int cardType)79 public Builder setCardType(int cardType) { 80 throw new IllegalArgumentException( 81 "Cannot change card type for " + getClass().getName()); 82 } 83 build()84 public ConditionHeaderContextualCard build() { 85 return new ConditionHeaderContextualCard(this); 86 } 87 } 88 }