summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherProvider.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-03-04 10:43:45 -0800
committerSunny Goyal <sunnygoyal@google.com>2015-03-04 10:43:45 -0800
commitfe4e4b91dc7db5d373690dd4bf2f3b5f1525b68a (patch)
tree207cf1cd49cc52d3781811719ea208b94a3c8bc3 /src/com/android/launcher3/LauncherProvider.java
parent8dbf0fff1f424df8db1bbedfe8e5cfd7783a92ea (diff)
downloadandroid_packages_apps_Trebuchet-fe4e4b91dc7db5d373690dd4bf2f3b5f1525b68a.tar.gz
android_packages_apps_Trebuchet-fe4e4b91dc7db5d373690dd4bf2f3b5f1525b68a.tar.bz2
android_packages_apps_Trebuchet-fe4e4b91dc7db5d373690dd4bf2f3b5f1525b68a.zip
Refactoring max id logic to a common method
Change-Id: I1f649b570ee43d6c0540a207693d2cbee4538fb8
Diffstat (limited to 'src/com/android/launcher3/LauncherProvider.java')
-rw-r--r--src/com/android/launcher3/LauncherProvider.java59
1 files changed, 23 insertions, 36 deletions
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index b61844452..cf66e5157 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -733,23 +733,7 @@ public class LauncherProvider extends ContentProvider {
}
private long initializeMaxItemId(SQLiteDatabase db) {
- Cursor c = db.rawQuery("SELECT MAX(_id) FROM favorites", null);
-
- // get the result
- final int maxIdIndex = 0;
- long id = -1;
- if (c != null && c.moveToNext()) {
- id = c.getLong(maxIdIndex);
- }
- if (c != null) {
- c.close();
- }
-
- if (id == -1) {
- throw new RuntimeException("Error: could not query max item id");
- }
-
- return id;
+ return getMaxId(db, TABLE_FAVORITES);
}
// Generates a new ID to use for an workspace screen in your database. This method
@@ -768,25 +752,7 @@ public class LauncherProvider extends ContentProvider {
}
private long initializeMaxScreenId(SQLiteDatabase db) {
- Cursor c = db.rawQuery("SELECT MAX(" + LauncherSettings.WorkspaceScreens._ID + ") FROM " + TABLE_WORKSPACE_SCREENS, null);
-
- // get the result
- final int maxIdIndex = 0;
- long id = -1;
- if (c != null && c.moveToNext()) {
- id = c.getLong(maxIdIndex);
- }
- if (c != null) {
- c.close();
- }
-
- if (id == -1) {
- throw new RuntimeException("Error: could not query max screen id");
- }
-
- // Log to disk
- Launcher.addDumpLog(TAG, "11683562 - initializeMaxScreenId(): " + id, true);
- return id;
+ return getMaxId(db, TABLE_WORKSPACE_SCREENS);
}
private boolean initializeExternalAdd(ContentValues values) {
@@ -1199,6 +1165,27 @@ public class LauncherProvider extends ContentProvider {
}
}
+ /**
+ * @return the max _id in the provided table.
+ */
+ private static long getMaxId(SQLiteDatabase db, String table) {
+ Cursor c = db.rawQuery("SELECT MAX(_id) FROM " + table, null);
+ // get the result
+ long id = -1;
+ if (c != null && c.moveToNext()) {
+ id = c.getLong(0);
+ }
+ if (c != null) {
+ c.close();
+ }
+
+ if (id == -1) {
+ throw new RuntimeException("Error: could not query max id in " + table);
+ }
+
+ return id;
+ }
+
static class SqlArguments {
public final String table;
public final String where;