Skip to content

Commit

Permalink
#169: exif SAF api
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Apr 14, 2020
1 parent bac3158 commit dbf1bc9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import de.k3b.android.androFotoFinder.queries.MediaDBRepository;
import de.k3b.android.androFotoFinder.queries.MergedMediaRepository;
import de.k3b.android.io.DocumentFileTranslator;
import de.k3b.android.io.ExifInterfaceExAndroid;
import de.k3b.android.osmdroid.forge.MapsForgeSupport;
import de.k3b.android.util.LogCat;
import de.k3b.android.util.PhotoChangeNotifyer;
Expand Down Expand Up @@ -152,6 +153,7 @@ public static RefWatcher getRefWatcher(Context context) {

super.onCreate();
FilePermissionActivity.init(this);
ExifInterfaceExAndroid.initFactory();

LibGlobal.appName = getString(R.string.app_name);
LibGlobal.appVersion = GuiUtil.getAppVersionName(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import de.k3b.android.util.PhotoPropertiesMediaFilesScanner;
import de.k3b.android.util.ResourceUtils;
import de.k3b.android.widget.AboutDialogPreference;
import de.k3b.android.widget.FilePermissionActivity;
import de.k3b.android.widget.HistoryEditText;
import de.k3b.android.widget.UpdateTask;
import de.k3b.geo.api.GeoPointDto;
Expand Down Expand Up @@ -98,6 +99,7 @@ public class PhotoPropertiesEditActivity extends BaseActivity implements Common
private static final String SETTINGS_KEY = "PhotoPropertiesEditActivity-";
private static final String SETTINGS_KEY_INITIAL = "ExifEditActivityInitial-";
private static final GeoUri PARSER = new GeoUri(GeoUri.OPT_PARSE_INFER_MISSING);
private static final boolean EXEC_IN_BACKGROUND = true;

/** current modified value of the first selected file */
private PhotoPropertiesAsString mCurrentData;
Expand Down Expand Up @@ -794,7 +796,6 @@ private void clearFilter() {

/** save exif changes back to image and database */
private void onSaveChanges() {
Activity ctx = this;
saveGuiToExif("onOk (finish)");
mHistory.saveHistory();
boolean finish = true;
Expand All @@ -812,21 +813,10 @@ private void onSaveChanges() {
if ((items != null) && (items.size() > 0)) {

//!!! todo #93: this code also in
AndroidFileCommands cmd = AndroidFileCommands.createFileCommand(this, true);

PhotoPropertiesDiffCopy exifChanges = new PhotoPropertiesDiffCopy(true, true).setDiff(mInitialData, mCurrentData);

if (exifChanges != null) {
if (!SYNC_UPDATE_EXIF) {
this.exifUpdate = new UpdateTask(R.string.exif_menu_title, ctx, cmd, exifChanges);
exifUpdate.execute(items);
finish = false;
} else {
// for debugging: sync debugging is easier
cmd.applyExifChanges(true, exifChanges, items, null);

this.setResult(EXIF_RESULT_ID, intent);
}
finish = execExifUpdate(items, exifChanges);
} // else no changes, nothing to do
} // if there are selected items
} // if save mode
Expand All @@ -837,6 +827,43 @@ private void onSaveChanges() {
}
}

private boolean execExifUpdate(final SelectedFiles items, final PhotoPropertiesDiffCopy exifChanges) {
boolean finish = true;

closeDialogIfNeeded();

File missingRoot = getMissingRootDirFileOrNull(items.getFiles());
if (missingRoot != null) {
// missing write permissions. Request from user
requestRootUriDialog(missingRoot, getText(R.string.exif_menu_title),
new IOnDirectoryPermissionGrantedHandler() {
@Override
public void afterGrant(FilePermissionActivity activity) {
// recursion: after grant do it again
((PhotoPropertiesEditActivity) activity).execExifUpdate(items, exifChanges);
}
});
return false;
}

AndroidFileCommands cmd = AndroidFileCommands.createFileCommand(this, EXEC_IN_BACKGROUND)
.setContext(this);

Intent intent = getIntent();
Activity ctx = this;
if (!SYNC_UPDATE_EXIF) {
this.exifUpdate = new UpdateTask(R.string.exif_menu_title, ctx, cmd, exifChanges);
exifUpdate.execute(items);
finish = false;
} else {
// for debugging: sync debugging is easier
cmd.applyExifChanges(true, exifChanges, items, null);

this.setResult(EXIF_RESULT_ID, intent);
}
return finish;
}

@Override
protected void onDestroy() {
// avoid memory leaks through cyclic dependencies
Expand Down

0 comments on commit dbf1bc9

Please sign in to comment.