Skip to content

Commit

Permalink
[FIX] If I create a page on the left side, it gets deleted after a sh…
Browse files Browse the repository at this point in the history
…ort while and the apps go over other apps on other pages (#679)
  • Loading branch information
Ptitg authored May 15, 2022
1 parent 7149c00 commit 748cb58
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/src/main/java/com/benny/openlauncher/util/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,16 @@ private Item getSelection(Cursor cursor) {
return item;
}

public void addPage(int position) {
_db.execSQL("UPDATE " + TABLE_HOME + " SET " + COLUMN_PAGE + " = " + COLUMN_PAGE + " + 1 WHERE " + COLUMN_PAGE + " >= ?",
new String[] {String.valueOf(position)});
}

public void removePage(int position) {
_db.execSQL("UPDATE " + TABLE_HOME + " SET " + COLUMN_PAGE + " = " + COLUMN_PAGE + " - 1 WHERE " + COLUMN_PAGE + " > ?",
new String[] {String.valueOf(position)});
}

public void open() {
_db = getWritableDatabase();
}
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/com/benny/openlauncher/widget/Desktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ public boolean onLongClick(View v) {
}

public void addPageLeft() {
// Shift pages to the right (including home page)
HomeActivity._db.addPage(0);
Setup.appSettings().setDesktopPageCurrent(Setup.appSettings().getDesktopPageCurrent()+1);

_desktop.getPages().add(0, getItemLayout());
notifyDataSetChanged();
}
Expand All @@ -210,6 +214,13 @@ public void removePage(int position, boolean deleteItems) {
}
}
}

// Shift pages to the left (including home page)
HomeActivity._db.removePage(position);
if (Setup.appSettings().getDesktopPageCurrent() > position) {
Setup.appSettings().setDesktopPageCurrent(Setup.appSettings().getDesktopPageCurrent() - 1);
}

_desktop.getPages().remove(position);
notifyDataSetChanged();
}
Expand Down Expand Up @@ -349,7 +360,7 @@ public final void addPageLeft(boolean showGrid) {
int previousPage = getCurrentItem();
_adapter.addPageLeft();
setCurrentItem(previousPage + 1, false);
setCurrentItem(previousPage - 1);
setCurrentItem(previousPage);
if (Setup.appSettings().getDesktopShowGrid()) {
for (CellContainer cellContainer : _pages) {
cellContainer.setHideGrid(!showGrid);
Expand Down

0 comments on commit 748cb58

Please sign in to comment.