Search in sources :

Example 16 with Tag

use of com.faltenreich.diaguard.shared.data.database.entity.Tag in project Diaguard by Faltenreich.

the class TagAutoCompleteAdapter method getFilter.

@NonNull
@Override
public Filter getFilter() {
    return new Filter() {

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults filterResults = new FilterResults();
            List<Tag> suggestions = new ArrayList<>();
            if (!TextUtils.isEmpty(constraint)) {
                for (Map.Entry<Tag, Boolean> entry : tags.entrySet()) {
                    Tag tag = entry.getKey();
                    if (tag != null && tag.getName().toLowerCase().contains(constraint.toString().toLowerCase())) {
                        suggestions.add(tag);
                    }
                }
            }
            filterResults.values = suggestions;
            filterResults.count = suggestions.size();
            return filterResults;
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults filterResults) {
            notifyDataSetChanged();
        }
    };
}
Also used : Filter(android.widget.Filter) ArrayList(java.util.ArrayList) Tag(com.faltenreich.diaguard.shared.data.database.entity.Tag) HashMap(java.util.HashMap) Map(java.util.Map) NonNull(androidx.annotation.NonNull)

Aggregations

Tag (com.faltenreich.diaguard.shared.data.database.entity.Tag)16 EntryTag (com.faltenreich.diaguard.shared.data.database.entity.EntryTag)11 ArrayList (java.util.ArrayList)9 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)7 FoodEaten (com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)7 Measurement (com.faltenreich.diaguard.shared.data.database.entity.Measurement)7 Category (com.faltenreich.diaguard.shared.data.database.entity.Category)6 Meal (com.faltenreich.diaguard.shared.data.database.entity.Meal)5 NonNull (androidx.annotation.NonNull)4 DateTime (org.joda.time.DateTime)4 Context (android.content.Context)3 View (android.view.View)3 ImageView (android.widget.ImageView)3 Food (com.faltenreich.diaguard.shared.data.database.entity.Food)3 ChipView (com.faltenreich.diaguard.shared.view.chip.ChipView)3 Handler (android.os.Handler)2 LayoutInflater (android.view.LayoutInflater)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2