summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherProvider.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-03-09 17:08:19 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-03-09 17:08:20 +0000
commitd5bf4ab5f75bbfd28162d8a45043cc5801fbfcc5 (patch)
tree0d9c01ac880957869a76f0944028c55ac6ed05d7 /src/com/android/launcher3/LauncherProvider.java
parent1c0e633bd59e0f14f799cbb6aee33266032998fa (diff)
parentfe4e4b91dc7db5d373690dd4bf2f3b5f1525b68a (diff)
downloadandroid_packages_apps_Trebuchet-d5bf4ab5f75bbfd28162d8a45043cc5801fbfcc5.tar.gz
android_packages_apps_Trebuchet-d5bf4ab5f75bbfd28162d8a45043cc5801fbfcc5.tar.bz2
android_packages_apps_Trebuchet-d5bf4ab5f75bbfd28162d8a45043cc5801fbfcc5.zip
Merge "Refactoring max id logic to a common method" into ub-launcher3-burnaby
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 747d7efb7..b7a271e4f 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -737,23 +737,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
@@ -772,25 +756,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) {
@@ -1203,6 +1169,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;