Skip to content

Commit

Permalink
#112 Bugfix AutoProcessingMode Filenamepattern now uses "DatePhotoTak…
Browse files Browse the repository at this point in the history
…en" instead of "LastModifiedFileDate"
  • Loading branch information
k3b committed Feb 26, 2018
1 parent e2c24ca commit 39cd9d8
Show file tree
Hide file tree
Showing 21 changed files with 355 additions and 147 deletions.
112 changes: 112 additions & 0 deletions app/src/main/java/de/k3b/android/androFotoFinder/AffUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2018 by k3b.
*
* This file is part of AndroFotoFinder.
*
* 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.androFotoFinder;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.io.collections.SelectedFiles;
import de.k3b.io.collections.SelectedItems;

/**
* App specific helper to query and (De)Serialize between Intent|Bundle and SelectedFiles|SelectedItems.
*
* Created by k3b on 22.02.2018.
*/

public class AffUtils {
/** For SelecedItems or SelectedFotos format: id,id,id,..... */
public static final String EXTRA_SELECTED_ITEM_IDS = "de.k3b.extra.SELECTED_ITEMS";
/** For SelectedFotos format: path,path,path,..... */
public static final String EXTRA_SELECTED_ITEM_PATHS = "de.k3b.extra.SELECTED_ITEMS_PATH";
/** For SelectedFotos format: date.ticks,date.ticks,date.ticks,..... */
public static final String EXTRA_SELECTED_ITEM_DATES = "de.k3b.extra.SELECTED_ITEMS_DATE";

public static SelectedFiles getSelectedFiles(Intent data) {
if (data != null) {
String selectedIDs = data.getStringExtra(EXTRA_SELECTED_ITEM_IDS);
String selectedFiles = data.getStringExtra(EXTRA_SELECTED_ITEM_PATHS);
String selectedDates = data.getStringExtra(EXTRA_SELECTED_ITEM_DATES);

if ((selectedIDs != null) && (selectedFiles != null)) {
return SelectedFiles.create(selectedFiles, selectedIDs, selectedDates);
}
}
return null;
}
public static SelectedFiles getSelectedFiles(Bundle data) {
if (data != null) {
String selectedIDs = (String) data.getSerializable(EXTRA_SELECTED_ITEM_IDS);
String selectedFiles = (String) data.getSerializable(EXTRA_SELECTED_ITEM_PATHS);
String selectedDates = (String) data.getSerializable(EXTRA_SELECTED_ITEM_DATES);

if ((selectedIDs != null) && (selectedFiles != null)) {
return SelectedFiles.create(selectedFiles, selectedIDs, selectedDates);
}
}
return null;
}

public static boolean putSelectedFiles(Intent destination, SelectedFiles selectedFiles) {
if ((destination != null) && (selectedFiles != null) && (selectedFiles.size() > 0)) {
destination.putExtra(EXTRA_SELECTED_ITEM_IDS, selectedFiles.toIdString());
destination.putExtra(EXTRA_SELECTED_ITEM_PATHS, selectedFiles.toString());
final String dateString = selectedFiles.toDateString();
if (dateString != null) destination.putExtra(EXTRA_SELECTED_ITEM_DATES, dateString);
return true;
}
return false;
}

public static boolean putSelectedFiles(Bundle destination, SelectedFiles selectedFiles) {
if ((destination != null) && (selectedFiles != null) && (selectedFiles.size() > 0)) {
destination.putSerializable(EXTRA_SELECTED_ITEM_IDS, selectedFiles.toIdString());
destination.putSerializable(EXTRA_SELECTED_ITEM_PATHS, selectedFiles.toString());
final String dateString = selectedFiles.toDateString();
if (dateString != null) destination.putSerializable(EXTRA_SELECTED_ITEM_DATES, dateString);
return true;
}
return false;
}

/** converts internal ID-list to string array of filenNames via media database. */
public static SelectedFiles querySelectedFiles(Context context, SelectedItems items) {
if ((items != null) && (items.size() > 0)) {
List<Long> ids = new ArrayList<Long>();
List<String> paths = new ArrayList<String>();
List<Date> datesPhotoTaken = new ArrayList<Date>();

if (FotoSql.getFileNames(context, items, ids, paths, datesPhotoTaken) != null) {
return new SelectedFiles(paths.toArray(new String[paths.size()]), ids.toArray(new Long[ids.size()]), datesPhotoTaken.toArray(new Date[datesPhotoTaken.size()]));
}
}
return null;
}

public static SelectedItems getSelectedItems(Intent intent) {
String selectedIDsString = intent.getStringExtra(EXTRA_SELECTED_ITEM_IDS);
return (selectedIDsString != null) ? new SelectedItems().parse(selectedIDsString) : null;
}
}
9 changes: 0 additions & 9 deletions app/src/main/java/de/k3b/android/androFotoFinder/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ public interface Common {
*/
static final String EXTRA_FILTER = "de.k3b.extra.FILTER";

/**
* geoEdit,picker
* Format:SelectedItems.toString/parseMultiple: id,id,id,....
* See https://github.com/k3b/AndroFotoFinder/wiki/intentapi#SelectedItems
*/
static final String EXTRA_SELECTED_ITEM_IDS = "de.k3b.extra.SELECTED_ITEMS";

static final String EXTRA_SELECTED_ITEM_PATHS = "de.k3b.extra.SELECTED_ITEMS_PATH";

/** detail,gallery: sql where ... order by ... group by ... */
public static final String EXTRA_QUERY = "de.k3b.extra.SQL";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ public static void showActivity(Activity context, IMetaApi exifDataToEdit, Strin
intent.setData(Uri.parse(url));
}

if ((selectedFiles != null) && (selectedFiles.size() > 0)) {
intent.putExtra(EXTRA_SELECTED_ITEM_IDS, selectedFiles.toIdString());
intent.putExtra(EXTRA_SELECTED_ITEM_PATHS, selectedFiles.toString());
}
AffUtils.putSelectedFiles(intent, selectedFiles);
}

