Skip to content

Commit

Permalink
#refactoring code (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
MalaRuparel2023 authored May 16, 2024
1 parent 1b2d846 commit ed4d9cc
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 155 deletions.
59 changes: 36 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
# Smart Filter Library

This is a library for creating and managing ....
This library provides a set of customizable filter components for Android applications. It supports both single and multi-selection filters in various formats such as radio groups, chip groups, and list views. The filters can be displayed either vertically or horizontally.

## Features

- Single Line Radio Group(Verticle/Horizontal)
- Multi Line Radio Group
- Row Item Radio Group(Verticle/Horizontal)
- Range Selection
- Chip Group Single Selection(Verticle/Horizontal)
- Chip Group Multi Selection(Verticle/Horizontal)
- Checked Single Selection(Verticle/Horizontal)
- Checked multi Selection(Verticle/Horizontal)
- Single Line Radio Group (Vertical/Horizontal)
- Multi Line Radio Group
- Row Item Radio Group (Vertical/Horizontal)
- Range Selection
- Chip Group Single Selection (Vertical/Horizontal)
- Chip Group Multi Selection (Vertical/Horizontal)
- Checked Single Selection (Vertical/Horizontal)
- Checked Multi Selection (Vertical/Horizontal)

## Getting Started

These instructions will get you a copy of the project up and running on your local machine
These instructions will guide you on how to get a copy of the project up and running on your local machine.

## Prerequisites


Before you can run the project, you need to have Android Studio installed on your machine. You also need to have a suitable Android device or emulator for running the application.

## Installing

- **Clone the repository: `git clone https://github.com/smartSenseSolutions/smart-filter-library.git`**
- **Open the project in Android Studio.**
- **Build and run the project on an emulator or device.**
1. Clone the repository: `git clone https://github.com/smartSenseSolutions/smart-filter-library.git`
2. Open the project in Android Studio.
3. Build and run the project on an emulator or device.

## Usage

The library provides a set of classes and methods for creating and managing filter components. Each filter type has its own class and configuration methods. The filters can be added to any ViewGroup in your layout.

The library also provides a set of default styles for the filters. You can customize these styles by providing your own drawable and color resources.

## Dependencies

The library depends on the following libraries:

- `androidx.appcompat:appcompat:1.3.1`
- `androidx.core:core-ktx:1.6.0`


## SingleSelection
Expand Down Expand Up @@ -117,16 +130,16 @@ This is a library for creating and managing ....

- **Verticle**

SmartFilter.addListViewSingleSelection {
addSingleSelectionListVertical(binding.root) { radioGroupData ->
toast("id: " + radioGroupData) } }
SmartFilter.addListViewSingleSelection {
addSingleSelectionListVertical(binding.root) { radioGroupData ->
toast("name: " + radioGroupData.name) } }

<img src="media/single_selection_vertical.png.png" width="250" />
- **Horizontal**

SmartFilter.addListViewSingleSelection {
addSingleSelectionListHorizontal(binding.root) { radioGroupData ->
toast("id: " + radioGroupData) } }
toast("name: " + radioGroupData.name) } }

<img src="media/single_selection_horizental.png.png.png" width="250" />

Expand All @@ -135,17 +148,17 @@ This is a library for creating and managing ....

- **Verticle**

SmartFilter.addListViewMultiSelection{
addMultiSelectionList(binding.root) { radioGroupData ->
toast("id: " + radioGroupData) } }
SmartFilter.addListViewMultiSelection{
addMultiSelectionListVertical(binding.root) { radioGroupData ->
toast("name: " + radioGroupData) } }

<img src="media/multi_selection_vertical.png" width="250" />

- **Horizontal**

SmartFilter.addListViewMultiSelection{
addMultiSelectionListHorizontal(binding.root) { radioGroupData ->
toast("id: " + radioGroupData) } }
toast("name: " + radioGroupData) } }

<img src="media/multi_selection_horizontal.png" width="250" />

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/ss/smartfilter/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class MainActivity : ComponentActivity() {
setContentView(binding.root)


SmartFilter.addRadioRawItemSingleSelection {
addRadioGroupRowItemVertical(binding.root) { radioGroupData ->
toast("name: ${radioGroupData.name} ") } }
SmartFilter.addRadioGroupSingleSelection {
addRadioGroupSingleLineVertical(binding.root) { radioGroupData ->
toast("name: ${radioGroupData.name} ") }}

}

Expand Down
30 changes: 15 additions & 15 deletions app/src/main/java/com/ss/smartfilter/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ fun addRadioGroupSingleLineVertical(rootView: ViewGroup,onItemSelected: (Data) -
orientation = Orientation.VERTICAL,
mData = mData(),
onItemSelected = onItemSelected,
bgSelector = R.drawable.singleline_rb_selector,
textSelector = R.color.single_text_color_selector
bgSelector = R.drawable.rb_selector,
textSelector = R.color.text_color_selector
)
)

