From 1005f5e300f10c425242c5395dc4d37ab2b2fea0 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 3 Oct 2019 23:53:41 +0200 Subject: [PATCH] Retain filter when updating the folder list --- .../com/fsck/k9/activity/ChooseFolder.java | 23 ++++++++----------- .../fsck/k9/activity/FolderListFilter.java | 4 ++-- 2 files changed, 12 insertions(+), 15 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 081957b3e..c1836d701 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 @@ -332,17 +332,7 @@ public class ChooseFolder extends K9ListActivity { @Override public void run() { // Now we're in the UI-thread, we can safely change the contents of the adapter. - mAdapter.mFolders.clear(); - mAdapter.mFolders.addAll(folderList); - mAdapter.mFilteredFolders = mAdapter.mFolders; - mAdapter.notifyDataSetChanged(); - - /* - * Only enable the text filter after the list has been - * populated to avoid possible race conditions because our - * FolderListFilter isn't really thread-safe. - */ - getListView().setTextFilterEnabled(true); + mAdapter.setFolders(folderList); } }); } @@ -358,6 +348,7 @@ public class ChooseFolder extends K9ListActivity { private List mFilteredFolders = Collections.unmodifiableList(mFolders); private Filter mFilter = new FolderListFilter(this); private FolderIconProvider folderIconProvider = new FolderIconProvider(getTheme()); + private CharSequence filterText; public FolderInfoHolder getItem(long position) { return getItem((int)position); @@ -452,10 +443,16 @@ public class ChooseFolder extends K9ListActivity { } @Override - public void setFilteredFolders(List folders) { - mFilteredFolders = new ArrayList<>(folders); + public void setFilteredFolders(CharSequence filterText, List folders) { + this.filterText = filterText; + mFilteredFolders = folders; notifyDataSetChanged(); } + + void setFolders(List folders) { + mFolders = folders; + getFilter().filter(filterText); + } } static class FolderViewHolder { 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 f30612f54..31ef6907e 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 @@ -53,12 +53,12 @@ public class FolderListFilter extends Filter { @Override protected void publishResults(CharSequence constraint, FilterResults results) { List folders = (List) results.values; - adapter.setFilteredFolders(folders); + adapter.setFilteredFolders(constraint, folders); } public interface FolderAdapter { List getFolders(); - void setFilteredFolders(List folders); + void setFilteredFolders(CharSequence filterText, List folders); } }