diff --git a/res/values/strings.xml b/res/values/strings.xml index 4f783a42a..321259db4 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -366,6 +366,7 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin Mark read/unread Delete Move to archive + No archive folders. Move Flag Unselect diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index 8f18700ba..d69d2ee55 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -827,11 +827,12 @@ public class MessageList mController.addListener(mAdapter.mListener); + final Preferences preferences = Preferences.getPreferences(this); + Account[] accountsWithNotification; if (mAccount != null) { accountsWithNotification = new Account[] { mAccount }; } else { - Preferences preferences = Preferences.getPreferences(this); accountsWithNotification = preferences.getAccounts(); } @@ -842,8 +843,32 @@ public class MessageList if (mAdapter.messages.isEmpty()) { if (mFolderName != null) { mController.listLocalMessages(mAccount, mFolderName, mAdapter.mListener); + // Hide the archive button if we don't have an archive folder. + if (!mAccount.hasArchiveFolder()) { + mBatchArchiveButton.setVisibility(View.GONE); + } } else if (mQueryString != null) { mController.searchLocalMessages(mAccountUuids, mFolderNames, null, mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags, mAdapter.mListener); + boolean hasArchiveFolder = false; + if(mAccountUuids == null) { + for (final Account acct : preferences.getAccounts()) { + if (acct != null && acct.hasArchiveFolder()) { + hasArchiveFolder = true; + break; + } + } + } else { + for (final String accountUuid : mAccountUuids) { + final Account acct = preferences.getAccount(accountUuid); + if (acct != null && acct.hasArchiveFolder()) { + hasArchiveFolder = true; + break; + } + } + } + if (!hasArchiveFolder) { + mBatchArchiveButton.setVisibility(View.GONE); + } } } else { diff --git a/src/com/fsck/k9/activity/setup/Prefs.java b/src/com/fsck/k9/activity/setup/Prefs.java index 2aa0fcd29..0325cff70 100644 --- a/src/com/fsck/k9/activity/setup/Prefs.java +++ b/src/com/fsck/k9/activity/setup/Prefs.java @@ -19,6 +19,7 @@ import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.widget.Toast; +import com.fsck.k9.Account; import com.fsck.k9.K9; import com.fsck.k9.Preferences; import com.fsck.k9.R; @@ -365,7 +366,20 @@ public class Prefs extends K9PreferenceActivity { mBatchButtonsArchive.setChecked(K9.batchButtonsArchive()); mBatchButtonsMove.setChecked(K9.batchButtonsMove()); mBatchButtonsFlag.setChecked(K9.batchButtonsFlag()); - mBatchButtonsUnselect.setChecked(K9.batchButtonsUnselect()); + mBatchButtonsUnselect.setChecked(K9.batchButtonsUnselect()); + + // If we don't have any accounts with an archive folder, then don't enable the preference. + boolean hasArchiveFolder = false; + for(final Account acct : Preferences.getPreferences(this).getAccounts()) { + if(acct.hasArchiveFolder()) { + hasArchiveFolder = true; + break; + } + } + if(!hasArchiveFolder) { + mBatchButtonsArchive.setEnabled(false); + mBatchButtonsArchive.setSummary(R.string.global_settings_archive_disabled_reason); + } } private void saveSettings() {