Commit 55349ca6 authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Prevent item from being added twice by first checking them

parent 0306fc15
Pipeline #87460 passed with stage
in 4 minutes and 47 seconds
...@@ -22,4 +22,12 @@ public class AppAddEvent extends Event{ ...@@ -22,4 +22,12 @@ public class AppAddEvent extends Event{
public UserHandle getUserHandle() { public UserHandle getUserHandle() {
return userHandle; return userHandle;
} }
@Override
public String toString() {
return "AppAddEvent{" +
"packageName='" + packageName + '\'' +
", userHandle=" + userHandle +
'}';
}
} }
...@@ -520,10 +520,7 @@ public class LauncherActivity extends AppCompatActivity implements ...@@ -520,10 +520,7 @@ public class LauncherActivity extends AppCompatActivity implements
} }
public void onAppAddEvent(AppAddEvent appAddEvent) { public void onAppAddEvent(AppAddEvent appAddEvent) {
moveTo = -1; updateOrAddApp(appAddEvent.getPackageName(),appAddEvent.getUserHandle());
ApplicationItem applicationItem = AppUtils.createAppItem(this, appAddEvent.getPackageName(),
appAddEvent.getUserHandle());
addLauncherItem(applicationItem);
//DatabaseManager.getManager(this).saveLayouts(pages, mDock); //DatabaseManager.getManager(this).saveLayouts(pages, mDock);
if (moveTo != -1) { if (moveTo != -1) {
mHorizontalPager.setCurrentPage(moveTo); mHorizontalPager.setCurrentPage(moveTo);
...@@ -538,7 +535,7 @@ public class LauncherActivity extends AppCompatActivity implements ...@@ -538,7 +535,7 @@ public class LauncherActivity extends AppCompatActivity implements
} }
public void onAppChangeEvent(AppChangeEvent appChangeEvent) { public void onAppChangeEvent(AppChangeEvent appChangeEvent) {
updateApp(appChangeEvent.getPackageName(), appChangeEvent.getUserHandle()); updateOrAddApp(appChangeEvent.getPackageName(), appChangeEvent.getUserHandle());
DatabaseManager.getManager(this).saveLayouts(pages, mDock); DatabaseManager.getManager(this).saveLayouts(pages, mDock);
} }
...@@ -558,6 +555,7 @@ public class LauncherActivity extends AppCompatActivity implements ...@@ -558,6 +555,7 @@ public class LauncherActivity extends AppCompatActivity implements
return; return;
} }
if (launcherItem != null) { if (launcherItem != null) {
BlissFrameLayout view = prepareLauncherItem(launcherItem); BlissFrameLayout view = prepareLauncherItem(launcherItem);
int current = 0; int current = 0;
...@@ -860,7 +858,7 @@ public class LauncherActivity extends AppCompatActivity implements ...@@ -860,7 +858,7 @@ public class LauncherActivity extends AppCompatActivity implements
} }
} }
private void updateApp(String packageName, UserHandle userHandle) { private void updateOrAddApp(String packageName, UserHandle userHandle) {
handleWobbling(false); handleWobbling(false);
ApplicationItem updatedAppItem = AppUtils.createAppItem(this, packageName, userHandle); ApplicationItem updatedAppItem = AppUtils.createAppItem(this, packageName, userHandle);
if (updatedAppItem == null) { if (updatedAppItem == null) {
...@@ -952,6 +950,7 @@ public class LauncherActivity extends AppCompatActivity implements ...@@ -952,6 +950,7 @@ public class LauncherActivity extends AppCompatActivity implements
existingAppItem); existingAppItem);
gridLayout.removeViewAt(j); gridLayout.removeViewAt(j);
addAppToGrid(gridLayout, blissFrameLayout, j); addAppToGrid(gridLayout, blissFrameLayout, j);
moveTo = i + 1;
return; return;
} }
} }
...@@ -964,6 +963,7 @@ public class LauncherActivity extends AppCompatActivity implements ...@@ -964,6 +963,7 @@ public class LauncherActivity extends AppCompatActivity implements
BlissFrameLayout blissFrameLayout = prepareLauncherItem(updatedAppItem); BlissFrameLayout blissFrameLayout = prepareLauncherItem(updatedAppItem);
gridLayout.removeViewAt(j); gridLayout.removeViewAt(j);
addAppToGrid(gridLayout, blissFrameLayout, j); addAppToGrid(gridLayout, blissFrameLayout, j);
moveTo = i + 1;
return; return;
} }
} }
......
Supports Markdown
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