1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-17 06:55:03 -05:00

IMAP folder creation.

This commit is contained in:
ashley willis 2012-01-09 02:30:06 -06:00
parent ffa77ad288
commit dedecedfe4
6 changed files with 136 additions and 8 deletions

View File

@ -40,6 +40,10 @@
android:id="@+id/filter_folders"
android:title="@string/filter_folders_action"
android:icon="@drawable/ic_menu_search"
/>
<item
android:id="@+id/create_folder"
android:title="@string/create_folder_action"
/>
</menu>

View File

@ -36,6 +36,10 @@
android:title="@string/filter_folders_action"
android:icon="@drawable/ic_menu_search"
/>
<item
android:id="@+id/create_folder"
android:title="@string/create_folder_action"
/>
<!-- </menu>
</item>-->

View File

@ -73,6 +73,7 @@
<string name="list_folders_action">Folder list</string>
<string name="refresh_folders_action">Refresh folders</string>
<string name="filter_folders_action">Find folder</string>
<string name="create_folder_action">Create folder</string>
<string name="mark_all_as_read_action">Mark all messages as read</string>
<string name="add_account_action">Add account</string>
<string name="compose_action">Compose</string>

View File

@ -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();
}
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() {

View File

@ -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);
}
@ -556,6 +605,11 @@ public class FolderList extends K9ListActivity {
return true;
case R.id.create_folder:
onCreateFolder();
return true;
case R.id.account_settings:
onEditAccount();

View File

@ -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;