diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..2c04f07
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+ListBottomSheetProject
\ No newline at end of file
diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
new file mode 100644
index 0000000..41a4dca
--- /dev/null
+++ b/.idea/deploymentTargetDropDown.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/zak/listbottomsheetproject/MainActivity.kt b/app/src/main/java/com/zak/listbottomsheetproject/MainActivity.kt
index e46dca1..f2e5af6 100644
--- a/app/src/main/java/com/zak/listbottomsheetproject/MainActivity.kt
+++ b/app/src/main/java/com/zak/listbottomsheetproject/MainActivity.kt
@@ -84,6 +84,11 @@ class MainActivity : AppCompatActivity() {
multiListSheet.show()
}
+ btnClearMultiSheet.setOnClickListener {
+
+ multiListSheet.clearSelectedItems()
+ }
+
}
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 473479e..9a418c4 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -45,4 +45,13 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnOpenSheet" />
+
+
\ No newline at end of file
diff --git a/listbottomsheet/build.gradle b/listbottomsheet/build.gradle
index 2cc79f4..4a74712 100644
--- a/listbottomsheet/build.gradle
+++ b/listbottomsheet/build.gradle
@@ -11,8 +11,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 31
- versionCode 11
- versionName "1.3.7"
+ versionCode 12
+ versionName "1.3.8"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
diff --git a/listbottomsheet/src/main/java/com/zak/listbottomsheet/MultiListBottomSheet.kt b/listbottomsheet/src/main/java/com/zak/listbottomsheet/MultiListBottomSheet.kt
index e19abd0..8048eb9 100644
--- a/listbottomsheet/src/main/java/com/zak/listbottomsheet/MultiListBottomSheet.kt
+++ b/listbottomsheet/src/main/java/com/zak/listbottomsheet/MultiListBottomSheet.kt
@@ -242,34 +242,30 @@ class MultiListBottomSheet private constructor(
txtSearch?.typeface = it
btnAction?.typeface = it
}
-
}
private fun setSearchable(searchable: Boolean) {
if (!searchable) {
return
- }
+ } //end if
//display the search view
bottomSheetView.findViewById(R.id.searchContainer).visibility = View.VISIBLE
+
//bind txtSearch watcher listener
bottomSheetView.findViewById(R.id.txtSearch).addTextChangedListener(object: TextWatcher {
override fun afterTextChanged(p0: Editable?) {
-
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
-
}
override fun onTextChanged(charSequence: CharSequence?, p1: Int, p2: Int, p3: Int) {
mAdapter?.filter?.filter(charSequence)
}
-
})
-
}
override fun show() {
@@ -285,4 +281,11 @@ class MultiListBottomSheet private constructor(
}, 0)
super.show()
}
+
+ fun clearSelectedItems() {
+ (recyclerView?.adapter as? MultiListAdapter)?.also {
+ it.selectedItemsList.clear()
+ it.notifyDataSetChanged()
+ }
+ }
}
\ No newline at end of file
diff --git a/listbottomsheet/src/main/java/com/zak/listbottomsheet/adapter/MultiListAdapter.kt b/listbottomsheet/src/main/java/com/zak/listbottomsheet/adapter/MultiListAdapter.kt
index 1c8b360..8da2708 100644
--- a/listbottomsheet/src/main/java/com/zak/listbottomsheet/adapter/MultiListAdapter.kt
+++ b/listbottomsheet/src/main/java/com/zak/listbottomsheet/adapter/MultiListAdapter.kt
@@ -14,7 +14,6 @@ import com.zak.listbottomsheet.ListItem
import com.zak.listbottomsheet.R
import java.util.*
-
class MultiListAdapter(
private val mContext: Context,
var mList: MutableList,
@@ -30,7 +29,6 @@ class MultiListAdapter(
val selectedItemsList = mutableListOf()
var listFiltered = mList.toMutableList()
-
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(mContext).inflate(
@@ -38,11 +36,9 @@ class MultiListAdapter(
parent,
false
)
-
return ViewHolder(view, selectedItemColor, defaultItemColor, selectedItemBackgroundColor, defaultItemBackgroundColor)
}
-
-
+
override fun getItemCount(): Int {
return listFiltered.size
}
@@ -59,7 +55,6 @@ class MultiListAdapter(
}
}
-
class ViewHolder(itemView: View,private val selectedColor: Int,
private val defaultItemColor: Int,
private val selectedItemBackgroundColor: Int,
@@ -83,14 +78,11 @@ class MultiListAdapter(
field = value
}
-
fun setOnClickListener(instance: MultiListAdapter, item: ListItem, listener: (ListItem) -> Unit) {
itemView.setOnClickListener {
if (!instance.selectedItemsList.remove(item)) { //if remove return false means it doesn't exists so add it to the list
- Log.d("##item", " will be added")
instance.selectedItemsList.add(item)
} //end if
- Log.d("##item", " size ${instance.selectedItemsList.size}")
instance.notifyItemChanged(adapterPosition)
listener(item)
}
@@ -107,7 +99,6 @@ class MultiListAdapter(
} else {
mList.filter {
- Log.d("##charSeq", "search in ${it.title}")
it.title.lowercase(Locale.getDefault()).contains(charSequence.toString()
.lowercase(Locale.getDefault()))
}.toMutableList()
@@ -122,7 +113,6 @@ class MultiListAdapter(
listFiltered = filterResults?.values as MutableList
notifyDataSetChanged()
}
-
}
}
}
\ No newline at end of file