diff options
author | Adam Cohen <adamcohen@google.com> | 2014-07-31 00:09:45 -0700 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2014-08-08 04:31:47 +0000 |
commit | 7ec3bbff8b6364dc609eb06ba85e6f3bb999c67e (patch) | |
tree | c8be2b7504bfb3940c07abb16097b62941764db0 /src | |
parent | fe9da818cde4d8be9903ad6ff42c7248ad54d822 (diff) | |
download | android_packages_apps_Trebuchet-7ec3bbff8b6364dc609eb06ba85e6f3bb999c67e.tar.gz android_packages_apps_Trebuchet-7ec3bbff8b6364dc609eb06ba85e6f3bb999c67e.tar.bz2 android_packages_apps_Trebuchet-7ec3bbff8b6364dc609eb06ba85e6f3bb999c67e.zip |
Fix screen issues with externally added items
-> Ensure that when an item is added to the db from an external
source that the screen id exists.
-> If the screen id does not exist, add that id as the largest rank
Change-Id: I98d68900c428d80666dab1909418c6d9b0f52e10
(cherry picked from commit 484526620012f88bcd9d5656a71d4218a9acd090)
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher3/LauncherProvider.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index f77cdca41..88ea45a43 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -1285,9 +1285,62 @@ public class LauncherProvider extends ContentProvider { } return false; } + + // Add screen id if not present + long screenId = values.getAsLong(LauncherSettings.Favorites.SCREEN); + if (!addScreenIdIfNecessary(screenId)) { + return false; + } + return true; + } + + // Returns true of screen id exists, or if successfully added + private boolean addScreenIdIfNecessary(long screenId) { + if (!hasScreenId(screenId)) { + int rank = getMaxScreenRank() + 1; + + ContentValues v = new ContentValues(); + v.put(LauncherSettings.WorkspaceScreens._ID, screenId); + v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, rank); + if (dbInsertAndCheck(this, getWritableDatabase(), + TABLE_WORKSPACE_SCREENS, null, v) < 0) { + return false; + } + } return true; } + private boolean hasScreenId(long screenId) { + SQLiteDatabase db = getWritableDatabase(); + Cursor c = db.rawQuery("SELECT * FROM " + TABLE_WORKSPACE_SCREENS + " WHERE " + + LauncherSettings.WorkspaceScreens._ID + " = " + screenId, null); + if (c != null) { + int count = c.getCount(); + c.close(); + return count > 0; + } else { + return false; + } + } + + private int getMaxScreenRank() { + SQLiteDatabase db = getWritableDatabase(); + Cursor c = db.rawQuery("SELECT MAX(" + LauncherSettings.WorkspaceScreens.SCREEN_RANK + + ") FROM " + TABLE_WORKSPACE_SCREENS, null); + + // get the result + final int maxRankIndex = 0; + int rank = -1; + if (c != null && c.moveToNext()) { + rank = c.getInt(maxRankIndex); + } + if (c != null) { + c.close(); + } + + return rank; + } + private static final void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException { int type; @@ -1334,6 +1387,7 @@ public class LauncherProvider extends ContentProvider { // Ensure that the max ids are initialized mMaxItemId = initializeMaxItemId(db); mMaxScreenId = initializeMaxScreenId(db); + return count; } |