diff --git a/app/src/main/java/com/benny/openlauncher/util/DatabaseHelper.java b/app/src/main/java/com/benny/openlauncher/util/DatabaseHelper.java index 3af9bafe..e93f6b05 100644 --- a/app/src/main/java/com/benny/openlauncher/util/DatabaseHelper.java +++ b/app/src/main/java/com/benny/openlauncher/util/DatabaseHelper.java @@ -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(); } diff --git a/app/src/main/java/com/benny/openlauncher/widget/Desktop.java b/app/src/main/java/com/benny/openlauncher/widget/Desktop.java index 48e6bd1e..219f08e8 100644 --- a/app/src/main/java/com/benny/openlauncher/widget/Desktop.java +++ b/app/src/main/java/com/benny/openlauncher/widget/Desktop.java @@ -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(); } @@ -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(); } @@ -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);