Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #264 from chakli/dev
Browse files Browse the repository at this point in the history
Actually filter paths
  • Loading branch information
lgallard authored Feb 28, 2021
2 parents 9069256 + f5941d2 commit f7724d6
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6273,10 +6273,15 @@ public void sendTorrent() {
// Load history for path and category autocomplete text field

class ContainsArrayAdapter extends ArrayAdapter<String> {

ArrayList<String> mPaths;
Filter mFilter;
public ContainsArrayAdapter(@NonNull Context context, int resource, @NonNull String[] objects) {

public ContainsArrayAdapter(@NonNull Context context, int resource, @NonNull ArrayList<String> objects) {
super(context, resource, objects);
mPaths = new ArrayList<>(objects);
}

@Override
public Filter getFilter() {
if (null == mFilter) {
Expand All @@ -6285,25 +6290,28 @@ public Filter getFilter() {
protected Filter.FilterResults performFiltering(CharSequence charSequence) {
List<String> listOfMatches = new ArrayList<String>();
if(charSequence != null) {
for (int i = 0; i < getCount(); i++) {
String item = getItem(i);
for (int i = 0; i < mPaths.size(); i++) {
String item = mPaths.get(i);
if (item != null && item.contains(charSequence)) {
listOfMatches.add(item);
}
}
}
Filter.FilterResults results = new Filter.FilterResults();
results.values = listOfMatches;
results.count = listOfMatches.size();
synchronized(this) {
results.values = listOfMatches;
results.count = listOfMatches.size();
}
return results;
}

@Override
protected void publishResults(CharSequence charSequence, Filter.FilterResults
filterResults) {
protected void publishResults(CharSequence charSequence, Filter.FilterResults filterResults) {
clear();
if (filterResults.count == 0) {
notifyDataSetInvalidated();
} else {
addAll((ArrayList<String>)filterResults.values);
notifyDataSetChanged();
}
}
Expand All @@ -6315,12 +6323,12 @@ protected void publishResults(CharSequence charSequence, Filter.FilterResults

// Path
ArrayAdapter<String> pathAdapter = new ContainsArrayAdapter (
this, android.R.layout.simple_list_item_1, path_history.toArray(new String[path_history.size()]));
this, android.R.layout.simple_list_item_1, new ArrayList<String>(path_history));
pathTextView.setAdapter(pathAdapter);

// Category
ArrayAdapter<String> categoryAdapter = new ContainsArrayAdapter (
this, android.R.layout.simple_list_item_1, category_history.toArray(new String[category_history.size()]));
this, android.R.layout.simple_list_item_1, new ArrayList<String>(category_history));
categoryTextView.setAdapter(categoryAdapter);

// Checkbox value
Expand Down

0 comments on commit f7724d6

Please sign in to comment.