if (requestCode != 0) {
Expand Down Expand Up @@ -276,14 +273,9 @@ public static IMetaApi getExifParam(Intent intent) {
private static SelectedFiles getSelectedFiles(String dbgContext, Context ctx, Intent intent, boolean mustLoadIDs) {
if (intent == null) return null;

SelectedFiles result = null;

String selectedIDs = intent.getStringExtra(EXTRA_SELECTED_ITEM_IDS);
String selectedFiles = intent.getStringExtra(EXTRA_SELECTED_ITEM_PATHS);
SelectedFiles result = AffUtils.getSelectedFiles(intent);

if ((selectedIDs != null) && (selectedFiles != null)) {
result = new SelectedFiles(selectedFiles, selectedIDs);
} else {
if (result == null) {
String path = IntentUtil.getFilePath(ctx, IntentUtil.getUri(intent));
String fileNames[] = SelectedFiles.getFileNameList(path);
Long[] ids = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ public static void showActivity(Activity context, PhotoWorkFlowDto workflow,
intent.setData(Uri.parse(directoryOrApmFileUrl));
}

if ((selectedFiles != null) && (selectedFiles.size() > 0)) {
intent.putExtra(EXTRA_SELECTED_ITEM_IDS, selectedFiles.toIdString());
intent.putExtra(EXTRA_SELECTED_ITEM_PATHS, selectedFiles.toString());
}
AffUtils.putSelectedFiles(intent, selectedFiles);

if (Global.debugEnabled) {
Log.d(Global.LOG_CONTEXT, mDebugPrefix + context.getClass().getSimpleName()
Expand Down Expand Up @@ -183,8 +180,11 @@ protected void onCreate(Bundle savedInstanceState) {
exampleExif.setData(example);
}
}

// do not predefine these
exampleExif.setDateTimeTaken(null);
exampleExif.setPath(null);
exampleExif.setTitle(null);
mCurrentData.setMediaDefaults(exampleExif);
}
this.exampleSrcfile = mProcessor.getFile(mSelectedFiles.getFile(0));
Expand Down Expand Up @@ -546,14 +546,9 @@ private File getExample(String dbgContext, Intent intent) {
private SelectedFiles getSelectedFiles(String dbgContext, Intent intent, boolean mustLoadIDs) {
if (intent == null) return null;

SelectedFiles result = null;
SelectedFiles result = AffUtils.getSelectedFiles(intent);

String selectedIDs = intent.getStringExtra(EXTRA_SELECTED_ITEM_IDS);
String selectedFiles = intent.getStringExtra(EXTRA_SELECTED_ITEM_PATHS);

if ((selectedIDs != null) && (selectedFiles != null)) {
result = new SelectedFiles(selectedFiles, selectedIDs);
} else {
if (result == null) {
String path = IntentUtil.getFilePath(this, IntentUtil.getUri(intent));
File rootDirFile = new File(path);
String[] fileNames = rootDirFile.list(MediaUtil.JPG_FILENAME_FILTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public static void global2Prefs(Context context) {
prefs.putBoolean("debugEnabledMemory", Global.debugEnabledMemory);

prefs.putBoolean("debugEnabledJpgMetaIo", FotoLibGlobal.debugEnabledJpgMetaIo);
prefs.putBoolean("debugEnabledJpg", FotoLibGlobal.debugEnabledJpg);

/** #100: true: private images get the extension ".jpg-p" which hides them from other gallery-apps and image pickers. */
prefs.putBoolean("renamePrivateJpg", FotoLibGlobal.renamePrivateJpg);
Expand Down Expand Up @@ -206,6 +207,7 @@ public static void prefs2Global(Context context) {
Global.locked = getPref(prefs, "locked", Global.locked);
Global.passwordHash = getPref(prefs, "passwordHash", Global.passwordHash);

FotoLibGlobal.debugEnabledJpg = getPref(prefs, "debugEnabledJpg", FotoLibGlobal.debugEnabledJpg);
FotoLibGlobal.debugEnabledJpgMetaIo = getPref(prefs, "debugEnabledJpgMetaIo", FotoLibGlobal.debugEnabledJpgMetaIo);

/** #100: true: private images get the extension ".jpg-p" which hides them from other gallery-apps and image pickers. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Date;
import java.util.List;

import de.k3b.android.androFotoFinder.AffUtils;
import de.k3b.android.androFotoFinder.ThumbNailUtils;
import de.k3b.android.androFotoFinder.imagedetail.HugeImageLoader;
import de.k3b.android.androFotoFinder.queries.FotoSql;
Expand Down Expand Up @@ -205,17 +206,7 @@ public String toString() {
}

public SelectedFiles createSelectedFiles(Context context, SelectedItems items) {
if ((items != null) && (items.size() > 0)) {
List<Long> ids = new ArrayList<Long>();
List<String> paths = new ArrayList<String>();
List<Date> datesPhotoTaken = new ArrayList<Date>();

FotoSql.getFileNames(context, items, ids, paths, datesPhotoTaken);
if (paths.size() > 0) {
return new SelectedFiles(paths.toArray(new String[paths.size()]), ids.toArray(new Long[ids.size()]), datesPhotoTaken.toArray(new Date[datesPhotoTaken.size()]));
}
}
return null;
return AffUtils.querySelectedFiles(context, items);
}

public String getFullFilePath(int position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import android.app.Activity;
import android.app.LoaderManager;
import android.content.Context;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
Expand All @@ -48,11 +47,11 @@
import org.osmdroid.api.IGeoPoint;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import de.k3b.FotoLibGlobal;
import de.k3b.android.androFotoFinder.AffUtils;
import de.k3b.android.androFotoFinder.Common;
import de.k3b.android.androFotoFinder.ExifEditActivity;
import de.k3b.android.androFotoFinder.FotoGalleryActivity;
Expand Down Expand Up @@ -374,7 +373,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
mGetGeo = ((schema != null) && ("geo".compareTo(schema) == 0));
}

String path = (intent == null) ? null : intent.getStringExtra(EXTRA_SELECTED_ITEM_PATHS);
String path = (intent == null) ? null : intent.getStringExtra(AffUtils.EXTRA_SELECTED_ITEM_PATHS);

String filterValue = ((intent != null) && (path == null)) ? intent.getStringExtra(EXTRA_FILTER) : null;
IGalleryFilter filter = (filterValue != null) ? GalleryFilterParameter.parse(filterValue, new GalleryFilterParameter()) : null;
Expand Down Expand Up @@ -834,6 +833,7 @@ public boolean onOptionsItemSelected(MenuItem menuItem) {

// Handle menuItem selection
AndroidFileCommands fileCommands = mFileCommands;

final SelectedFiles selectedFiles = this.mAdapter.createSelectedFiles(getActivity(), this.mSelectedItems);
if ((mSelectedItems != null) && (fileCommands.onOptionsItemSelected(menuItem, selectedFiles))) {
return true;
Expand Down Expand Up @@ -965,9 +965,7 @@ public static MoveOrCopyDestDirPicker newInstance(boolean move, final SelectedFi
// Supply index input as an argument.
Bundle args = new Bundle();
args.putBoolean("move", move);

args.putSerializable(EXTRA_SELECTED_ITEM_PATHS, srcFotos.toString());
args.putSerializable(EXTRA_SELECTED_ITEM_IDS, srcFotos.toIdString());
AffUtils.putSelectedFiles(args, srcFotos);

f.setArguments(args);

Expand All @@ -984,12 +982,7 @@ public boolean getMove() {

/** overwritten by dialog host to get selected photos for edit autoprocessing mode */
@Override public SelectedFiles getSrcFotos() {
String selectedIDs = (String) getArguments().getSerializable(EXTRA_SELECTED_ITEM_IDS);
String selectedFiles = (String) getArguments().getSerializable(EXTRA_SELECTED_ITEM_PATHS);

if ((selectedIDs == null) && (selectedFiles == null)) return null;
SelectedFiles result = new SelectedFiles(selectedFiles, selectedIDs);
return result;
return AffUtils.getSelectedFiles(getArguments());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Date;
import java.util.List;

import de.k3b.android.androFotoFinder.AffUtils;
import de.k3b.android.androFotoFinder.Common;
import de.k3b.android.androFotoFinder.ExifEditActivity;
import de.k3b.android.androFotoFinder.FotoGalleryActivity;
Expand Down Expand Up @@ -274,8 +275,7 @@ public static MoveOrCopyDestDirPicker newInstance(boolean move, final SelectedFi
// Supply index input as an argument.
Bundle args = new Bundle();
args.putBoolean("move", move);
args.putSerializable(EXTRA_SELECTED_ITEM_PATHS, srcFotos.toString());
args.putSerializable(EXTRA_SELECTED_ITEM_IDS, srcFotos.toIdString());
AffUtils.putSelectedFiles(args, srcFotos);
f.setArguments(args);

return f;
Expand All @@ -290,12 +290,7 @@ public boolean getMove() {
}

public SelectedFiles getSrcFotos() {
String selectedIDs = (String) getArguments().getSerializable(EXTRA_SELECTED_ITEM_IDS);
String selectedFiles = (String) getArguments().getSerializable(EXTRA_SELECTED_ITEM_PATHS);

if ((selectedIDs == null) && (selectedFiles == null)) return null;
SelectedFiles result = new SelectedFiles(selectedFiles, selectedIDs);
return result;
return AffUtils.getSelectedFiles(getArguments());
}

/**
Expand Down Expand Up @@ -392,8 +387,8 @@ public void onCreate(Bundle savedInstanceState) {
childIntent.setAction(intent.getAction());
IntentUtil.setDataAndTypeAndNormalize(childIntent, intent.getData(), intent.getType());
copyExtras(childIntent, intent.getExtras(),
EXTRA_FILTER, EXTRA_POSITION, EXTRA_QUERY, EXTRA_SELECTED_ITEM_IDS,
EXTRA_SELECTED_ITEM_PATHS, EXTRA_STREAM, EXTRA_TITLE);
EXTRA_FILTER, EXTRA_POSITION, EXTRA_QUERY, AffUtils.EXTRA_SELECTED_ITEM_IDS, AffUtils.EXTRA_SELECTED_ITEM_DATES,
AffUtils.EXTRA_SELECTED_ITEM_PATHS, EXTRA_STREAM, EXTRA_TITLE);
startActivityForResult(childIntent, ACTION_RESULT_FORWARD);
} else { // not in forward mode
setContentView(R.layout.activity_image_view_pager);
Expand Down
Loading

0 comments on commit 39cd9d8

Please sign in to comment.