Commit 600c2536 authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Handle folder item removal properly

parent bc29bb5d
Pipeline #141699 passed with stage
in 1 minute and 55 seconds
......@@ -82,7 +82,9 @@ import foundation.e.blisslauncher.features.test.graphics.DragPreviewProvider;
import foundation.e.blisslauncher.features.test.uninstall.UninstallHelper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
......@@ -2764,20 +2766,46 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
if (child != null) {
// Note: We can not remove the view directly from CellLayoutChildren as this
// does not re-mark the spaces as unoccupied.
child.clearAnimation();
layout.removeViewInLayout(child);
if (child instanceof DropTarget) {
mDragController.removeDropTarget((DropTarget) child);
}
// Remove item from database
DatabaseManager.getManager(getContext()).removeItem(itemToRemove.id);
} else if (itemToRemove.container >= 0) {
// The item may belong to a folder.
View parent = idToViewMap.get(String.valueOf(itemToRemove.container));
if (parent != null) {
/*
FolderItem folderInfo = (FolderItem) parent.getTag();
folderInfo.prepareAutoUpdate();
folderInfo.remove((WorkspaceItemInfo) itemToRemove, false);
*/
// TODO: Properly handle item removal from folder.
FolderItem folder = (FolderItem) parent.getTag();
parent.clearAnimation();
// Close folder before making any changes
mLauncher.closeFolder();
folder.items.remove(itemToRemove);
DatabaseManager.getManager(getContext()).removeItem(itemToRemove.id);
if (folder.items.size() == 0) {
layout.removeView(parent);
if (parent instanceof DropTarget) {
mDragController.removeDropTarget((DropTarget) child);
}
} else if (folder.items.size() == 1) {
LauncherItem lastFolderItem = folder.items.get(0);
layout.removeViewInLayout(parent);
if (parent instanceof DropTarget) {
mDragController.removeDropTarget((DropTarget) parent);
}
lastFolderItem.container = folder.container;
lastFolderItem.cell = folder.cell;
lastFolderItem.screenId = folder.screenId;
bindItems(Collections.singletonList(lastFolderItem), true);
} else {
folder.icon = new GraphicsUtil(getContext()).generateFolderIcon(getContext(), folder);
layout.removeViewInLayout(parent);
if (parent instanceof DropTarget) {
mDragController.removeDropTarget((DropTarget) parent);
}
bindItems(Arrays.asList(folder), true);
}
}
}
}
......
......@@ -134,4 +134,9 @@ public class DatabaseManager {
public void removeWidget(int id) {
mAppExecutors.diskIO().execute(() -> LauncherDB.getDatabase(mContext).widgetDao().delete(id));
}
public void removeItem(String id) {
mAppExecutors.diskIO().execute(
() -> LauncherDB.getDatabase(mContext).launcherDao().delete(id));
}
}
......@@ -21,7 +21,6 @@ import android.util.LongSparseArray;
import foundation.e.blisslauncher.BlissLauncher;
import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.core.Utilities;
import foundation.e.blisslauncher.core.broadcast.PackageAddedRemovedHandler;
import foundation.e.blisslauncher.core.database.DatabaseManager;
import foundation.e.blisslauncher.core.database.model.ApplicationItem;
import foundation.e.blisslauncher.core.database.model.FolderItem;
......@@ -118,84 +117,6 @@ public class AppProvider {
final LauncherApps launcher = (LauncherApps) mContext.getSystemService(
Context.LAUNCHER_APPS_SERVICE);
assert launcher != null;
/*launcher.registerCallback(new LauncherApps.Callback() {
@Override
public void onPackageRemoved(String packageName, android.os.UserHandle user) {
if (packageName.equalsIgnoreCase(MICROG_PACKAGE) || packageName.equalsIgnoreCase(
MUPDF_PACKAGE)) {
return;
}
PackageAddedRemovedHandler.handleEvent(mContext,
"android.intent.action.PACKAGE_REMOVED",
packageName, new UserHandle(manager.getSerialNumberForUser(user), user),
false
);
}
@Override
public void onPackageAdded(String packageName, android.os.UserHandle user) {
if (packageName.equalsIgnoreCase(MICROG_PACKAGE) || packageName.equalsIgnoreCase(
MUPDF_PACKAGE)) {
return;
}
PackageAddedRemovedHandler.handleEvent(mContext,
"android.intent.action.PACKAGE_ADDED",
packageName, new UserHandle(manager.getSerialNumberForUser(user), user),
false
);
}
@Override
public void onPackageChanged(String packageName, android.os.UserHandle user) {
if (packageName.equalsIgnoreCase(MICROG_PACKAGE) || packageName.equalsIgnoreCase(
MUPDF_PACKAGE)) {
return;
}
PackageAddedRemovedHandler.handleEvent(mContext,
"android.intent.action.PACKAGE_CHANGED",
packageName, new UserHandle(manager.getSerialNumberForUser(user), user),
true
);
}
@Override
public void onPackagesAvailable(String[] packageNames, android.os.UserHandle user,
boolean replacing) {
Log.d(TAG, "onPackagesAvailable() called with: packageNames = [" + packageNames + "], user = [" + user + "], replacing = [" + replacing + "]");
for (String packageName : packageNames) {
PackageAddedRemovedHandler.handleEvent(mContext,
"android.intent.action.MEDIA_MOUNTED",
packageName, new UserHandle(manager.getSerialNumberForUser(user), user), false
);
}
}
@Override
public void onPackagesUnavailable(String[] packageNames, android.os.UserHandle user,
boolean replacing) {
Log.d(TAG, "onPackagesUnavailable() called with: packageNames = [" + packageNames + "], user = [" + user + "], replacing = [" + replacing + "]");
PackageAddedRemovedHandler.handleEvent(mContext,
"android.intent.action.MEDIA_UNMOUNTED",
null, new UserHandle(manager.getSerialNumberForUser(user), user), false
);
}
@Override
public void onPackagesSuspended(String[] packageNames, android.os.UserHandle user) {
Log.d(TAG, "onPackagesSuspended() called with: packageNames = [" + packageNames + "], user = [" + user + "]");
}
@Override
public void onPackagesUnsuspended(String[] packageNames, android.os.UserHandle user) {
super.onPackagesUnsuspended(packageNames, user);
Log.d(TAG, "onPackagesUnsuspended() called with: packageNames = [" + packageNames + "], user = [" + user + "]");
}
});*/
mAppsRepository = AppsRepository.getAppsRepository();
}
......
......@@ -113,7 +113,7 @@ public abstract class LauncherItemMatcher {
return new LauncherItemMatcher() {
@Override
public boolean matches(LauncherItem info, ComponentName cn) {
return packageNames.contains(cn.getPackageName()) && info.user.equals(user);
return packageNames.contains(cn.getPackageName()) && info.user.getRealHandle().equals(user);
}
};
}
......
......@@ -1710,7 +1710,7 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
val set = AnimatorSet()
/*ValueAnimator valueAnimator = ValueAnimator.ofInt(18, 0);
valueAnimator.addUpdateListener(animation ->
valueAnimator.addUpdateListener(animati on ->
BlurWallpaperProvider.getInstance(this).blurWithLauncherView(mergedView, (Integer) animation.getAnimatedValue()));*/
/*ValueAnimator valueAnimator = ValueAnimator.ofInt(18, 0);
valueAnimator.addUpdateListener(animation ->
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment