ConcurrentModification bugfix & NOTICE udpate
This commit is contained in:
parent
ec60a0daa2
commit
b5a869f177
2 changed files with 40 additions and 32 deletions
5
NOTICE
5
NOTICE
|
@ -1,3 +1,4 @@
|
||||||
1. This source code is prohibited from usage of any kind in any kind of AI-based (neural networks, graph networks, prediction models, weighted predictors and/or any machine learning algorhitms of any kind) software and/or models (including, but not limited to using as training data; using to build search index; used as token sequence for vectorization; used as input of any AI-based software and/or models);
|
1. This source code is prohibited from usage of any kind in any kind of AI/NN/ML-based (neural networks, graph networks, prediction models, weighted predictors and/or any machine learning algorhitms of any kind) software and/or models (including, but not limited to using as training data; using to build search index; used as token sequence for vectorization; used as input of any AI/NN/ML-based software and/or models);
|
||||||
2. Initial creator attribution (pegasko) must persist among all subsequent copies of any depth on any media;
|
2. Initial creator attribution (pegasko) must persist among all subsequent copies of any depth on any media;
|
||||||
3. Take care of your cat(s);
|
3. Сommercial (or any kind of profit) distribution is allowed only with explicit agreement of the author (pegasko);
|
||||||
|
4. Take care of your cat(s);
|
||||||
|
|
|
@ -26,26 +26,21 @@ import android.widget.Filter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import art.pegasko.yeeemp.base.TagStat;
|
import art.pegasko.yeeemp.base.TagStat;
|
||||||
|
|
||||||
public class EventEditTagsAdapter extends ArrayAdapter<TagStat> {
|
public class EventEditTagsAdapter extends ArrayAdapter<TagStat> {
|
||||||
public static final String TAG = EventEditTagsAdapter.class.getSimpleName();
|
public static final String TAG = EventEditTagsAdapter.class.getSimpleName();
|
||||||
|
|
||||||
private ArrayList<TagStat> items;
|
private ArrayList<TagStat> tags;
|
||||||
private ArrayList<TagStat> itemsAll;
|
|
||||||
private ArrayList<TagStat> suggestions;
|
|
||||||
private int viewResourceId;
|
|
||||||
private int viewFieldId;
|
|
||||||
private LayoutInflater inflater;
|
private LayoutInflater inflater;
|
||||||
|
private final int viewResourceId;
|
||||||
|
private final int viewFieldId;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public EventEditTagsAdapter(Context context, int viewResourceId, int viewFieldId, ArrayList<TagStat> items) {
|
public EventEditTagsAdapter(Context context, int viewResourceId, int viewFieldId, ArrayList<TagStat> tags) {
|
||||||
super(context, viewResourceId, items);
|
super(context, viewResourceId, tags);
|
||||||
this.items = items;
|
this.tags = tags;
|
||||||
this.itemsAll = (ArrayList<TagStat>) items.clone();
|
|
||||||
this.suggestions = new ArrayList<TagStat>();
|
|
||||||
this.viewResourceId = viewResourceId;
|
this.viewResourceId = viewResourceId;
|
||||||
this.viewFieldId = viewFieldId;
|
this.viewFieldId = viewFieldId;
|
||||||
this.inflater = LayoutInflater.from(context);
|
this.inflater = LayoutInflater.from(context);
|
||||||
|
@ -71,7 +66,7 @@ public class EventEditTagsAdapter extends ArrayAdapter<TagStat> {
|
||||||
throw new RuntimeException("You must supply a resource ID for a TextView");
|
throw new RuntimeException("You must supply a resource ID for a TextView");
|
||||||
}
|
}
|
||||||
|
|
||||||
text.setText(items.get(position).tag.getName() + " (" + Integer.toString(items.get(position).count) + ")");
|
text.setText(tags.get(position).tag.getName() + " (" + tags.get(position).count + ")");
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +76,11 @@ public class EventEditTagsAdapter extends ArrayAdapter<TagStat> {
|
||||||
return nameFilter;
|
return nameFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
Filter nameFilter = new Filter() {
|
private Filter nameFilter = new Filter() {
|
||||||
|
// TODO: Stop using mutable global
|
||||||
|
// Reusable filter result
|
||||||
|
private ArrayList<TagStat> tagsSuggestions = new ArrayList<TagStat>();
|
||||||
|
|
||||||
public String convertResultToString(Object resultValue) {
|
public String convertResultToString(Object resultValue) {
|
||||||
String str = ((TagStat) (resultValue)).tag.getName();
|
String str = ((TagStat) (resultValue)).tag.getName();
|
||||||
return str;
|
return str;
|
||||||
|
@ -89,31 +88,39 @@ public class EventEditTagsAdapter extends ArrayAdapter<TagStat> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FilterResults performFiltering(CharSequence constraint) {
|
protected FilterResults performFiltering(CharSequence constraint) {
|
||||||
if (constraint != null) {
|
synchronized (tagsSuggestions) {
|
||||||
suggestions.clear();
|
if (constraint != null) {
|
||||||
for (TagStat product : itemsAll) {
|
tagsSuggestions.clear();
|
||||||
if (product.tag.getName().contains(constraint.toString().toLowerCase())) {
|
for (TagStat tag : tags) {
|
||||||
suggestions.add(product);
|
if (tag.tag.getName().contains(constraint.toString().toLowerCase())) {
|
||||||
|
tagsSuggestions.add(tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
FilterResults filterResults = new FilterResults();
|
||||||
|
// TODO: Spank me for using global mutable instance for returning immutable result (causes concurrent modification when publishResults())
|
||||||
|
filterResults.values = tagsSuggestions;
|
||||||
|
filterResults.count = tagsSuggestions.size();
|
||||||
|
return filterResults;
|
||||||
|
} else {
|
||||||
|
return new FilterResults();
|
||||||
}
|
}
|
||||||
FilterResults filterResults = new FilterResults();
|
|
||||||
filterResults.values = suggestions;
|
|
||||||
filterResults.count = suggestions.size();
|
|
||||||
return filterResults;
|
|
||||||
} else {
|
|
||||||
return new FilterResults();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||||
@SuppressWarnings("unchecked") ArrayList<TagStat> filteredList = (ArrayList<TagStat>) results.values;
|
if (results.values == null)
|
||||||
if (results != null && results.count > 0) {
|
return;
|
||||||
clear();
|
|
||||||
for (TagStat c : filteredList) {
|
synchronized (results.values) {
|
||||||
add(c);
|
ArrayList<TagStat> filteredList = (ArrayList<TagStat>) results.values;
|
||||||
|
if (results.count > 0) {
|
||||||
|
clear();
|
||||||
|
for (TagStat c : filteredList) {
|
||||||
|
add(c);
|
||||||
|
}
|
||||||
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue