Skip to content

Commit 9d4a52e

Browse files
committed
#155: ao10: fixed move photo(s) with and without autoprocessing
1 parent 0115062 commit 9d4a52e

File tree

7 files changed

+57
-12
lines changed

7 files changed

+57
-12
lines changed

Diff for: app/src/main/java/de/k3b/android/androFotoFinder/media/AndroidExifInterfaceEx.java

+34-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package de.k3b.android.androFotoFinder.media;
2121

2222
import android.content.ContentValues;
23+
import android.net.Uri;
2324
import android.util.Log;
2425

2526
import java.io.IOException;
@@ -61,6 +62,18 @@ public ExifInterfaceEx create() {
6162
@Override
6263
public void saveAttributes(IFile inFile, IFile outFile,
6364
boolean deleteInFileOnFinish, Boolean hasXmp) throws IOException {
65+
if (deleteInFileOnFinish) {
66+
renameInDatabase(":saveAttributes", inFile.getCanonicalPath(), outFile.getCanonicalPath(), true);
67+
} else {
68+
if (inFile.equals(outFile)) {
69+
// !!!
70+
// renameSouraceFileBeforeReplaceOrThrow
71+
72+
} else {
73+
insertIntoDatabase(outFile, hasXmp);
74+
}
75+
}
76+
//!!! update media database
6477
super.saveAttributes(inFile, outFile, deleteInFileOnFinish, hasXmp);
6578
this.hasXmp = hasXmp;
6679
}
@@ -90,6 +103,26 @@ protected void beforeCloseSaveOutputStream() {
90103
super.beforeCloseSaveOutputStream();
91104
}
92105

106+
private void insertIntoDatabase(IFile outFile, Boolean hasXmp) {
107+
ContentValues values = new ContentValues();
108+
PhotoPropertiesMediaDBContentValues mediaValueAdapter = new PhotoPropertiesMediaDBContentValues().set(values, null);
109+
110+
PhotoPropertiesUtil.copyNonEmpty(mediaValueAdapter, this);
111+
112+
Date lastModified = new Date();
113+
TagSql.setFileModifyDate(values, lastModified);
114+
if (this.hasXmp != null) {
115+
if (this.hasXmp) {
116+
TagSql.setXmpFileModifyDate(values, lastModified);
117+
} else {
118+
TagSql.setXmpFileModifyDate(values, TagSql.EXT_LAST_EXT_SCAN_NO_XMP);
119+
}
120+
}
121+
122+
values.put(FotoSql.SQL_COL_PATH, outFile.getCanonicalPath());
123+
Uri result = FotoSql.getMediaDBApi().execInsert("Copy with Autoprocessing", values);
124+
}
125+
93126
// TODO additional database parameters (see scanner)
94127
// DateLastModified, xmpDate, ....
95128
private boolean renameInDatabase(String dbgContext, String fromPath, String toPath, boolean thransferExif) {
@@ -138,7 +171,7 @@ private void debugIdPaths(String dbgContext, String... paths) {
138171
" is not null");
139172
final SelectedFiles selectedfiles = FotoSql.getSelectedfiles(sqlWhere.toString(), VISIBILITY.PRIVATE_PUBLIC);
140173
Log.d(Global.LOG_CONTEXT, dbgContext + "\n\t["
141-
+ StringUtils.appendMessage((String[]) paths)
174+
+ StringUtils.appendMessage(paths)
142175
+ "] :\n\t\t"
143176
+ selectedfiles.toIdString() + " -> " + selectedfiles.toPathListString());
144177
}

Diff for: app/src/main/java/de/k3b/android/androFotoFinder/queries/MergedMediaRepository.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public int execUpdate(String dbgContext, long id, ContentValues values) {
7474
public int execUpdate(String dbgContext, String path, ContentValues values, VISIBILITY visibility) {
7575
int result = super.execUpdate(
7676
dbgContext, path, values, visibility);
77-
localDatabase.execUpdate(dbgContext, path, values, visibility);
77+
result = localDatabase.execUpdate(dbgContext, path, values, visibility);
7878
return result;
7979
}
8080

@@ -185,7 +185,7 @@ public Uri execInsert(String dbgContext, ContentValues values) {
185185
// insert with same pk as contentprovider does
186186
values.put(FotoSql.SQL_COL_PK, FotoSql.getId(result));
187187
}
188-
localDatabase.execInsert(dbgContext, values);
188+
result = localDatabase.execInsert(dbgContext, values);
189189
values.remove(FotoSql.SQL_COL_PK);
190190
return result;
191191
}

Diff for: app/src/main/java/de/k3b/android/io/AndroidFileFacade.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,14 @@ public boolean renameTo(@NonNull String newName) {
153153

154154
@Override
155155
public boolean delete() {
156-
return exists() && getAndroidFile(false).delete();
156+
boolean result = exists() && getAndroidFile(false).delete();
157+
158+
if (result) {
159+
// File (and reference to it) does not exist any more
160+
androidFileMayExist = false;
161+
androidFile = null;
162+
}
163+
return result;
157164
}
158165

159166
@Override

Diff for: app/src/main/java/de/k3b/android/io/DocumentFileTranslator.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class DocumentFileTranslator {
6969
private static final File internalRootCandidate = new File("/storage/emulated/0");
7070
// for debugging
7171
private static int id = 1;
72-
private String mDebugPrefix;
72+
private final String mDebugPrefix;
7373
private static Root root = null;
7474

7575
private DocumentFileTranslator(Context context, String namePrefix) {
@@ -228,15 +228,16 @@ public DocumentFile getOrCreateDirectory(File directory) {
228228
*/
229229
public DocumentFile getDocumentFileOrDirOrNull(File fileOrDir, Boolean isDir) {
230230
DocumentFile result = null;
231-
final String context = FileFacade.debugLogFacade ? (mDebugPrefix + "getDocumentFile('" + fileOrDir.getAbsolutePath() +
232-
"') ") : null;
231+
String path = fileOrDir != null ? fileOrDir.getAbsolutePath() : "";
232+
final String context = FileFacade.debugLogFacade ? (mDebugPrefix + "getDocumentFile('"
233+
+ path + "') ") : null;
233234
try {
234235
result = getDocumentFileOrDirImpl(fileOrDir);
235236
if ((context != null) && (result == null)) {
236237
Log.i(TAG, context + "not found");
237238
}
238239
} catch (Exception ex) {
239-
Log.w(TAG, mDebugPrefix + "getDocumentFile('" + fileOrDir.getAbsolutePath() +
240+
Log.w(TAG, mDebugPrefix + "getDocumentFile('" + path +
240241
"') ", ex);
241242

242243
}
@@ -297,7 +298,7 @@ public static String pathFromUri(String uri) {
297298

298299
private static class Root {
299300
private final Context context;
300-
private Map<String, String> dir2uri = new HashMap<>();
301+
private final Map<String, String> dir2uri = new HashMap<>();
301302

302303
public Root(Context context) {
303304
this.context = context.getApplicationContext();

Diff for: fastlane/metadata/android/en-US/changelogs/48.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changes from 0.8.3 to ???
44
* #155: Android-10 support (experimental)
55
* #173: incremental media scanner
66
* #180: Fixed: Show image with uri that cannot be translated to file (i.e. WhatsApp show photo in gallery)
7+
* #93: Bugfix crash in Autoprocessing with date-based-rename when photo has no dateCreated
78
* fixed CSV IPhotoProperties import
89
* version bumbs android-9 (sdk-28), gradle-6.1.1, osmdroid-6.1.6 mapsforge:0.13.0
910
* new translation eu (Basque)

Diff for: fotolib2/src/main/java/de/k3b/io/FileCommands.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private static boolean _osFileCopy(IFile targetFullPath, IFile sourceFullPath, F
155155
*/
156156
public int applyExifChanges(boolean move, PhotoPropertiesDiffCopy exifChanges, SelectedFiles selectedFiles, IProgessListener progessListener) {
157157
// source files are the same as dest files.
158-
final File[] destFiles = selectedFiles.getFiles();
158+
final IFile[] destFiles = selectedFiles.getIFiles();
159159
return moveOrCopyFiles(move, "change_exif", exifChanges, selectedFiles, destFiles, progessListener);
160160
}
161161

Diff for: fotolib2/src/main/java/de/k3b/media/PhotoPropertiesBulkUpdateService.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public PhotoPropertiesUpdateHandler applyChanges(IFile inFilePath, IFile outFile
9999
PhotoPropertiesUpdateHandler exifHandler = null;
100100
try {
101101
long lastModified = inFilePath.lastModified();
102-
exifHandler = PhotoPropertiesUpdateHandler.create(inFilePath, outFile, false, "PhotoPropertiesUpdateHandler:");
102+
exifHandler = PhotoPropertiesUpdateHandler.create(inFilePath, outFile, deleteOriginalWhenFinished, "PhotoPropertiesUpdateHandler:");
103103
debugExif(sb, "old", exifHandler, inFilePath);
104104
List<String> oldTags = exifHandler.getTags();
105105

@@ -119,16 +119,19 @@ public PhotoPropertiesUpdateHandler applyChanges(IFile inFilePath, IFile outFile
119119
if (!sameFile || (changed != null)) {
120120
debugExif(sb, "assign ", exifHandler, inFilePath);
121121

122+
122123
exifHandler.save("PhotoPropertiesUpdateHandler save");
123124

125+
// After move inFilePath is invalid
126+
124127
if (LibGlobal.preserveJpgFileModificationDate) {
125128
// preseve file modification date
126129
inFilePath.setLastModified(lastModified);
127130
}
128131

129132
if (sb != null) {
130133
PhotoPropertiesUpdateHandler exifVerify = PhotoPropertiesUpdateHandler.create(inFilePath,
131-
null, false, "dbg in PhotoPropertiesUpdateHandler", true, true, false);
134+
null, deleteOriginalWhenFinished, "dbg in PhotoPropertiesUpdateHandler", true, true, false);
132135
debugExif(sb, "new ", exifVerify, inFilePath);
133136
}
134137

0 commit comments

Comments
 (0)