mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-30 23:00:09 -05:00
Fixes issue 939
Heavily inspired from Gmail implementation. Currently implemented only for MessageView delete operation.
This commit is contained in:
parent
842a5ee123
commit
9b285ae3fc
6
res/values/ids.xml
Normal file
6
res/values/ids.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<item type="id" name="dialog_confirm_delete"/>
|
||||
|
||||
</resources>
|
@ -319,6 +319,13 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
|
||||
<string name="global_settings_messageview_return_to_list_label">Return to list after delete</string>
|
||||
<string name="global_settings_messageview_return_to_list_summary">Return to message list after message deletion</string>
|
||||
|
||||
<string name="global_settings_confirm_actions_title">Confirm actions</string>
|
||||
<string name="global_settings_confirm_actions_summary">Show a dialog whenever you perform selected actions</string>
|
||||
<string name="global_settings_confirm_action_archive">Archive</string>
|
||||
<string name="global_settings_confirm_action_delete">Delete (message view only)</string>
|
||||
<string name="global_settings_confirm_action_spam">Spam</string>
|
||||
<string name="global_settings_confirm_action_send">Send</string>
|
||||
|
||||
<string name="account_setup_basics_title">Set up a new account</string>
|
||||
<string name="account_setup_basics_instructions">Enter this account\'s email address:</string>
|
||||
<string name="account_setup_basics_instructions2_fmt">(You may add <xliff:g id="number_accounts">%d</xliff:g> more accounts.)</string>
|
||||
@ -933,4 +940,10 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
|
||||
<string name="charset_not_found">This message can\'t be displayed because the charset \"<xliff:g id="charset">%s</xliff:g>\" wasn\'t found.</string>
|
||||
|
||||
<string name="select_text_now">Select text to copy.</string>
|
||||
|
||||
<string name="dialog_confirm_delete_title">Confirm deletion</string>
|
||||
<string name="dialog_confirm_delete_message">Do you want to delete this message?</string>
|
||||
<string name="dialog_confirm_delete_confirm_button">Delete</string>
|
||||
<string name="dialog_confirm_delete_cancel_button">Do not delete</string>
|
||||
|
||||
</resources>
|
||||
|
@ -70,6 +70,15 @@
|
||||
android:title="@string/start_integrated_inbox_title"
|
||||
android:summary="@string/start_integrated_inbox_summary" />
|
||||
|
||||
<com.fsck.k9.preferences.CheckboxListPreference
|
||||
android:key="confirm_actions"
|
||||
android:title="@string/global_settings_confirm_actions_title"
|
||||
android:summary="@string/global_settings_confirm_actions_summary"
|
||||
android:dialogTitle="@string/global_settings_confirm_actions_title"
|
||||
android:positiveButtonText="@android:string/ok"
|
||||
android:negativeButtonText="@android:string/cancel"
|
||||
/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/accountlist_preferences" android:key="accountlist_preferences">
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 <code>null</code>
|
||||
*/
|
||||
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;
|
||||
|
@ -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());
|
||||
|
84
src/com/fsck/k9/preferences/CheckboxListPreference.java
Normal file
84
src/com/fsck/k9/preferences/CheckboxListPreference.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user