From f273805ee34ceb443cfdad64720ba61d9a6ede3b Mon Sep 17 00:00:00 2001 From: Matthew Brace Date: Thu, 11 Dec 2008 05:25:59 +0000 Subject: [PATCH] Added user preference for the display limit of messages. The display limit is also used for the visible limit increment. If no limit is specified, the default limit is used. The limit is also account specific and not global. --- res/layout/account_setup_options.xml | 10 + res/values/arrays.xml | 13 + res/values/strings.xml | 8 + res/xml/account_settings_preferences.xml | 6 + src/com/fsck/k9/Account.java | 22 ++ src/com/fsck/k9/MessagingController.java | 6 +- src/com/fsck/k9/R.java | 243 ++++++++++-------- .../fsck/k9/activity/FolderMessageList.java | 17 +- .../k9/activity/setup/AccountSettings.java | 16 ++ .../activity/setup/AccountSetupOptions.java | 23 ++ src/com/fsck/k9/k9.java | 4 +- src/com/fsck/k9/mail/Folder.java | 8 + src/com/fsck/k9/mail/store/LocalStore.java | 17 +- src/com/fsck/k9/mail/store/WebDavStore.java | 33 +-- 14 files changed, 282 insertions(+), 144 deletions(-) diff --git a/res/layout/account_setup_options.xml b/res/layout/account_setup_options.xml index 9f1b9753c..a6e67852b 100644 --- a/res/layout/account_setup_options.xml +++ b/res/layout/account_setup_options.xml @@ -14,6 +14,16 @@ android:id="@+id/account_check_frequency" android:layout_height="wrap_content" android:layout_width="fill_parent" /> + + 60 + + @string/account_setup_options_mail_display_count_10 + @string/account_setup_options_mail_display_count_25 + @string/account_setup_options_mail_display_count_50 + @string/account_setup_options_mail_display_count_100 + + + + 10 + 25 + 50 + 100 + diff --git a/res/values/strings.xml b/res/values/strings.xml index 0afe88c38..4601f1fd8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -217,6 +217,13 @@ Welcome to K-9 Mail setup. K-9 is an open source email client for Android based Send email from this account by default. Notify me when email arrives. + + Number of emails to display + 10 Messages + 25 Messages + 50 Messages + 100 Messages + Setup could not finish Username or password incorrect.\n(%s) Cannot safely connect to server.\n(%s) @@ -232,6 +239,7 @@ Welcome to K-9 Mail setup. K-9 is an open source email client for Android based Notify in status bar when email arrives Show combined Inbox Email check frequency + Number of emails to display Incoming settings Configure the incoming email server Outgoing settings diff --git a/res/xml/account_settings_preferences.xml b/res/xml/account_settings_preferences.xml index f82f484b2..962a98d19 100644 --- a/res/xml/account_settings_preferences.xml +++ b/res/xml/account_settings_preferences.xml @@ -33,6 +33,12 @@ android:entryValues="@array/account_settings_check_frequency_values" android:dialogTitle="@string/account_settings_mail_check_frequency_label" /> + displayCountsAdapter = new ArrayAdapter(this, + android.R.layout.simple_spinner_item, displayCounts); + displayCountsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + mDisplayCountView.setAdapter(displayCountsAdapter); + mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); boolean makeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false); @@ -77,6 +96,8 @@ public class AccountSetupOptions extends Activity implements OnClickListener { mNotifyView.setChecked(mAccount.isNotifyNewMail()); SpinnerOption.setSpinnerOptionValue(mCheckFrequencyView, mAccount .getAutomaticCheckIntervalMinutes()); + SpinnerOption.setSpinnerOptionValue(mDisplayCountView, mAccount + .getDisplayCount()); } private void onDone() { @@ -84,6 +105,8 @@ public class AccountSetupOptions extends Activity implements OnClickListener { mAccount.setNotifyNewMail(mNotifyView.isChecked()); mAccount.setAutomaticCheckIntervalMinutes((Integer)((SpinnerOption)mCheckFrequencyView .getSelectedItem()).value); + mAccount.setDisplayCount((Integer)((SpinnerOption)mDisplayCountView + .getSelectedItem()).value); mAccount.save(Preferences.getPreferences(this)); if (mDefaultView.isChecked()) { Preferences.getPreferences(this).setDefaultAccount(mAccount); diff --git a/src/com/fsck/k9/k9.java b/src/com/fsck/k9/k9.java index 6a6ad46ab..84bec0af7 100644 --- a/src/com/fsck/k9/k9.java +++ b/src/com/fsck/k9/k9.java @@ -85,12 +85,12 @@ public class k9 extends Application { * on each new folder and can be incremented with "Load more messages..." by the * VISIBLE_LIMIT_INCREMENT */ - public static final int DEFAULT_VISIBLE_LIMIT = 100; + public static int DEFAULT_VISIBLE_LIMIT = 25; /** * Number of additioanl messages to load when a user selectes "Load more messages..." */ - public static final int VISIBLE_LIMIT_INCREMENT = 100; + public static int VISIBLE_LIMIT_INCREMENT = 25; /** * The maximum size of an attachment we're willing to download (either View or Save) diff --git a/src/com/fsck/k9/mail/Folder.java b/src/com/fsck/k9/mail/Folder.java index 2f951e336..88d599a52 100644 --- a/src/com/fsck/k9/mail/Folder.java +++ b/src/com/fsck/k9/mail/Folder.java @@ -41,6 +41,14 @@ public abstract class Folder { public abstract boolean create(FolderType type) throws MessagingException; + /** + * Create a new folder with a specified display limit. Not abstract to allow + * remote folders to not override or worry about this call if they don't care to. + */ + public boolean create(FolderType type, int displayLimit) throws MessagingException { + return create(type); + } + public abstract boolean exists() throws MessagingException; /** diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 5075c53d0..1676cc622 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -242,8 +242,12 @@ public class LocalStore extends Store { } public void resetVisibleLimits() { + resetVisibleLimits(k9.DEFAULT_VISIBLE_LIMIT); + } + + public void resetVisibleLimits(int visibleLimit) { ContentValues cv = new ContentValues(); - cv.put("visible_limit", Integer.toString(k9.DEFAULT_VISIBLE_LIMIT)); + cv.put("visible_limit", Integer.toString(visibleLimit)); mDb.update("folders", cv, null, null); } @@ -405,6 +409,17 @@ public class LocalStore extends Store { return true; } + public boolean create(FolderType type, int visibleLimit) throws MessagingException { + if (exists()) { + throw new MessagingException("Folder " + mName + " already exists."); + } + mDb.execSQL("INSERT INTO folders (name, visible_limit) VALUES (?, ?)", new Object[] { + mName, + visibleLimit + }); + return true; + } + @Override public void close(boolean expunge) throws MessagingException { if (expunge) { diff --git a/src/com/fsck/k9/mail/store/WebDavStore.java b/src/com/fsck/k9/mail/store/WebDavStore.java index b90dae372..39ba2b3c5 100644 --- a/src/com/fsck/k9/mail/store/WebDavStore.java +++ b/src/com/fsck/k9/mail/store/WebDavStore.java @@ -774,24 +774,25 @@ public class WebDavStore extends Store { public Message[] getMessages(String[] uids, MessageRetrievalListener listener) throws MessagingException { ArrayList messageList = new ArrayList(); Message[] messages; - - if (uids == null) { - messages = getMessages(0, k9.DEFAULT_VISIBLE_LIMIT, listener); - } else { - for (int i = 0, count = uids.length; i < count; i++) { - if (listener != null) { - listener.messageStarted(uids[i], i, count); - } - WebDavMessage message = new WebDavMessage(uids[i], this); - messageList.add(message); - - if (listener != null) { - listener.messageFinished(message, i, count); - } - } - messages = messageList.toArray(new Message[] {}); + if (uids == null || + uids.length == 0) { + return messageList.toArray(new Message[] {}); } + + for (int i = 0, count = uids.length; i < count; i++) { + if (listener != null) { + listener.messageStarted(uids[i], i, count); + } + + WebDavMessage message = new WebDavMessage(uids[i], this); + messageList.add(message); + + if (listener != null) { + listener.messageFinished(message, i, count); + } + } + messages = messageList.toArray(new Message[] {}); return messages; }