🎈 A horizontal list of filters, customizable on Android.
Step 1. Add the JitPack repository to your build file
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Step 2.Add the dependency below to your module's build.gradle
file:
dependencies {
implementation 'com.github.koohyar7342:FilterRecycle:1.0.2'
}
creating FilterRecycle in xml
<com.koohyar.filterRecycle.FilterRecycle
android:id="@+id/testing_recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:fr_card_content_padding="@dimen/default_content_padding"
app:fr_selected_background_color="@android:color/holo_orange_light"
app:fr_selected_text_color="@android:color/holo_red_light"
app:fr_unselected_Background_color="@android:color/white"
app:fr_unselected_text_color="@android:color/black"
/>
create a list of filters
private var filtersList = listOf<FilterModel>(
FilterModel(0, "فیلتر 0", "فیلتر 0", false),
FilterModel(1, "فیلتر 1", "فیلتر 1", false),
FilterModel(2, "فیلتر 2", "فیلتر 2", false),
FilterModel(3, "فیلتر 3", "فیلتر 3", false),
FilterModel(4, "فیلتر 4", "فیلتر 4", false),
FilterModel(5, "فیلتر 5", "فیلتر 5", false),
FilterModel(6, "فیلتر 6", "فیلتر 6", false),
FilterModel(7, "فیلتر 7", "فیلتر 7", false),
FilterModel(8, "فیلتر 8", "فیلتر 8", false),
FilterModel(9, "فیلتر 9", "فیلتر 9", false),
)
initilize the recyclerview with created filtersList and lifecycleScope
binding.testingRecycle.initializeRecycleView(filtersList, lifecycleScope)
set clickListener on filters
binding.testingRecycle.setClickListener(object : FilterClickListener {
override fun onAddFilter(position: Int, id: Int): Boolean {
// Apply adding filter
return true // or return false if you want cancel adding
}
override fun onRemoveFilter(position: Int, id: Int): Boolean {
// Apply removing filter
return true //or return false if you want cancel removing
}
})
selecting filter with it's id manually
binding.testingRecycle.setSelectedFilter(1) // just set filter with id=1 as selected
removing filter with it's id manually
binding.testingRecycle.removeSelectedFilter(1) // just set filter with id=1 as Unselected
Support me here https://koohyar7342.github.io
Also, follow me on GitHub for my next creations!