diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/queries/DatabaseHelper.java b/app/src/main/java/de/k3b/android/androFotoFinder/queries/DatabaseHelper.java index 307cbf80..ba157b8c 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/queries/DatabaseHelper.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/queries/DatabaseHelper.java @@ -50,8 +50,11 @@ public class DatabaseHelper extends SQLiteOpenHelper { private static DatabaseHelper instance = null; private static DatabaseContext databaseContext = null; + private final Context context; + public DatabaseHelper(final Context context, final String databaseName) { super(context, databaseName, null, DatabaseHelper.DATABASE_VERSION); + this.context = context.getApplicationContext(); } public static SQLiteDatabase getWritableDatabase(Context context) { @@ -72,7 +75,8 @@ private static DatabaseHelper getInstance(Context context) { } - public static void version2Upgrade_ReCreateMediaDbTable(final SQLiteDatabase db) { + public static void version2Upgrade_ReCreateMediaDbTable(Context context, final SQLiteDatabase db) { + MediaDBRepository.saveSyncStats(context, 1, 1); execSql(db, "(Re)CreateMediaDbTable:", MediaDBRepository.Impl.DDL); } @@ -130,7 +134,7 @@ private static void execSql(SQLiteDatabase db, String dbgContext, String... ddlS public void onCreate(final SQLiteDatabase db) { execSql(db, "First Create DB: ", TransactionLogSql.CREATE_TABLE); - version2Upgrade_ReCreateMediaDbTable(db); + version2Upgrade_ReCreateMediaDbTable(context, db); } @Override @@ -139,7 +143,7 @@ public void onUpgrade(final SQLiteDatabase db, final int oldVersion, Log.w(this.getClass().toString(), "Upgrading database from version " + oldVersion + " to " + newVersion + ". (Old data is kept.)"); if (oldVersion < DatabaseHelper.DATABASE_VERSION_2_MEDIA_DB_COPY) { - version2Upgrade_ReCreateMediaDbTable(db); + version2Upgrade_ReCreateMediaDbTable(context, db); } } } diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/queries/MediaContent2DBUpdateService.java b/app/src/main/java/de/k3b/android/androFotoFinder/queries/MediaContent2DBUpdateService.java index 4bc01475..c1bc189f 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/queries/MediaContent2DBUpdateService.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/queries/MediaContent2DBUpdateService.java @@ -55,7 +55,7 @@ public MediaContent2DBUpdateService(Context context, SQLiteDatabase writableData } public void clearMediaCopy() { - DatabaseHelper.version2Upgrade_ReCreateMediaDbTable(writableDatabase); + DatabaseHelper.version2Upgrade_ReCreateMediaDbTable(context, writableDatabase); } public int rebuild(Context context, IProgessListener progessListener) { diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/queries/MediaDBRepository.java b/app/src/main/java/de/k3b/android/androFotoFinder/queries/MediaDBRepository.java index 3a2e185e..b44ac71b 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/queries/MediaDBRepository.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/queries/MediaDBRepository.java @@ -410,6 +410,16 @@ public static ContentValues getContentValues(String fullFilePathFilter, ContentV } + public static void saveSyncStats(Context context, long maxDateAddedSecs, long maxDateUpdatedSecs) { + SharedPreferences prefsInstance = PreferenceManager + .getDefaultSharedPreferences(context.getApplicationContext()); + + SharedPreferences.Editor prefs = prefsInstance.edit(); + if (maxDateUpdatedSecs > 0) prefs.putLong("maxDateUpdatedSecs", maxDateUpdatedSecs + 1); + if (maxDateAddedSecs > 0) prefs.putLong("maxDateAddedSecs", maxDateAddedSecs + 1); + prefs.apply(); + } + public static class Impl { public static final String DATABASE_TABLE_NAME = "files"; public static final String DATABASE_TABLE_NAME_BACKUP = "backup"; @@ -752,7 +762,7 @@ public static int updateMediaCopy( } // while over all old items db.setTransactionSuccessful(); // This commits the transaction if there were no exceptions - saveStats(context, maxDateAddedSecs, maxDateUpdatedSecs); + saveSyncStats(context, maxDateAddedSecs, maxDateUpdatedSecs); if (Global.debugEnabledSql) { java.util.Date endTime = new java.util.Date(); @@ -786,16 +796,6 @@ public static int updateMediaCopy( return progress; } - private static void saveStats(Context context, long maxDateAddedSecs, long maxDateUpdatedSecs) { - SharedPreferences prefsInstance = PreferenceManager - .getDefaultSharedPreferences(context.getApplicationContext()); - - SharedPreferences.Editor prefs = prefsInstance.edit(); - if (maxDateUpdatedSecs > 0) prefs.putLong("maxDateUpdatedSecs", maxDateUpdatedSecs + 1); - if (maxDateAddedSecs > 0) prefs.putLong("maxDateAddedSecs", maxDateAddedSecs + 1); - prefs.apply(); - } - protected static long getDateInSecs(Cursor c, int colPosition) { long dateInSecs = (c.isNull(colPosition)) ? 0 : c.getLong(colPosition); if (dateInSecs > nextMonthTimeInSecs) { @@ -805,4 +805,5 @@ protected static long getDateInSecs(Cursor c, int colPosition) { return dateInSecs; } } + }