Skip to content

Commit

Permalink
#155: Gallery refresh query after change after exif edit
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Jan 3, 2020
1 parent 731b0ec commit ca57d2d
Show file tree
Hide file tree
Showing 10 changed files with 534 additions and 385 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 by k3b.
* Copyright (c) 2017-2020 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand All @@ -19,8 +19,6 @@

package de.k3b.android.androFotoFinder;

import android.app.Activity;

import java.io.Closeable;
import java.io.IOException;

Expand All @@ -37,7 +35,7 @@
public class AndroidTransactionLogger extends TransactionLoggerBase implements Closeable {
private AndroidFileCommands execLog;

public AndroidTransactionLogger(Activity ctx, long now, AndroidFileCommands execLog) {
public AndroidTransactionLogger(AndroidFileCommands execLog, long now) {
super(execLog, now);

this.execLog = execLog;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019 by k3b.
* Copyright (c) 2015-2020 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -334,18 +334,30 @@ public boolean mustRequery(long updateId) {
return modified;
}

private static int transactionNumber = 0;

@Override
public void beginTransaction() {
if (Global.debugEnabledSql) {
Log.i(LOG_TAG, "beginTransaction #" + (++transactionNumber));
}

db.beginTransaction();
}

@Override
public void setTransactionSuccessful() {
if (Global.debugEnabledSql) {
Log.i(LOG_TAG, "setTransactionSuccessful #" + transactionNumber);
}
db.setTransactionSuccessful();
}

@Override
public void endTransaction() {
if (Global.debugEnabledSql) {
Log.i(LOG_TAG, "endTransaction #" + transactionNumber);
}
db.endTransaction();
}
public static class Impl {
Expand Down
23 changes: 12 additions & 11 deletions app/src/main/java/de/k3b/android/util/AndroidFileCommands.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019 by k3b.
* Copyright (c) 2015-2020 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -37,14 +37,14 @@
import java.io.File;
import java.util.Date;

import de.k3b.android.androFotoFinder.AndroidTransactionLogger;
import de.k3b.android.androFotoFinder.Global;
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.queries.IMediaDBApi;
import de.k3b.android.androFotoFinder.tagDB.TagSql;
import de.k3b.android.androFotoFinder.transactionlog.TransactionLogSql;
import de.k3b.database.QueryParameter;
Expand Down Expand Up @@ -258,15 +258,9 @@ public void onMoveOrCopyDirectoryPick(boolean move, SelectedFiles selectedFiles,
protected int moveOrCopyFiles(final boolean move, String what, PhotoPropertiesDiffCopy exifChanges,
SelectedFiles fotos, File[] destFiles,
IProgessListener progessListener) {
IMediaDBApi api = FotoSql.getMediaDBApi();
try {
api.beginTransaction();
int result = super.moveOrCopyFiles(move, what, exifChanges, fotos, destFiles, progessListener);
api.setTransactionSuccessful();
return result;
} finally {
api.endTransaction();
}
int result = super.moveOrCopyFiles(move, what, exifChanges, fotos, destFiles, progessListener);
// api.setTransactionSuccessful();
return result;
}

@NonNull
Expand Down Expand Up @@ -572,6 +566,10 @@ public PhotoPropertiesBulkUpdateService createWorkflow(TransactionLoggerBase log
return new AndroidPhotoPropertiesBulkUpdateService(mContext, logger, dbgContext);
}

@Override
protected TransactionLoggerBase createTransactionLogger(long now) {
return new AndroidTransactionLogger(this, now);
}

/** adds android database specific logging to base implementation */
@Override
Expand All @@ -587,6 +585,9 @@ public void addTransactionLog(
ContentValues values = TransactionLogSql.set(null, currentMediaID, fileFullPath, modificationDate,
mediaTransactionLogEntryType, commandData);
db.insert(TransactionLogSql.TABLE, null, values);
if (Global.debugEnabledSql) {
Log.i(FotoSql.LOG_TAG, "addTransactionLog: " + values);
}
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/de/k3b/android/util/DataChangeNotifyer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2019-2020 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>
*/

package de.k3b.android.util;

public class DataChangeNotifyer {
public static DataChangedListener dataChangedListener = null;

public static void setDataChangedListener(DataChangedListener dataChangedListener) {
DataChangeNotifyer.dataChangedListener = dataChangedListener;
}

public interface DataChangedListener {
void onNotifyDataChanged();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019 by k3b.
* Copyright (c) 2015-2020 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -45,6 +45,7 @@
import de.k3b.android.androFotoFinder.Global;
import de.k3b.android.androFotoFinder.media.PhotoPropertiesMediaDBContentValues;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.queries.IMediaDBApi;
import de.k3b.android.androFotoFinder.tagDB.TagSql;
import de.k3b.database.QueryParameter;
import de.k3b.geo.api.GeoPointDto;
Expand Down Expand Up @@ -159,19 +160,27 @@ public static int hideFolderMedia(Activity context, String path) {
}

public int updateMediaDatabase_Android42(Context context, String[] oldPathNames, String... newPathNames) {
final boolean hasNew = excludeNomediaFiles(newPathNames) > 0;
final boolean hasOld = excludeNomediaFiles(oldPathNames) > 0;
int result = 0;

if (hasNew && hasOld) {
result = renameInMediaDatabase(context, oldPathNames, newPathNames);
} else if (hasOld) {
result = deleteInMediaDatabase(context, oldPathNames);
} if (hasNew) {
result = insertIntoMediaDatabase(context, newPathNames);
IMediaDBApi api = FotoSql.getMediaDBApi();
try {
api.beginTransaction();
final boolean hasNew = excludeNomediaFiles(newPathNames) > 0;
final boolean hasOld = excludeNomediaFiles(oldPathNames) > 0;
int result = 0;

if (hasNew && hasOld) {
result = renameInMediaDatabase(context, oldPathNames, newPathNames);
} else if (hasOld) {
result = deleteInMediaDatabase(context, oldPathNames);
}
if (hasNew) {
result = insertIntoMediaDatabase(context, newPathNames);
}
TagSql.fixPrivate();
api.setTransactionSuccessful();
return result;
} finally {
api.endTransaction();
}
TagSql.fixPrivate();
return result;
}

/**
Expand Down Expand Up @@ -275,7 +284,10 @@ private int renameInMediaDatabase(Context context, String[] oldPathNames, String
String newPathName = newPathNames[i];

if ((oldPathName != null) && (newPathName != null)) {
old2NewFileNames.put(oldPathName, newPathName);
//!!! ?seiteneffekt update other fields?
if (oldPathName.compareToIgnoreCase(newPathName) != 0) {
old2NewFileNames.put(oldPathName, newPathName);
}
} else if (oldPathName != null) {
deleteFileNames.add(oldPathName);
} else if (newPathName != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2019 by k3b.
* Copyright (c) 2016-2020 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -50,17 +50,13 @@ protected Integer doInBackground(String[]... pathNames) {
return mScanner.updateMediaDatabase_Android42(mContext, pathNames[0], pathNames[1]);
}

@Override
protected void onPostExecute(Integer modifyCount) {
super.onPostExecute(modifyCount);
String message = this.mContext.getString(R.string.scanner_update_result_format, modifyCount);
Toast.makeText(this.mContext, message, Toast.LENGTH_LONG).show();
if (Global.debugEnabled) {
Log.i(Global.LOG_CONTEXT, CONTEXT + "A42 scanner finished: " + message);
}

private static void notifyIfThereAreChanges(Integer modifyCount, Context context, String why) {
if (modifyCount > 0) {
PhotoPropertiesMediaFilesScanner.notifyChanges(mContext, mWhy);
PhotoPropertiesMediaFilesScanner.notifyChanges(context, why);
if (DataChangeNotifyer.dataChangedListener != null) {
DataChangeNotifyer.dataChangedListener.onNotifyDataChanged();
}

}
}

Expand All @@ -73,12 +69,22 @@ public static void updateMediaDBInBackground(PhotoPropertiesMediaFilesScanner sc
} else {
// Continute in background task
int modifyCount = scanner.updateMediaDatabase_Android42(context.getApplicationContext(), oldPathNames, newPathNames);
if (modifyCount > 0) {
PhotoPropertiesMediaFilesScanner.notifyChanges(context, why + " within current non-gui-task");
}
notifyIfThereAreChanges(modifyCount, context, why + " within current non-gui-task");
}
}

@Override
protected void onPostExecute(Integer modifyCount) {
super.onPostExecute(modifyCount);
String message = this.mContext.getString(R.string.scanner_update_result_format, modifyCount);
Toast.makeText(this.mContext, message, Toast.LENGTH_LONG).show();
if (Global.debugEnabled) {
Log.i(Global.LOG_CONTEXT, CONTEXT + "A42 scanner finished: " + message);
}

notifyIfThereAreChanges(modifyCount, mContext, mWhy);
}

/** return true if this is executed in the gui thread */
private static boolean isGuiThread() {
return (Looper.myLooper() == Looper.getMainLooper());
Expand Down
44 changes: 36 additions & 8 deletions app/src/main/java/de/k3b/android/widget/UpdateTask.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
package de.k3b.android.widget;

/**
* Created by EVE on 20.11.2017.
/*
* Copyright (c) 2017-2020 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>
*/
package de.k3b.android.widget;

import android.app.Activity;
import android.util.Log;

import de.k3b.android.androFotoFinder.Global;
import de.k3b.android.androFotoFinder.R;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.queries.IMediaDBApi;
import de.k3b.android.util.AndroidFileCommands;
import de.k3b.io.IProgessListener;
import de.k3b.io.collections.SelectedFiles;
Expand All @@ -23,7 +39,7 @@ public class UpdateTask extends AsyncTaskWithProgressDialog<SelectedFiles> imple
private final AndroidFileCommands cmd;

public UpdateTask(Activity ctx, AndroidFileCommands cmd,
PhotoPropertiesDiffCopy exifChanges) {
PhotoPropertiesDiffCopy exifChanges) {
super(ctx, R.string.exif_menu_title);
this.exifChanges = exifChanges;
this.cmd = cmd;
Expand All @@ -33,13 +49,25 @@ public UpdateTask(Activity ctx, AndroidFileCommands cmd,
protected Integer doInBackground(SelectedFiles... params) {
publishProgress("...");

int result = 0;
if (exifChanges != null) {
SelectedFiles items = params[0];

return cmd.applyExifChanges(true, exifChanges, items, null);

if (true) {
result = cmd.applyExifChanges(true, exifChanges, items, null);
} else {
// disabled: does not work because of overlapping transactions
IMediaDBApi api = FotoSql.getMediaDBApi();
try {
api.beginTransaction();
result = cmd.applyExifChanges(true, exifChanges, items, null);
api.setTransactionSuccessful();
} finally {
api.endTransaction();
}
}
}
return 0;
return result;
}

@Override
Expand Down
8 changes: 6 additions & 2 deletions fotolib2/src/main/java/de/k3b/io/FileCommands.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2018 by k3b.
* Copyright (c) 2015-2020 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -274,7 +274,7 @@ protected int moveOrCopyFiles(final boolean move, String what, PhotoPropertiesDi
int pos = 0;
long now = new Date().getTime();
MediaTransactionLogEntryType moveOrCopyCommand = (move) ? MediaTransactionLogEntryType.MOVE : MediaTransactionLogEntryType.COPY;
TransactionLoggerBase logger = (exifChanges == null) ? null : new TransactionLoggerBase(this, now);
TransactionLoggerBase logger = (exifChanges == null) ? null : createTransactionLogger(now);
boolean sameFile;

while (pos < fileCount) {
Expand Down Expand Up @@ -373,6 +373,10 @@ protected int moveOrCopyFiles(final boolean move, String what, PhotoPropertiesDi
return itemCount;
}

protected TransactionLoggerBase createTransactionLogger(long now) {
return new TransactionLoggerBase(this, now);
}

private PhotoAutoprocessingDto getPhotoAutoprocessingDto(File destDirFolder) {
PhotoAutoprocessingDto autoProccessData = null;
try {
Expand Down

0 comments on commit ca57d2d

Please sign in to comment.