1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

move folderlist initialization into an asynctask, so it's not so slow to populate

This commit is contained in:
Jesse Vincent 2010-12-24 22:48:29 +00:00
parent b99eb47d15
commit db7649c9af

View File

@ -4,6 +4,7 @@ package com.fsck.k9.activity.setup;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Vibrator; import android.os.Vibrator;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
@ -573,8 +574,7 @@ public class AccountSettings extends K9PreferenceActivity
mNotificationOpensUnread = (CheckBoxPreference)findPreference(PREFERENCE_NOTIFICATION_OPENS_UNREAD); mNotificationOpensUnread = (CheckBoxPreference)findPreference(PREFERENCE_NOTIFICATION_OPENS_UNREAD);
mNotificationOpensUnread.setChecked(mAccount.goToUnreadMessageSearch()); mNotificationOpensUnread.setChecked(mAccount.goToUnreadMessageSearch());
populateFolderPreferences(); new PopulateFolderPrefsTask().execute();
mChipColor = findPreference(PREFERENCE_CHIP_COLOR); mChipColor = findPreference(PREFERENCE_CHIP_COLOR);
mChipColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() mChipColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
@ -901,54 +901,82 @@ public class AccountSettings extends K9PreferenceActivity
Integer.parseInt(mAccountVibratePattern.getValue()), Integer.parseInt(mAccountVibratePattern.getValue()),
Integer.parseInt(mAccountVibrateTimes.getValue())), -1); Integer.parseInt(mAccountVibrateTimes.getValue())), -1);
} }
private void populateFolderPreferences() {
private class PopulateFolderPrefsTask extends AsyncTask<Void, Void, Void>
{
List<? extends Folder> folders = new LinkedList<LocalFolder>(); List<? extends Folder> folders = new LinkedList<LocalFolder>();
try String[] allFolderValues;
String[] allFolderLabels;
protected Void doInBackground(Void... params)
{ {
folders = mAccount.getLocalStore().getPersonalNamespaces(false); try
} {
catch (Exception e) folders = mAccount.getLocalStore().getPersonalNamespaces(false);
{ }
/// this can't be checked in catch (Exception e)
} {
final String[] allFolderValues = new String[folders.size()+2]; /// this can't be checked in
final String[] allFolderLabels = new String[folders.size()+2]; }
allFolderValues[0] = K9.FOLDER_NONE; allFolderValues = new String[folders.size()+2];
allFolderLabels[0] = K9.FOLDER_NONE; allFolderLabels = new String[folders.size()+2];
// There's a non-zero chance that "outbox" won't actually exist, so we force it into the list allFolderValues[0] = K9.FOLDER_NONE;
allFolderValues[1] = mAccount.getOutboxFolderName(); allFolderLabels[0] = K9.FOLDER_NONE;
allFolderLabels[1] = mAccount.getOutboxFolderName();
// There's a non-zero chance that "outbox" won't actually exist, so we force it into the list
allFolderValues[1] = mAccount.getOutboxFolderName();
allFolderLabels[1] = mAccount.getOutboxFolderName();
int i =2; int i =2;
for (Folder folder : folders) for (Folder folder : folders)
{ {
allFolderLabels[i] = folder.getName(); allFolderLabels[i] = folder.getName();
allFolderValues[i] = folder.getName(); allFolderValues[i] = folder.getName();
i++; i++;
}
return null;
} }
mAutoExpandFolder = (ListPreference)findPreference(PREFERENCE_AUTO_EXPAND_FOLDER);
initListPreference(mAutoExpandFolder, mAccount.getAutoExpandFolderName(), allFolderLabels,allFolderValues);
mArchiveFolder = (ListPreference)findPreference(PREFERENCE_ARCHIVE_FOLDER); protected void onPreExecute()
initListPreference(mArchiveFolder, mAccount.getArchiveFolderName(), allFolderLabels,allFolderValues); {
mAutoExpandFolder = (ListPreference)findPreference(PREFERENCE_AUTO_EXPAND_FOLDER);
mAutoExpandFolder.setEnabled(false);
mArchiveFolder = (ListPreference)findPreference(PREFERENCE_ARCHIVE_FOLDER);
mArchiveFolder.setEnabled(false);
mDraftsFolder = (ListPreference)findPreference(PREFERENCE_DRAFTS_FOLDER);
mDraftsFolder.setEnabled(false);
mOutboxFolder = (ListPreference)findPreference(PREFERENCE_OUTBOX_FOLDER);
mOutboxFolder.setEnabled(false);
mSentFolder = (ListPreference)findPreference(PREFERENCE_SENT_FOLDER);
mSentFolder.setEnabled(false);
mSpamFolder = (ListPreference)findPreference(PREFERENCE_SPAM_FOLDER);
mSpamFolder.setEnabled(false);
mTrashFolder = (ListPreference)findPreference(PREFERENCE_TRASH_FOLDER);
mTrashFolder.setEnabled(false);
mDraftsFolder = (ListPreference)findPreference(PREFERENCE_DRAFTS_FOLDER); }
initListPreference(mDraftsFolder, mAccount.getDraftsFolderName(), allFolderLabels,allFolderValues); protected void onPostExecute(Void res)
{
initListPreference(mAutoExpandFolder, mAccount.getAutoExpandFolderName(), allFolderLabels,allFolderValues);
initListPreference(mArchiveFolder, mAccount.getArchiveFolderName(), allFolderLabels,allFolderValues);
initListPreference(mDraftsFolder, mAccount.getDraftsFolderName(), allFolderLabels,allFolderValues);
initListPreference(mOutboxFolder, mAccount.getOutboxFolderName(), allFolderLabels,allFolderValues);
initListPreference(mSentFolder, mAccount.getSentFolderName(), allFolderLabels,allFolderValues);
initListPreference(mSpamFolder, mAccount.getSpamFolderName(), allFolderLabels,allFolderValues);
initListPreference(mTrashFolder, mAccount.getTrashFolderName(), allFolderLabels,allFolderValues);
mAutoExpandFolder.setEnabled(true);
mArchiveFolder.setEnabled(true);
mDraftsFolder.setEnabled(true);
mOutboxFolder.setEnabled(true);
mSentFolder.setEnabled(true);
mSpamFolder.setEnabled(true);
mTrashFolder.setEnabled(true);
mOutboxFolder = (ListPreference)findPreference(PREFERENCE_OUTBOX_FOLDER); }
initListPreference(mOutboxFolder, mAccount.getOutboxFolderName(), allFolderLabels,allFolderValues);
mSentFolder = (ListPreference)findPreference(PREFERENCE_SENT_FOLDER);
initListPreference(mSentFolder, mAccount.getSentFolderName(), allFolderLabels,allFolderValues);
mSpamFolder = (ListPreference)findPreference(PREFERENCE_SPAM_FOLDER);
initListPreference(mSpamFolder, mAccount.getSpamFolderName(), allFolderLabels,allFolderValues);
mTrashFolder = (ListPreference)findPreference(PREFERENCE_TRASH_FOLDER);
initListPreference(mTrashFolder, mAccount.getTrashFolderName(), allFolderLabels,allFolderValues);
} }
} }