Expand All @@ -36,8 +36,8 @@ fun addRadioGroupSingleLineHorizontal(rootView: ViewGroup,onItemSelected: (Data)
orientation = Orientation.HORIZONTAL,
mData = mData(),
onItemSelected = onItemSelected,
bgSelector = R.drawable.singleline_rb_selector,
textSelector = R.color.single_text_color_selector
bgSelector = R.drawable.rb_selector,
textSelector = R.color.text_color_selector
)
)

Expand All @@ -64,7 +64,7 @@ fun addRadioGroupRowItemHorizontal(rootView: ViewGroup,onItemSelected: (Data) ->
mData = mData(),
onItemSelected = onItemSelected,
bgSelector = R.drawable.row_item_selector,
textSelector = R.color.single_text_color_selector
textSelector = R.color.text_color_selector

)
)
Expand All @@ -77,7 +77,7 @@ fun addRadioGroupRowItemVertical(rootView: ViewGroup,onItemSelected: (Data) -> U
mData = mData(),
onItemSelected = onItemSelected,
bgSelector = R.drawable.row_item_selector,
textSelector = R.color.single_text_color_selector
textSelector = R.color.text_color_selector

)
)
Expand All @@ -86,12 +86,12 @@ fun addSingleSelectionChipGroupVertical(rootView: ViewGroup, onItemSelected: (Da
SingleSelectionParams(
rootView = rootView,
singleGroupSubType = SingleGroupSubType.CHIP_GROUP,
chipType = SingleChipType.ENTRY_CHIP,
chipType = SingleChipType.ACTION_CHIP,
orientation = Orientation.VERTICAL,
mData = mData(),
onItemSelected = onItemSelected,
bgSelector = R.color.chip_bg_selector,
textSelector = R.color.multiline_text_selector
textSelector = R.color.chip_text_selector
)
)
fun addSingleSelectionChipGroupHorizontal(rootView: ViewGroup, onItemSelected: (Data) -> Unit) = Params.SingleSelection(
Expand All @@ -109,7 +109,7 @@ fun addSingleSelectionChipGroupHorizontal(rootView: ViewGroup, onItemSelected: (
fun addMultiSelectionChipGroupVertical(rootView: ViewGroup, onItemsSelected: (List<Int>) -> Unit) = Params.MultiSelection(
MultiSelectionParams(
rootView = rootView,
chipType = MultiChipType.FILTER_CHIP,
chipType = MultiChipType.ACTION_CHIP,
orientation = Orientation.VERTICAL,
mData = mData(),
onItemsSelected = onItemsSelected,
Expand Down Expand Up @@ -139,7 +139,7 @@ fun addSingleSelectionListHorizontal(rootView: ViewGroup, onItemselected: (Data)
mData = mData(),
onItemSelected = onItemselected,
bgSelector = R.drawable.ic_check_selector,
textSelector = R.color.chip_text_selector
textSelector = R.color.text_color_selector
)
)
fun addSingleSelectionListVertical(rootView: ViewGroup, onItemselected: (Data) -> Unit) = Params.SingleSelection(
Expand All @@ -151,7 +151,7 @@ fun addSingleSelectionListVertical(rootView: ViewGroup, onItemselected: (Data) -
mData = mData(),
onItemSelected = onItemselected,
bgSelector = R.drawable.ic_check_selector,
textSelector = R.color.chip_text_selector
textSelector = R.color.text_color_selector
)
)
fun addMultiSelectionListVertical(rootView: ViewGroup, onItemsSelected: (List<Int>) -> Unit) = Params.MultiSelection(
Expand All @@ -162,8 +162,8 @@ fun addMultiSelectionListVertical(rootView: ViewGroup, onItemsSelected: (List<I
orientation = Orientation.VERTICAL,
mData = mData(),
onItemsSelected = onItemsSelected,
bgSelector = R.color.chip_bg_selector,
textSelector = R.color.chip_text_selector
bgSelector = R.drawable.ic_check_selector,
textSelector = R.color.text_color_selector
)
)
fun addMultiSelectionListHorizontal(rootView: ViewGroup, onItemsSelected: (List<Int>) -> Unit) = Params.MultiSelection(
Expand All @@ -174,7 +174,7 @@ fun addMultiSelectionListHorizontal(rootView: ViewGroup, onItemsSelected: (List
orientation = Orientation.HORIZONTAL,
mData = mData(),
onItemsSelected = onItemsSelected,
bgSelector = R.color.chip_bg_selector,
textSelector = R.color.chip_text_selector
bgSelector = R.drawable.ic_check_selector,
textSelector = R.color.text_color_selector
)
)
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<item name="android:layout_marginBottom">8dp</item>
</style>
<style name="AppTheme.RadioButton" parent="Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:button">@drawable/singleline_rb_selector</item>
<item name="android:button">@drawable/rb_selector</item>
<item name="android:padding">8dp</item>
<item name="android:layout_margin">8dp</item>
<item name="android:textColor">@color/single_text_color_selector</item>
<item name="android:textColor">@color/text_color_selector</item>
<item name="android:textSize">8sp</item>
</style>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ data class SingleSelectionParams(
val orientation: Int,
val mData: ArrayList<Data>,
val onItemSelected: (Data) -> Unit,
@DrawableRes val bgSelector: Int =android.R.color.darker_gray,
@DrawableRes val bgSelector: Int = R.drawable.abc_btn_radio_material,
@ColorRes val textSelector: Int = android.R.color.black

)
/*
@DrawableRes val bgSelector: Int = com.ss.smartfilterlib.R.drawable.multiline_default,
@ColorRes val textSelector: Int = com.ss.smartfilterlib.R.color.black*/
/*
@ColorRes val bgSelector: Int = android.R.color.darker_gray,
@ColorRes val textSelector: Int = android.R.color.black*/
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@ import com.ss.smartfilterlib.utils.BaseRecycleView


/**
* created by Mala Ruparel ON 02/05/24
* MultiSelectionListView is a custom view that allows multiple selection from a list of options.
* The options are presented in a RecyclerView.
*
* @property smartOrientation The orientation of the RecyclerView, can be either vertical or horizontal.
* @property viewTextSelector The ColorStateList for the text color of the list items.
* @property checkSelector The resource ID for the drawable to use when an item is checked.
* @property dataFromXml The resource ID of the string array containing the list items.
* @property onMultiSelectionClicked The listener for checked change events of the list items.
*
* @constructor Creates a new MultiSelectionListView with the given context, attrs, and defStyle.
*/
class MultiSelectionListView @JvmOverloads constructor( context: Context,attrs: AttributeSet? = null,defStyle: Int = 0) : BaseRecycleView(context, attrs, defStyle){


init {
initAttributes(attrs=attrs)
initializeView()
populateDataFromAttributes()
}



override fun initializeView() {
layoutManager = when (smartOrientation) {
SmartOrientation.VERTICAL -> LinearLayoutManager(context, VERTICAL, false)
Expand All @@ -48,14 +55,11 @@ class MultiSelectionListView @JvmOverloads constructor( context: Context,attrs:
}
private fun populateDataFromAttributes() {
if (dataFromXml != 0) {
val mData = resources.getStringArray(dataFromXml);
mData.forEach {
val data = Data(name = it)
mList.add(data)
resources.getStringArray(dataFromXml).forEach {
mList.add(Data(name = it))
}
setItems(mList)
}

}

fun configureView(data: ArrayList<Data>, orientation: Int, checkSelector: Int, primaryTextColor: Int, onCheckedChangeListener: ((List<Int>) -> Unit)?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ss.smartfilterlib.multiselection

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.HorizontalScrollView
import android.widget.ScrollView
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -39,19 +40,17 @@ class MultiselectionChipGroup @JvmOverloads constructor(context: Context, attrs:
}
private fun populateDataFromAttributes() {
if (dataFromXml != 0) {
val mData = resources.getStringArray(dataFromXml)
val data = mData.map { Data(name = it) } as ArrayList<Data>
setOrientation()
setItems(data, MultiChipType.ENTRY_CHIP)
setItems(resources.getStringArray(dataFromXml).map { Data(name = it) }, MultiChipType.ENTRY_CHIP)
}
}
override fun initializeView() {
containerScrollView = ScrollView(context)
containerHorizontalScrollView = HorizontalScrollView(context)

val layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
containerScrollView.layoutParams = layoutParams
containerHorizontalScrollView.layoutParams = layoutParams
containerScrollView = ScrollView(context).apply {
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
}
containerHorizontalScrollView = HorizontalScrollView(context).apply {
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
}

chipGroup = ChipGroup(context)
}
Expand Down Expand Up @@ -106,6 +105,7 @@ class MultiselectionChipGroup @JvmOverloads constructor(context: Context, attrs:
return Chip(context, null, R.style.EntryChipStyle).apply {
isClickable = true
isCheckedIconVisible = false
textAlignment = View.TEXT_ALIGNMENT_CENTER
}
}

Expand Down Expand Up @@ -137,6 +137,7 @@ class MultiselectionChipGroup @JvmOverloads constructor(context: Context, attrs:
return Chip(context, null, R.style.FilterChipStyle).apply {
isCloseIconVisible = false
isChipIconVisible = true
textAlignment = View.TEXT_ALIGNMENT_CENTER
}
}

Expand Down Expand Up @@ -174,6 +175,11 @@ class MultiselectionChipGroup @JvmOverloads constructor(context: Context, attrs:
multiCheckedChangeListener?.invoke( checkedChipIds.toList())

}
chip.setOnCloseIconClickListener {
chipGroup.removeView(chip)
checkedChipIds.remove(chip.id)
multiCheckedChangeListener?.invoke(checkedChipIds.toList())
}

}

Expand Down
Loading

0 comments on commit ed4d9cc

Please sign in to comment.