diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/PhotoPropertiesEditActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/PhotoPropertiesEditActivity.java index 18b176c1..dd3da811 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/PhotoPropertiesEditActivity.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/PhotoPropertiesEditActivity.java @@ -821,7 +821,7 @@ private void onOk() { if (exifChanges != null) { if (!SYNC_UPDATE_EXIF) { - this.exifUpdate = new UpdateTask(ctx, cmd, exifChanges); + this.exifUpdate = new UpdateTask(R.string.exif_menu_title, ctx, cmd, exifChanges); exifUpdate.execute(items); finish = false; } else { diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java b/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java index e3c8fce7..325fdf0d 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java @@ -87,6 +87,7 @@ import de.k3b.android.util.ResourceUtils; import de.k3b.android.widget.AboutDialogPreference; import de.k3b.android.widget.Dialogs; +import de.k3b.android.widget.UpdateTask; import de.k3b.database.QueryParameter; import de.k3b.geo.api.GeoPointDto; import de.k3b.geo.api.IGeoPointInfo; @@ -95,7 +96,6 @@ import de.k3b.io.GalleryFilterParameter; import de.k3b.io.IDirectory; import de.k3b.io.IGalleryFilter; -import de.k3b.io.IProgessListener; import de.k3b.io.ListUtils; import de.k3b.io.PhotoAutoprocessingDto; import de.k3b.io.StringUtils; @@ -188,6 +188,11 @@ public class GalleryCursorFragment extends Fragment implements Queryable, Direc */ private WeakReference mTagPickerDialog = null; + /** + * not null while background task is active + */ + private static UpdateTask exifUpdate = null; + /**************** construction ******************/ /** * Use this factory method to create a new instance of @@ -451,6 +456,8 @@ public void onItemClick(AdapterView parent, View v, int position, long id) { } requery("onCreateView"); + updateExifUpdateTask(this.getActivity()); + return result; } @@ -460,6 +467,8 @@ public void onAttach(Activity activity) { super.onAttach(activity); mFileCommands.setContext(activity); mFileCommands.setLogFilePath(mFileCommands.getDefaultLogFile()); + updateExifUpdateTask(activity); + if (Global.debugEnabledMemory) { Log.d(Global.LOG_CONTEXT, mDebugPrefix + " - onAttach cmd (" + @@ -539,6 +548,7 @@ public void onActivityResult(final int requestCode, @Override public void onDetach() { + updateExifUpdateTask(null); Global.debugMemory(mDebugPrefix, "onDetach"); super.onDetach(); mGalleryListener = null; @@ -568,6 +578,7 @@ public void onPause() { @Override public void onDestroy() { + updateExifUpdateTask(null); Global.debugMemory(mDebugPrefix, "before onDestroy"); mDestDirPicker = null; @@ -948,7 +959,7 @@ public boolean onOptionsItemSelected(MenuItem menuItem) { cmdShowDetails(); return true; case R.id.cmd_scan: - return fileCommands.cmdMediaScannerWithQuestion(); + return fileCommands.cmdMediaScannerWithQuestion(this.getActivity()); default: return super.onOptionsItemSelected(menuItem); @@ -1099,11 +1110,21 @@ private boolean cmdRenameMultible(MenuItem menuItem, final SelectedFiles fotos) private void onRenameMultible(PhotoAutoprocessingDto autoprocessingData, SelectedFiles selectedFiles) { AndroidFileCommands cmd = AndroidFileCommands.createFileCommand(this.getActivity(), true); - IProgessListener progessListener = null; + exifUpdate = new UpdateTask(R.string.exif_menu_title, this.getActivity(), cmd, true, null, autoprocessingData); + exifUpdate.execute(selectedFiles); - cmd.moveOrCopyFilesTo(true, selectedFiles, null, autoprocessingData, progessListener); } + private static void updateExifUpdateTask(Activity activity) { + if (exifUpdate != null) { + if (exifUpdate.isNotFinishedYet()) { + exifUpdate.setActivity(activity); + } else { + exifUpdate.destroy(); + exifUpdate = null; + } + } + } private boolean cmdMoveOrCopyWithDestDirPicker(final boolean move, String lastCopyToPath, final SelectedFiles fotos) { if (AndroidFileCommands.canProcessFile(this.getActivity(), false)) { diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/queries/DatabaseHelper.java b/app/src/main/java/de/k3b/android/androFotoFinder/queries/DatabaseHelper.java index 12327a67..e03b8a9e 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/queries/DatabaseHelper.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/queries/DatabaseHelper.java @@ -73,7 +73,7 @@ private void version3Upgrade_TIMESLICE_WITH_NOTES(final SQLiteDatabase db) { } private static DatabaseHelper instance = null; - public static SQLiteDatabase getWritableDatabase(Activity context) { + public static SQLiteDatabase getWritableDatabase(Context context) { if (instance == null) { instance = new DatabaseHelper(new DatabaseContext(context), "APhotoManager"); } diff --git a/app/src/main/java/de/k3b/android/util/AndroidFileCommands.java b/app/src/main/java/de/k3b/android/util/AndroidFileCommands.java index 392ee504..ceaf9807 100644 --- a/app/src/main/java/de/k3b/android/util/AndroidFileCommands.java +++ b/app/src/main/java/de/k3b/android/util/AndroidFileCommands.java @@ -69,7 +69,7 @@ public class AndroidFileCommands extends FileCommands { private static final String SETTINGS_KEY_LAST_COPY_TO_PATH = "last_copy_to_path"; private static final String mDebugPrefix = "AndroidFileCommands."; private boolean isInBackground = false; - protected Activity mContext; // must be activity because of fragmentManager + protected Context mContext; private AlertDialog mActiveAlert = null; private boolean mHasNoMedia = false; private PhotoPropertiesMediaFilesScanner mScanner = null; @@ -123,17 +123,17 @@ protected void onPostProcess(String what, int opCode, SelectedFiles selectedFile Context context = this.mContext; String message = getModifyMessage(context, opCode, modifyCount, itemCount); if ((itemCount > 0) && (mScanner != null)) { - PhotoPropertiesMediaFilesScannerAsyncTask.updateMediaDBInBackground(mScanner, mContext, message, oldPathNames, newPathNames); + PhotoPropertiesMediaFilesScannerAsyncTask.updateMediaDBInBackground(mScanner, context, message, oldPathNames, newPathNames); } - if (false && this.mHasNoMedia && (mContext != null)) { + if (false && this.mHasNoMedia && (context != null)) { // a nomedia file is affected => must update gui - this.mContext.getContentResolver().notifyChange(FotoSql.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, null, false); + context.getContentResolver().notifyChange(FotoSql.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, null, false); this.mHasNoMedia = false; } if (!isInBackground) { - Toast.makeText(mContext, message, Toast.LENGTH_LONG).show(); + Toast.makeText(context, message, Toast.LENGTH_LONG).show(); } } @@ -343,7 +343,7 @@ private static class MediaScannerDirectoryPickerFragment extends DirectoryPicker @Override protected void onDirectoryPick(IDirectory selection) { if ((mParent != null) && (selection != null)) { - mParent.onMediaScannerAnswer(selection.getAbsolute()); + mParent.onMediaScannerAnswer(mContext, selection.getAbsolute()); } dismiss(); } @@ -371,15 +371,15 @@ public void dismiss() { } - public boolean cmdMediaScannerWithQuestion() { + public boolean cmdMediaScannerWithQuestion(Activity activity) { final RecursivePhotoPropertiesMediaFilesScannerAsyncTask scanner = RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner; if (scanner != null) { // connect gui to already running scanner if possible scanner.resumeIfNeccessary(); // if paused resume it. - showMediaScannerStatus(scanner); + showMediaScannerStatus(scanner, activity); return true; - } else if (AndroidFileCommands.canProcessFile(mContext, this.isInBackground)) { + } else if (AndroidFileCommands.canProcessFile(activity, this.isInBackground)) { // show dialog to get start parameter MediaScannerDirectoryPickerFragment destDir = new MediaScannerDirectoryPickerFragment(); @@ -388,11 +388,11 @@ public boolean cmdMediaScannerWithQuestion() { destDir.defineDirectoryNavigation(OsUtils.getRootOSDirectory(null), FotoSql.QUERY_TYPE_UNDEFINED, getLastCopyToPath()); - if (!LockScreen.isLocked(mContext)) { + if (!LockScreen.isLocked(activity)) { destDir.setContextMenuId(R.menu.menu_context_pick_osdir); } - destDir.show(mContext.getFragmentManager(), "scannerPick"); + destDir.show(activity.getFragmentManager(), "scannerPick"); return true; } @@ -400,8 +400,8 @@ public boolean cmdMediaScannerWithQuestion() { } /** answer from "which directory to start scanner from"? */ - private void onMediaScannerAnswer(String scanRootDir) { - if ((AndroidFileCommands.canProcessFile(mContext, this.isInBackground)) || (RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner == null)){ + private void onMediaScannerAnswer(Activity activity, String scanRootDir) { + if ((AndroidFileCommands.canProcessFile(activity, this.isInBackground)) || (RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner == null)){ // remove ".nomedia" file from scan root File nomedia = new File(scanRootDir, PhotoPropertiesMediaFilesScanner.MEDIA_IGNORE_FILENAME); @@ -415,10 +415,10 @@ private void onMediaScannerAnswer(String scanRootDir) { Log.i(Global.LOG_CONTEXT, mDebugPrefix + "onMediaScannerAnswer start scanning " + scanRootDir); } - final String message = mContext.getString(R.string.scanner_menu_title); + final String message = activity.getString(R.string.scanner_menu_title); final RecursivePhotoPropertiesMediaFilesScannerAsyncTask scanner = (RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner != null) ? RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner : - new RecursivePhotoPropertiesMediaFilesScannerAsyncTask(mScanner, mContext, message); + new RecursivePhotoPropertiesMediaFilesScannerAsyncTask(mScanner, activity, message); synchronized (this) { if (RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner == null) { RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner = scanner; @@ -426,13 +426,13 @@ private void onMediaScannerAnswer(String scanRootDir) { } // else scanner is already running } - showMediaScannerStatus(RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner); + showMediaScannerStatus(RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner, activity); } } - private void showMediaScannerStatus(RecursivePhotoPropertiesMediaFilesScannerAsyncTask mediaScanner) { + private void showMediaScannerStatus(RecursivePhotoPropertiesMediaFilesScannerAsyncTask mediaScanner, Activity activity) { if (mediaScanner != null) { - mediaScanner.showStatusDialog(mContext); + mediaScanner.showStatusDialog(activity); } } @@ -484,9 +484,10 @@ public int setGeo(double latitude, double longitude, SelectedFiles selectedItems return 0; } - public AndroidFileCommands setContext(Activity mContext) { - this.mContext = mContext; - if (mContext != null) { + public AndroidFileCommands setContext(Activity activity) { + this.mContext = null; + if (activity != null) { + this.mContext = activity.getApplicationContext(); closeLogFile(); mScanner = PhotoPropertiesMediaFilesScanner.getInstance(mContext); } diff --git a/app/src/main/java/de/k3b/android/widget/UpdateTask.java b/app/src/main/java/de/k3b/android/widget/UpdateTask.java index 81aee347..926b0f58 100644 --- a/app/src/main/java/de/k3b/android/widget/UpdateTask.java +++ b/app/src/main/java/de/k3b/android/widget/UpdateTask.java @@ -7,10 +7,12 @@ import android.app.Activity; import android.util.Log; +import java.io.File; + import de.k3b.android.androFotoFinder.Global; -import de.k3b.android.androFotoFinder.R; import de.k3b.android.util.AndroidFileCommands; import de.k3b.io.IProgessListener; +import de.k3b.io.PhotoAutoprocessingDto; import de.k3b.io.collections.SelectedFiles; import de.k3b.media.PhotoPropertiesDiffCopy; @@ -22,11 +24,31 @@ public class UpdateTask extends AsyncTaskWithProgressDialog imple private PhotoPropertiesDiffCopy exifChanges; private final AndroidFileCommands cmd; - public UpdateTask(Activity ctx, AndroidFileCommands cmd, - PhotoPropertiesDiffCopy exifChanges) { - super(ctx, R.string.exif_menu_title); + private boolean move; + private File destDirFolder; + private PhotoAutoprocessingDto autoProccessData; + + public UpdateTask(int resIdDlgTitle, Activity ctx, AndroidFileCommands cmd, + PhotoPropertiesDiffCopy exifChanges) { + this(resIdDlgTitle, ctx, cmd, exifChanges, true, null, null); + } + + public UpdateTask(int resIdDlgTitle, Activity ctx, AndroidFileCommands cmd, + boolean move, File destDirFolder, + PhotoAutoprocessingDto autoProccessData) { + this(resIdDlgTitle, ctx, cmd, null, move, destDirFolder, autoProccessData); + } + + private UpdateTask(int resIdDlgTitle, Activity ctx, AndroidFileCommands cmd, + PhotoPropertiesDiffCopy exifChanges, + boolean move, File destDirFolder, + PhotoAutoprocessingDto autoProccessData) { + super(ctx, resIdDlgTitle); this.exifChanges = exifChanges; this.cmd = cmd; + this.move = move; + this.autoProccessData = autoProccessData; + this.destDirFolder = destDirFolder; } @Override @@ -36,10 +58,14 @@ protected Integer doInBackground(SelectedFiles... params) { if (exifChanges != null) { SelectedFiles items = params[0]; - return cmd.applyExifChanges(true, exifChanges, items, null); + return cmd.applyExifChanges(move, exifChanges, items, this); + + } else { + SelectedFiles items = params[0]; + + return cmd.moveOrCopyFilesTo(move, items, destDirFolder, autoProccessData, this); } - return 0; } @Override diff --git a/app/src/main/res/menu/menu_gallery_multiselect_mode_all.xml b/app/src/main/res/menu/menu_gallery_multiselect_mode_all.xml index 955e874f..c3ca66b3 100644 --- a/app/src/main/res/menu/menu_gallery_multiselect_mode_all.xml +++ b/app/src/main/res/menu/menu_gallery_multiselect_mode_all.xml @@ -55,13 +55,14 @@ + />