From 740298c7be982b06dda200999cdbddd479d82d18 Mon Sep 17 00:00:00 2001 From: Ptitg <105381847+Ptitg@users.noreply.github.com> Date: Sat, 14 May 2022 18:36:10 +0200 Subject: [PATCH] [FIX] If I create a page on the left side, it gets deleted after a short while and the apps go over other apps on other pages --- .../com/benny/openlauncher/util/DatabaseHelper.java | 10 ++++++++++ .../java/com/benny/openlauncher/widget/Desktop.java | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) 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 3af9bafe9..e93f6b058 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 48e6bd1e8..219f08e89 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);