diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/media/PhotoPropertiesMediaDBCsvImportActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/media/PhotoPropertiesMediaDBCsvImportActivity.java index e087c754..b91ae326 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/media/PhotoPropertiesMediaDBCsvImportActivity.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/media/PhotoPropertiesMediaDBCsvImportActivity.java @@ -36,12 +36,12 @@ import de.k3b.android.androFotoFinder.Global; import de.k3b.android.androFotoFinder.R; +import de.k3b.android.androFotoFinder.queries.FotoSql; import de.k3b.android.androFotoFinder.tagDB.TagSql; import de.k3b.android.io.AndroidFileCommands; import de.k3b.android.util.IntentUtil; import de.k3b.csv2db.csv.CsvLoader; import de.k3b.io.FileUtils; -import de.k3b.io.VISIBILITY; import de.k3b.io.filefacade.FileFacade; import de.k3b.io.filefacade.IFile; import de.k3b.media.PhotoPropertiesCsvItem; @@ -206,7 +206,9 @@ private void updateDB(String dbgContext, String _path, long xmlLastFileModifyDat TagSql.setFileModifyDate(dbValues, new Date()); - mUpdateCount += TagSql.execUpdate(dbgContext, path, xmlLastFileModifyDate, dbValues, VISIBILITY.PRIVATE_PUBLIC); + dbValues.put(FotoSql.SQL_COL_PATH, path); + mUpdateCount += TagSql.insertOrUpdateMediaDatabaseFromCsv( + dbgContext, path, xmlLastFileModifyDate, dbValues, null); mItemCount++; } } diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/queries/MergedMediaRepository.java b/app/src/main/java/de/k3b/android/androFotoFinder/queries/MergedMediaRepository.java index 8117e73c..3677d079 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/queries/MergedMediaRepository.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/queries/MergedMediaRepository.java @@ -50,7 +50,7 @@ public int execUpdate(String dbgContext, long id, ContentValues values) { dbgContext += " " + id + " not found or no change in contentprovider."; String path = values.getAsString(FotoSql.SQL_COL_PATH); - Long changedId = FotoSql.getId(dbgContext, getWriteChild(), path); + Long changedId = FotoSql.getId(dbgContext, contentProvider, path); if (changedId != null && id != changedId.longValue()) { // pk in contentprovidser has changed dbgContext += " unsing " + path + "(" + changedId + ") instead"; @@ -66,7 +66,8 @@ public int execUpdate(String dbgContext, long id, ContentValues values) { @Override public int execUpdate(String dbgContext, String path, ContentValues values, VISIBILITY visibility) { - int result = super.execUpdate(dbgContext, path, values, visibility); + int result = super.execUpdate( + dbgContext, path, values, visibility); database.execUpdate(dbgContext, path, values, visibility); return result; } @@ -91,7 +92,7 @@ public int exexUpdateImpl(String dbgContext, ContentValues values, String sqlWhe public Long insertOrUpdateMediaDatabase(String dbgContext, String dbUpdateFilterJpgFullPathName, ContentValues values, VISIBILITY visibility, Long updateSuccessValue) { Long result = updateSuccessValue; - + Uri uriWithId = null; int modifyCount = contentProvider.execUpdate(dbgContext, dbUpdateFilterJpgFullPathName, values, visibility); @@ -100,13 +101,28 @@ public Long insertOrUpdateMediaDatabase(String dbgContext, String dbUpdateFilter FotoSql.addDateAdded(values); // insert into contentProvider and database - Uri uriWithId = execInsert(dbgContext, values); - result = FotoSql.getId(uriWithId); - } else { - // update into contentprovider successfull. also add to database - database.execUpdate(dbgContext, dbUpdateFilterJpgFullPathName, - values, visibility); + uriWithId = contentProvider.execInsert(dbgContext, values); + + if (uriWithId != null) { + result = FotoSql.getId(uriWithId); + values.put(FotoSql.SQL_COL_PK, result); + } } + + modifyCount = database.execUpdate(dbgContext, dbUpdateFilterJpgFullPathName, + values, visibility); + + if (modifyCount == 0) { + // update failed (probably becauce oldFullPathName not found. try insert it. + FotoSql.addDateAdded(values); + + // insert into contentProvider and database + uriWithId = database.execInsert(dbgContext, values); + if (uriWithId != null) { + result = FotoSql.getId(uriWithId); + } + } + return result; } @@ -125,7 +141,7 @@ public Uri execInsert(String dbgContext, ContentValues values) { // not inserted because in android-contentprovider may already exist. // get id from android-contentprovider String path = values.getAsString(FotoSql.SQL_COL_PATH); - Long id = FotoSql.getId(dbgContext, getWriteChild(), path); + Long id = FotoSql.getId(dbgContext, contentProvider, path); if (id == null) { Log.i(LOG_TAG, dbgContext + " Path '" + path + "' not found. Aborted."); diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/tagDB/TagSql.java b/app/src/main/java/de/k3b/android/androFotoFinder/tagDB/TagSql.java index 1b88220d..98cbc674 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/tagDB/TagSql.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/tagDB/TagSql.java @@ -346,8 +346,10 @@ public static void setFileModifyDate(ContentValues values, long fileModifyDateSe * @param allowSetNulls if one of these columns are null, the set null is copied, too * @return number of changed db items */ - public static int updateDB(String dbgContext, String oldFullJpgFilePath, - PhotoPropertiesUpdateHandler jpg, MediaFormatter.FieldID... allowSetNulls) { + public static Long updateDB( + String dbgContext, String oldFullJpgFilePath, + PhotoPropertiesUpdateHandler jpg, + MediaFormatter.FieldID... allowSetNulls) { if ((jpg != null) && (!PhotoPropertiesMediaFilesScanner.isNoMedia(oldFullJpgFilePath))) { ContentValues dbValues = new ContentValues(); PhotoPropertiesMediaDBContentValues mediaValueAdapter = new PhotoPropertiesMediaDBContentValues(); @@ -372,21 +374,23 @@ public static int updateDB(String dbgContext, String oldFullJpgFilePath, TagSql.setXmpFileModifyDate(dbValues, xmpFilelastModified); TagSql.setFileModifyDate(dbValues, newFullJpgFilePath); - return TagSql.execUpdate(dbgContext, oldFullJpgFilePath, - TagSql.EXT_LAST_EXT_SCAN_UNKNOWN, dbValues, VISIBILITY.PRIVATE_PUBLIC); + return TagSql.insertOrUpdateMediaDatabaseFromCsv( + dbgContext, oldFullJpgFilePath, + TagSql.EXT_LAST_EXT_SCAN_UNKNOWN, + dbValues, VISIBILITY.PRIVATE_PUBLIC); } } - return 0; + return 0L; } - public static int execUpdate(String dbgContext, String path, long xmpFileDate, ContentValues values, VISIBILITY visibility) { - if (!Global.Media.enableXmpNone || isPseudoXmpFileDateVauel(xmpFileDate)) { - return getMediaDBApi().execUpdate(dbgContext, path, values, visibility); - } - return getMediaDBApi().exexUpdateImpl(dbgContext, values, FILTER_EXPR_PATH_AND_XMP_DATE_LESS_THAN, new String[]{path, Long.toString(xmpFileDate)}); + public static Long insertOrUpdateMediaDatabaseFromCsv( + String dbgContext, String path, long xmpFileDate, + ContentValues values, VISIBILITY visibility) { + return getMediaDBApi().insertOrUpdateMediaDatabase( + dbgContext, path, values, visibility,1L); } public static List getPhotosNeverScanned(String path) {