From ffe5b527f6b93b53590b4533fa6624d2f389722b Mon Sep 17 00:00:00 2001 From: Pavel Salomatov Date: Wed, 16 Jan 2019 17:59:34 +0300 Subject: [PATCH] UpdatesDbHelper: Move identical code into helper method Change-Id: I2e19d9756fab94d9fcd3352b0baef45300044d3a --- src/org/lineageos/updater/UpdatesDbHelper.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/org/lineageos/updater/UpdatesDbHelper.java b/src/org/lineageos/updater/UpdatesDbHelper.java index 1ee7a475..71a20758 100644 --- a/src/org/lineageos/updater/UpdatesDbHelper.java +++ b/src/org/lineageos/updater/UpdatesDbHelper.java @@ -78,19 +78,18 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { public long addUpdate(Update update) { SQLiteDatabase db = getWritableDatabase(); ContentValues values = new ContentValues(); - values.put(UpdateEntry.COLUMN_NAME_STATUS, update.getPersistentStatus()); - values.put(UpdateEntry.COLUMN_NAME_PATH, update.getFile().getAbsolutePath()); - values.put(UpdateEntry.COLUMN_NAME_DOWNLOAD_ID, update.getDownloadId()); - values.put(UpdateEntry.COLUMN_NAME_TIMESTAMP, update.getTimestamp()); - values.put(UpdateEntry.COLUMN_NAME_TYPE, update.getType()); - values.put(UpdateEntry.COLUMN_NAME_VERSION, update.getVersion()); - values.put(UpdateEntry.COLUMN_NAME_SIZE, update.getFileSize()); + fillContentValues(update, values); return db.insert(UpdateEntry.TABLE_NAME, null, values); } public long addUpdateWithOnConflict(Update update, int conflictAlgorithm) { SQLiteDatabase db = getWritableDatabase(); ContentValues values = new ContentValues(); + fillContentValues(update, values); + return db.insertWithOnConflict(UpdateEntry.TABLE_NAME, null, values, conflictAlgorithm); + } + + private static void fillContentValues(Update update, ContentValues values) { values.put(UpdateEntry.COLUMN_NAME_STATUS, update.getPersistentStatus()); values.put(UpdateEntry.COLUMN_NAME_PATH, update.getFile().getAbsolutePath()); values.put(UpdateEntry.COLUMN_NAME_DOWNLOAD_ID, update.getDownloadId()); @@ -98,7 +97,6 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { values.put(UpdateEntry.COLUMN_NAME_TYPE, update.getType()); values.put(UpdateEntry.COLUMN_NAME_VERSION, update.getVersion()); values.put(UpdateEntry.COLUMN_NAME_SIZE, update.getFileSize()); - return db.insertWithOnConflict(UpdateEntry.TABLE_NAME, null, values, conflictAlgorithm); } public boolean removeUpdate(String downloadId) {