`<com.ernestoyaquello.dragdropswiperecyclerview.DragDropSwipeRecyclerView`
android:layout_width="match_parent"
android:id="@+id/rv_orders"
app:behind_swiped_item_custom_layout="@layout/behind_swiped_vertical_list"
app:behind_swiped_item_custom_layout_secondary="@layout/behind_swiped_vertical_list_secondary"
android:layout_height="match_parent" />`
`private fun setupRecyclerView(orders: List<OrderSingle>) {
if (swipeRefresh.isRefreshing) {
swipeRefresh.isRefreshing = false
}
if(currentPage == 1) {
mainOrdersList = orders.toMutableList()
layoutManager = LinearLayoutManager(this)
rv_orders.layoutManager = layoutManager
adapter = OrdersAdapter(this, this, mainOrdersList, mainOrdersList, status!!)
rv_orders.adapter = adapter
adapter.notifyDataSetChanged()
rv_orders.orientation = DragDropSwipeRecyclerView.ListOrientation.VERTICAL_LIST_WITH_VERTICAL_DRAGGING
rv_orders.behindSwipedItemLayoutId = R.layout.behind_swiped_vertical_list
rv_orders.behindSwipedItemSecondaryLayoutId = R.layout.behind_swiped_vertical_list_secondary
rv_orders.reduceItemAlphaOnSwiping = true
rv_orders.scrollListener = onListScrollListener
rv_orders.dragListener = onItemDragListener
rv_orders.swipeListener = onItemSwipeListener
rv_orders.disableSwipeDirection(DragDropSwipeRecyclerView.ListOrientation.DirectionFlag.UP)
rv_orders.disableSwipeDirection(DragDropSwipeRecyclerView.ListOrientation.DirectionFlag.DOWN)
rv_orders.isNestedScrollingEnabled = true
rv_orders.setHasFixedSize(true)
when (status) {
"NEW" -> {
rv_orders.disableSwipeDirection(DragDropSwipeRecyclerView.ListOrientation.DirectionFlag.RIGHT)
}
"PENDING" -> {
rv_orders.disableSwipeDirection(DragDropSwipeRecyclerView.ListOrientation.DirectionFlag.LEFT)
}
else -> {
rv_orders.disableSwipeDirection(DragDropSwipeRecyclerView.ListOrientation.DirectionFlag.LEFT)
rv_orders.disableSwipeDirection(DragDropSwipeRecyclerView.ListOrientation.DirectionFlag.RIGHT)
}
}
} else {
mainOrdersList.addAll(orders)
Log.e("More loading","SIZE " + mainOrdersList.size)
Log.e("More loading","SIZE 2 " + orders.size)
adapter.notifyDataSetChanged()
}
}`
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val view =
LayoutInflater.from(parent.context).inflate(R.layout.single_item_order, parent, false)
return MyViewHolder(view)
}
override fun getItemCount(): Int {
Log.e("COUNT", filteredData.size.toString())
return filteredData.size
}
class MyViewHolder(view: View) : DragDropSwipeAdapter.ViewHolder(view) {
val singleOrderItem: LinearLayout = view.findViewById(R.id.singleOrderItem)
val orderId: TextView = view.findViewById(R.id.tv_orderId_SO)
val status: TextView = view.findViewById(R.id.tv_status_SO)
val name: TextView = view.findViewById(R.id.tv_name_SO)
private val address: TextView = view.findViewById(R.id.tv_address_SO)
val dragIcon: ImageView = view.findViewById(R.id.drag_icon)
fun bindTo(item: OrderSingle, context: Context, statusText: String) {
try {
orderId.text = "ORDER ID: ${item.orderId}"
status.text = item.orderStatus
if(item.orderStatus == "PICKUP") {
status.text = "REMAINING"
}
when (statusText) {
"PENDING", "NEW" -> {
status.setTextColor(ContextCompat.getColor(context, R.color.pending))
}
"DELIVERED" -> {
status.setTextColor(ContextCompat.getColor(context, R.color.delivered))
}
else -> {
status.setTextColor(ContextCompat.getColor(context, R.color.colorPrimary))
}
}
name.text = item.shipTo
address.text = item.shippingAddress
} catch (e: Exception) {
e.printStackTrace()
}
}
}
override fun getFilter(): Filter {
return object : Filter() {
override fun performFiltering(charSequence: CharSequence): FilterResults? {
val charString = charSequence.toString()
if (charString.isEmpty()) {
filteredData = data
} else {
val filteredList: MutableList<OrderSingle> = ArrayList()
for (row in data) { // name match condition. this might differ depending on your requirement
if (
row.orderId.toLowerCase(Locale.ROOT).contains(charString.toLowerCase(Locale.ROOT)) ||
row.shipTo.toLowerCase(Locale.ROOT).contains(charString.toLowerCase(Locale.ROOT)) ||
row.shippingAddress.toLowerCase(Locale.ROOT).contains(charString.toLowerCase(Locale.ROOT)) ||
row.orderStatus.toLowerCase(Locale.ROOT).contains(charString.toLowerCase(Locale.ROOT)) ||
row.deliveryType.toLowerCase(Locale.ROOT).contains(charString.toLowerCase(Locale.ROOT))
) {
filteredList.add(row)
}
}
filteredData = filteredList
}
val filterResults = FilterResults()
filterResults.values = filteredData
return filterResults
}
override fun publishResults(
charSequence: CharSequence?,
filterResults: FilterResults
) {
filteredData = filterResults.values as List<OrderSingle>
notifyDataSetChanged()
}
}
}
override fun getViewHolder(itemView: View): MyViewHolder {
return MyViewHolder(itemView)
}
override fun getViewToTouchToStartDraggingItem(
item: OrderSingle,
viewHolder: MyViewHolder,
position: Int
) = viewHolder.dragIcon
override fun onBindViewHolder(item: OrderSingle, viewHolder: MyViewHolder, position: Int) {
viewHolder.bindTo(item, context, statusText)
viewHolder.singleOrderItem.setOnClickListener {
if(statusText != "NEW")
listener.onItemClick(filteredData[position].orderId)
}
}
Whenever the list pull pulled from top to bottom, new data set is called and that in turn calls 'setupRecyclerView' and provides it with new data list and as soon as I refresh the list, both the behindSwipedItemLayout disappears and I get empty background when swiped.