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 17, 2020
1 parent feaa790 commit 1f263b3
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 116 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class MediaContentproviderRepositoryImpl {
public static Cursor createCursorForQuery(
StringBuilder out_debugMessage, String dbgContext, final Context context,
QueryParameter parameters, VISIBILITY visibility, CancellationSignal cancellationSignal) {
if (visibility != null) FotoSql.setWhereVisibility(parameters, visibility);
FotoSql.setWhereVisibility(parameters, visibility);
return createCursorForQuery(out_debugMessage, dbgContext, context, parameters.toFrom(),
parameters.toAndroidWhere(),
parameters.toAndroidParameters(), parameters.toOrderBy(),
Expand Down
20 changes: 1 addition & 19 deletions app/src/main/java/de/k3b/android/io/AndroidFileCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@
import de.k3b.android.androFotoFinder.LockScreen;
import de.k3b.android.androFotoFinder.R;
import de.k3b.android.androFotoFinder.directory.DirectoryPickerFragment;
import de.k3b.android.androFotoFinder.media.AndroidPhotoPropertiesBulkUpdateService;
import de.k3b.android.androFotoFinder.queries.DatabaseHelper;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.tagDB.TagSql;
import de.k3b.android.androFotoFinder.transactionlog.TransactionLogSql;
import de.k3b.android.util.OsUtils;
import de.k3b.android.util.PhotoChangeNotifyer;
import de.k3b.android.util.PhotoPropertiesMediaFilesScanner;
import de.k3b.android.util.PhotoPropertiesMediaFilesScannerAsyncTask;
import de.k3b.android.util.RecursivePhotoPropertiesMediaFilesScannerAsyncTask;
import de.k3b.android.widget.FilePermissionActivity;
import de.k3b.database.QueryParameter;
Expand All @@ -68,7 +66,6 @@
import de.k3b.io.filefacade.FileFacade;
import de.k3b.io.filefacade.IFile;
import de.k3b.media.MediaFormatter;
import de.k3b.media.PhotoPropertiesBulkUpdateService;
import de.k3b.media.PhotoPropertiesDiffCopy;
import de.k3b.media.PhotoPropertiesUpdateHandler;
import de.k3b.transactionlog.MediaTransactionLogEntryType;
Expand Down Expand Up @@ -146,16 +143,6 @@ protected void onPostProcess(

Context context = this.mContext;
String message = getModifyMessage(context, opCode, modifyCount, itemCount);
if ((itemCount > 0) && (mScanner != null)) {
PhotoPropertiesMediaFilesScannerAsyncTask.updateMediaDBInBackground(mScanner, context, message, oldPathNames, newPathNames);
}

if (false && this.mHasNoMedia && (context != null)) {
// a nomedia file is affected => must update gui
context.getContentResolver().notifyChange(FotoSql.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, null, false);
this.mHasNoMedia = false;
}

if (!isInBackground) {
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
}
Expand Down Expand Up @@ -231,6 +218,7 @@ public boolean rename(SelectedFiles selectedFiles, IFile dest, IProgessListener
return (result != 0);
}

@Deprecated
public int execRename(File srcDirFile, String newFolderName) {
// this will allow to be newFolderName = "../someOtherDir/newName" or even "/absolute/path/to"
File destDirFile = FileUtils.tryGetCanonicalFile(new File(srcDirFile.getParent(), newFolderName));
Expand Down Expand Up @@ -671,12 +659,6 @@ public String toString() {
return result.toString();
}

/** overwrite to create a android specific Workflow */
@Override
public PhotoPropertiesBulkUpdateService createWorkflow(TransactionLoggerBase logger, String dbgContext) {
return new AndroidPhotoPropertiesBulkUpdateService(mContext, logger, dbgContext);
}

@Override
protected TransactionLoggerBase createTransactionLogger(long now) {
return new AndroidTransactionLogger(this, now);
Expand Down
31 changes: 2 additions & 29 deletions app/src/main/java/de/k3b/android/io/AndroidFileCommandsDbImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import android.content.ContentValues;
import android.net.Uri;

import java.io.File;

import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.queries.MediaDBRepository;
import de.k3b.io.FileCommands;
Expand All @@ -46,12 +44,11 @@ public class AndroidFileCommandsDbImpl extends FileCommands {
*/
@Override
protected boolean osFileCopy(IFile targetFullPath, IFile sourceFullPath) {
//!!! TODO muss noch getestet werden
final String srcPath = sourceFullPath.getAbsolutePath();
String toPath = null;
boolean dbSuccess = false;
if (PhotoPropertiesUtil.isImage(srcPath, PhotoPropertiesUtil.IMG_TYPE_ALL)) {
toPath = new File(targetFullPath.getFile(), targetFullPath.getName()).getAbsolutePath();
toPath = targetFullPath.getAbsolutePath();
dbSuccess = (null != copyInDatabase("osFileCopy", srcPath, toPath));
}

Expand All @@ -75,7 +72,7 @@ protected boolean osFileMove(IFile targetFullPath, IFile sourceFullPath) {
boolean dbSuccess = false;
// Database update must be done before super.osFileMove to avoid deleting/recreating old file entry
if (PhotoPropertiesUtil.isImage(srcPath, PhotoPropertiesUtil.IMG_TYPE_ALL)) {
toPath = new File(targetFullPath.getFile(), targetFullPath.getName()).getAbsolutePath();
toPath = targetFullPath.getAbsolutePath();
dbSuccess = renameInDatabase("osFileMove", srcPath, toPath);
}
final boolean osSuccess = super.osFileMove(targetFullPath, sourceFullPath);
Expand All @@ -86,30 +83,6 @@ protected boolean osFileMove(IFile targetFullPath, IFile sourceFullPath) {
return osSuccess;
}

/**
* Renames a file from the sourceFullPath path to the target path.
* Android specific: also updates database.
*
* @param sourceFullPath the path of the file that shall be copied including the file name with ending
* @param targetFullPath the path of the file that shall be written to with filename
*/
@Override
protected boolean osRenameTo(IFile targetFullPath, IFile sourceFullPath) {
final String srcPath = sourceFullPath.getAbsolutePath();
String toPath = null;
boolean dbSuccess = false;
if (PhotoPropertiesUtil.isImage(srcPath, PhotoPropertiesUtil.IMG_TYPE_ALL)) {
toPath = targetFullPath.getAbsolutePath();
dbSuccess = renameInDatabase("osRenameTo", srcPath, toPath);
}
final boolean osSuccess = super.osRenameTo(targetFullPath, sourceFullPath);
if (!osSuccess && dbSuccess) {
// os falled. Rollback
renameInDatabase("osRenameTo-rollback", toPath, srcPath);
}
return osSuccess;
}

@Override
protected boolean osDeleteFile(IFile file) {
return super.osDeleteFile(file);
Expand Down
5 changes: 3 additions & 2 deletions fotolib2/src/main/java/de/k3b/io/FileCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ protected int moveOrCopyFiles(final boolean move, String what, PhotoPropertiesDi
MediaTransactionLogEntryType moveOrCopyCommand = (move) ? MediaTransactionLogEntryType.MOVE : MediaTransactionLogEntryType.COPY;
TransactionLoggerBase logger = (exifChanges == null) ? null : createTransactionLogger(now);
boolean sameFile;

//!!! TODO ??begin transaction??
while (pos < fileCount) {
IFile sourceFile = sourceFiles[pos];
IFile destFile = destFiles[pos].getCanonicalFile();
Expand Down Expand Up @@ -424,7 +424,8 @@ protected int moveOrCopyFiles(final boolean move, String what, PhotoPropertiesDi
}
}
pos++;
} // foreach selected file
} // foreach selected file.
// !!! TODO ??COMMIT TRANSACTION??
int modifyCount = mModifiedDestFiles.size();

IFile[] modifiedSourceFiles = ((mModifiedSrcFiles != null) && (mModifiedSrcFiles.size() > 0)) ? mModifiedSrcFiles.toArray(new IFile[modifyCount]) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ public PhotoPropertiesUpdateHandler applyChanges(IFile inFilePath, IFile outFile
inFilePath.setLastModified(lastModified);
}

id = updateMediaDB(id, inFilePath.getAbsolutePath(), outFile);

if (sb != null) {
PhotoPropertiesUpdateHandler exifVerify = PhotoPropertiesUpdateHandler.create(inFilePath,
null, false, "dbg in PhotoPropertiesUpdateHandler", true, true, false);
Expand Down Expand Up @@ -221,11 +219,6 @@ protected IFile handleVisibility(VISIBILITY newVisibility, IFile outFile, PhotoP
return null;
}

/** todo overwrite in android class to implement update media db */
protected long updateMediaDB(long id, String oldJpgAbsolutePath, IFile newJpgFile) {
return id;
}

private StringBuilder createDebugStringBuilder(IFile filePath) {
if(filePath != null) {
return new StringBuilder("Set Exif to file='").append(filePath.getAbsolutePath()).append("'\n\t");
Expand Down

0 comments on commit 1f263b3

Please sign in to comment.