Skip to content

Commit

Permalink
#169: Update exif-file-info also updates mediadb without changing med…
Browse files Browse the repository at this point in the history
…iadb-id: Imagedetail: EditExif,rename,move,copy,delete
  • Loading branch information
k3b committed Dec 22, 2020
1 parent 1f263b3 commit 2f732c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
25 changes: 18 additions & 7 deletions app/src/main/java/de/k3b/android/io/AndroidFileCommandsDbImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ protected boolean osFileMove(IFile targetFullPath, IFile sourceFullPath) {
// Database update must be done before super.osFileMove to avoid deleting/recreating old file entry
if (PhotoPropertiesUtil.isImage(srcPath, PhotoPropertiesUtil.IMG_TYPE_ALL)) {
toPath = targetFullPath.getAbsolutePath();
dbSuccess = renameInDatabase("osFileMove", srcPath, toPath);
//!!! TODO PhotoPropertiesMediaFilesScanner.isNoMedia(targetFullPath))
dbSuccess = renameInDatabase("osFileMove", targetFullPath, sourceFullPath);
}
final boolean osSuccess = super.osFileMove(targetFullPath, sourceFullPath);
if (!osSuccess && dbSuccess) {
// os falled. Rollback
renameInDatabase("osFileMove-rollback", toPath, srcPath);
renameInDatabase("osFileMove-rollback", sourceFullPath, targetFullPath);
}
return osSuccess;
}
Expand All @@ -88,11 +89,21 @@ protected boolean osDeleteFile(IFile file) {
return super.osDeleteFile(file);
}

private boolean renameInDatabase(String dbgContext, String fromPath, String toPath) {
ContentValues values = new ContentValues();
values.put(FotoSql.SQL_COL_PATH, toPath);
final int execResultCount = FotoSql.getMediaDBApi().
execUpdate(this.getClass().getSimpleName() + dbgContext, fromPath, values, null);
private boolean renameInDatabase(String dbgContext, IFile targetFullPath, IFile sourceFullPath) {
final String srcPath = sourceFullPath.getAbsolutePath();
String toPath = null;
boolean dbSuccess = false;

// TODO !!! check nomedia !!!
// Database update must be done before super.osFileMove to avoid deleting/recreating old file entry
if (PhotoPropertiesUtil.isImage(srcPath, PhotoPropertiesUtil.IMG_TYPE_ALL)) {
toPath = targetFullPath.getAbsolutePath();

ContentValues values = new ContentValues();
values.put(FotoSql.SQL_COL_PATH, toPath);
final int execResultCount = FotoSql.getMediaDBApi().
execUpdate(this.getClass().getSimpleName() + dbgContext, fromPath, values, null);
}

return 1 == execResultCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static void notifyChanges(Context context, String why) {

public static boolean isNoMedia(int maxLevel, IFile[] pathNames) {
if (pathNames != null) {
for(IFile path : pathNames) {
for (IFile path : pathNames) {
if (isNoMedia(path, maxLevel)) {
return true;
}
Expand All @@ -126,6 +126,10 @@ public static boolean isNoMedia(int maxLevel, IFile[] pathNames) {
return false;
}

public static boolean isNoMedia(IFile path) {
return isNoMedia(path, PhotoPropertiesMediaFilesScanner.DEFAULT_SCAN_DEPTH);
}

public static boolean isNoMedia(IFile path, int maxLevel) {
return isNoMedia(path, maxLevel, null);
}
Expand Down

0 comments on commit 2f732c0

Please sign in to comment.