From bc713807cd234763c72842045623cfffdb8d2cc9 Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 4 Oct 2019 00:10:34 +0200 Subject: [PATCH] Don't fetch list of folders from adapter in worker thread --- .../java/com/fsck/k9/activity/ChooseFolder.java | 16 +++++++--------- .../com/fsck/k9/activity/FolderListFilter.java | 11 ++++++----- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/activity/ChooseFolder.java b/app/ui/src/main/java/com/fsck/k9/activity/ChooseFolder.java index c1836d701..213989c78 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/ChooseFolder.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/ChooseFolder.java @@ -40,6 +40,8 @@ import com.fsck.k9.mailstore.LocalFolder; import com.fsck.k9.ui.folders.FolderIconProvider; import timber.log.Timber; +import static java.util.Collections.emptyList; + public class ChooseFolder extends K9ListActivity { public static final String EXTRA_ACCOUNT = "com.fsck.k9.ChooseFolder_account"; @@ -344,9 +346,9 @@ public class ChooseFolder extends K9ListActivity { }; class FolderListAdapter extends BaseAdapter implements Filterable, FolderAdapter { - private List mFolders = new ArrayList<>(); - private List mFilteredFolders = Collections.unmodifiableList(mFolders); - private Filter mFilter = new FolderListFilter(this); + private List mFolders = emptyList(); + private List mFilteredFolders = emptyList(); + private Filter mFilter = new FolderListFilter(this, mFolders); private FolderIconProvider folderIconProvider = new FolderIconProvider(getTheme()); private CharSequence filterText; @@ -437,11 +439,6 @@ public class ChooseFolder extends K9ListActivity { return mFilter; } - @Override - public List getFolders() { - return mFolders; - } - @Override public void setFilteredFolders(CharSequence filterText, List folders) { this.filterText = filterText; @@ -451,7 +448,8 @@ public class ChooseFolder extends K9ListActivity { void setFolders(List folders) { mFolders = folders; - getFilter().filter(filterText); + mFilter = new FolderListFilter(this, folders); + mFilter.filter(filterText); } } diff --git a/app/ui/src/main/java/com/fsck/k9/activity/FolderListFilter.java b/app/ui/src/main/java/com/fsck/k9/activity/FolderListFilter.java index 31ef6907e..e2df35e9c 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/FolderListFilter.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/FolderListFilter.java @@ -11,10 +11,12 @@ import android.widget.Filter; */ public class FolderListFilter extends Filter { private final FolderAdapter adapter; + private final List folders; - public FolderListFilter(FolderAdapter folders) { - this.adapter = folders; + public FolderListFilter(FolderAdapter adapter, List folders) { + this.adapter = adapter; + this.folders = folders; } @Override @@ -23,7 +25,7 @@ public class FolderListFilter extends Filter { Locale locale = Locale.getDefault(); if (searchTerm == null || searchTerm.length() == 0) { - List list = new ArrayList<>(adapter.getFolders()); + List list = new ArrayList<>(folders); results.values = list; results.count = list.size(); } else { @@ -31,7 +33,7 @@ public class FolderListFilter extends Filter { String[] words = searchTermString.split(" "); List newValues = new ArrayList<>(); - for (FolderInfoHolder folderInfoHolder : adapter.getFolders()) { + for (FolderInfoHolder folderInfoHolder : folders) { String valueText = folderInfoHolder.displayName.toLowerCase(locale); for (String word : words) { @@ -58,7 +60,6 @@ public class FolderListFilter extends Filter { public interface FolderAdapter { - List getFolders(); void setFilteredFolders(CharSequence filterText, List folders); } }