Fixes Issue 1474

Fixes Issue 1562

Issue 1474:
Provide new facility to totally wipe all data for an account but leave
settings intact.  This is useful because sometimes storage is so full
that SQLite cannot perform the usual VACUUM or message deletion.

Add confirmation dialogs to destructive Clear and Recreate operations.

Remove destructive Clear from FolderList so as not to have to
duplicate the confirmation dialogs.

Issue 1562:
Suppress notifications when new messages arrive in Trash, Sent or
Drafts special folders.
This commit is contained in:
Daniel Applebaum 2010-05-12 04:17:52 +00:00
parent 337d785cd2
commit 8b92bc3836
7 changed files with 149 additions and 24 deletions

View File

@ -15,6 +15,8 @@
android:title="@string/compact_action" />
<item android:id="@+id/clear"
android:title="@string/clear_action" />
<item android:id="@+id/recreate"
android:title="@string/recreate_action" />
<item android:id="@+id/delete_account"
android:title="@string/remove_account_action" />
<item android:id="@+id/clear_pending"

View File

@ -74,11 +74,6 @@
android:title="@string/compact_action"
android:icon="@drawable/ic_menu_compact"
/>
<item
android:id="@+id/clear"
android:title="@string/clear_action"
android:icon="@drawable/ic_menu_clear"
/>
</menu>
</item>

View File

@ -139,6 +139,7 @@
<string name="compacting_account">Compacting account \"<xliff:g id="account">%s</xliff:g>\"</string>
<string name="clearing_account">Clearing account \"<xliff:g id="account">%s</xliff:g>\"</string>
<string name="recreating_account">Recreating account \"<xliff:g id="account">%s</xliff:g>\"</string>
<string name="notification_new_title">New mail</string>
<string name="notification_new_scrolling">New mail from <xliff:g id="sender">%s</xliff:g></string>
@ -388,7 +389,8 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="account_setup_options_title">Account options</string>
<string name="compact_action">Compact</string>
<string name="clear_action">Clear all data (danger!)</string>
<string name="clear_action">Clear messages (danger!)</string>
<string name="recreate_action">Recreate data (Last Resort!)</string>
<string name="account_setup_options_mail_check_frequency_label">Folder poll check frequency</string>
<!-- Frequency also used in account_settings_* -->
@ -604,9 +606,15 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="sort_by_attach">Attachments</string>
<string name="message_web_view_error">%s</string>
<string name="account_delete_dlg_title">Remove</string>
<string name="account_delete_dlg_instructions_fmt">The account \"<xliff:g id="account">%s</xliff:g>\" will be removed from K-9.</string>
<string name="account_delete_dlg_title">Remove Account</string>
<string name="account_delete_dlg_instructions_fmt">The account \"<xliff:g id="account">%s</xliff:g>\" will be removed from K-9 Mail.</string>
<string name="account_recreate_dlg_title">Recreate Account</string>
<string name="account_recreate_dlg_instructions_fmt">All data for \"<xliff:g id="account">%s</xliff:g>\" will be removed from K-9 Mail, but account settings will be retained.</string>
<string name="account_clear_dlg_title">Clear Account</string>
<string name="account_clear_dlg_instructions_fmt">All messages in \"<xliff:g id="account">%s</xliff:g>\" will be removed from K-9 Mail, but account settings will be retained.</string>
<string name="provider_note_yahoo">Free Yahoo! Mail accounts only work over T-Mobile wireless networks. Yahoo! Mail Plus users should configure POP settings manually.</string>
<string name="provider_note_live">Only some \"Plus\" accounts include POP access
allowing this program to connect. If you are not able to sign in with

View File

