Skip to content

Commit

Permalink
update: fixing bug item remove
Browse files Browse the repository at this point in the history
  • Loading branch information
amirisback committed Mar 25, 2024
1 parent f0a2bcb commit 5d67208
Show file tree
Hide file tree
Showing 39 changed files with 163 additions and 182 deletions.
@@ -1,6 +1,5 @@
package com.frogobox.recycler.core

import android.util.Log
import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -15,61 +14,16 @@ import androidx.recyclerview.widget.RecyclerView
*/


abstract class CoreFrogoRecyclerViewAdapter<T, VH : CoreFrogoRecyclerViewHolder<T>> : RecyclerView.Adapter<VH>() {
abstract class CoreFrogoRecyclerViewAdapter<T, VH : CoreFrogoRecyclerViewHolder<T>> :
RecyclerView.Adapter<VH>(), FrogoRecyclerNotifyListener<T> {

/**
* Base Of Core FrogoRecyclerViewHolder
*/

protected val listData = mutableListOf<T>()

protected var notifyListener = object : FrogoRecyclerNotifyListener<T> {

override fun frogoNotifyData(): MutableList<T> {
return innerFrogoNotifyData()
}

override fun frogoNotifyDataSetChanged() {
innerFrogoNotifyDataSetChanged()
}

override fun frogoNotifyItemChanged(data: T, position: Int, payload: Any) {
innerFrogoNotifyItemChanged(data, position, payload)
}

override fun frogoNotifyItemChanged(data: T, position: Int) {
innerFrogoNotifyItemChanged(data, position)
}

override fun frogoNotifyItemInserted(data: T, position: Int) {
innerFrogoNotifyItemInserted(data, position)
}

override fun frogoNotifyItemMoved(data: T, fromPosition: Int, toPosition: Int) {
innerFrogoNotifyItemMoved(data, fromPosition, toPosition)
}

override fun frogoNotifyItemRangeChanged(data: List<T>, positionStart: Int, payload: Any) {
innerFrogoNotifyItemRangeChanged(data, positionStart, payload)
}

override fun frogoNotifyItemRangeChanged(data: List<T>, positionStart: Int) {
innerFrogoNotifyItemRangeChanged(data, positionStart)
}

override fun frogoNotifyItemRangeInserted(data: List<T>, positionStart: Int) {
innerFrogoNotifyItemRangeInserted(data, positionStart)
}

override fun frogoNotifyItemRangeRemoved(positionStart: Int, itemCount: Int) {
innerFrogoNotifyItemRangeRemoved(positionStart, itemCount)
}

override fun frogoNotifyItemRemoved(item: T) {
innerFrogoNotifyItemRemoved(item)
}
protected val listData = mutableListOf<T>()

}
protected var notifyListener = this

protected val asyncListDiffer = AsyncListDiffer(this, object : DiffUtil.ItemCallback<T>() {
override fun areItemsTheSame(oldItem: T & Any, newItem: T & Any): Boolean {
Expand All @@ -90,74 +44,74 @@ abstract class CoreFrogoRecyclerViewAdapter<T, VH : CoreFrogoRecyclerViewHolder<
}

// Notify Data List
fun innerFrogoNotifyData(): MutableList<T> {
override fun frogoNotifyData(): MutableList<T> {
return listData
}

// Notify Data Set Changed
fun innerFrogoNotifyDataSetChanged() {
override fun frogoNotifyDataSetChanged() {
notifyDataSetChanged()
}

// Notify Data Item Changed
fun innerFrogoNotifyItemChanged(data: T, position: Int, payload: Any) {
override fun frogoNotifyItemChanged(data: T, position: Int, payload: Any) {
listData[position] = data
notifyItemChanged(position, payload)
asyncListDiffer.submitList(listData)
}

// Notify Data Item Changed
fun innerFrogoNotifyItemChanged(data: T, position: Int) {
override fun frogoNotifyItemChanged(data: T, position: Int) {
listData[position] = data
notifyItemChanged(position)
asyncListDiffer.submitList(listData)
}

// Notify Data Item Inserted
fun innerFrogoNotifyItemInserted(data: T, position: Int) {
override fun frogoNotifyItemInserted(data: T, position: Int) {
listData.add(position, data)
notifyItemInserted(position)
asyncListDiffer.submitList(listData)
}

// Notify Data Item Moved
fun innerFrogoNotifyItemMoved(data: T, fromPosition: Int, toPosition: Int) {
override fun frogoNotifyItemMoved(data: T, fromPosition: Int, toPosition: Int) {
listData.removeAt(fromPosition)
listData.add(toPosition, data)
notifyItemMoved(fromPosition, toPosition)
asyncListDiffer.submitList(listData)
}

// Notify Data Item Range Changed
fun innerFrogoNotifyItemRangeChanged(data: List<T>, positionStart: Int, payload: Any) {
override fun frogoNotifyItemRangeChanged(data: List<T>, positionStart: Int, payload: Any) {
listData.addAll(positionStart, data)
notifyItemRangeChanged(positionStart, data.size, payload)
asyncListDiffer.submitList(listData)
}

// Notify Data Item Range Changed
fun innerFrogoNotifyItemRangeChanged(data: List<T>, positionStart: Int) {
override fun frogoNotifyItemRangeChanged(data: List<T>, positionStart: Int) {
listData.addAll(positionStart, data)
notifyItemRangeChanged(positionStart, data.size)
asyncListDiffer.submitList(listData)
}

// Notify Data Item Range Inserted
fun innerFrogoNotifyItemRangeInserted(data: List<T>, positionStart: Int) {
override fun frogoNotifyItemRangeInserted(data: List<T>, positionStart: Int) {
listData.addAll(positionStart, data)
notifyItemRangeChanged(positionStart, data.size)
asyncListDiffer.submitList(listData)
}

// Notify Data Item Range Removed
fun innerFrogoNotifyItemRangeRemoved(positionStart: Int, itemCount: Int) {
override fun frogoNotifyItemRangeRemoved(positionStart: Int, itemCount: Int) {
listData.subList(positionStart, (positionStart + itemCount)).clear()
notifyItemRangeRemoved(positionStart, itemCount)
asyncListDiffer.submitList(listData)
}

// Notify Data Item Removed
fun innerFrogoNotifyItemRemoved(item : T) {
override fun frogoNotifyItemRemoved(item: T) {
val index = listData.indexOf(item)
listData.remove(item)
notifyItemRemoved(index)
Expand Down
Expand Up @@ -7,7 +7,7 @@ import androidx.viewbinding.ViewBinding
* Created by Faisal Amir
* =========================================
* FrogoRecyclerViewAdapter
* Copyright (C) 14/04/2020.
* Copyright (C) 14/04/2020.
* All rights reserved
* -----------------------------------------
* Name : Muhammad Faisal Amir
Expand All @@ -16,7 +16,7 @@ import androidx.viewbinding.ViewBinding
* -----------------------------------------
* FrogoBox Inc
* com.frogobox.recycler.content
*
*
*/

class FrogoBindingAdapter<T, VB : ViewBinding> : FrogoRecyclerBindingAdapter<T, VB>() {
Expand All @@ -31,6 +31,9 @@ class FrogoBindingAdapter<T, VB : ViewBinding> : FrogoRecyclerBindingAdapter<T,
parent: ViewGroup,
viewType: Int
): FrogoRecyclerBindingHolder<T, VB> {
return FrogoBindingHolder(frogoViewHolderCallback!!.setViewBinding(parent), frogoViewHolderCallback)
return FrogoBindingHolder(
frogoViewHolderCallback!!.setViewBinding(parent),
frogoViewHolderCallback
)
}
}
Expand Up @@ -2,7 +2,7 @@ package com.frogobox.recycler.core

import androidx.viewbinding.ViewBinding

/*
/**
* Created by Faisal Amir
* =========================================
* FrogoRecyclerViewAdapter
Expand Down
Expand Up @@ -3,7 +3,7 @@ package com.frogobox.recycler.core
import android.view.View
import androidx.recyclerview.widget.RecyclerView

/*
/**
* Created by faisalamir on 23/07/21
* FrogoRecyclerView
* -----------------------------------------
Expand Down
Expand Up @@ -4,7 +4,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.frogobox.recycler.R


/*
/**
* Created by faisalamir on 24/07/21
* FrogoRecyclerView
* -----------------------------------------
Expand Down
Expand Up @@ -4,7 +4,7 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding

/*
/**
* Created by faisalamir on 24/07/21
* FrogoRecyclerView
* -----------------------------------------
Expand Down
@@ -1,6 +1,6 @@
package com.frogobox.recycler.core

/*
/**
* Created by Faisal Amir on 04/02/2021
* FrogoRecyclerView Source Code
* -----------------------------------------
Expand Down
Expand Up @@ -2,7 +2,7 @@ package com.frogobox.recycler.core

import androidx.viewbinding.ViewBinding

/*
/**
* Created by Faisal Amir on 04/02/2021
* FrogoRecyclerView Source Code
* -----------------------------------------
Expand Down
@@ -1,7 +1,11 @@
package com.frogobox.recycler.core

import android.content.Context
import androidx.recyclerview.widget.*
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.google.android.flexbox.FlexboxLayoutManager

/**
Expand All @@ -12,7 +16,7 @@ import com.google.android.flexbox.FlexboxLayoutManager
* E-mail : faisalamircs@gmail.com
* Github : github.com/amirisback
* -----------------------------------------
* Copyright (C) 2021 FrogoBox Inc.
* Copyright (C) 2021 FrogoBox Inc.
* All rights reserved
*
*/
Expand Down Expand Up @@ -70,7 +74,11 @@ object FrogoLayoutManager : IFrogoLayoutManager {
return GridLayoutManager(context, spanCount)
}

override fun flexboxLayout(context: Context, flexDirection: Int, justifyContent: Int): FlexboxLayoutManager {
override fun flexboxLayout(
context: Context,
flexDirection: Int,
justifyContent: Int
): FlexboxLayoutManager {
return FlexboxLayoutManager(context).apply {
this.flexDirection = flexDirection
this.justifyContent = justifyContent
Expand Down
Expand Up @@ -5,7 +5,7 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

/*
/**
* Created by Amir on 03/03/2021
* FrogoRecyclerView Source Code
* -----------------------------------------
Expand Down
Expand Up @@ -3,7 +3,7 @@ package com.frogobox.recycler.core
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

/*
/**
* Created by Amir on 03/03/2021
* FrogoRecyclerView Source Code
* -----------------------------------------
Expand Down
Expand Up @@ -6,7 +6,7 @@ import androidx.viewbinding.ViewBinding
* Created by Faisal Amir
* =========================================
* FrogoRecyclerViewAdapter
* Copyright (C) 29/04/2020.
* Copyright (C) 29/04/2020.
* All rights reserved
* -----------------------------------------
* Name : Muhammad Faisal Amir
Expand All @@ -15,10 +15,11 @@ import androidx.viewbinding.ViewBinding
* -----------------------------------------
* FrogoBox Inc
* com.frogobox.recycler.base
*
*
*/

abstract class FrogoRecyclerBindingAdapter<T, VB : ViewBinding> : CoreFrogoRecyclerViewAdapter<T, FrogoRecyclerBindingHolder<T, VB>>() {
abstract class FrogoRecyclerBindingAdapter<T, VB : ViewBinding> :
CoreFrogoRecyclerViewAdapter<T, FrogoRecyclerBindingHolder<T, VB>>() {

protected var bindingListener: FrogoRecyclerBindingListener<T, VB>? = null

Expand All @@ -36,7 +37,12 @@ abstract class FrogoRecyclerBindingAdapter<T, VB : ViewBinding> : CoreFrogoRecyc
}

override fun onBindViewHolder(holder: FrogoRecyclerBindingHolder<T, VB>, position: Int) {
holder.bindItem(asyncListDiffer.currentList[position], position, bindingListener, notifyListener)
holder.bindItem(
asyncListDiffer.currentList[position],
position,
bindingListener,
notifyListener
)
}

fun setupData(data: List<T>?) {
Expand Down
Expand Up @@ -3,7 +3,7 @@ package com.frogobox.recycler.core
import androidx.viewbinding.ViewBinding


/*
/**
* Created by faisalamir on 11/12/21
* FrogoRecyclerView
* -----------------------------------------
Expand Down
@@ -1,7 +1,7 @@
package com.frogobox.recycler.core


/*
/**
* Created by faisalamir on 11/12/21
* FrogoRecyclerView
* -----------------------------------------
Expand All @@ -17,7 +17,7 @@ package com.frogobox.recycler.core
interface FrogoRecyclerNotifyListener<T> {

// Notify Data List
fun frogoNotifyData() : MutableList<T>
fun frogoNotifyData(): MutableList<T>

// Notify Data Set Changed
fun frogoNotifyDataSetChanged()
Expand Down Expand Up @@ -48,5 +48,5 @@ interface FrogoRecyclerNotifyListener<T> {

// Notify Data Item Removed
fun frogoNotifyItemRemoved(item: T)

}

0 comments on commit 5d67208

Please sign in to comment.