diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/AffUtils.java b/app/src/main/java/de/k3b/android/androFotoFinder/AffUtils.java new file mode 100644 index 00000000..04e34d46 --- /dev/null +++ b/app/src/main/java/de/k3b/android/androFotoFinder/AffUtils.java @@ -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 + */ +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 ids = new ArrayList(); + List paths = new ArrayList(); + List datesPhotoTaken = new ArrayList(); + + 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; + } +} diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/Common.java b/app/src/main/java/de/k3b/android/androFotoFinder/Common.java index 8eaf9178..eaf4c37c 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/Common.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/Common.java @@ -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"; diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/ExifEditActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/ExifEditActivity.java index e029552d..aa428402 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/ExifEditActivity.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/ExifEditActivity.java @@ -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) { @@ -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; diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/PhotoAutoprocessingEditActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/PhotoAutoprocessingEditActivity.java index 60e98aae..f4a6ceb0 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/PhotoAutoprocessingEditActivity.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/PhotoAutoprocessingEditActivity.java @@ -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() @@ -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)); @@ -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); diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java index 25cce110..79613681 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java @@ -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); @@ -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. */ diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorAdapter.java b/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorAdapter.java index 01c47dc3..015f1901 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorAdapter.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorAdapter.java @@ -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; @@ -205,17 +206,7 @@ public String toString() { } public SelectedFiles createSelectedFiles(Context context, SelectedItems items) { - if ((items != null) && (items.size() > 0)) { - List ids = new ArrayList(); - List paths = new ArrayList(); - List datesPhotoTaken = new ArrayList(); - - 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) { 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 436debc9..3b88a6fe 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 @@ -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; @@ -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; @@ -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; @@ -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; @@ -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); @@ -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 diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java b/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java index eb017810..46bab0e4 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/imagedetail/ImageDetailActivityViewPager.java @@ -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; @@ -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; @@ -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()); } /** @@ -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); diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/GeoEditActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/GeoEditActivity.java index 3b521412..8ac7da01 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/GeoEditActivity.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/GeoEditActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2017 by k3b. + * Copyright (c) 2015-2018 by k3b. * * This file is part of AndroFotoFinder. * @@ -38,9 +38,11 @@ import java.util.Arrays; +import de.k3b.android.androFotoFinder.AffUtils; import de.k3b.android.androFotoFinder.Common; import de.k3b.android.androFotoFinder.Global; import de.k3b.android.androFotoFinder.R; +import de.k3b.android.androFotoFinder.queries.FotoSql; import de.k3b.android.util.AndroidFileCommands; import de.k3b.android.util.MediaScanner; import de.k3b.android.widget.HistoryEditText; @@ -83,10 +85,7 @@ public static void showActivity(Activity context, SelectedFiles selectedFiles, i final Intent intent = new Intent().setClass(context, GeoEditActivity.class); - if ((selectedFiles != null) && (selectedFiles.size() > 0)) { - intent.putExtra(EXTRA_SELECTED_ITEM_IDS, selectedFiles.toIdString()); - intent.putExtra(EXTRA_SELECTED_ITEM_PATHS, selectedFiles.toString()); - + if (AffUtils.putSelectedFiles(intent, selectedFiles)) { Long id = selectedFiles.getId(0); IGeoPointInfo initialPoint = MediaScanner.getInstance(context).getPositionFromFile(selectedFiles.getFileNames()[0], (id != null) ? id.toString() : null); if (initialPoint != null) { @@ -118,7 +117,7 @@ protected void onCreate(Bundle savedInstanceState) { if (Global.debugEnabled && (intent != null)){ Log.d(Global.LOG_CONTEXT, mDebugPrefix + "onCreate " + intent.toUri(Intent.URI_INTENT_SCHEME)); } - SelectedFiles selectedItems = getItems(intent); + SelectedFiles selectedItems = AffUtils.getSelectedFiles(intent); if (selectedItems != null) { mSelectedItems = selectedItems; @@ -180,16 +179,6 @@ protected void onDestroy() { super.onDestroy(); } - public static SelectedFiles getItems(Intent intent) { - if (intent == null) return null; - String selectedIDs = intent.getStringExtra(EXTRA_SELECTED_ITEM_IDS); - String selectedFiles = intent.getStringExtra(EXTRA_SELECTED_ITEM_PATHS); - - if ((selectedIDs == null) && (selectedFiles == null)) return null; - SelectedFiles result = new SelectedFiles(selectedFiles, selectedIDs); - return result; - } - private String fromGui() { try { mCurrentPoint.setLatitude(getLatitude()); @@ -313,10 +302,7 @@ private void showLatLonPicker(String geoUri) { calculatedSelectedFotosIds.addAll(Arrays.asList(mSelectedItems.getIds())); } - if (calculatedSelectedFotosIds.size() > 0) { - intent.putExtra(EXTRA_SELECTED_ITEM_IDS, calculatedSelectedFotosIds.toString()); - //!!! ???EXTRA_SELECTED_ITEM_PATHS - } + AffUtils.putSelectedFiles(intent, AffUtils.querySelectedFiles(this, calculatedSelectedFotosIds)); try { // #7: allow choosing geo pick from map or from "photo with geo" this.startActivityForResult(Intent.createChooser(intent, this.getString(R.string.geo_edit_menu_title)), GeoEditActivity.RESULT_ID); diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/MapGeoPickerActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/MapGeoPickerActivity.java index 8c2b8411..6effeca2 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/MapGeoPickerActivity.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/locationmap/MapGeoPickerActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2017 by k3b. + * Copyright (c) 2015-2018 by k3b. * * This file is part of AndroFotoFinder / #APhotoManager. * @@ -35,6 +35,7 @@ import org.osmdroid.api.IGeoPoint; +import de.k3b.android.androFotoFinder.AffUtils; import de.k3b.android.androFotoFinder.BookmarkController; import de.k3b.android.androFotoFinder.Common; import de.k3b.android.androFotoFinder.FotoGalleryActivity; @@ -85,10 +86,7 @@ public static void showActivity(Activity context, SelectedFiles selectedItems, G localFilter.get(filter); } - if ((selectedItems != null) && (selectedItems.size() > 0)) { - intent.putExtra(EXTRA_SELECTED_ITEM_PATHS, selectedItems.toString()); - intent.putExtra(EXTRA_SELECTED_ITEM_IDS, selectedItems.toIdString()); - + if (AffUtils.putSelectedFiles(intent, selectedItems)) { IGeoPoint initialPoint = FotoSql.execGetPosition(context, null, selectedItems.getId(0)); if (initialPoint != null) { GeoUri PARSER = new GeoUri(GeoUri.OPT_PARSE_INFER_MISSING); @@ -167,8 +165,7 @@ protected void onCreate(Bundle savedInstanceState) { rectangle.setLogituedMax(initalZoom.getLongitude()).setLatitudeMax(initalZoom.getLatitude()); } // else (savedInstanceState != null) restore after rotation. fragment takes care of restoring map pos - String selectedIDsString = intent.getStringExtra(EXTRA_SELECTED_ITEM_IDS); - SelectedItems selectedItems = (selectedIDsString != null) ? new SelectedItems().parse(selectedIDsString) : null; + SelectedItems selectedItems = AffUtils.getSelectedItems(intent); // TODO !!! #62 gpx/kml files: wie an LocatonMapFragment übergeben?? String filter = null; diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/queries/FotoSql.java b/app/src/main/java/de/k3b/android/androFotoFinder/queries/FotoSql.java index 92da5b04..3b7e8fe2 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/queries/FotoSql.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/queries/FotoSql.java @@ -272,6 +272,7 @@ public static QueryParameter getQueryGroupByPlace(double groupingFactor) { // "0 AS " + SQL_COL_COUNT, SQL_COL_MAX_WITH + " AS " + SQL_COL_WIDTH, SQL_COL_GPS, + SQL_COL_DATE_TAKEN, SQL_COL_PATH}; public static final QueryParameter queryDetail = new QueryParameter() @@ -782,7 +783,7 @@ protected static int exexUpdateImpl(String dbgContext, Context context, ContentV int result = context.getContentResolver().update(SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, values, sqlWhere, selectionArgs); - if (Global.debugEnabledSql) { + if (Global.debugEnabledSql || FotoLibGlobal.debugEnabledJpg) { Log.i(Global.LOG_CONTEXT, dbgContext + ":FotoSql.exexUpdate\n" + QueryParameter.toString(null, values.toString(), SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME, sqlWhere, selectionArgs, null, result)); @@ -819,7 +820,7 @@ public static Uri execInsert(String dbgContext, Context context, ContentValues v // on my android-4.4 insert with media_type=1001 (private) does insert with media_type=1 (image) Uri result = context.getContentResolver().insert(providerUri, values); - if (Global.debugEnabledSql) { + if (Global.debugEnabledSql || FotoLibGlobal.debugEnabledJpg) { Log.i(Global.LOG_CONTEXT, dbgContext + ":FotoSql.execInsert" + values.toString() + " => " + result); } @@ -877,7 +878,7 @@ public static int deleteMedia(String dbgContext, Context context, String where, lastSelectionArgs = null; delCount = context.getContentResolver() .delete(SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, lastUsedWhereClause, lastSelectionArgs); - if (Global.debugEnabledSql) { + if (Global.debugEnabledSql || FotoLibGlobal.debugEnabledJpg) { Log.i(Global.LOG_CONTEXT, dbgContext + "-b: FotoSql.deleteMedia delete\n" + QueryParameter.toString(null, null, SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME, lastUsedWhereClause, lastSelectionArgs, null, delCount)); @@ -885,7 +886,7 @@ public static int deleteMedia(String dbgContext, Context context, String where, } else { delCount = context.getContentResolver() .delete(SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, lastUsedWhereClause, lastSelectionArgs); - if (Global.debugEnabledSql) { + if (Global.debugEnabledSql || FotoLibGlobal.debugEnabledJpg) { Log.i(Global.LOG_CONTEXT, dbgContext +": FotoSql.deleteMedia\ndelete " + QueryParameter.toString(null, null, SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME, @@ -983,33 +984,31 @@ public static Date getDate(Cursor cursor,int colDateTimeTaken) { } /** converts internal ID-list to string array of filenNames via media database. */ - public static String[] getFileNames(Context context, SelectedItems items, List ids, List paths, List datesPhotoTaken) { + public static List getFileNames(Context context, SelectedItems items, List ids, List paths, List datesPhotoTaken) { if (!items.isEmpty()) { - List result = (paths != null) ? paths : new ArrayList(); - // query ordered by DatePhotoTaken so that lower rename-numbers correspond to older images. QueryParameter parameters = new QueryParameter(queryAutoRename); setWhereSelectionPks(parameters, items); - Cursor cursor = null; + List result = getFileNamesImpl(context, parameters, ids, paths, datesPhotoTaken); + int size = result.size(); - try { - cursor = createCursorForQuery("getFileNames", context, parameters, VISIBILITY.PRIVATE_PUBLIC); - - int colPath = cursor.getColumnIndex(SQL_COL_DISPLAY_TEXT); - if (colPath == -1) colPath = cursor.getColumnIndex(SQL_COL_PATH); - int colIds = (ids == null) ? -1 : cursor.getColumnIndex(SQL_COL_PK); - int colDates = (datesPhotoTaken == null) ? -1 : cursor.getColumnIndex(SQL_COL_DATE_TAKEN); - while (cursor.moveToNext()) { - result.add(cursor.getString(colPath)); - if (colIds >= 0) ids.add(cursor.getLong(colIds)); - if (colDates >= 0) datesPhotoTaken.add(getDate(cursor, colDates)); - } - } finally { - if (cursor != null) { - cursor.close(); - } + if (size > 0) { + return result; } + } + return null; + + } + + /** converts internal ID-list to string array of filenNames via media database. */ + public static String[] getFileNames(Context context, String pksAsListString , List ids, List paths, List datesPhotoTaken) { + if ((pksAsListString != null) && !pksAsListString.isEmpty()) { + // query ordered by DatePhotoTaken so that lower rename-numbers correspond to older images. + QueryParameter parameters = new QueryParameter(queryAutoRename); + setWhereSelectionPks(parameters, pksAsListString); + + List result = getFileNamesImpl(context, parameters, ids, paths, datesPhotoTaken); int size = result.size(); if (size > 0) { @@ -1017,7 +1016,31 @@ public static String[] getFileNames(Context context, SelectedItems items, List getFileNamesImpl(Context context, QueryParameter parameters, List ids, List paths, List datesPhotoTaken) { + List result = (paths != null) ? paths : new ArrayList(); + Cursor cursor = null; + + try { + cursor = createCursorForQuery("getFileNames", context, parameters, VISIBILITY.PRIVATE_PUBLIC); + + int colPath = cursor.getColumnIndex(SQL_COL_DISPLAY_TEXT); + if (colPath == -1) colPath = cursor.getColumnIndex(SQL_COL_PATH); + int colIds = (ids == null) ? -1 : cursor.getColumnIndex(SQL_COL_PK); + int colDates = (datesPhotoTaken == null) ? -1 : cursor.getColumnIndex(SQL_COL_DATE_TAKEN); + while (cursor.moveToNext()) { + result.add(cursor.getString(colPath)); + if (colIds >= 0) ids.add(cursor.getLong(colIds)); + if (colDates >= 0) datesPhotoTaken.add(getDate(cursor, colDates)); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + return result; } protected static String getFilterExpressionVisibility(VISIBILITY _visibility) { diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index 6be5c962..1c2776ef 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -1,6 +1,6 @@ + diff --git a/fotolib2/src/main/java/de/k3b/FotoLibGlobal.java b/fotolib2/src/main/java/de/k3b/FotoLibGlobal.java index 4ae7eec8..14d3e386 100644 --- a/fotolib2/src/main/java/de/k3b/FotoLibGlobal.java +++ b/fotolib2/src/main/java/de/k3b/FotoLibGlobal.java @@ -32,6 +32,9 @@ public class FotoLibGlobal { */ public static boolean debugEnabled = false; + /** if debugEnabledJpg jpg files (copy/move/delete/exif) */ + public static boolean debugEnabledJpg = false; + /** if debugEnabledJpgMetaIo debug read/write jpg/exif/iptc/xmp io */ public static boolean debugEnabledJpgMetaIo = false; diff --git a/fotolib2/src/main/java/de/k3b/io/FileCommands.java b/fotolib2/src/main/java/de/k3b/io/FileCommands.java index 1b78f5d8..9a71ce08 100644 --- a/fotolib2/src/main/java/de/k3b/io/FileCommands.java +++ b/fotolib2/src/main/java/de/k3b/io/FileCommands.java @@ -107,7 +107,7 @@ public int deleteFiles(SelectedFiles fotos, IProgessListener progessListener) { } } onPostProcess(dbgContext, OP_DELETE, fotos, deleteCount, fileNames.length, fileNames, null); - if (FotoLibGlobal.debugEnabledJpgMetaIo) { + if (FotoLibGlobal.debugEnabledJpg || FotoLibGlobal.debugEnabledJpgMetaIo) { long dbgLoadEndTimestamp = new Date().getTime(); FileCommands.logger.debug(dbgContext + " process items:" + deleteCount @@ -324,7 +324,7 @@ protected int moveOrCopyFiles(final boolean move, String what, MediaDiffCopy exi // new style move/copy image with sidecarfile(s) with exif autoprocessing // for the log the file has already been copied/moved - logger.set(id, destPath); + logger.set(id, sourcePath); MetaWriterExifXml exifProcessor = createWorkflow(logger, what).applyChanges(sourceFile, destPath, id, move, mediaDiffCopy); @@ -444,6 +444,10 @@ private void addProcessedFiles(boolean move, File dest, File source) { protected boolean osFileMove(File dest, File source) { if (source.renameTo(dest)) { // move within same mountpoint + if (FotoLibGlobal.debugEnabledJpg) { + logger.info("osFileMove(rename) '" + source + + "' => '" + dest + "'"); + } return true; } @@ -453,9 +457,17 @@ protected boolean osFileMove(File dest, File source) { && !osFileExists(dest) && osFileCopy(dest, source)) { if (osDeleteFile(source)) { + if (FotoLibGlobal.debugEnabledJpg) { + logger.info("osFileMove(copy+delete) '" + source + + "' => '" + dest + "'"); + } return true; // move: copy + delete(source) : success } else { // cannot delete souce: undo copy + if (FotoLibGlobal.debugEnabledJpg) { + logger.info("osFileMove failed for '" + source + + "' => '" + dest + "'"); + } osDeleteFile(dest); } } @@ -500,12 +512,18 @@ private static boolean _osFileCopy(File targetFullPath, File sourceFullPath, Fil FileUtils.close(in,"_osFileCopy-close"); FileUtils.close(out,"_osFileCopy-close"); } + if (FotoLibGlobal.debugEnabledJpg) { + logger.info("osFileCopy '" + sourceFullPath + + "' => '" + targetFullPath + "' success=" + result); + } return result; } /** to be replaced by mock/stub in unittests */ protected boolean osDeleteFile(File file) { - return file.delete(); + final boolean result = file.delete(); + if (FotoLibGlobal.debugEnabledJpg) logger.info("osDeleteFile '" + file + "' success=" + result); + return result; } /** to be replaced by mock/stub in unittests */ @@ -532,7 +550,7 @@ public void addTransactionLog( MediaTransactionLogEntryDto dto = new MediaTransactionLogEntryDto(currentMediaID, fileFullPath, modificationDate, mediaTransactionLogEntryType, commandData); - if (logger.isDebugEnabled()) { + if (FotoLibGlobal.debugEnabledJpg) { logger.info(getClass().getSimpleName() + ".addTransactionLog(" + dto.toString() + ")"); } this.log(mediaTransactionLogEntryType.getCommand(fileFullPath, commandData)); diff --git a/fotolib2/src/main/java/de/k3b/io/collections/SelectedFiles.java b/fotolib2/src/main/java/de/k3b/io/collections/SelectedFiles.java index 02fe3559..38a2ab85 100644 --- a/fotolib2/src/main/java/de/k3b/io/collections/SelectedFiles.java +++ b/fotolib2/src/main/java/de/k3b/io/collections/SelectedFiles.java @@ -39,8 +39,19 @@ public static String[] getFileNameList(String fileNameListAsString) { return (fileNameListAsString != null) ? fileNameListAsString.split(DELIMITER) : null; } - public SelectedFiles(String fileNameListAsString, String idListAsString) { - this(getFileNameList(fileNameListAsString), parseIds(idListAsString), null); + public static SelectedFiles create(String fileNameListAsString, String idListAsString, String selectedDates) { + Date[] dates = null; + if (selectedDates != null) { + Long[] dateIds = parseIds(selectedDates); + if ((dateIds != null) && (dateIds.length > 0)) { + dates = new Date[dateIds.length]; + for(int i = 0; i < dateIds.length; i++) { + Long dateId = dateIds[i]; + dates[i] = ((dateId != null) && (dateId.longValue() != 0)) ? new Date(dateId.longValue()) : null; + } + } + } + return new SelectedFiles(getFileNameList(fileNameListAsString), parseIds(idListAsString), dates); } public SelectedFiles(String[] fileNameList, Long[] ids, Date[] datesPhotoTaken) { @@ -54,12 +65,20 @@ public SelectedFiles(String[] fileNameList, Long[] ids, Date[] datesPhotoTaken) mDatesPhotoTaken = datesPhotoTaken; } - private static Long[] parseIds(String idListAsString) { - if (idListAsString == null) return null; + private static Long[] parseIds(String listAsString) { + Long[] result = null; + + if ((listAsString != null) && (listAsString.length() > 0)) { + String itemsAsString[] = listAsString.split(DELIMITER); + result = new Long[itemsAsString.length]; + for (int i= 0; i < itemsAsString.length; i++) { + result[i] = Long.valueOf(itemsAsString[i]); + } + } - SelectedItems ids = new SelectedItems().parse(idListAsString); - return ids.toArray(new Long[ids.size()]); + return result; } + /** removes SORUNDER from beginning/end if present. Package to allow unittests */ static String reomoveApostrophes(String fileName) { if ((fileName != null) && (fileName.length() > 2) @@ -104,6 +123,17 @@ public String toString() { return toString(SORUNDER, mFileNames); } + public static String toString(String SORUNDER, Date[] values) { + if ((values != null) && (values.length > 0)) { + Long[] lvalue = new Long[values.length]; + for (int i = 0; i < values.length; i++) { + lvalue[i] = (values[i] == null) ? 0 : values[i].getTime(); + } + return toString(SORUNDER, lvalue); + } + return null; + } + public static String toString(String SORUNDER, T[] values) { // Arrays.asList() StringBuilder result = new StringBuilder(); @@ -127,6 +157,11 @@ public String toIdString() { return toString("", this.mIds); } + /** converts this into komma seperated list of names */ + public String toDateString() { + return toString("", this.mDatesPhotoTaken); + } + public int size() { return (mFileNames == null) ? 0 : mFileNames.length; } diff --git a/fotolib2/src/main/java/de/k3b/media/ExifInterface.java b/fotolib2/src/main/java/de/k3b/media/ExifInterface.java index 1189cb7f..caca24bd 100644 --- a/fotolib2/src/main/java/de/k3b/media/ExifInterface.java +++ b/fotolib2/src/main/java/de/k3b/media/ExifInterface.java @@ -1,7 +1,7 @@ // ExifInterface source code from android-6 - special version without jni /* * Copyright (C) 2007 The Android Open Source Project under the Apache License, Version 2.0 - * Copyright (C) 2016-2017 by k3b under the GPL-v3+. + * Copyright (C) 2016-2018 by k3b under the GPL-v3+. * * This file is part of AndroFotoFinder / #APhotoManager. * @@ -50,6 +50,7 @@ import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; + /** * This is a class for reading and writing Exif tags in a JPEG file. * It is based on ExifInterface of android-6 version. @@ -1517,13 +1518,17 @@ public void saveAttributes(File inFile, File outFile, boolean deleteInFileOnFini closeQuietly(out); if (deleteInFileOnFinish || overwriteOriginal) { - renamedInFile.delete(); + deleteFile(renamedInFile); } } // Discard the thumbnail in memory mThumbnailBytes = null; } + protected boolean deleteFile(File renamedInFile) { + return renamedInFile.delete(); + } + /** repairs wrong/missing attributes */ protected void fixAttributes() { if (ExifInterface.fixDateOnSave) { diff --git a/fotolib2/src/main/java/de/k3b/media/ExifInterfaceEx.java b/fotolib2/src/main/java/de/k3b/media/ExifInterfaceEx.java index c1317a98..15e6c0e7 100644 --- a/fotolib2/src/main/java/de/k3b/media/ExifInterfaceEx.java +++ b/fotolib2/src/main/java/de/k3b/media/ExifInterfaceEx.java @@ -27,9 +27,9 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.text.ParsePosition; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.TimeZone; @@ -94,10 +94,25 @@ public void saveAttributes(File inFile, File outFile, boolean deleteInFileOnFini fixDateTakenIfNeccessary(inFile); super.saveAttributes(inFile, outFile, deleteInFileOnFinish); setFilelastModified(outFile); - if (FotoLibGlobal.debugEnabledJpgMetaIo) { - logger.debug(mDbg_context + - " saved: " + MediaUtil.toString(this, false, null, MediaUtil.FieldID.path, MediaUtil.FieldID.clasz)); + } + + // Stores a new JPEG image with EXIF attributes into a given output stream. + @Override + public void saveJpegAttributes(InputStream inputStream, OutputStream outputStream, byte[] thumbnail) + throws IOException { + if (FotoLibGlobal.debugEnabledJpg || FotoLibGlobal.debugEnabledJpgMetaIo) { + logger.debug(mDbg_context + " saveJpegAttributes: " + getPath()); } + super.saveJpegAttributes(inputStream, outputStream, thumbnail); + } + + @Override + protected boolean deleteFile(File file) { + boolean result = super.deleteFile(file); + if (result && FotoLibGlobal.debugEnabledJpg || FotoLibGlobal.debugEnabledJpgMetaIo) { + logger.debug(mDbg_context + " deleteFile: " + file); + } + return result; } private void fixDateTakenIfNeccessary(File inFile) { diff --git a/fotolib2/src/main/java/de/k3b/media/JpgMetaWorkflow.java b/fotolib2/src/main/java/de/k3b/media/JpgMetaWorkflow.java index 952bffee..b4573848 100644 --- a/fotolib2/src/main/java/de/k3b/media/JpgMetaWorkflow.java +++ b/fotolib2/src/main/java/de/k3b/media/JpgMetaWorkflow.java @@ -132,13 +132,13 @@ public MetaWriterExifXml applyChanges(File inFilePath, String outFilePath, if (!sameFile && deleteOriginalWhenFinished) { File delete = FileProcessor.getSidecar(inFilePath, false); - if (delete != null) delete.delete(); + deleteFile(delete); delete = FileProcessor.getSidecar(inFilePath, true); - if (delete != null) delete.delete(); + deleteFile(delete); delete = inFilePath; - if (delete != null) delete.delete(); + deleteFile(delete); } } else { if (sb != null) sb.append("no changes "); @@ -170,6 +170,15 @@ public MetaWriterExifXml applyChanges(File inFilePath, String outFilePath, } } + protected void deleteFile(File delete) { + if ((delete != null) && delete.exists()) { + delete.delete(); + if (FotoLibGlobal.debugEnabledJpg) { + logger.info("JpgMetaWorkflow deleteFile " + delete); + } + } + } + /** return modified out file or null if filename must not change due to visibility rule */ protected File handleVisibility(VISIBILITY newVisibility, File outFile, MetaWriterExifXml exif) { if (FotoLibGlobal.renamePrivateJpg) { diff --git a/fotolib2/src/test/java/de/k3b/io/FileCommandAutoIntegrationTests.java b/fotolib2/src/test/java/de/k3b/io/FileCommandAutoIntegrationTests.java index 7853c679..85d1a1df 100644 --- a/fotolib2/src/test/java/de/k3b/io/FileCommandAutoIntegrationTests.java +++ b/fotolib2/src/test/java/de/k3b/io/FileCommandAutoIntegrationTests.java @@ -54,10 +54,13 @@ public class FileCommandAutoIntegrationTests { private static final Logger LOGGER = LoggerFactory.getLogger(FileCommandAutoIntegrationTests.class); public static final String TEST_CLASS_NAME = FileCommandAutoIntegrationTests.class.getSimpleName(); + private static final String FAKE_ID = "1"; + private static final String FAKE_DATE = "1223372036854775807"; + private static final File OUTDIR = new File(TestUtil.OUTDIR_ROOT, TEST_CLASS_NAME + "/out").getAbsoluteFile(); private static final File INDIR = new File(TestUtil.OUTDIR_ROOT, TEST_CLASS_NAME + "/in").getAbsoluteFile(); private static final File INJPG = new File(INDIR, "myTestSource.jpg").getAbsoluteFile(); - public static final SelectedFiles FAKE_SELECTED_FILES = new SelectedFiles(INJPG.getAbsolutePath(), "1"); + public static final SelectedFiles FAKE_SELECTED_FILES = SelectedFiles.create(INJPG.getAbsolutePath(), FAKE_ID, FAKE_DATE); @BeforeClass public static void setUpClass() throws IOException { @@ -90,7 +93,7 @@ public void shouldApplyExifChange() throws IOException { MediaDiffCopy addExif = new MediaDiffCopy(new MediaDTO().setTitle("title added by " + TEST_CLASS_NAME), true); // false do not delete source file - int changes = sut.applyExifChanges(false, addExif,new SelectedFiles(testJpg.toString(), "1"), null); + int changes = sut.applyExifChanges(false, addExif,SelectedFiles.create(testJpg.toString(), FAKE_ID, FAKE_DATE), null); Assert.assertEquals(1, changes); } @@ -133,7 +136,7 @@ public void autoShouldAddTagSameFileNoRenameRule() throws IOException { TestUtil.saveTestResourceAs("test-WitExtraData.jpg", inFile); FileCommands sut = createFileCommands(outFileBaseName); - SelectedFiles selectedFiles = new SelectedFiles(inFile.getAbsolutePath(), "1"); + SelectedFiles selectedFiles = SelectedFiles.create(inFile.getAbsolutePath(), FAKE_ID, FAKE_DATE); final IMetaApi exifChanges = new MediaDTO(); exifChanges.setTags(ListUtils.fromString(tagAdded)); @@ -168,7 +171,7 @@ protected void checkMoveCopyWithAutoPrivate(final String outFileBaseName, boolea TestUtil.saveTestResourceAs("test-WitExtraData.jpg", inFile); FileCommands sut = createFileCommands(outFileBaseName); - SelectedFiles selectedFiles = new SelectedFiles(inFile.getAbsolutePath(), "1"); + SelectedFiles selectedFiles = SelectedFiles.create(inFile.getAbsolutePath(), FAKE_ID, FAKE_DATE); final IMetaApi exifChanges = new MediaDTO(); exifChanges.setVisibility(VISIBILITY.PRIVATE); @@ -193,7 +196,7 @@ public void autoShouldAddTagSameFileRenameRuleMatching() throws IOException { TestUtil.saveTestResourceAs("test-WitExtraData.jpg", inFile); FileCommands sut = createFileCommands(outFileBaseName); - SelectedFiles selectedFiles = new SelectedFiles(inFile.getAbsolutePath(), "1"); + SelectedFiles selectedFiles = SelectedFiles.create(inFile.getAbsolutePath(), FAKE_ID, FAKE_DATE); final IMetaApi exifChanges = new MediaDTO(); exifChanges.setTags(ListUtils.fromString(tagAdded)); @@ -218,7 +221,7 @@ public void autoShouldAddTagWithRename() throws IOException { TestUtil.saveTestResourceAs("test-WitExtraData.jpg", inFile); FileCommands sut = createFileCommands(outFileBaseName); - SelectedFiles selectedFiles = new SelectedFiles(inFile.getAbsolutePath(), "1"); + SelectedFiles selectedFiles = SelectedFiles.create(inFile.getAbsolutePath(), FAKE_ID, FAKE_DATE); final IMetaApi exifChanges = new MediaDTO(); exifChanges.setTags(ListUtils.fromString(tagAdded)); @@ -243,7 +246,7 @@ public void shouldMoveRenameAutoExifSameDir() throws IOException { FileCommands sut = createFileCommands(outFileBaseName); final String newName = outFileBaseName + "-new"; - SelectedFiles selectedFiles = new SelectedFiles(inFile.getAbsolutePath(), "1"); + SelectedFiles selectedFiles = SelectedFiles.create(inFile.getAbsolutePath(), FAKE_ID, FAKE_DATE); // 0 avoid rounding of lat/lon; visibility not supported is only public final IMetaApi exifChanges = TestUtil.createTestMediaDTO(0).setVisibility(VISIBILITY.PUBLIC); @@ -274,7 +277,7 @@ public void shouldChangeFileNameOnVisibilityPrivate() throws IOException { FileCommands sut = createFileCommands(outFileBaseName); final String newName = outFileBaseName + "-new"; - SelectedFiles selectedFiles = new SelectedFiles(inFile.getAbsolutePath(), "1"); + SelectedFiles selectedFiles = SelectedFiles.create(inFile.getAbsolutePath(), FAKE_ID, FAKE_DATE); // final IMetaApi exifChanges = new MediaDTO().setVisibility(VISIBILITY.PUBLIC).setRating(3); final IMetaApi exifChanges = new MediaDTO().setVisibility(VISIBILITY.PRIVATE); diff --git a/fotolib2/src/test/java/de/k3b/io/collections/SelectedFilesTests.java b/fotolib2/src/test/java/de/k3b/io/collections/SelectedFilesTests.java index 8a1e904f..6448cf6d 100644 --- a/fotolib2/src/test/java/de/k3b/io/collections/SelectedFilesTests.java +++ b/fotolib2/src/test/java/de/k3b/io/collections/SelectedFilesTests.java @@ -1,19 +1,39 @@ +/* + * Copyright (c) 2016-2018 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 + */ package de.k3b.io.collections; import org.junit.Assert; import org.junit.Test; /** - * Created by EVE on 06.10.2016. + * Created by k3b on 06.10.2016. */ public class SelectedFilesTests { @Test public void shoudParseAndFormatString() { - String names = "'a','b','c'"; - String ids = "1,2,3"; - SelectedFiles sut = new SelectedFiles(names, ids); + String names = "'b','z','c'"; + String ids = "71,2,3"; + String selectedDates = "2223372036854775807,1223372036854775807,3223372036854775807"; + SelectedFiles sut = SelectedFiles.create(names, ids, selectedDates); Assert.assertEquals("names", names, sut.toString()); Assert.assertEquals("ids", ids, sut.toIdString()); + Assert.assertEquals("dates", selectedDates, sut.toDateString()); } }