Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Yalantis/SearchFilter

Implementing Search Filter Animation in Kotlin for Quora Meets LinkedIn, Our App Design Concept
https://github.com/Yalantis/SearchFilter

android animation search-filters

Last synced: 12 days ago
JSON representation

Implementing Search Filter Animation in Kotlin for Quora Meets LinkedIn, Our App Design Concept

Awesome Lists containing this project

README

        

# SearchFilter

[![License](http://img.shields.io/badge/license-MIT-green.svg?style=flat)]()
[![](https://jitpack.io/v/yalantis/searchfilter.svg)](https://jitpack.io/#yalantis/searchfilter)
[![Yalantis](https://raw.githubusercontent.com/Yalantis/PullToRefresh/develop/PullToRefreshDemo/Resources/badge_dark.png)](https://yalantis.com/?utm_source=github)

Get it on Google Play

[Live DEMO on appetize.io](https://appetize.io/app/3jke81pv6zuv9b4mt4gc53afc4)

Check this [project on dribbble](https://dribbble.com/shots/2818273-Female-in-IT-Filters)

Read how we did it [on our blog](https://yalantis.com/blog/develop-filter-animation-kotlin-android/)

##Requirements
- Android SDK 18+

##Usage

Add to your root build.gradle:
```Groovy
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
```

Add the dependency:
```Groovy
dependencies {
compile 'com.github.Yalantis:SearchFilter:v1.0.4'
}
```

## How to use this library

Firstly you need to place `Filter` above your `RecyclerView` in the layout file

```xml


```

After that you need to create a class that extends `FilterAdapter` and to pass your model class as a generic.
Here you can easily customize the appearance of filter items. For the sample app I created `Tag` model to represent
the category of a question in the conversation.

```java

class Adapter extends FilterAdapter {

Adapter(@NotNull List extends Tag> items) {
super(items);
}

@NotNull
@Override
public FilterItem createView(int position, Tag item) {
FilterItem filterItem = new FilterItem(ExampleActivity.this);

filterItem.setStrokeColor(mColors[0]);
filterItem.setTextColor(mColors[0]);
filterItem.setCheckedTextColor(ContextCompat.getColor(ExampleActivity.this, android.R.color.white));
filterItem.setColor(ContextCompat.getColor(ExampleActivity.this, android.R.color.white));
filterItem.setCheckedColor(mColors[position]);
filterItem.setText(item.getText());
filterItem.deselect();

return filterItem;
}
}

```

To receive all the events from the `Filter` such as selection or deselection of a filter item it's necessary
to add a `FilterListener` with the same model class passed as a generic

```java

private FilterListener mListener = new FilterListener() {

@Override
public void onFiltersSelected(@NotNull ArrayList filters) {

}

@Override
public void onNothingSelected() {

}

@Override
public void onFilterSelected(Tag item) {

}

@Override
public void onFilterDeselected(Tag item) {

}

};

```

Basically `Filter` setup looks like that

```java

mFilter = (Filter) findViewById(R.id.filter);
mFilter.setAdapter(new Adapter(getTags()));
mFilter.setListener(this);

//the text to show when there's no selected items
mFilter.setNoSelectedItemText(getString(R.string.str_all_selected));
mFilter.build();

```

For more usage examples please review sample app

## Let us know!

We’d be really happy if you sent us links to your projects where you use our component. Just send an email to [email protected] And do let us know if you have any questions or suggestion regarding the animation.

P.S. We’re going to publish more awesomeness wrapped in code and a tutorial on how to make UI for iOS (Android) better than better. Stay tuned!

## License

The MIT License (MIT)

Copyright © 2016 Yalantis, https://yalantis.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.