From dedecedfe472bf0e79434dd93091929cc2895de2 Mon Sep 17 00:00:00 2001 From: ashley willis Date: Mon, 9 Jan 2012 02:30:06 -0600 Subject: [PATCH] IMAP folder creation. --- res/menu/folder_list_option.xml | 4 ++ res/menu/folder_select_option.xml | 4 ++ res/values/strings.xml | 1 + src/com/fsck/k9/activity/ChooseFolder.java | 74 ++++++++++++++++++++-- src/com/fsck/k9/activity/FolderList.java | 56 +++++++++++++++- src/com/fsck/k9/mail/store/ImapStore.java | 5 ++ 6 files changed, 136 insertions(+), 8 deletions(-) diff --git a/res/menu/folder_list_option.xml b/res/menu/folder_list_option.xml index 6af522cfd..b5e27039d 100644 --- a/res/menu/folder_list_option.xml +++ b/res/menu/folder_list_option.xml @@ -40,6 +40,10 @@ android:id="@+id/filter_folders" android:title="@string/filter_folders_action" android:icon="@drawable/ic_menu_search" + /> + diff --git a/res/menu/folder_select_option.xml b/res/menu/folder_select_option.xml index 8b9d7a240..36142cbb2 100644 --- a/res/menu/folder_select_option.xml +++ b/res/menu/folder_select_option.xml @@ -36,6 +36,10 @@ android:title="@string/filter_folders_action" android:icon="@drawable/ic_menu_search" /> + diff --git a/res/values/strings.xml b/res/values/strings.xml index 5e31de571..75e58c81e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -73,6 +73,7 @@ Folder list Refresh folders Find folder + Create folder Mark all messages as read Add account Compose diff --git a/src/com/fsck/k9/activity/ChooseFolder.java b/src/com/fsck/k9/activity/ChooseFolder.java index dc4a88115..958f776d0 100644 --- a/src/com/fsck/k9/activity/ChooseFolder.java +++ b/src/com/fsck/k9/activity/ChooseFolder.java @@ -19,12 +19,19 @@ import android.widget.EditText; import android.widget.Filter; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import com.fsck.k9.*; import com.fsck.k9.Account.FolderMode; import com.fsck.k9.controller.MessagingController; import com.fsck.k9.controller.MessagingListener; import com.fsck.k9.mail.Folder; import com.fsck.k9.mail.MessagingException; +import com.fsck.k9.mail.Store; +import com.fsck.k9.mail.store.ImapStore; +import com.fsck.k9.mail.store.LocalStore; +import com.fsck.k9.mail.store.LocalStore.LocalFolder; +import com.fsck.k9.mail.store.Pop3Store; +import com.fsck.k9.mail.store.WebDavStore; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -106,7 +113,7 @@ public class ChooseFolder extends K9ListActivity { mMode = mAccount.getFolderTargetMode(); - MessagingController.getInstance(getApplication()).listFolders(mAccount, false, mListener); + onRefresh(false); this.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { @@ -204,13 +211,16 @@ public class ChooseFolder extends K9ListActivity { case R.id.list_folders: { onRefresh(); - return true; } case R.id.filter_folders: { - onEnterFilter(); - } + onEnterFilter(); return true; + } + case R.id.create_folder: { + onCreateFolder(); + return true; + } default: return super.onOptionsItemSelected(item); } @@ -219,7 +229,13 @@ public class ChooseFolder extends K9ListActivity { private void onRefresh() { - MessagingController.getInstance(getApplication()).listFolders(mAccount, true, mListener); + onRefresh(true); + + } + + private void onRefresh(final boolean forceRemote) { + + MessagingController.getInstance(getApplication()).listFolders(mAccount, forceRemote, mListener); } @@ -268,6 +284,51 @@ public class ChooseFolder extends K9ListActivity { } + /* + Show a dialog to create a new folder on the remote Store. + Currently only IMAP is supported. + Exactly the same as activity.FolderList.onCreateFolder(). + */ + private void onCreateFolder() { + final EditText input = new EditText(this); + AlertDialog.Builder dialog = new AlertDialog.Builder(this); + dialog.setTitle(R.string.create_folder_action); + dialog.setView(input); + dialog.setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + String folderName = input.getText().toString().trim(); + try { + Store store = mAccount.getRemoteStore(); + if (store instanceof ImapStore) { + boolean result = ((ImapStore)store).createFolder(folderName); + String toastText = "Creation of folder \"" + folderName + + ((result) ? "\" succeeded." : "\" failed."); + Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG).show(); + onRefresh(result); + onRefresh(false); // NEW + } else if (store instanceof WebDavStore) { + String toastText = "Creating WebDav Folders not currently implemented."; + Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG).show(); + } else if (store instanceof Pop3Store) { + String toastText = "Creating Local Folders not currently implemented."; + Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG).show(); + } else { + Log.d(K9.LOG_TAG, "Unhandled store type " + store.getClass()); + } + } catch (com.fsck.k9.mail.MessagingException me) { + Log.e(K9.LOG_TAG, "MessagingException trying to create new folder \"" + + folderName + "\": " + me); + } + } + }); + dialog.setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + /* User clicked cancel so do some stuff */ + } + }); + dialog.show(); + } + private void setDisplayMode(FolderMode aMode) { mMode = aMode; // invalidate the current filter as it is working on an inval @@ -275,8 +336,7 @@ public class ChooseFolder extends K9ListActivity { myFilter.invalidate(); } //re-populate the list - MessagingController.getInstance(getApplication()).listFolders(mAccount, - false, mListener); + onRefresh(false); } private MessagingListener mListener = new MessagingListener() { diff --git a/src/com/fsck/k9/activity/FolderList.java b/src/com/fsck/k9/activity/FolderList.java index e225c8689..f8cabb500 100644 --- a/src/com/fsck/k9/activity/FolderList.java +++ b/src/com/fsck/k9/activity/FolderList.java @@ -35,7 +35,12 @@ 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; +import com.fsck.k9.mail.store.ImapStore; +import com.fsck.k9.mail.store.LocalStore; import com.fsck.k9.mail.store.LocalStore.LocalFolder; +import com.fsck.k9.mail.store.Pop3Store; +import com.fsck.k9.mail.store.WebDavStore; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.service.MailService; import java.util.ArrayList; @@ -469,6 +474,50 @@ public class FolderList extends K9ListActivity { } + /* + Show a dialog to create a new folder on the remote Store. + Currently only IMAP is supported. + Exactly the same as activity.ChooseFolder.onCreateFolder(). + */ + private void onCreateFolder() { + final EditText input = new EditText(this); + AlertDialog.Builder dialog = new AlertDialog.Builder(this); + dialog.setTitle(R.string.create_folder_action); + dialog.setView(input); + dialog.setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + String folderName = input.getText().toString().trim(); + try { + Store store = mAccount.getRemoteStore(); + if (store instanceof ImapStore) { + boolean result = ((ImapStore)store).createFolder(folderName); + String toastText = "Creation of folder \"" + folderName + + ((result) ? "\" succeeded." : "\" failed."); + Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG).show(); + onRefresh(result); + } else if (store instanceof WebDavStore) { + String toastText = "Creating WebDav Folders not currently implemented."; + Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG).show(); + } else if (store instanceof Pop3Store) { + String toastText = "Creating Local Folders not currently implemented."; + Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG).show(); + } else { + Log.d(K9.LOG_TAG, "Unhandled store type " + store.getClass()); + } + } catch (com.fsck.k9.mail.MessagingException me) { + Log.e(K9.LOG_TAG, "MessagingException trying to create new folder \"" + + folderName + "\": " + me); + } + } + }); + dialog.setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + /* User clicked cancel so do some stuff */ + } + }); + dialog.show(); + } + private void onEditPrefs() { Prefs.actionPrefs(this); } @@ -552,7 +601,12 @@ public class FolderList extends K9ListActivity { return true; case R.id.filter_folders: - onEnterFilter(); + onEnterFilter(); + + return true; + + case R.id.create_folder: + onCreateFolder(); return true; diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index cbd298002..f99ca3256 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -787,6 +787,11 @@ public class ImapStore extends Store { } } + public boolean createFolder(String name) throws com.fsck.k9.mail.MessagingException { + ImapFolder folder = new ImapFolder(this, name); + return folder.create(null); + } + @Override public boolean isMoveCapable() { return true;