Search in sources :

Example 1 with ListSearchAdapter

use of carbon.widget.ListSearchAdapter in project Carbon by ZieIony.

the class SearchToolbarActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    List<DefaultAvatarTextItem> items = generateItems();
    RowListAdapter<DefaultAvatarTextItem> adapter = new RowListAdapter<>(items, AvatarTextRow::new);
    RecyclerView recyclerView = findViewById(R.id.recycler);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adapter);
    searchEditText = findViewById(R.id.searchEditText);
    searchEditText.setDataProvider(new ListSearchAdapter<DefaultAvatarTextItem>(items) {

        @NotNull
        @Override
        public String[] getItemWords(DefaultAvatarTextItem item) {
            return new String[] { item.getText() };
        }
    });
    searchEditText.setOnFilterListener((SearchEditText.OnFilterListener<DefaultAvatarTextItem>) filterResults -> {
        if (filterResults == null) {
            adapter.setItems(items);
        } else if (filterResults.size() == 2) {
            adapter.setItems(new ArrayList<>());
        } else {
            adapter.setItems(filterResults);
        }
    });
    findViewById(R.id.clear).setOnClickListener(v -> searchEditText.setText(""));
    searchBar = findViewById(R.id.searchbar);
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setOnMenuItemClicked((view, item, position) -> openSearch(view));
    closeButton = findViewById(R.id.close);
    closeButton.setOnClickListener(v -> closeSearch());
}
Also used : ThemedActivity(tk.zielony.carbonsamples.ThemedActivity) Bundle(android.os.Bundle) FastOutSlowInInterpolator(androidx.interpolator.view.animation.FastOutSlowInInterpolator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SampleAnnotation(tk.zielony.carbonsamples.SampleAnnotation) Drawable(android.graphics.drawable.Drawable) StringNameGenerator(tk.zielony.randomdata.person.StringNameGenerator) ArrayList(java.util.ArrayList) AvatarTextRow(carbon.component.AvatarTextRow) SearchEditText(carbon.widget.SearchEditText) DrawableAvatarGenerator(tk.zielony.randomdata.person.DrawableAvatarGenerator) List(java.util.List) RecyclerView(carbon.widget.RecyclerView) ListSearchAdapter(carbon.widget.ListSearchAdapter) Toolbar(carbon.widget.Toolbar) RandomData(tk.zielony.randomdata.RandomData) R(tk.zielony.carbonsamples.R) DefaultAvatarTextItem(carbon.component.DefaultAvatarTextItem) View(android.view.View) RowListAdapter(carbon.recycler.RowListAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NotNull(org.jetbrains.annotations.NotNull) FrameLayout(carbon.widget.FrameLayout) DefaultAvatarTextItem(carbon.component.DefaultAvatarTextItem) RowListAdapter(carbon.recycler.RowListAdapter) AvatarTextRow(carbon.component.AvatarTextRow) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NotNull(org.jetbrains.annotations.NotNull) SearchEditText(carbon.widget.SearchEditText) RecyclerView(carbon.widget.RecyclerView) Toolbar(carbon.widget.Toolbar)

Aggregations

Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 View (android.view.View)1 FastOutSlowInInterpolator (androidx.interpolator.view.animation.FastOutSlowInInterpolator)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 AvatarTextRow (carbon.component.AvatarTextRow)1 DefaultAvatarTextItem (carbon.component.DefaultAvatarTextItem)1 RowListAdapter (carbon.recycler.RowListAdapter)1 FrameLayout (carbon.widget.FrameLayout)1 ListSearchAdapter (carbon.widget.ListSearchAdapter)1 RecyclerView (carbon.widget.RecyclerView)1 SearchEditText (carbon.widget.SearchEditText)1 Toolbar (carbon.widget.Toolbar)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1 R (tk.zielony.carbonsamples.R)1 SampleAnnotation (tk.zielony.carbonsamples.SampleAnnotation)1