• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.launcher3.widget.model;
18 
19 import static java.lang.annotation.RetentionPolicy.SOURCE;
20 
21 import androidx.annotation.IntDef;
22 
23 import com.android.launcher3.model.WidgetItem;
24 import com.android.launcher3.model.data.ItemInfo;
25 import com.android.launcher3.model.data.PackageItemInfo;
26 import com.android.launcher3.widget.WidgetItemComparator;
27 
28 import java.lang.annotation.Retention;
29 import java.util.List;
30 import java.util.stream.Collectors;
31 
32 /** Holder class to store the package information of an entry shown in the widgets list. */
33 public abstract class WidgetsListBaseEntry {
34     public final PackageItemInfo mPkgItem;
35 
36     /**
37      * Character that is used as a section name for the {@link ItemInfo#title}.
38      * (e.g., "G" will be stored if title is "Google")
39      */
40     public final String mTitleSectionName;
41 
42     public final List<WidgetItem> mWidgets;
43 
WidgetsListBaseEntry(PackageItemInfo pkgItem, String titleSectionName, List<WidgetItem> items)44     public WidgetsListBaseEntry(PackageItemInfo pkgItem, String titleSectionName,
45             List<WidgetItem> items) {
46         mPkgItem = pkgItem;
47         mTitleSectionName = titleSectionName;
48         this.mWidgets =
49                 items.stream().sorted(new WidgetItemComparator()).collect(Collectors.toList());
50     }
51 
52     /**
53      * Returns the ranking of this entry in the
54      * {@link com.android.launcher3.widget.picker.WidgetsListAdapter}.
55      *
56      * <p>Entries with smaller value should be shown first. See
57      * {@link com.android.launcher3.widget.picker.WidgetsDiffReporter} for more details.
58      */
59     @Rank
getRank()60     public abstract int getRank();
61 
62     /**
63      * Marker interface for subclasses that are headers for widget list items.
64      *
65      * @param <T> The type of this class.
66      */
67     public interface Header<T extends WidgetsListBaseEntry & Header<T>> {
68         /** Returns whether the widget list is currently expanded. */
isWidgetListShown()69         boolean isWidgetListShown();
70 
71         /** Returns a copy of the item with the widget list shown. */
withWidgetListShown()72         T withWidgetListShown();
73     }
74 
75     @Retention(SOURCE)
76     @IntDef({RANK_WIDGETS_LIST_HEADER, RANK_WIDGETS_LIST_SEARCH_HEADER, RANK_WIDGETS_LIST_CONTENT})
77     public @interface Rank {
78     }
79 
80     public static final int RANK_WIDGETS_LIST_HEADER = 1;
81     public static final int RANK_WIDGETS_LIST_SEARCH_HEADER = 2;
82     public static final int RANK_WIDGETS_LIST_CONTENT = 3;
83 }
84