diff --git a/res/values/ids.xml b/res/values/ids.xml new file mode 100644 index 000000000..a2b91bfee --- /dev/null +++ b/res/values/ids.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index b4d645f00..e0b805fd6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -319,6 +319,13 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin Return to list after delete Return to message list after message deletion + Confirm actions + Show a dialog whenever you perform selected actions + Archive + Delete (message view only) + Spam + Send + Set up a new account Enter this account\'s email address: (You may add %d more accounts.) @@ -933,4 +940,10 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin This message can\'t be displayed because the charset \"%s\" wasn\'t found. Select text to copy. + + Confirm deletion + Do you want to delete this message? + Delete + Do not delete + diff --git a/res/xml/global_preferences.xml b/res/xml/global_preferences.xml index 40bcd7458..95e8001a7 100644 --- a/res/xml/global_preferences.xml +++ b/res/xml/global_preferences.xml @@ -70,6 +70,15 @@ android:title="@string/start_integrated_inbox_title" android:summary="@string/start_integrated_inbox_summary" /> + + diff --git a/src/com/fsck/k9/K9.java b/src/com/fsck/k9/K9.java index 9bf9eff44..31235999e 100644 --- a/src/com/fsck/k9/K9.java +++ b/src/com/fsck/k9/K9.java @@ -106,6 +106,7 @@ public class K9 extends Application private static boolean mAnimations = true; + private static boolean mConfirmDelete = false; private static boolean mMessageListStars = true; private static boolean mMessageListCheckboxes = false; @@ -353,6 +354,8 @@ public class K9 extends Application editor.putInt("theme", theme); editor.putBoolean("useGalleryBugWorkaround", useGalleryBugWorkaround); + editor.putBoolean("confirmDelete", mConfirmDelete); + fontSizes.save(editor); } @@ -384,6 +387,8 @@ public class K9 extends Application useGalleryBugWorkaround = sprefs.getBoolean("useGalleryBugWorkaround", K9.isGalleryBuggy()); + mConfirmDelete = sprefs.getBoolean("confirmDelete", false); + fontSizes.load(sprefs); try @@ -684,6 +689,16 @@ public class K9 extends Application return galleryBuggy; } + public static boolean confirmDelete() + { + return mConfirmDelete; + } + + public static void setConfirmDelete(final boolean confirm) + { + mConfirmDelete = confirm; + } + /** * Check if this system contains a buggy Gallery 3D package. * @@ -706,4 +721,5 @@ public class K9 extends Application return false; } } + } diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index b65f38c6d..405dbd645 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -16,8 +16,11 @@ import java.util.regex.Pattern; import org.apache.commons.io.IOUtils; +import android.app.AlertDialog; +import android.app.Dialog; import android.content.ContentResolver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ResolveInfo; import android.content.res.Configuration; @@ -1291,7 +1294,54 @@ public class MessageView extends K9Activity implements OnClickListener super.onResume(); } + /** + * Called from UI thread when user select Delete + */ private void onDelete() + { + if (K9.confirmDelete()) + { + showDialog(R.id.dialog_confirm_delete); + } + else + { + delete(); + } + } + + /** + * @param id + * @return Never null + */ + protected Dialog createConfirmDeleteDialog(final int id) + { + final AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.dialog_confirm_delete_title); + builder.setMessage(R.string.dialog_confirm_delete_message); + builder.setPositiveButton(R.string.dialog_confirm_delete_confirm_button, + new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int which) + { + dismissDialog(id); + delete(); + } + }); + builder.setNegativeButton(R.string.dialog_confirm_delete_cancel_button, + new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int which) + { + dismissDialog(id); + } + }); + final AlertDialog dialog = builder.create(); + return dialog; + } + + private void delete() { if (mMessage != null) { @@ -1923,6 +1973,27 @@ public class MessageView extends K9Activity implements OnClickListener return super.onPrepareOptionsMenu(menu); } + // XXX when switching to API version 8, override onCreateDialog(int, Bundle) + /** + * @param id + * The id of the dialog. + * @return The dialog. If you return null, the dialog will not be created. + * @see android.app.Activity#onCreateDialog(int, Bundle) + */ + @Override + protected Dialog onCreateDialog(final int id) + { + switch (id) + { + case R.id.dialog_confirm_delete: + { + final Dialog dialog = createConfirmDeleteDialog(id); + return dialog; + } + } + return super.onCreateDialog(id); + } + private void prepareMenuItems() { Menu menu = optionsMenu; diff --git a/src/com/fsck/k9/activity/setup/Prefs.java b/src/com/fsck/k9/activity/setup/Prefs.java index 3bce165f5..ff3570ab1 100644 --- a/src/com/fsck/k9/activity/setup/Prefs.java +++ b/src/com/fsck/k9/activity/setup/Prefs.java @@ -20,6 +20,7 @@ import com.fsck.k9.R; import com.fsck.k9.activity.Accounts; import com.fsck.k9.activity.DateFormatter; import com.fsck.k9.activity.K9PreferenceActivity; +import com.fsck.k9.preferences.CheckboxListPreference; import com.fsck.k9.service.MailService; public class Prefs extends K9PreferenceActivity @@ -53,6 +54,9 @@ public class Prefs extends K9PreferenceActivity private static final String PREFERENCE_MEASURE_ACCOUNTS = "measure_accounts"; private static final String PREFERENCE_COUNT_SEARCH = "count_search"; private static final String PREFERENCE_GALLERY_BUG_WORKAROUND = "use_gallery_bug_workaround"; + + private static final String PREFERENCE_CONFIRM_ACTIONS = "confirm_actions"; + private ListPreference mLanguage; private ListPreference mTheme; private ListPreference mDateFormat; @@ -75,6 +79,7 @@ public class Prefs extends K9PreferenceActivity private CheckBoxPreference mCountSearch; private CheckBoxPreference mUseGalleryBugWorkaround; + private CheckboxListPreference mConfirmActions; private String initBackgroundOps; @@ -233,6 +238,10 @@ public class Prefs extends K9PreferenceActivity mUseGalleryBugWorkaround = (CheckBoxPreference)findPreference(PREFERENCE_GALLERY_BUG_WORKAROUND); mUseGalleryBugWorkaround.setChecked(K9.useGalleryBugWorkaround()); + + mConfirmActions = (CheckboxListPreference) findPreference(PREFERENCE_CONFIRM_ACTIONS); + mConfirmActions.setItems(new CharSequence[] {getString(R.string.global_settings_confirm_action_delete)}); + mConfirmActions.setCheckedItems(new boolean[] {K9.confirmDelete()}); } @Override @@ -267,6 +276,8 @@ public class Prefs extends K9PreferenceActivity K9.setUseGalleryBugWorkaround(mUseGalleryBugWorkaround.isChecked()); + K9.setConfirmDelete(mConfirmActions.getCheckedItems()[0]); + Editor editor = preferences.edit(); K9.save(editor); DateFormatter.setDateFormat(editor, mDateFormat.getValue()); diff --git a/src/com/fsck/k9/preferences/CheckboxListPreference.java b/src/com/fsck/k9/preferences/CheckboxListPreference.java new file mode 100644 index 000000000..6998ca540 --- /dev/null +++ b/src/com/fsck/k9/preferences/CheckboxListPreference.java @@ -0,0 +1,84 @@ +package com.fsck.k9.preferences; + +import android.app.AlertDialog.Builder; +import android.content.Context; +import android.content.DialogInterface; +import android.preference.DialogPreference; +import android.util.AttributeSet; + +public class CheckboxListPreference extends DialogPreference +{ + + private CharSequence[] mItems; + + private boolean[] mCheckedItems; + + /** + * checkboxes state when the dialog is displayed + */ + private boolean[] mPendingItems; + + /** + * @param context + * @param attrs + * @param defStyle + */ + public CheckboxListPreference(Context context, AttributeSet attrs, int defStyle) + { + super(context, attrs, defStyle); + } + + /** + * @param context + * @param attrs + */ + public CheckboxListPreference(Context context, AttributeSet attrs) + { + super(context, attrs); + } + + @Override + protected void onPrepareDialogBuilder(final Builder builder) + { + mPendingItems = new boolean[mItems.length]; + + System.arraycopy(mCheckedItems, 0, mPendingItems, 0, mCheckedItems.length); + + builder.setMultiChoiceItems(mItems, mPendingItems, + new DialogInterface.OnMultiChoiceClickListener() + { + @Override + public void onClick(final DialogInterface dialog, final int which, + final boolean isChecked) + { + mPendingItems[which] = isChecked; + } + }); + } + + @Override + protected void onDialogClosed(boolean positiveResult) + { + if (positiveResult) + { + System.arraycopy(mPendingItems, 0, mCheckedItems, 0, mPendingItems.length); + } + mPendingItems = null; + } + + public void setItems(final CharSequence[] items) + { + mItems = items; + } + + public void setCheckedItems(final boolean[] items) + { + mCheckedItems = items; + } + + public boolean[] getCheckedItems() + { + return mCheckedItems; + } + +}