Skip to content

Commit

Permalink
Add: DrawerFolders support in recycler/adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
machiav3lli committed Sep 29, 2024
1 parent edcaa4a commit 2969366
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/com/android/launcher3/allapps/AllAppsRecyclerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ protected void updatePoolSize() {
}
pool.setMaxRecycledViews(
AllAppsGridAdapter.VIEW_TYPE_ICON, maxPoolSizeForAppIcons);
pool.setMaxRecycledViews(AllAppsGridAdapter.VIEW_TYPE_FOLDER, maxPoolSizeForAppIcons);
}

@Override
Expand Down
38 changes: 36 additions & 2 deletions src/com/android/launcher3/allapps/BaseAllAppsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.view.View.OnFocusChangeListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;
Expand All @@ -31,8 +32,12 @@
import com.android.launcher3.Utilities;
import com.android.launcher3.allapps.search.SearchAdapterProvider;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.views.ActivityContext;
import com.saggitt.omega.NeoLauncher;
import com.saggitt.omega.groups.DrawerFolderItem;
import com.saggitt.omega.groups.category.DrawerFolderInfo;

/**
* Adapter for all the apps.
Expand All @@ -54,11 +59,14 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
public static final int VIEW_TYPE_WORK_EDU_CARD = 1 << 4;
public static final int VIEW_TYPE_WORK_DISABLED_CARD = 1 << 5;

public static final int NEXT_ID = 6;
// Drawer folders
public static final int VIEW_TYPE_FOLDER = 1 << 6;

public static final int NEXT_ID = 7;

// Common view type masks
public static final int VIEW_TYPE_MASK_DIVIDER = VIEW_TYPE_ALL_APPS_DIVIDER;
public static final int VIEW_TYPE_MASK_ICON = VIEW_TYPE_ICON;
public static final int VIEW_TYPE_MASK_ICON = VIEW_TYPE_ICON | VIEW_TYPE_FOLDER;

protected final SearchAdapterProvider<?> mAdapterProvider;

Expand Down Expand Up @@ -89,6 +97,8 @@ public static class AdapterItem {
public int rowAppIndex;
// The associated ItemInfoWithIcon for the item
public AppInfo itemInfo = null;
// The associated folder for the folder
public DrawerFolderItem folderItem = null;

public AdapterItem(int viewType) {
this.viewType = viewType;
Expand All @@ -103,6 +113,12 @@ public static AdapterItem asApp(AppInfo appInfo) {
return item;
}

public static AdapterItem asFolder(DrawerFolderInfo folderInfo) {
AdapterItem item = new AdapterItem(VIEW_TYPE_FOLDER);
item.folderItem = new DrawerFolderItem(folderInfo);
return item;
}

protected boolean isCountedForAccessibility() {
return viewType == VIEW_TYPE_ICON;
}
Expand Down Expand Up @@ -191,6 +207,13 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
icon.getLayoutParams().height += mExtraTextHeight;
}
return new ViewHolder(icon);
case VIEW_TYPE_FOLDER:
FrameLayout frame = new FrameLayout(mActivityContext);
ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(
mActivityContext.getDeviceProfile().allAppsCellWidthPx,
mActivityContext.getDeviceProfile().allAppsCellHeightPx);
frame.setLayoutParams(lp);
return new ViewHolder(frame);
case VIEW_TYPE_EMPTY_SEARCH:
return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search,
parent, false));
Expand Down Expand Up @@ -221,6 +244,17 @@ public void onBindViewHolder(ViewHolder holder, int position) {
icon.applyFromApplicationInfo(adapterItem.itemInfo);
break;
}
case VIEW_TYPE_FOLDER: {
ViewGroup container = (ViewGroup) holder.itemView;
FolderIcon folderIcon = mApps.getAdapterItems().get(position)
.folderItem.getFolderIcon(NeoLauncher.getLauncher(mActivityContext), container);

container.removeAllViews();
container.addView(folderIcon);

//folderIcon.verifyHighRes();
break;
}
case VIEW_TYPE_EMPTY_SEARCH: {
AppInfo info = mApps.getAdapterItems().get(position).itemInfo;
if (info != null) {
Expand Down

0 comments on commit 2969366

Please sign in to comment.