Search in sources :

Example 1 with Category

use of org.rajawali3d.examples.data.Category in project Rajawali by Rajawali.

the class CategoryAdapter method filter.

public void filter(@NonNull Context context, @NonNull String query) {
    String queryLC = query.trim().toLowerCase(Locale.ENGLISH);
    List<Category> categories = new LinkedList<>();
    if (queryLC.length() == 0) {
        categories.addAll(categoriesOriginal);
    } else {
        for (Category category : categoriesOriginal) {
            List<Example> filtered = new LinkedList<>();
            Example[] examples = category.getExamples();
            // If the category matches the query, add all examples then move to the next item
            String categoryName = context.getString(category.getName()).toLowerCase(Locale.ENGLISH);
            if (categoryName.contains(queryLC)) {
                categories.add(category);
                continue;
            }
            // Iterate the examples adding matches to the filtered list
            for (Example example : examples) {
                String exampleName = context.getString(example.getName()).toLowerCase(Locale.ENGLISH);
                if (exampleName.contains(queryLC)) {
                    filtered.add(example);
                }
            }
            // If the category has any matching examples, keep it and add the matches
            final int size = filtered.size();
            if (size > 0) {
                Example[] filteredExamples = filtered.toArray(new Example[size]);
                Category filteredCategory = new Category(category.getName(), filteredExamples);
                categories.add(filteredCategory);
            }
        }
    }
    setReferencesFromList(categories);
}
Also used : Category(org.rajawali3d.examples.data.Category) Example(org.rajawali3d.examples.data.Example) LinkedList(java.util.LinkedList)

Example 2 with Category

use of org.rajawali3d.examples.data.Category in project Rajawali by Rajawali.

the class CategoryAdapter method filterDone.

public boolean filterDone(@NonNull Context context) {
    if (categoriesDisplayed.size() == 1) {
        Category category = categoriesDisplayed.get(0);
        Example[] examples = category.getExamples();
        if (examples.length == 1) {
            Example example = examples[0];
            onExampleSelected(context, example);
            return true;
        }
    }
    return false;
}
Also used : Category(org.rajawali3d.examples.data.Category) Example(org.rajawali3d.examples.data.Example)

Example 3 with Category

use of org.rajawali3d.examples.data.Category in project Rajawali by Rajawali.

the class CategoryAdapter method setReferencesFromList.

void setReferencesFromList(List<Category> categories) {
    final List<NamedIndexReference<INamed>> indexReferences;
    indexReferences = new LinkedList<>();
    for (Category category : categories) {
        indexReferences.add(new CategoryReference(category));
        Example[] examples = category.getExamples();
        for (Example example : examples) {
            indexReferences.add(new ExampleReference(example));
        }
    }
    categoriesDisplayed = categories;
    setReferences(indexReferences);
}
Also used : Category(org.rajawali3d.examples.data.Category) Example(org.rajawali3d.examples.data.Example)

Aggregations

Category (org.rajawali3d.examples.data.Category)3 Example (org.rajawali3d.examples.data.Example)3 LinkedList (java.util.LinkedList)1