Skip to content

Commit

Permalink
#169: fixed ao10-mediascanner: open jpg from filemanager not yet in a…
Browse files Browse the repository at this point in the history
…pm-local-database
  • Loading branch information
k3b committed Feb 10, 2021
1 parent 150fc6f commit 10b8758
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public static RefWatcher getRefWatcher(Context context) {
MediaContentproviderRepositoryImpl.LOG_TAG,
DocumentFileTranslator.TAG, DocumentFileTranslator.TAG_DOCFILE,
FileFacade.LOG_TAG, AndroidFileFacade.LOG_TAG,
"SQLiteDatabase",
FilePermissionActivity.TAG) {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private static int updateIncompleteMediaDatabase(String debugPrefix, Context con
if (dirToScan == null) return 0;

String dbPathSearch = null;
ArrayList<String> missing = new ArrayList<String>();
ArrayList<IFile> missing = new ArrayList<>();
dbPathSearch = dirToScan.getAbsolutePath() + "/%";
List<String> known = FotoSql.execGetFotoPaths(dbPathSearch);
IFile[] existing = dirToScan.listFiles();
Expand All @@ -185,7 +185,7 @@ private static int updateIncompleteMediaDatabase(String debugPrefix, Context con
for (IFile file : existing) {
String found = file.getAbsolutePath();
if (PhotoPropertiesUtil.isImage(found, PhotoPropertiesUtil.IMG_TYPE_ALL) && !known.contains(found)) {
missing.add(found);
missing.add(file);
}
}
}
Expand All @@ -195,15 +195,15 @@ private static int updateIncompleteMediaDatabase(String debugPrefix, Context con
message.append(debugPrefix).append("updateIncompleteMediaDatabase('")
.append(dbPathSearch).append("') : \n\t");

for (String s : missing) {
message.append(s).append("; ");
for (IFile s : missing) {
message.append(s.getName()).append("; ");
}
Log.d(Global.LOG_CONTEXT, message.toString());
}

PhotoPropertiesMediaFilesScannerAsyncTask scanner = new PhotoPropertiesMediaFilesScannerAsyncTask(
PhotoPropertiesMediaFilesScanner.getInstance(context), context, why);
scanner.execute(null, FileFacade.get("updateIncompleteMediaDatabase", missing));
scanner.execute(null, missing.toArray(new IFile[missing.size()]));
return missing.size();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,13 @@ public Uri execInsert(String dbgContext, ContentValues values) {
Exception excpetion = null;
try {
// on my android-4.4 insert with media_type=1001 (private) does insert with media_type=1 (image)
result = db.insert(Impl.table, null, values);
if (result > 0) {
currentUpdateId++;
currentUpdateReason = dbgContext;
result = db.insertWithOnConflict(Impl.table, null, values, SQLiteDatabase.CONFLICT_REPLACE );
if (result == -1) {
return null;
}

currentUpdateId++;
currentUpdateReason = dbgContext;
} catch (Exception ex) {
excpetion = ex;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ private int insertAndroid42(String dbgContext, IFile file) {
ContentValues values = createDefaultContentValues();
FotoSql.addDateAdded(values);

getExifFromFile(values, file);
return (null != FotoSql.getMediaDBApi().execInsert(dbgContext, values)) ? 1 : 0;
IPhotoProperties exif = getExifFromFile(values, file);
return (null != FotoSql.getMediaDBApi().insertOrUpdateMediaDatabase(dbgContext, exif.getPath(), values, exif.getVisibility(), 1L)) ? 1 : 0;
}
return 0;
}
Expand Down

0 comments on commit 10b8758

Please sign in to comment.