diff options
author | Mario Bertschler <bmario@google.com> | 2017-10-18 10:31:36 -0700 |
---|---|---|
committer | Mario Bertschler <bmario@google.com> | 2017-11-14 10:28:54 -0800 |
commit | ac9408a5cd7744a8dbc66a61114665ab6e4051de (patch) | |
tree | edb48150310dde96c444ec64952fd9678d825a13 /src/com/android/launcher3/allapps/AlphabeticalAppsList.java | |
parent | f405f507b70c0bd54adcfd69cc2c7a2b245d10d6 (diff) | |
download | android_packages_apps_Trebuchet-ac9408a5cd7744a8dbc66a61114665ab6e4051de.tar.gz android_packages_apps_Trebuchet-ac9408a5cd7744a8dbc66a61114665ab6e4051de.tar.bz2 android_packages_apps_Trebuchet-ac9408a5cd7744a8dbc66a61114665ab6e4051de.zip |
Enable work profile tab in all apps.
This CL will bring two tabs to all apps: Personal and Work,
currently only if the user has a workfile set up and
behind a feature flag defaulting to disabled.
Bug: 68713881
Change-Id: Ib5a558281ef3593359db3ad593ee1d0cf279f547
Diffstat (limited to 'src/com/android/launcher3/allapps/AlphabeticalAppsList.java')
-rw-r--r-- | src/com/android/launcher3/allapps/AlphabeticalAppsList.java | 120 |
1 files changed, 52 insertions, 68 deletions
diff --git a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java index f0b650bd2..f9dde2f97 100644 --- a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java +++ b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java @@ -30,6 +30,7 @@ import com.android.launcher3.discovery.AppDiscoveryItem; import com.android.launcher3.discovery.AppDiscoveryUpdateState; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.ComponentKeyMapper; +import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.LabelComparator; import java.util.ArrayList; @@ -165,7 +166,7 @@ public class AlphabeticalAppsList { // The set of apps from the system not including predictions private final List<AppInfo> mApps = new ArrayList<>(); - private final HashMap<ComponentKey, AppInfo> mComponentToAppMap = new HashMap<>(); + private final HashMap<ComponentKey, AppInfo> mComponentToAppMap; // The set of filtered apps with the current filter private final List<AppInfo> mFilteredApps = new ArrayList<>(); @@ -188,13 +189,20 @@ public class AlphabeticalAppsList { private int mNumAppsPerRow; private int mNumPredictedAppsPerRow; private int mNumAppRowsInAdapter; + private ItemInfoMatcher mItemFilter; - public AlphabeticalAppsList(Context context) { + public AlphabeticalAppsList(Context context, HashMap<ComponentKey, AppInfo> componentToAppMap) { + mComponentToAppMap = componentToAppMap; mLauncher = Launcher.getLauncher(context); mIndexer = new AlphabeticIndexCompat(context); mAppNameComparator = new AppInfoComparator(context); } + public void updateItemFilter(ItemInfoMatcher itemFilter) { + this.mItemFilter = itemFilter; + onAppsUpdated(); + } + /** * Sets the number of apps per row. */ @@ -374,40 +382,18 @@ public class AlphabeticalAppsList { } /** - * Sets the current set of apps. - */ - public void setApps(List<AppInfo> apps) { - mComponentToAppMap.clear(); - addOrUpdateApps(apps); - } - - /** - * Adds or updates existing apps in the list - */ - public void addOrUpdateApps(List<AppInfo> apps) { - for (AppInfo app : apps) { - mComponentToAppMap.put(app.toComponentKey(), app); - } - onAppsUpdated(); - } - - /** - * Removes some apps from the list. - */ - public void removeApps(List<AppInfo> apps) { - for (AppInfo app : apps) { - mComponentToAppMap.remove(app.toComponentKey()); - } - onAppsUpdated(); - } - - /** * Updates internals when the set of apps are updated. */ - private void onAppsUpdated() { + void onAppsUpdated() { // Sort the list of apps mApps.clear(); - mApps.addAll(mComponentToAppMap.values()); + + for (AppInfo app : mComponentToAppMap.values()) { + if (mItemFilter == null || mItemFilter.matches(app, null)) { + mApps.add(app); + } + } + Collections.sort(mApps, mAppNameComparator); // As a special case for some languages (currently only Simplified Chinese), we may need to @@ -474,42 +460,45 @@ public class AlphabeticalAppsList { mFastScrollerSections.clear(); mAdapterItems.clear(); - if (DEBUG_PREDICTIONS) { - if (mPredictedAppComponents.isEmpty() && !mApps.isEmpty()) { - mPredictedAppComponents.add(new ComponentKeyMapper<AppInfo>(new ComponentKey(mApps.get(0).componentName, - Process.myUserHandle()))); - mPredictedAppComponents.add(new ComponentKeyMapper<AppInfo>(new ComponentKey(mApps.get(0).componentName, - Process.myUserHandle()))); - mPredictedAppComponents.add(new ComponentKeyMapper<AppInfo>(new ComponentKey(mApps.get(0).componentName, - Process.myUserHandle()))); - mPredictedAppComponents.add(new ComponentKeyMapper<AppInfo>(new ComponentKey(mApps.get(0).componentName, - Process.myUserHandle()))); + if (!FeatureFlags.ALL_APPS_TABS_ENABLED) { + if (DEBUG_PREDICTIONS) { + if (mPredictedAppComponents.isEmpty() && !mApps.isEmpty()) { + mPredictedAppComponents.add(new ComponentKeyMapper<AppInfo>(new ComponentKey(mApps.get(0).componentName, + Process.myUserHandle()))); + mPredictedAppComponents.add(new ComponentKeyMapper<AppInfo>(new ComponentKey(mApps.get(0).componentName, + Process.myUserHandle()))); + mPredictedAppComponents.add(new ComponentKeyMapper<AppInfo>(new ComponentKey(mApps.get(0).componentName, + Process.myUserHandle()))); + mPredictedAppComponents.add(new ComponentKeyMapper<AppInfo>(new ComponentKey(mApps.get(0).componentName, + Process.myUserHandle()))); + } } - } - - // Process the predicted app components - mPredictedApps.clear(); - if (mPredictedAppComponents != null && !mPredictedAppComponents.isEmpty() && !hasFilter()) { - mPredictedApps.addAll(processPredictedAppComponents(mPredictedAppComponents)); - if (!mPredictedApps.isEmpty()) { - // Add a section for the predictions - lastFastScrollerSectionInfo = new FastScrollSectionInfo(""); - mFastScrollerSections.add(lastFastScrollerSectionInfo); - - // Add the predicted app items - for (AppInfo info : mPredictedApps) { - AdapterItem appItem = AdapterItem.asPredictedApp(position++, "", info, - appIndex++); - if (lastFastScrollerSectionInfo.fastScrollToItem == null) { - lastFastScrollerSectionInfo.fastScrollToItem = appItem; + // Process the predicted app components + mPredictedApps.clear(); + if (mPredictedAppComponents != null && !mPredictedAppComponents.isEmpty() && !hasFilter()) { + mPredictedApps.addAll(processPredictedAppComponents(mPredictedAppComponents)); + + if (!mPredictedApps.isEmpty()) { + // Add a section for the predictions + lastFastScrollerSectionInfo = new FastScrollSectionInfo(""); + mFastScrollerSections.add(lastFastScrollerSectionInfo); + + // Add the predicted app items + for (AppInfo info : mPredictedApps) { + AdapterItem appItem = AdapterItem.asPredictedApp(position++, "", info, + appIndex++); + if (lastFastScrollerSectionInfo.fastScrollToItem == null) { + lastFastScrollerSectionInfo.fastScrollToItem = appItem; + } + mAdapterItems.add(appItem); + mFilteredApps.add(info); } - mAdapterItems.add(appItem); - mFilteredApps.add(info); - } - mAdapterItems.add(AdapterItem.asPredictionDivider(position++)); + mAdapterItems.add(AdapterItem.asPredictionDivider(position++)); + } } + } // Recreate the filtered and sectioned apps (for convenience for the grid layout) from the @@ -626,7 +615,6 @@ public class AlphabeticalAppsList { if (mSearchResults == null) { return mApps; } - ArrayList<AppInfo> result = new ArrayList<>(); for (ComponentKey key : mSearchResults) { AppInfo match = mComponentToAppMap.get(key); @@ -648,10 +636,6 @@ public class AlphabeticalAppsList { return result; } - public AppInfo findApp(ComponentKeyMapper<AppInfo> mapper) { - return mapper.getItem(mComponentToAppMap); - } - /** * Returns the cached section name for the given title, recomputing and updating the cache if * the title has no cached section name. |