Giter Site home page Giter Site logo

yalantis / searchfilter Goto Github PK

View Code? Open in Web Editor NEW
1.7K 65.0 253.0 5.55 MB

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

Home Page: https://yalantis.com

Java 22.32% Kotlin 77.68%
android search-filters animation

searchfilter's Introduction

SearchFilter

License Yalantis

Get it on Google Play

Live DEMO on appetize.io

Check this project on dribbble

Read how we did it on our blog

##Requirements

  • Android SDK 18+

##Usage

Add to your root build.gradle:

allprojects {
	repositories {
	...
	maven { url "https://jitpack.io" }
	}
}

Add the dependency:

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 version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            android:elevation="4dp"
            android:paddingRight="16dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.v7.widget.AppCompatImageView
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_centerVertical="true"
                    android:src="@drawable/ic_alarm"
                    android:tint="@android:color/white" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:text="Questions"
                    android:textColor="@android:color/white"
                    android:textSize="20sp" />

                <android.support.v7.widget.AppCompatImageView
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/ic_search"
                    android:tint="@android:color/white" />

            </RelativeLayout>

        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#E4E6E3"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/container_height"
            tools:listitem="@layout/item_list" />

        <com.yalantis.filter.widget.Filter
            android:id="@+id/filter"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </FrameLayout>
</android.support.design.widget.CoordinatorLayout>

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.

class Adapter extends FilterAdapter<Tag> {

        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

private FilterListener<Tag> mListener = new FilterListener<Tag>() {

        @Override
        public void onFiltersSelected(@NotNull ArrayList<Tag> filters) {
            
        }

        @Override
        public void onNothingSelected() {

        }

        @Override
        public void onFilterSelected(Tag item) {

        }

        @Override
        public void onFilterDeselected(Tag item) {

        }

    };

Basically Filter setup looks like that

 mFilter = (Filter<Tag>) 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.

searchfilter's People

Contributors

antonshilov avatar igalata avatar teerawk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

searchfilter's Issues

SetCancelIcon

There is a way to change the cancel icon? I am using "setCancelIcon", but it is not working.

NoDefClassFound AnimatorCompatHelper

I'm with recyclerview-v7:26.1.0.

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/animation/AnimatorCompatHelper;
                                                                                   at com.yalantis.filter.animator.FiltersListItemAnimator.resetAnimation(FiltersListItemAnimator.kt:427)
                                                                                   at com.yalantis.filter.animator.FiltersListItemAnimator.animateRemove(FiltersListItemAnimator.kt:136)
                                                                                   at android.support.v7.widget.SimpleItemAnimator.animateDisappearance(SimpleItemAnimator.java:109)
                                                                                   at android.support.v7.widget.RecyclerView.animateDisappearance(RecyclerView.java:3931)
                                                                                   at android.support.v7.widget.RecyclerView$4.processDisappeared(RecyclerView.java:523)
                                                                                   at android.support.v7.widget.ViewInfoStore.process(ViewInfoStore.java:242)
                                                                                   at android.support.v7.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:3763)
                                                                                   at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3421)
                                                                                   at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3962)
                                                                                   at android.view.View.layout(View.java:19586)
                                                                                   at android.view.ViewGroup.layout(ViewGroup.java:6053)
                                                                                   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
                                                                                   at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
                                                                                   at android.view.View.layout(View.java:19586)
                                                                                   at android.view.ViewGroup.layout(ViewGroup.java:6053)

Error collapse filter in first time

Hello!
I'm implemented SearchFilter like the example. When I load my fragment in first time, filter is expanded. I click in collapse button and the filter list collapse and expand quickly . In this moment, I can select a tag or click in collapse button and work correctly. It's a error?

mFilter = (Filter<Tag>) view.findViewById(R.id.filter); mFilter.setAdapter(new Adapter(getTags())); mFilter.setListener(this); mFilter.setNoSelectedItemText("Filtros de búsqueda"); mFilter.build();

Can it be collapse by default when loading the first time? Thanks

KotlinNullPointerException

Hi,

im using new androidx libary and i keep get this exception -

kotlin.KotlinNullPointerException
at com.yalantis.filter.widget.Filter.onSaveInstanceState(Filter.kt:349)

Is it possible to change FilterItem's text after Filter#build() called?

I need to update text to show number of search results for each FilterItem.
I can see only one way to do this with current API: recreate Filter view each time I need to update any FilterItem.
This method is ineffective and cause blinking on update (because of collapsing panel each time Filter is built).
Is there any better solution?

select only single filter at a time

i am unable to find the solution ,i want to select only one filter at a time i request . if i try to select multiple filters only the last will be selected

Null Pointer Exception, Why?

kotlin.KotlinNullPointerException
at com.yalantis.filter.widget.Filter.onSaveInstanceState(Filter.kt:349)
at android.view.View.dispatchSaveInstanceState(View.java:20650)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:3961)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:3967)
at android.view.View.saveHierarchyState(View.java:20633)
at androidx.fragment.app.FragmentStateManager.saveViewState(FragmentStateManager.java:721)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:330)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2106)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Configuring FilterItem corner radius

There is no way to change FilterItem corner radius outside of the library. I think it would be nice to have a property to change the radius value.

Program type already present: org.jetbrains.annotations.NotNull

Hi,
When i add SearchFilter library and try to run app i get this error:
Program type already present: org.jetbrains.annotations.NotNull
Message{kind=ERROR, text=Program type already present: org.jetbrains.annotations.NotNull, sources=[Unknown source file], tool name=Optional.of(D8)}

KotlinNullPointerException

kotlin.KotlinNullPointerException: null
    at com.yalantis.filter.widget.Filter.onSaveInstanceState(Filter.kt:349)
    at android.view.View.dispatchSaveInstanceState(View.java:20183)
    at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:4014)
    at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:4020)
    at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:4020)
    at android.view.View.saveHierarchyState(View.java:20166)
    at androidx.fragment.app.FragmentManagerImpl.saveFragmentViewState(FragmentManagerImpl.java:2273)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:951)
    at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
    at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:434)
    at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2076)
    at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1866)
    at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1821)
    at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
    at androidx.fragment.app.FragmentManagerImpl$2.run(FragmentManagerImpl.java:150)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7050)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

How to select an item programmatically?

I want to remember my last selection. And for that, I have to select som items programmatically. How do I do that?

Filter.onItemSelected(FilterItem) doesn't work properly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.