Added the ability to completely wipe the localy cached messages of a syncced folder.

This commit is contained in:
Jesse Vincent 2010-11-14 00:49:25 +00:00
parent 32ea04a5b3
commit 675651286b
4 changed files with 63 additions and 0 deletions

View File

@ -24,6 +24,10 @@
android:id="@+id/folder_settings"
android:title="@string/folder_settings_action"
/>
<item
android:id="@+id/clear_local_folder"
android:title="@string/clear_local_folder_action"
/>
<item
android:id="@+id/expunge"
android:title="@string/expunge_action"

View File

@ -114,6 +114,7 @@
<string name="dump_settings_action">Dump settings</string>
<string name="empty_trash_action">Empty Trash</string>
<string name="expunge_action">Expunge</string>
<string name="clear_local_folder_action">Clear local messages</string>
<string name="set_sort_action">Choose sort</string>
<string name="reverse_sort_action">Reverse sort</string>
<string name="about_action">About</string>

View File

@ -31,6 +31,7 @@ import com.fsck.k9.helper.power.TracingPowerManager.TracingWakeLock;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.store.LocalStore.LocalFolder;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.service.MailService;
import java.util.ArrayList;
@ -538,6 +539,43 @@ public class FolderList extends K9ListActivity
MessagingController.getInstance(getApplication()).expunge(account, folderName, null);
}
private void onClearFolder(Account account, String folderName)
{
// There has to be a cheaper way to get at the localFolder object than this
LocalFolder localFolder = null;
try
{
if (account == null || folderName == null || !account.isAvailable(FolderList.this))
{
Log.i(K9.LOG_TAG, "not clear folder of unavailable account");
return;
}
localFolder = account.getLocalStore().getFolder(folderName);
localFolder.open(Folder.OpenMode.READ_WRITE);
if (localFolder != null)
{
localFolder.clearAllMessages();
}
}
catch (Exception e)
{
Log.e(K9.LOG_TAG, "Exception while clearing folder", e);
}
finally
{
if (localFolder != null)
{
localFolder.close();
}
}
}
private void sendMail(Account account)
{
MessagingController.getInstance(getApplication()).sendPendingMessages(account, mAdapter.mListener);
@ -675,6 +713,10 @@ public class FolderList extends K9ListActivity
onExpunge(mAccount, folder.name);
break;
case R.id.clear_local_folder:
onClearFolder(mAccount,folder.name);
break;
}
return super.onContextItemSelected(item);

View File

@ -3475,6 +3475,22 @@ public class LocalStore extends Store implements Serializable, LocalStoreMigrati
}
public void clearAllMessages() throws MessagingException
{
final String where = "folder_id = ?";
final String[] params = new String[]
{
Long.toString(mFolderId)
};
clearMessagesWhere(where, params);
setPushState(null);
setLastPush(0);
setLastChecked(0);
}
private void resetUnreadAndFlaggedCounts()
{
try