1 /*
2  * Copyright (C) 2016 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 package com.android.launcher3.widget.model;
17 
18 import androidx.annotation.Px;
19 
20 import com.android.launcher3.model.WidgetItem;
21 import com.android.launcher3.model.data.PackageItemInfo;
22 
23 import java.util.List;
24 
25 /**
26  * Holder class to store all the information related to a list of widgets from the same app which is
27  * shown in the {@link com.android.launcher3.widget.picker.WidgetsFullSheet}.
28  */
29 public final class WidgetsListContentEntry extends WidgetsListBaseEntry {
30 
31     @Px private final int mMaxSpanSize;
32 
33     /**
34      * Constructor for {@link WidgetsListContentEntry}.
35      *
36      * @param pkgItem package info associated with the entry
37      * @param titleSectionName title section name associated with the entry.
38      * @param items list of widgets for the package.
39      */
WidgetsListContentEntry(PackageItemInfo pkgItem, String titleSectionName, List<WidgetItem> items)40     public WidgetsListContentEntry(PackageItemInfo pkgItem, String titleSectionName,
41             List<WidgetItem> items) {
42         this(pkgItem, titleSectionName, items, /* maxSpanSize= */ 0);
43     }
44 
45     /**
46      * Constructor for {@link WidgetsListContentEntry}.
47      *
48      * @param pkgItem package info associated with the entry
49      * @param titleSectionName title section name associated with the entry.
50      * @param items list of widgets for the package.
51      * @param maxSpanSize the max horizontal span in pixels that is allowed for grouping more
52      *                           than one widgets in a table row.
53      */
WidgetsListContentEntry(PackageItemInfo pkgItem, String titleSectionName, List<WidgetItem> items, @Px int maxSpanSize)54     public WidgetsListContentEntry(PackageItemInfo pkgItem, String titleSectionName,
55             List<WidgetItem> items, @Px int maxSpanSize) {
56         super(pkgItem, titleSectionName, items);
57         mMaxSpanSize = maxSpanSize;
58     }
59 
60     @Override
toString()61     public String toString() {
62         return "Content:" + mPkgItem.packageName + ":" + mWidgets.size() + " maxSpanSize: "
63                 + mMaxSpanSize;
64     }
65 
66     /**
67      * Returns a copy of this {@link WidgetsListContentEntry} with updated {@code maxSpanSize}.
68      *
69      * @param maxSpanSize the maximum horizontal span in pixels that is allowed for grouping
70      *                           more than one widgets in a table row.
71      */
withMaxSpanSize(@x int maxSpanSize)72     public WidgetsListContentEntry withMaxSpanSize(@Px int maxSpanSize) {
73         if (mMaxSpanSize == maxSpanSize) return this;
74         return new WidgetsListContentEntry(
75                 mPkgItem,
76                 mTitleSectionName,
77                 mWidgets,
78                 /* maxSpanSize= */ maxSpanSize);
79     }
80 
81     /**
82      * Returns the max horizontal span size in pixels that is allowed for grouping more than one
83      * widget in a table row.
84      */
85     @Px
getMaxSpanSize()86     public int getMaxSpanSize() {
87         return mMaxSpanSize;
88     }
89 
90     @Override
equals(Object obj)91     public boolean equals(Object obj) {
92         if (!(obj instanceof WidgetsListContentEntry)) return false;
93         WidgetsListContentEntry otherEntry = (WidgetsListContentEntry) obj;
94         return mWidgets.equals(otherEntry.mWidgets) && mPkgItem.equals(otherEntry.mPkgItem)
95                 && mTitleSectionName.equals(otherEntry.mTitleSectionName)
96                 && mMaxSpanSize == otherEntry.mMaxSpanSize;
97     }
98 }
99