mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-24 02:12:15 -05:00
move folderlist initialization into an asynctask, so it's not so slow to populate
This commit is contained in:
parent
b99eb47d15
commit
db7649c9af
@ -4,6 +4,7 @@ package com.fsck.k9.activity.setup;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.CheckBoxPreference;
|
||||
@ -573,8 +574,7 @@ public class AccountSettings extends K9PreferenceActivity
|
||||
mNotificationOpensUnread = (CheckBoxPreference)findPreference(PREFERENCE_NOTIFICATION_OPENS_UNREAD);
|
||||
mNotificationOpensUnread.setChecked(mAccount.goToUnreadMessageSearch());
|
||||
|
||||
populateFolderPreferences();
|
||||
|
||||
new PopulateFolderPrefsTask().execute();
|
||||
|
||||
mChipColor = findPreference(PREFERENCE_CHIP_COLOR);
|
||||
mChipColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
|
||||
@ -901,54 +901,82 @@ public class AccountSettings extends K9PreferenceActivity
|
||||
Integer.parseInt(mAccountVibratePattern.getValue()),
|
||||
Integer.parseInt(mAccountVibrateTimes.getValue())), -1);
|
||||
}
|
||||
private void populateFolderPreferences() {
|
||||
|
||||
private class PopulateFolderPrefsTask extends AsyncTask<Void, Void, Void>
|
||||
{
|
||||
List<? extends Folder> folders = new LinkedList<LocalFolder>();
|
||||
try
|
||||
String[] allFolderValues;
|
||||
String[] allFolderLabels;
|
||||
protected Void doInBackground(Void... params)
|
||||
{
|
||||
folders = mAccount.getLocalStore().getPersonalNamespaces(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
/// this can't be checked in
|
||||
}
|
||||
final String[] allFolderValues = new String[folders.size()+2];
|
||||
final String[] allFolderLabels = new String[folders.size()+2];
|
||||
allFolderValues[0] = K9.FOLDER_NONE;
|
||||
allFolderLabels[0] = K9.FOLDER_NONE;
|
||||
try
|
||||
{
|
||||
folders = mAccount.getLocalStore().getPersonalNamespaces(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
/// this can't be checked in
|
||||
}
|
||||
allFolderValues = new String[folders.size()+2];
|
||||
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[1] = mAccount.getOutboxFolderName();
|
||||
allFolderLabels[1] = mAccount.getOutboxFolderName();
|
||||
allFolderValues[0] = K9.FOLDER_NONE;
|
||||
allFolderLabels[0] = K9.FOLDER_NONE;
|
||||
|
||||
// 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;
|
||||
for (Folder folder : folders)
|
||||
{
|
||||
allFolderLabels[i] = folder.getName();
|
||||
allFolderValues[i] = folder.getName();
|
||||
i++;
|
||||
int i =2;
|
||||
for (Folder folder : folders)
|
||||
{
|
||||
allFolderLabels[i] = folder.getName();
|
||||
allFolderValues[i] = folder.getName();
|
||||
i++;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
mAutoExpandFolder = (ListPreference)findPreference(PREFERENCE_AUTO_EXPAND_FOLDER);
|
||||
initListPreference(mAutoExpandFolder, mAccount.getAutoExpandFolderName(), allFolderLabels,allFolderValues);
|
||||
|
||||
mArchiveFolder = (ListPreference)findPreference(PREFERENCE_ARCHIVE_FOLDER);
|
||||
initListPreference(mArchiveFolder, mAccount.getArchiveFolderName(), allFolderLabels,allFolderValues);
|
||||
protected void onPreExecute()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user