Skip to content

Commit

Permalink
#36 .nomedia impl continued ImageDetailActivityViewPager implemented …
Browse files Browse the repository at this point in the history
…setGeo for nomedia jpg
  • Loading branch information
k3b committed May 30, 2016
1 parent 59de4a2 commit bd92357
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,18 +461,32 @@ protected void notifySelectionChanged(IDirectory selectedChild) {
if ((mDirectoryListener != null) && (selectedChild != null)) mDirectoryListener.onDirectorySelectionChanged(selectedChild.getAbsolute(), mDirTypId);
}

/**
* To be overwritten to check if a path can be picked.
*
* @param path to be checked if it cannot be handled
* @return null if no error else error message with the reason why it cannot be selected
*/
protected String getStatusErrorMessage(String path) {
return null;
}

private void updateStatus() {
int itemCount = getItemCount(mCurrentSelection);
boolean canPressOk = (itemCount > 0);

String selectedPath = (this.mCurrentSelection != null) ? this.mCurrentSelection.getAbsolute() : null;

String statusMessage = (itemCount == 0) ? mContext.getString(R.string.selection_none_hint) : getStatusErrorMessage(selectedPath);
boolean canPressOk = (statusMessage == null);

if (mCmdOk != null) mCmdOk.setEnabled(canPressOk);
if (mCmdPopup != null) mCmdPopup.setEnabled(canPressOk);

if (mStatus != null) {
if (canPressOk) {
if (statusMessage == null) {
mStatus.setText(this.mCurrentSelection.getAbsolute());
} else {
mStatus.setText(R.string.selection_none_hint);
mStatus.setText(statusMessage);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,22 @@ public SelectedItems getSrcFotos() {
return (SelectedItems) getArguments().getSerializable("srcFotos");
}

/**
* To be overwritten to check if a path can be picked.
*
* @param path to be checked if it cannot be handled
* @return null if no error else error message with the reason why it cannot be selected
*/
@Override
protected String getStatusErrorMessage(String path) {
String errorMessage = (sFileCommands == null) ? null : sFileCommands.checkWriteProtected(0, new File(path));
if (errorMessage != null) {
int pos = errorMessage.indexOf('\n');
return (pos > 0) ? errorMessage.substring(0,pos) : errorMessage;
}
return super.getStatusErrorMessage(path);
}

@Override
protected void onDirectoryPick(IDirectory selection) {
// super.onDirectoryPick(selection);
Expand Down Expand Up @@ -744,20 +760,22 @@ public void handleMessage(Message m) {
};

private void startStopSlideShow(boolean start) {
mViewPager.setLocked(start);
if (start != mSlideShowStarted) {
if (start) {
onSlideShowNext();
mSlideShowTimer.sendMessageDelayed(Message.obtain(mSlideShowTimer, SLIDESHOW_HANDLER_ID), Global.slideshowIntervalInMilliSecs);
} else {
mSlideShowTimer.removeMessages(SLIDESHOW_HANDLER_ID);
}
mSlideShowStarted = start;
if (mViewPager != null) {
mViewPager.setLocked(start);
if (start != mSlideShowStarted) {
if (start) {
onSlideShowNext();
mSlideShowTimer.sendMessageDelayed(Message.obtain(mSlideShowTimer, SLIDESHOW_HANDLER_ID), Global.slideshowIntervalInMilliSecs);
} else {
mSlideShowTimer.removeMessages(SLIDESHOW_HANDLER_ID);
}
mSlideShowStarted = start;

// #24 Prevent sleepmode while slideshow is active
if (this.mViewPager != null) this.mViewPager.setKeepScreenOn(start);

if (mMenuSlideshow != null) mMenuSlideshow.setChecked(start);
// #24 Prevent sleepmode while slideshow is active
if (this.mViewPager != null) this.mViewPager.setKeepScreenOn(start);

if (mMenuSlideshow != null) mMenuSlideshow.setChecked(start);
}
}
}

Expand Down
123 changes: 78 additions & 45 deletions app/src/main/java/de/k3b/android/util/AndroidFileCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,25 @@ public boolean onOptionsItemSelected(final MenuItem item, final SelectedItems se
return false;
}

/**
* Check if all files in selectedFileNamesToBeModified are not write protected.
*
* @return null if no error. else formated error message.
*/
public String checkWriteProtected(int resIdAction, final File... filesToBeModified) {
// <string name="file_err_writeprotected">\'%1$s\' ist schreibgeschützt. \'%2$s\' ist nicht möglich.</string>
if (filesToBeModified != null) {
for (File file : filesToBeModified) {
if ((file != null) && (file.exists()) && (!file.canWrite())) {
String action = (resIdAction == 0) ? "" : mContext.getString(resIdAction);
// file_err_writeprotected="writeprotected \'%1$s\'.\n\n \'%2$s\' is not possible."
return mContext.getString(R.string.file_err_writeprotected, file.getAbsolutePath(), action);
}
}
}
return null;
}

public boolean rename(Long fileId, File dest, File src) {
int result = moveOrCopyFiles(true, "rename", new File[]{dest}, new File[]{src});
return (result != 0);
Expand All @@ -156,9 +175,10 @@ public boolean rename(Long fileId, File dest, File src) {
public void onMoveOrCopyDirectoryPick(boolean move, IDirectory destFolder, SelectedItems srcFotos) {
if (destFolder != null) {
String copyToPath = destFolder.getAbsolute();
setLastCopyToPath(copyToPath);
File destDirFolder = new File(copyToPath);

setLastCopyToPath(copyToPath);

String[] selectedFileNames = srcFotos.getFileNames(mId2FileNameConverter);
moveOrCopyFilesTo(move, destDirFolder, SelectedFiles.getFiles(selectedFileNames));
}
Expand All @@ -179,45 +199,52 @@ private void setLastCopyToPath(String copyToPath) {

public boolean cmdDeleteFileWithQuestion(final SelectedItems fotos) {
String[] pathNames = fotos.getFileNames(mId2FileNameConverter);
StringBuffer names = new StringBuffer();
for (String name : pathNames) {
names.append(name).append("\n");
}
final String message = mContext
.getString(R.string.delete_question_message_format, names.toString());

final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
final String title = mContext.getText(R.string.delete_question_title)
.toString();

builder.setTitle(title + pathNames.length);
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(R.string.btn_yes,
new DialogInterface.OnClickListener() {
@Override
public void onClick(
final DialogInterface dialog,
final int id) {
mActiveAlert = null; deleteFiles(fotos);
String errorMessage = checkWriteProtected(R.string.delete_menu_title, SelectedFiles.getFiles(pathNames));

if (errorMessage != null) {
Toast.makeText(this.mContext, errorMessage, Toast.LENGTH_LONG).show();
} else {
StringBuffer names = new StringBuffer();
for (String name : pathNames) {
names.append(name).append("\n");
}
final String message = mContext
.getString(R.string.delete_question_message_format, names.toString());

final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
final String title = mContext.getText(R.string.delete_question_title)
.toString();

builder.setTitle(title + pathNames.length);
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(R.string.btn_yes,
new DialogInterface.OnClickListener() {
@Override
public void onClick(
final DialogInterface dialog,
final int id) {
mActiveAlert = null;
deleteFiles(fotos);
}
}
}
)
.setNegativeButton(R.string.btn_no,
new DialogInterface.OnClickListener() {
@Override
public void onClick(
final DialogInterface dialog,
final int id) {
mActiveAlert = null;
dialog.cancel();
)
.setNegativeButton(R.string.btn_no,
new DialogInterface.OnClickListener() {
@Override
public void onClick(
final DialogInterface dialog,
final int id) {
mActiveAlert = null;
dialog.cancel();
}
}
}
);
);

final AlertDialog alert = builder.create();
mActiveAlert = alert;
alert.show();
final AlertDialog alert = builder.create();
mActiveAlert = alert;
alert.show();
}
return true;
}

Expand Down Expand Up @@ -320,30 +347,36 @@ private void showMediaScannerStatus(RecursiveMediaScanner mediaScanner) {
public int setGeo(double latitude, double longitude, SelectedFiles selectedItems, int itemsPerProgress) {
if (!Double.isNaN(latitude) && !Double.isNaN(longitude) && (selectedItems != null) && (selectedItems.size() > 0)) {
// in case that current activity is destroyed while running async, applicationContext will allow to finish database operation
Context applicationContext = this.mContext.getApplicationContext();
int itemcount = 0;
int countdown = 0;
String[] fileNames = selectedItems.getFileNames();
if (fileNames != null) {
File[] files = SelectedFiles.getFiles(fileNames);
File[] files = SelectedFiles.getFiles(selectedItems.getFileNames());
String errorMessage = checkWriteProtected(R.string.geo_edit_menu_title, files);

if (errorMessage != null) {
Toast.makeText(this.mContext, errorMessage, Toast.LENGTH_LONG).show();
} else if (files != null) {
Context applicationContext = this.mContext.getApplicationContext();
int maxCount = files.length+1;
openLogfile();
int resultFile = 0;
for (File file : files) {
countdown--;
if (countdown <= 0) {
countdown = itemsPerProgress;
onProgress(itemcount, maxCount);
}
ExifGps.saveLatLon(file, latitude, longitude, mContext.getString(R.string.app_name), GuiUtil.getAppVersionName(mContext));
if (ExifGps.saveLatLon(file, latitude, longitude, mContext.getString(R.string.app_name), GuiUtil.getAppVersionName(mContext))) {
resultFile++;
}
itemcount++;
log("CALL setgps ", getFilenameForLog(file),
" ", DirectoryFormatter.parseLatLon(latitude), " ", DirectoryFormatter.parseLatLon(longitude));
itemcount++;
}
onProgress(itemcount, maxCount);
int result = FotoSql.execUpdateGeo(applicationContext, latitude, longitude, selectedItems);
int resultSql = FotoSql.execUpdateGeo(applicationContext, latitude, longitude, selectedItems);
closeLogFile();
onProgress(++itemcount, maxCount);
return result;
return Math.max(resultFile,resultSql);
}
}
return 0;
Expand Down
Loading

0 comments on commit bd92357

Please sign in to comment.