Rename fields in FolderListFilter
This commit is contained in:
parent
80c2d20c9b
commit
9df97445c2
1 changed files with 12 additions and 12 deletions
|
@ -11,28 +11,28 @@ import android.widget.Filter;
|
||||||
* Filter to search for occurrences of the search-expression in any place of the folder name.
|
* Filter to search for occurrences of the search-expression in any place of the folder name.
|
||||||
*/
|
*/
|
||||||
public class FolderListFilter<T> extends Filter {
|
public class FolderListFilter<T> extends Filter {
|
||||||
private FilterableAdapter<T> mFolders;
|
private FilterableAdapter<T> adapter;
|
||||||
private List<T> mOriginalValues = null;
|
private List<T> unfilteredFolderList = null;
|
||||||
|
|
||||||
public FolderListFilter(final FilterableAdapter<T> folders) {
|
public FolderListFilter(final FilterableAdapter<T> folders) {
|
||||||
this.mFolders = folders;
|
this.adapter = folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FilterResults performFiltering(CharSequence searchTerm) {
|
protected FilterResults performFiltering(CharSequence searchTerm) {
|
||||||
FilterResults results = new FilterResults();
|
FilterResults results = new FilterResults();
|
||||||
|
|
||||||
if (mOriginalValues == null) {
|
if (unfilteredFolderList == null) {
|
||||||
int count = mFolders.getCount();
|
int count = adapter.getCount();
|
||||||
mOriginalValues = new ArrayList<>(count);
|
unfilteredFolderList = new ArrayList<>(count);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
mOriginalValues.add(mFolders.getItem(i));
|
unfilteredFolderList.add(adapter.getItem(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Locale locale = Locale.getDefault();
|
Locale locale = Locale.getDefault();
|
||||||
if ((searchTerm == null) || (searchTerm.length() == 0)) {
|
if ((searchTerm == null) || (searchTerm.length() == 0)) {
|
||||||
List<T> list = new ArrayList<>(mOriginalValues);
|
List<T> list = new ArrayList<>(unfilteredFolderList);
|
||||||
results.values = list;
|
results.values = list;
|
||||||
results.count = list.size();
|
results.count = list.size();
|
||||||
} else {
|
} else {
|
||||||
|
@ -40,7 +40,7 @@ public class FolderListFilter<T> extends Filter {
|
||||||
final String[] words = searchTermString.split(" ");
|
final String[] words = searchTermString.split(" ");
|
||||||
final int wordCount = words.length;
|
final int wordCount = words.length;
|
||||||
|
|
||||||
final List<T> values = mOriginalValues;
|
final List<T> values = unfilteredFolderList;
|
||||||
|
|
||||||
final List<T> newValues = new ArrayList<>();
|
final List<T> newValues = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -66,18 +66,18 @@ public class FolderListFilter<T> extends Filter {
|
||||||
@Override
|
@Override
|
||||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||||
final List<T> folders = (List<T>) results.values;
|
final List<T> folders = (List<T>) results.values;
|
||||||
mFolders.clear();
|
adapter.clear();
|
||||||
if (folders != null) {
|
if (folders != null) {
|
||||||
for (T folder : folders) {
|
for (T folder : folders) {
|
||||||
if (folder != null) {
|
if (folder != null) {
|
||||||
mFolders.add(folder);
|
adapter.add(folder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Timber.w("FolderListFilter.publishResults - null search-result ");
|
Timber.w("FolderListFilter.publishResults - null search-result ");
|
||||||
}
|
}
|
||||||
|
|
||||||
mFolders.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface FilterableAdapter<T> {
|
public interface FilterableAdapter<T> {
|
||||||
|
|
Loading…
Reference in a new issue