@ -4382,7 +4382,43 @@ public class MessagingController implements Runnable
}
catch (Exception e)
{
Log.e(K9.LOG_TAG, "Failed to compact account " + account.getDescription(), e);
Log.e(K9.LOG_TAG, "Failed to clear account " + account.getDescription(), e);
}
}
});
}
public void recreate(final Account account, final MessagingListener ml)
{
putBackground("recreate:" + account.getDescription(), ml, new Runnable()
{
public void run()
{
try
{
LocalStore localStore = account.getLocalStore();
long oldSize = localStore.getSize();
localStore.recreate();
localStore.resetVisibleLimits(account.getDisplayCount());
long newSize = localStore.getSize();
AccountStats stats = new AccountStats();
stats.size = newSize;
stats.unreadMessageCount = 0;
stats.flaggedMessageCount = 0;
if (ml != null)
{
ml.accountSizeChanged(account, oldSize, newSize);
ml.accountStatusChanged(account, stats);
}
for (MessagingListener l : getListeners())
{
l.accountSizeChanged(account, oldSize, newSize);
l.accountStatusChanged(account, stats);
}
}
catch (Exception e)
{
Log.e(K9.LOG_TAG, "Failed to recreate account " + account.getDescription(), e);
}
}
});
@ -4399,6 +4435,18 @@ public class MessagingController implements Runnable
{
return false;
}
Folder folder = message.getFolder();
if (folder != null)
{
String folderName = folder.getName();
if (account.getTrashFolderName().equals(folderName)
|| account.getDraftsFolderName().equals(folderName)
|| account.getSentFolderName().equals(folderName))
{
return false;
}
}
// If we have a message, set the notification to "<From>: <Subject>"
StringBuffer messageNotice = new StringBuffer();

View File

@ -35,6 +35,8 @@ import java.util.concurrent.ConcurrentHashMap;
public class Accounts extends K9ListActivity implements OnItemClickListener, OnClickListener
{
private static final int DIALOG_REMOVE_ACCOUNT = 1;
private static final int DIALOG_CLEAR_ACCOUNT = 2;
private static final int DIALOG_RECREATE_ACCOUNT = 3;
private ConcurrentHashMap<String, AccountStats> accountStats = new ConcurrentHashMap<String, AccountStats>();
private ConcurrentHashMap<BaseAccount, String> pendingWork = new ConcurrentHashMap<BaseAccount, String>();
@ -526,6 +528,10 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
{
case DIALOG_REMOVE_ACCOUNT:
return createRemoveAccountDialog();
case DIALOG_CLEAR_ACCOUNT:
return createClearAccountDialog();
case DIALOG_RECREATE_ACCOUNT:
return createRecreateAccountDialog();
}
return super.onCreateDialog(id);
}
@ -584,6 +590,64 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
})
.create();
}
private Dialog createClearAccountDialog()
{
return new AlertDialog.Builder(this)
.setTitle(R.string.account_clear_dlg_title)
.setMessage(getString(R.string.account_clear_dlg_instructions_fmt, mSelectedContextAccount.getDescription()))
.setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
dismissDialog(DIALOG_CLEAR_ACCOUNT);
if (mSelectedContextAccount instanceof Account)
{
Account realAccount = (Account)mSelectedContextAccount;
mHandler.workingAccount(realAccount, R.string.clearing_account);
MessagingController.getInstance(getApplication()).clear(realAccount, null);
}
}
})
.setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
dismissDialog(DIALOG_CLEAR_ACCOUNT);
}
})
.create();
}
private Dialog createRecreateAccountDialog()
{
return new AlertDialog.Builder(this)
.setTitle(R.string.account_recreate_dlg_title)
.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt, mSelectedContextAccount.getDescription()))
.setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
dismissDialog(DIALOG_RECREATE_ACCOUNT);
if (mSelectedContextAccount instanceof Account)
{
Account realAccount = (Account)mSelectedContextAccount;
mHandler.workingAccount(realAccount, R.string.recreating_account);
MessagingController.getInstance(getApplication()).recreate(realAccount, null);
}
}
})
.setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
dismissDialog(DIALOG_RECREATE_ACCOUNT);
}
})
.create();
}
@Override
public boolean onContextItemSelected(MenuItem item)
@ -626,6 +690,9 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
case R.id.clear:
onClear(realAccount);
break;
case R.id.recreate:
onRecreate(realAccount);
break;
}
return true;
}
@ -640,8 +707,12 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
private void onClear(Account account)
{
mHandler.workingAccount(account, R.string.clearing_account);
MessagingController.getInstance(getApplication()).clear(account, null);
showDialog(DIALOG_CLEAR_ACCOUNT);
}
private void onRecreate(Account account)
{
showDialog(DIALOG_RECREATE_ACCOUNT);
}

View File

@ -509,10 +509,6 @@ public class FolderList extends K9ListActivity
return true;
case R.id.clear:
onClear(mAccount);
return true;
case R.id.display_1st_class:
{
setDisplayMode(FolderMode.FIRST_CLASS);
@ -549,12 +545,6 @@ public class FolderList extends K9ListActivity
MessagingController.getInstance(getApplication()).compact(account, null);
}
private void onClear(Account account)
{
mHandler.workingAccount(R.string.clearing_account);
MessagingController.getInstance(getApplication()).clear(account, null);
}
@Override public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);

View File

@ -90,6 +90,12 @@ public class LocalStore extends Store implements Serializable
String[] tokens = dbFile.getName().split("\\.");
uUid = tokens[0];
openOrCreateDataspace(application);
}
private void openOrCreateDataspace(Application application)
{
File parentDir = new File(mPath).getParentFile();
if (!parentDir.exists())
{
@ -106,8 +112,7 @@ public class LocalStore extends Store implements Serializable
if (mDb.getVersion() != DB_VERSION)
{
doDbUpgrade(mDb, application);
}
}
}
private void doDbUpgrade(SQLiteDatabase mDb, Application application)
@ -437,6 +442,12 @@ public class LocalStore extends Store implements Serializable
}
}
public void recreate()
{
delete();
openOrCreateDataspace(mApplication);
}
public void pruneCachedAttachments() throws MessagingException
{