Fix 6046544 Deleting a photo takes multiple steps and the flow is inconsistent with other deleting flows on other core apps
This CL adds a confirm dialog to delete command and removes all confirm/cancel menu items from the actionbar.
b:6046544
Change-Id: I3afe7b59b4f6d1216e192a621621f7bf544e1919
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index 78bb34c..6be302b 100644
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -435,6 +435,7 @@
DataManager manager = mActivity.getDataManager();
int action = item.getItemId();
+ boolean needsConfirm = false;
switch (action) {
case android.R.id.home: {
if (mSetPathString != null) {
@@ -480,20 +481,21 @@
}
return true;
}
+ case R.id.action_delete:
+ needsConfirm = true;
case R.id.action_setas:
- case R.id.action_confirm_delete:
case R.id.action_rotate_ccw:
case R.id.action_rotate_cw:
case R.id.action_show_on_map:
case R.id.action_edit:
mSelectionManager.deSelectAll();
mSelectionManager.toggle(path);
- mMenuExecutor.onMenuClicked(item, null);
+ mMenuExecutor.onMenuClicked(item, needsConfirm, null);
return true;
case R.id.action_import:
mSelectionManager.deSelectAll();
mSelectionManager.toggle(path);
- mMenuExecutor.onMenuClicked(item,
+ mMenuExecutor.onMenuClicked(item, needsConfirm,
new ImportCompleteListener(mActivity));
return true;
default :
diff --git a/src/com/android/gallery3d/ui/ActionModeHandler.java b/src/com/android/gallery3d/ui/ActionModeHandler.java
index 32820f3..0188393 100644
--- a/src/com/android/gallery3d/ui/ActionModeHandler.java
+++ b/src/com/android/gallery3d/ui/ActionModeHandler.java
@@ -110,6 +110,10 @@
root.lockRenderThread();
try {
boolean result;
+ // Give listener a chance to process this command before it's routed to
+ // ActionModeHandler, which handles command only based on the action id.
+ // Sometimes the listener may have more background information to handle
+ // an action command.
if (mListener != null) {
result = mListener.onActionItemClicked(item);
if (result) {
@@ -118,18 +122,22 @@
}
}
ProgressListener listener = null;
- if (item.getItemId() == R.id.action_import) {
+ boolean needsConfirm = false;
+ int action = item.getItemId();
+ if (action == R.id.action_import) {
listener = new ImportCompleteListener(mActivity);
+ } else if (item.getItemId() == R.id.action_delete) {
+ needsConfirm = true;
}
- result = mMenuExecutor.onMenuClicked(item, listener);
- if (item.getItemId() == R.id.action_select_all) {
+ mMenuExecutor.onMenuClicked(item, needsConfirm, listener);
+ if (action == R.id.action_select_all) {
updateSupportedOperation();
updateSelectionMenu();
}
- return result;
} finally {
root.unlockRenderThread();
}
+ return true;
}
private void updateSelectionMenu() {
diff --git a/src/com/android/gallery3d/ui/MenuExecutor.java b/src/com/android/gallery3d/ui/MenuExecutor.java
index 918feea..a0f3449 100644
--- a/src/com/android/gallery3d/ui/MenuExecutor.java
+++ b/src/com/android/gallery3d/ui/MenuExecutor.java
@@ -17,8 +17,11 @@
package com.android.gallery3d.ui;
import android.app.Activity;
+import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
@@ -172,10 +175,9 @@
return ids.get(0);
}
- public boolean onMenuClicked(MenuItem menuItem, ProgressListener listener) {
+ private void onMenuClicked(int action, ProgressListener listener) {
int title;
DataManager manager = mActivity.getDataManager();
- int action = menuItem.getItemId();
switch (action) {
case R.id.action_select_all:
if (mSelectionManager.inSelectAllMode()) {
@@ -183,14 +185,12 @@
} else {
mSelectionManager.selectAll();
}
- return true;
case R.id.action_crop: {
Path path = getSingleSelectedPath();
String mimeType = getMimeType(manager.getMediaType(path));
Intent intent = new Intent(CropImage.ACTION_CROP)
.setDataAndType(manager.getContentUri(path), mimeType);
((Activity) mActivity).startActivity(intent);
- return true;
}
case R.id.action_setas: {
Path path = getSingleSelectedPath();
@@ -203,9 +203,8 @@
Activity activity = (Activity) mActivity;
activity.startActivity(Intent.createChooser(
intent, activity.getString(R.string.set_as)));
- return true;
}
- case R.id.action_confirm_delete:
+ case R.id.action_delete:
title = R.string.delete;
break;
case R.id.action_rotate_cw:
@@ -224,10 +223,27 @@
title = R.string.Import;
break;
default:
- return false;
+ return;
}
startAction(action, title, listener);
- return true;
+ }
+
+ public void onMenuClicked(MenuItem menuItem, boolean needsConfirm,
+ final ProgressListener listener) {
+ final int action = menuItem.getItemId();
+
+ if (needsConfirm) {
+ new AlertDialog.Builder(mActivity.getAndroidContext())
+ .setMessage(R.string.confirm_action)
+ .setPositiveButton(R.string.confirm, new OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ onMenuClicked(action, listener);
+ }
+ })
+ .setNegativeButton(R.string.cancel, null).create().show();
+ } else {
+ onMenuClicked(action, listener);
+ }
}
public void startAction(int action, int title, ProgressListener listener) {
@@ -257,7 +273,7 @@
long startTime = System.currentTimeMillis();
switch (cmd) {
- case R.id.action_confirm_delete:
+ case R.id.action_delete:
manager.delete(path);
break;
case R.id.action_rotate_cw: