Issue 364

Provide preference for which folder is automatically expanded when
entering the Folder/Message list.

Can be set to -NONE-, so that no folder is automatically expanded.

Defaults to Inbox, which is like the default behavior of the core
Android Email.

Fails to move the automatically opened folder to the top of the
screen.  This needs more work.

The already selected folder should be highlighted (or otherwise
indicated) in the ChooseFolder Activity.  This needs more work.
This commit is contained in:
Daniel Applebaum 2009-04-08 18:14:52 +00:00
parent f307bfc1eb
commit ee4ac07788
9 changed files with 216 additions and 66 deletions

View File

@ -263,7 +263,9 @@ Welcome to K-9 Mail setup. K-9 is an open source email client for Android based
<string name="account_setup_incoming_imap_folder_sent">Sent folder name</string>
<string name="account_setup_incoming_imap_folder_trash">Trash folder name</string>
<string name="account_setup_incoming_imap_folder_outbox">Outbox folder name</string>
<string name="account_setup_auto_expand_folder">Auto-expand folder</string>
<string name="account_setup_incoming_webdav_path_prefix_label">WebDav(Exchange) path</string>
<string name="account_setup_incoming_webdav_path_prefix_hint">Optional</string>

View File

@ -45,6 +45,13 @@
android:entryValues="@array/account_settings_hide_buttons_values"
android:dialogTitle="@string/account_settings_hide_buttons_label" />
<Preference
android:key="account_setup_auto_expand_folder"
android:singleLine="true"
android:title="@string/account_setup_auto_expand_folder"
android:summary=""
/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/account_settings_display_sync">

View File

@ -47,6 +47,7 @@ public class Account implements Serializable {
String mSentFolderName;
String mTrashFolderName;
String mOutboxFolderName;
String mAutoExpandFolderName;
FolderMode mFolderDisplayMode;
FolderMode mFolderSyncMode;
FolderMode mFolderTargetMode;
@ -128,6 +129,8 @@ public class Account implements Serializable {
"Trash");
mOutboxFolderName = preferences.mSharedPreferences.getString(mUuid + ".outboxFolderName",
"Outbox");
mAutoExpandFolderName = preferences.mSharedPreferences.getString(mUuid + ".autoExpandFolderName",
"Inbox");
mAccountNumber = preferences.mSharedPreferences.getInt(mUuid + ".accountNumber", 0);
mVibrate = preferences.mSharedPreferences.getBoolean(mUuid + ".vibrate", false);
@ -282,6 +285,7 @@ public class Account implements Serializable {
editor.remove(mUuid + ".sentFolderName");
editor.remove(mUuid + ".trashFolderName");
editor.remove(mUuid + ".outboxFolderName");
editor.remove(mUuid + ".autoExpandFolderName");
editor.remove(mUuid + ".accountNumber");
editor.remove(mUuid + ".vibrate");
editor.remove(mUuid + ".ringtone");
@ -349,6 +353,7 @@ public class Account implements Serializable {
editor.putString(mUuid + ".sentFolderName", mSentFolderName);
editor.putString(mUuid + ".trashFolderName", mTrashFolderName);
editor.putString(mUuid + ".outboxFolderName", mOutboxFolderName);
editor.putString(mUuid + ".autoExpandFolderName", mAutoExpandFolderName);
editor.putInt(mUuid + ".accountNumber", mAccountNumber);
editor.putBoolean(mUuid + ".vibrate", mVibrate);
editor.putString(mUuid + ".hideButtonsEnum", mHideMessageViewButtons.name());
@ -518,6 +523,14 @@ public class Account implements Serializable {
mOutboxFolderName = outboxFolderName;
}
public String getAutoExpandFolderName() {
return mAutoExpandFolderName;
}
public void setAutoExpandFolderName(String autoExpandFolderName) {
mAutoExpandFolderName = autoExpandFolderName;
}
public int getAccountNumber() {
return mAccountNumber;
}

View File

@ -93,6 +93,11 @@ public class Email extends Application {
* the server refers to as the user's Inbox. Placed here to ease use.
*/
public static final String INBOX = "INBOX";
/**
* For use when displaying that no folder is selected
*/
public static final String FOLDER_NONE = "-NONE-";
/**
* Specifies how many messages will be shown in a folder by default. This number is set

View File

@ -358,9 +358,7 @@ public class Accounts extends ListActivity implements OnItemClickListener, OnCli
}
private void onOpenAccount(Account account) {
//FolderMessageList.actionHandleAccount(this, account); // Dan's way
FolderMessageList.actionHandleAccount(this, account, Email.INBOX); // Everbody else's way
FolderMessageList.actionHandleAccount(this, account);
}
public void onClick(View view) {

View File

@ -36,12 +36,16 @@ public class ChooseFolder extends ListActivity
private ChooseFolderHandler mHandler = new ChooseFolderHandler();
String heldInbox = null;
boolean hideCurrentFolder = true;
boolean showOptionNone = false;
boolean showDisplayableOnly = false;
public static final String EXTRA_ACCOUNT = "com.android.email.ChooseFolder_account";
public static final String EXTRA_CUR_FOLDER = "com.android.email.ChooseFolder_curfolder";
public static final String EXTRA_NEW_FOLDER = "com.android.email.ChooseFolder_newfolder";
public static final String EXTRA_MESSAGE_UID = "com.android.email.ChooseFolder_messageuid";
public static final String EXTRA_SHOW_CURRENT = "com.android.email.ChooseFolder_showcurrent";
public static final String EXTRA_SHOW_FOLDER_NONE = "com.android.email.ChooseFolder_showOptionNone";
public static final String EXTRA_SHOW_DISPLAYABLE_ONLY = "com.android.email.ChooseFolder_showDisplayableOnly";
@Override
public void onCreate(Bundle savedInstanceState)
@ -60,6 +64,12 @@ public class ChooseFolder extends ListActivity
if (intent.getStringExtra(EXTRA_SHOW_CURRENT) != null) {
hideCurrentFolder = false;
}
if (intent.getStringExtra(EXTRA_SHOW_FOLDER_NONE) != null) {
showOptionNone = true;
}
if (intent.getStringExtra(EXTRA_SHOW_DISPLAYABLE_ONLY) != null) {
showDisplayableOnly = true;
}
if(mFolder == null)
mFolder = "";
@ -88,9 +98,7 @@ public class ChooseFolder extends ListActivity
{
destFolderName = heldInbox;
}
intent.putExtra(EXTRA_NEW_FOLDER, destFolderName);
intent.putExtra(EXTRA_MESSAGE_UID, mUID);
setResult(RESULT_OK, intent);
finish();
@ -105,6 +113,7 @@ public class ChooseFolder extends ListActivity
private static final int MSG_PROGRESS = 2;
private static final int MSG_DATA_CHANGED = 3;
private static final int MSG_SET_SELECTED_FOLDER = 4;
public void handleMessage(android.os.Message msg)
{
@ -115,6 +124,12 @@ public class ChooseFolder extends ListActivity
break;
case MSG_DATA_CHANGED:
adapter.notifyDataSetChanged();
break;
case MSG_SET_SELECTED_FOLDER:
// TODO: I want this to highlight the chosen folder, but this doesn't work.
// getListView().setSelection(msg.arg1);
// getListView().setItemChecked(msg.arg1, true);
break;
}
}
@ -125,6 +140,14 @@ public class ChooseFolder extends ListActivity
msg.arg1 = progress ? 1 : 0;
sendMessage(msg);
}
public void setSelectedFolder(int position)
{
android.os.Message msg = new android.os.Message();
msg.what = MSG_SET_SELECTED_FOLDER;
msg.arg1 = position;
sendMessage(msg);
}
public void dataChanged()
{
@ -169,7 +192,15 @@ public class ChooseFolder extends ListActivity
{
return;
}
Account.FolderMode aMode = account.getFolderTargetMode();
Account.FolderMode aMode = Account.FolderMode.ALL;
if (showDisplayableOnly)
{
aMode = account.getFolderDisplayMode();
}
else
{
aMode = account.getFolderTargetMode();
}
Preferences prefs = Preferences.getPreferences(getApplication().getApplicationContext());
ArrayList<String> localFolders = new ArrayList<String>();
@ -204,6 +235,11 @@ public class ChooseFolder extends ListActivity
}
if (showOptionNone)
{
localFolders.add("-NONE-");
}
Collections.sort(localFolders, new Comparator<String>() {
public int compare(String aName, String bName)
{
@ -215,11 +251,22 @@ public class ChooseFolder extends ListActivity
{
return 1;
}
if (Email.FOLDER_NONE.equalsIgnoreCase(aName))
{
return 1;
}
if (Email.FOLDER_NONE.equalsIgnoreCase(bName))
{
return -1;
}
return aName.compareToIgnoreCase(bName);
}
});
adapter.setNotifyOnChange(false);
adapter.clear();
int selectedFolder = -1;
int position = 0;
for (String name : localFolders) {
if (Email.INBOX.equalsIgnoreCase(name))
{
@ -229,8 +276,18 @@ public class ChooseFolder extends ListActivity
else {
adapter.add(name);
}
if((name.equals(mFolder) || (Email.INBOX.equalsIgnoreCase(mFolder) && Email.INBOX.equalsIgnoreCase(name)))) {
selectedFolder = position;
}
position++;
}
if (selectedFolder != -1)
{
mHandler.setSelectedFolder(selectedFolder);
}
mHandler.dataChanged();
}
};
}

View File

@ -1,14 +1,9 @@
package com.android.email.activity;
import java.lang.reflect.Array;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.EnumMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -46,12 +41,11 @@ import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import com.android.email.Account;
import com.android.email.Email;
import com.android.email.MessagingController;
import static com.android.email.MessagingController.SORT_TYPE;
import com.android.email.MessagingListener;
import com.android.email.Preferences;
import com.android.email.R;
import com.android.email.Utility;
import com.android.email.Preferences;
import com.android.email.activity.Accounts;
import com.android.email.MessagingController.SORT_TYPE;
import com.android.email.activity.FolderMessageList.FolderMessageListAdapter.FolderInfoHolder;
import com.android.email.activity.FolderMessageList.FolderMessageListAdapter.MessageInfoHolder;
import com.android.email.activity.setup.AccountSettings;
@ -61,13 +55,11 @@ import com.android.email.mail.Flag;
import com.android.email.mail.Folder;
import com.android.email.mail.Message;
import com.android.email.mail.MessagingException;
import com.android.email.mail.Part;
import com.android.email.mail.Store;
import com.android.email.mail.Message.RecipientType;
import com.android.email.mail.internet.MimeUtility;
import com.android.email.mail.store.LocalStore;
import com.android.email.mail.store.LocalStore.LocalFolder;
import com.android.email.mail.store.LocalStore.LocalMessage;
import com.android.email.mail.store.LocalStore;
/**
* FolderMessageList is the primary user interface for the program. This
@ -562,7 +554,12 @@ public class FolderMessageList extends ExpandableListActivity
if (savedInstanceState == null)
{
mInitialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
}
if (mInitialFolder == null)
{
mInitialFolder = mAccount.getAutoExpandFolderName();
}
}
/*
* Since the color chip is always the same color for a given account we just
@ -669,33 +666,34 @@ public class FolderMessageList extends ExpandableListActivity
}
@Override
public void onGroupExpand(int groupPosition)
{
super.onGroupExpand(groupPosition);
if (mExpandedGroup != -1)
{
mListView.collapseGroup(mExpandedGroup);
}
mExpandedGroup = groupPosition;
public void onGroupExpand(int groupPosition)
{
if (!mRestoringState)
{
/*
* Scroll the selected item to the top of the screen.
*/
int position = mListView.getFlatListPosition(ExpandableListView
.getPackedPositionForGroup(groupPosition));
mListView.setSelectionFromTop(position, 0);
}
Log.i(Email.LOG_TAG, "onGroupExpand(" + groupPosition + "), mRestoringState = " + mRestoringState);
super.onGroupExpand(groupPosition);
if (mExpandedGroup != -1)
{
mListView.collapseGroup(mExpandedGroup);
}
mExpandedGroup = groupPosition;
final FolderInfoHolder folder = (FolderInfoHolder) mAdapter
.getGroup(groupPosition);
if (folder.messages.size() == 0 || folder.needsRefresh)
{
folder.needsRefresh = false;
new Thread(new FolderUpdateWorker(folder.name, false)).start();
}
if (!mRestoringState)
{
/*
* Scroll the selected item to the top of the screen.
*/
int position = mListView.getFlatListPosition(ExpandableListView
.getPackedPositionForGroup(groupPosition));
mListView.setSelectionFromTop(position, 0);
}
final FolderInfoHolder folder = (FolderInfoHolder) mAdapter.getGroup(groupPosition);
if (folder.messages.size() == 0 || folder.needsRefresh)
{
folder.needsRefresh = false;
new Thread(new FolderUpdateWorker(folder.name, false)).start();
}
}
@ -1456,23 +1454,25 @@ public class FolderMessageList extends ExpandableListActivity
}
@Override
public void listFoldersFinished(Account account)
{
if (!account.equals(mAccount))
{
return;
public void listFoldersFinished(Account account)
{
if (!account.equals(mAccount))
{
return;
}
mHandler.progress(false);
mHandler.dataChanged();
if (mInitialFolder != null && Email.FOLDER_NONE.equals(mInitialFolder) == false)
{
int groupPosition = getFolderPosition(mInitialFolder);
mInitialFolder = null;
if (groupPosition != -1)
{
mHandler.expandGroup(groupPosition);
}
mHandler.progress(false);
if (mInitialFolder != null)
{
int groupPosition = getFolderPosition(mInitialFolder);
mInitialFolder = null;
if (groupPosition != -1)
{
mHandler.expandGroup(groupPosition);
}
}
mHandler.dataChanged();
}
}
@Override
public void accountReset(Account account)

View File

@ -6,20 +6,28 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.preference.PreferenceActivity;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.preference.RingtonePreference;
import android.preference.Preference.OnPreferenceClickListener;
import com.android.email.Account;
import com.android.email.Email;
import com.android.email.Preferences;
import com.android.email.R;
import com.android.email.activity.ChooseFolder;
public class AccountSettings extends PreferenceActivity {
private static final String EXTRA_ACCOUNT = "account";
private static final int SELECT_AUTO_EXPAND_FOLDER = 1;
private static final String PREFERENCE_TOP_CATERGORY = "account_settings";
private static final String PREFERENCE_DESCRIPTION = "account_description";
@ -38,6 +46,7 @@ public class AccountSettings extends PreferenceActivity {
private static final String PREFERENCE_SYNC_MODE = "folder_sync_mode";
private static final String PREFERENCE_TARGET_MODE = "folder_target_mode";
private static final String PREFERENCE_DELETE_POLICY = "delete_policy";
private static final String PREFERENCE_AUTO_EXPAND_FOLDER = "account_setup_auto_expand_folder";
private Account mAccount;
@ -54,6 +63,7 @@ public class AccountSettings extends PreferenceActivity {
private ListPreference mSyncMode;
private ListPreference mTargetMode;
private ListPreference mDeletePolicy;
private Preference mAutoExpandFolder;
public static void actionSettings(Context context, Account account) {
Intent i = new Intent(context, AccountSettings.class);
@ -196,7 +206,18 @@ public class AccountSettings extends PreferenceActivity {
mAccountVibrate = (CheckBoxPreference) findPreference(PREFERENCE_VIBRATE);
mAccountVibrate.setChecked(mAccount.isVibrate());
mAutoExpandFolder = (Preference)findPreference(PREFERENCE_AUTO_EXPAND_FOLDER);
mAutoExpandFolder.setSummary(translateFolder(mAccount.getAutoExpandFolderName()));
mAutoExpandFolder.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
onChooseAutoExpandFolder();
return false;
}
});
findPreference(PREFERENCE_COMPOSITION).setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
@ -245,10 +266,22 @@ public class AccountSettings extends PreferenceActivity {
SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
mAccount.setRingtone(prefs.getString(PREFERENCE_RINGTONE, null));
mAccount.setHideMessageViewButtons(Account.HideButtons.valueOf(mAccountHideButtons.getValue()));
mAccount.setAutoExpandFolderName(reverseTranslateFolder(mAutoExpandFolder.getSummary().toString()));
mAccount.save(Preferences.getPreferences(this));
Email.setServicesEnabled(this);
// TODO: refresh folder list here
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case SELECT_AUTO_EXPAND_FOLDER:
mAutoExpandFolder.setSummary(translateFolder(data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER)));
return;
}
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
@ -270,4 +303,43 @@ public class AccountSettings extends PreferenceActivity {
AccountSetupOutgoing.actionEditOutgoingSettings(this, mAccount);
}
public void onChooseAutoExpandFolder()
{
Intent selectIntent = new Intent(this, ChooseFolder.class);
selectIntent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount);
selectIntent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mAutoExpandFolder.getSummary());
selectIntent.putExtra(ChooseFolder.EXTRA_SHOW_CURRENT, "yes");
selectIntent.putExtra(ChooseFolder.EXTRA_SHOW_FOLDER_NONE, "yes");
selectIntent.putExtra(ChooseFolder.EXTRA_SHOW_DISPLAYABLE_ONLY, "yes");
startActivityForResult(selectIntent, SELECT_AUTO_EXPAND_FOLDER);
}
private String translateFolder(String in)
{
if (Email.INBOX.equalsIgnoreCase(in))
{
return getString(R.string.special_mailbox_name_inbox);
}
else
{
return in;
}
}
private String reverseTranslateFolder(String in)
{
if (getString(R.string.special_mailbox_name_inbox).equals(in))
{
return Email.INBOX;
}
else
{
return in;
}
}
}

View File

@ -272,12 +272,8 @@ public class MailService extends Service {
if (unreadMessageCount > 0)
{
notif.number = unreadMessageCount;
// Dan's way
//Intent i = FolderMessageList.actionHandleAccountIntent(context, thisAccount);
// Everybody else's way
Intent i = FolderMessageList.actionHandleAccountIntent(context, thisAccount, Email.INBOX);
Intent i = FolderMessageList.actionHandleAccountIntent(context, thisAccount);
PendingIntent pi = PendingIntent.getActivity(context, 0, i, 0);