Don't fetch list of folders from adapter in worker thread

This commit is contained in:
cketti 2019-10-04 00:10:34 +02:00
parent 1005f5e300
commit bc713807cd
2 changed files with 13 additions and 14 deletions

View file

@ -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<FolderInfoHolder> mFolders = new ArrayList<>();
private List<FolderInfoHolder> mFilteredFolders = Collections.unmodifiableList(mFolders);
private Filter mFilter = new FolderListFilter(this);
private List<FolderInfoHolder> mFolders = emptyList();
private List<FolderInfoHolder> 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<FolderInfoHolder> getFolders() {
return mFolders;
}
@Override
public void setFilteredFolders(CharSequence filterText, List<FolderInfoHolder> folders) {
this.filterText = filterText;
@ -451,7 +448,8 @@ public class ChooseFolder extends K9ListActivity {
void setFolders(List<FolderInfoHolder> folders) {
mFolders = folders;
getFilter().filter(filterText);
mFilter = new FolderListFilter(this, folders);
mFilter.filter(filterText);
}
}

View file

@ -11,10 +11,12 @@ import android.widget.Filter;
*/
public class FolderListFilter extends Filter {
private final FolderAdapter adapter;
private final List<FolderInfoHolder> folders;
public FolderListFilter(FolderAdapter folders) {
this.adapter = folders;
public FolderListFilter(FolderAdapter adapter, List<FolderInfoHolder> 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<FolderInfoHolder> list = new ArrayList<>(adapter.getFolders());
List<FolderInfoHolder> 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<FolderInfoHolder> 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<FolderInfoHolder> getFolders();
void setFilteredFolders(CharSequence filterText, List<FolderInfoHolder> folders);
}
}