Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] If I create a page on the left side, it gets deleted after a sh… #679

Merged
merged 1 commit into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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