Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
BlissLauncher
Commits
bc29bb5d
Commit
bc29bb5d
authored
Oct 13, 2021
by
Amit Kumar
💻
Browse files
Handle onRemove event
parent
0dd4980a
Pipeline
#140615
passed with stage
in 1 minute and 56 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/AndroidManifest.xml
View file @
bc29bb5d
...
...
@@ -165,7 +165,6 @@
</intent-filter>
</receiver>
-->
<receiver
android:name=
"core.broadcast.PackageAddedRemovedHandler"
/>
<meta-data
android:name=
"android.nfc.disable_beam_default"
...
...
app/src/main/java/foundation/e/blisslauncher/core/customviews/LauncherPagedView.java
View file @
bc29bb5d
...
...
@@ -37,6 +37,7 @@ import android.view.animation.AnimationUtils;
import
android.view.animation.OvershootInterpolator
;
import
android.widget.GridLayout
;
import
android.widget.Toast
;
import
foundation.e.blisslauncher.BuildConfig
;
import
foundation.e.blisslauncher.R
;
import
foundation.e.blisslauncher.core.Utilities
;
...
...
@@ -61,6 +62,7 @@ import foundation.e.blisslauncher.features.shortcuts.ShortcutKey;
import
foundation.e.blisslauncher.features.test.Alarm
;
import
foundation.e.blisslauncher.features.test.CellLayout
;
import
foundation.e.blisslauncher.features.test.IconTextView
;
import
foundation.e.blisslauncher.features.test.LauncherItemMatcher
;
import
foundation.e.blisslauncher.features.test.LauncherState
;
import
foundation.e.blisslauncher.features.test.LauncherStateManager
;
import
foundation.e.blisslauncher.features.test.OnAlarmListener
;
...
...
@@ -78,6 +80,7 @@ import foundation.e.blisslauncher.features.test.dragndrop.DropTarget;
import
foundation.e.blisslauncher.features.test.dragndrop.SpringLoadedDragController
;
import
foundation.e.blisslauncher.features.test.graphics.DragPreviewProvider
;
import
foundation.e.blisslauncher.features.test.uninstall.UninstallHelper
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
...
...
@@ -86,6 +89,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.function.Predicate
;
import
org.jetbrains.annotations.NotNull
;
public
class
LauncherPagedView
extends
PagedView
<
PageIndicatorDots
>
implements
View
.
OnTouchListener
,
...
...
@@ -426,7 +430,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
throw
new
RuntimeException
(
"Unexpected info type"
);
}
if
(
item
.
itemType
==
Constants
.
ITEM_TYPE_SHORTCUT
)
{
if
(
item
.
itemType
==
Constants
.
ITEM_TYPE_SHORTCUT
)
{
// Increment the count for the given shortcut
ShortcutKey
pinnedShortcut
=
ShortcutKey
.
fromItem
((
ShortcutItem
)
item
);
MutableInt
count
=
pinnedShortcutCounts
.
get
(
pinnedShortcut
);
...
...
@@ -441,7 +445,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
if
(
count
.
value
==
1
)
{
DeepShortcutManager
.
getInstance
(
getContext
()).
pinShortcut
(
pinnedShortcut
);
}
}
// Save the WorkspaceItemInfo for binding in the workspace
addedItemsFinal
.
add
(
itemInfo
);
...
...
@@ -2736,6 +2739,55 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
computeScrollHelper
(
false
);
}
/**
* Removes items that match the {@param matcher}. When applications are removed
* as a part of an update, this is called to ensure that other widgets and application
* shortcuts are not removed.
*/
public
void
removeItemsByMatcher
(
@NotNull
LauncherItemMatcher
matcher
)
{
for
(
final
CellLayout
layout
:
getWorkspaceAndHotseatCellLayouts
())
{
HashMap
<
String
,
View
>
idToViewMap
=
new
HashMap
<>();
ArrayList
<
LauncherItem
>
items
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
layout
.
getChildCount
();
j
++)
{
final
View
view
=
layout
.
getChildAt
(
j
);
if
(
view
.
getTag
()
instanceof
LauncherItem
)
{
LauncherItem
item
=
(
LauncherItem
)
view
.
getTag
();
items
.
add
(
item
);
idToViewMap
.
put
(
item
.
id
,
view
);
}
}
for
(
LauncherItem
itemToRemove
:
matcher
.
filterItemInfos
(
items
))
{
View
child
=
idToViewMap
.
get
(
itemToRemove
.
id
);
if
(
child
!=
null
)
{
// Note: We can not remove the view directly from CellLayoutChildren as this
// does not re-mark the spaces as unoccupied.
layout
.
removeViewInLayout
(
child
);
if
(
child
instanceof
DropTarget
)
{
mDragController
.
removeDropTarget
((
DropTarget
)
child
);
}
}
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.
}
}
}
}
// Strip all the empty screens
stripEmptyScreens
();
updateDatabase
(
getWorkspaceAndHotseatCellLayouts
());
}
public
interface
ItemOperator
{
/**
* Process the next itemInfo, possibly with side-effect on the next item.
...
...
app/src/main/java/foundation/e/blisslauncher/features/launcher/AppProvider.java
View file @
bc29bb5d
...
...
@@ -119,7 +119,7 @@ public class AppProvider {
Context
.
LAUNCHER_APPS_SERVICE
);
assert
launcher
!=
null
;
launcher
.
registerCallback
(
new
LauncherApps
.
Callback
()
{
/*
launcher.registerCallback(new LauncherApps.Callback() {
@Override
public void onPackageRemoved(String packageName, android.os.UserHandle user) {
if (packageName.equalsIgnoreCase(MICROG_PACKAGE) || packageName.equalsIgnoreCase(
...
...
@@ -194,7 +194,7 @@ public class AppProvider {
super.onPackagesUnsuspended(packageNames, user);
Log.d(TAG, "onPackagesUnsuspended() called with: packageNames = [" + packageNames + "], user = [" + user + "]");
}
});
});
*/
mAppsRepository
=
AppsRepository
.
getAppsRepository
();
}
...
...
app/src/main/java/foundation/e/blisslauncher/features/test/LauncherAppState.java
View file @
bc29bb5d
...
...
@@ -109,7 +109,6 @@ public class LauncherAppState {
mCallbacks
.
put
(
mModel
,
wrappedCallback
);
}
launcherApps
.
registerCallback
(
wrappedCallback
);
mModel
.
registerCallbacks
(
launcherApps
);
// Register intent receivers
IntentFilter
filter
=
new
IntentFilter
();
filter
.
addAction
(
Intent
.
ACTION_LOCALE_CHANGED
);
...
...
app/src/main/java/foundation/e/blisslauncher/features/test/LauncherItemMatcher.java
View file @
bc29bb5d
...
...
@@ -5,6 +5,7 @@ import android.os.UserHandle;
import
java.util.HashSet
;
import
foundation.e.blisslauncher.core.database.model.ApplicationItem
;
import
foundation.e.blisslauncher.core.database.model.FolderItem
;
import
foundation.e.blisslauncher.core.database.model.LauncherItem
;
import
foundation.e.blisslauncher.core.database.model.ShortcutItem
;
...
...
@@ -22,7 +23,13 @@ public abstract class LauncherItemMatcher {
public
final
HashSet
<
LauncherItem
>
filterItemInfos
(
Iterable
<
LauncherItem
>
infos
)
{
HashSet
<
LauncherItem
>
filtered
=
new
HashSet
<>();
for
(
LauncherItem
i
:
infos
)
{
if
(
i
instanceof
ShortcutItem
)
{
if
(
i
instanceof
ApplicationItem
)
{
ApplicationItem
info
=
(
ApplicationItem
)
i
;
ComponentName
cn
=
info
.
getTargetComponent
();
if
(
cn
!=
null
&&
matches
(
info
,
cn
))
{
filtered
.
add
(
info
);
}
}
else
if
(
i
instanceof
ShortcutItem
)
{
ShortcutItem
info
=
(
ShortcutItem
)
i
;
ComponentName
cn
=
info
.
getTargetComponent
();
if
(
cn
!=
null
&&
matches
(
info
,
cn
))
{
...
...
app/src/main/java/foundation/e/blisslauncher/features/test/LauncherModel.java
View file @
bc29bb5d
...
...
@@ -19,31 +19,25 @@ package foundation.e.blisslauncher.features.test;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.LauncherApps
;
import
android.content.pm.ShortcutInfo
;
import
android.os.Handler
;
import
android.os.HandlerThread
;
import
android.os.Looper
;
import
android.os.Process
;
import
android.os.UserHandle
;
import
android.telecom.Call
;
import
android.util.Log
;
import
android.util.Pair
;
import
androidx.annotation.NonNull
;
import
java.lang.ref.WeakReference
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
foundation.e.blisslauncher.core.database.model.LauncherItem
;
import
foundation.e.blisslauncher.core.executors.MainThreadExecutor
;
import
foundation.e.blisslauncher.core.utils.Constants
;
import
foundation.e.blisslauncher.core.utils.Preconditions
;
import
foundation.e.blisslauncher.features.shortcuts.
Deep
Shortcut
Manag
er
;
import
foundation.e.blisslauncher.features.shortcuts.
Install
Shortcut
Receiv
er
;
public
class
LauncherModel
extends
BroadcastReceiver
implements
OnAppsChangedCallback
{
...
...
@@ -53,17 +47,19 @@ public class LauncherModel extends BroadcastReceiver implements
static
final
String
TAG
=
"Launcher.Model"
;
private
final
MainThreadExecutor
mUiExecutor
=
new
MainThreadExecutor
();
final
LauncherAppState
mApp
;
final
LauncherAppState
mApp
;
final
Object
mLock
=
new
Object
();
WeakReference
<
Callbacks
>
mCallbacks
;
static
final
HandlerThread
sWorkerThread
=
new
HandlerThread
(
"launcher-loader"
);
private
static
final
Looper
mWorkerLooper
;
static
{
sWorkerThread
.
start
();
mWorkerLooper
=
sWorkerThread
.
getLooper
();
}
static
final
Handler
sWorker
=
new
Handler
(
mWorkerLooper
);
@Override
...
...
@@ -75,6 +71,22 @@ public class LauncherModel extends BroadcastReceiver implements
public
void
onPackagesRemoved
(
UserHandle
user
,
String
...
packages
)
{
final
HashSet
<
String
>
removedPackages
=
new
HashSet
<>();
Collections
.
addAll
(
removedPackages
,
packages
);
if
(!
removedPackages
.
isEmpty
())
{
LauncherItemMatcher
removeMatch
=
LauncherItemMatcher
.
ofPackages
(
removedPackages
,
user
);
deleteAndBindComponentsRemoved
(
removeMatch
);
// Remove any queued items from the install queue
if
(
sWorkerThread
.
getThreadId
()
==
Process
.
myTid
())
{
}
else
{
// If we are not on the worker thread, then post to the worker handler
sWorker
.
post
(()
->
InstallShortcutReceiver
.
removeFromInstallQueue
(
mApp
.
getContext
(),
removedPackages
,
user
));
}
}
}
private
void
deleteAndBindComponentsRemoved
(
LauncherItemMatcher
removeMatch
)
{
mCallbacks
.
get
().
bindWorkspaceComponentsRemoved
(
removeMatch
);
}
@Override
...
...
@@ -130,6 +142,8 @@ public class LauncherModel extends BroadcastReceiver implements
public
interface
Callbacks
{
void
bindAppsAdded
(
List
<
LauncherItem
>
items
);
void
bindWorkspaceComponentsRemoved
(
LauncherItemMatcher
matcher
);
}
LauncherModel
(
LauncherAppState
app
)
{
...
...
@@ -158,13 +172,12 @@ public class LauncherModel extends BroadcastReceiver implements
Callbacks
callbacks
=
getCallback
();
if
(
callbacks
!=
null
)
{
//callbacks.preAddApps();
List
<
LauncherItem
>
items
=
new
ArrayList
<>();
List
<
LauncherItem
>
items
=
new
ArrayList
<>();
for
(
Pair
<
LauncherItem
,
Object
>
entry
:
itemList
)
{
items
.
add
(
entry
.
first
);
}
mUiExecutor
.
execute
(()
->
callbacks
.
bindAppsAdded
(
items
));
}
}
public
Callbacks
getCallback
()
{
...
...
app/src/main/java/foundation/e/blisslauncher/features/test/TestActivity.kt
View file @
bc29bb5d
...
...
@@ -82,6 +82,7 @@ import foundation.e.blisslauncher.core.utils.AppUtils
import
foundation.e.blisslauncher.core.utils.Constants
import
foundation.e.blisslauncher.core.utils.IntSet
import
foundation.e.blisslauncher.core.utils.IntegerArray
import
foundation.e.blisslauncher.core.utils.ItemInfoMatcher
import
foundation.e.blisslauncher.core.utils.ListUtil
import
foundation.e.blisslauncher.core.utils.PackageUserKey
import
foundation.e.blisslauncher.core.utils.UserHandle
...
...
@@ -1100,7 +1101,6 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
}
private
fun
showApps
(
launcherItems
:
List
<
LauncherItem
>)
{
Log
.
d
(
TAG
,
"showApps() called with: launcherItems = $launcherItems"
)
hotseat
.
resetLayout
(
false
)
val
populatedItems
=
populateItemPositions
(
launcherItems
)
val
orderedScreenIds
=
IntegerArray
()
...
...
@@ -1778,7 +1778,18 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
override
fun
bindAppsAdded
(
items
:
MutableList
<
LauncherItem
>)
{
if
(
items
.
isEmpty
())
return
workspace
.
bindItemsAdded
(
items
)
}
workspace
?.
bindItemsAdded
(
items
)
/**
* A package was uninstalled/updated. We take both the super set of packageNames
* in addition to specific applications to remove, the reason being that
* this can be called when a package is updated as well. In that scenario,
* we only remove specific components from the workspace and hotseat, where as
* package-removal should clear all items by package name.
*/
override
fun
bindWorkspaceComponentsRemoved
(
matcher
:
LauncherItemMatcher
)
{
workspace
.
removeItemsByMatcher
(
matcher
)
dragController
.
onAppsRemoved
(
matcher
)
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment