-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from FarshidRoohi/develop
Release new version
- Loading branch information
Showing
25 changed files
with
602 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
customAdapterRecycleView/src/main/java/io/github/farshidroohi/DiffUtilAdapterRecyclerView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.github.farshidroohi | ||
|
||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.viewbinding.ViewBinding | ||
import io.github.farshidroohi.vh.BaseViewHolder | ||
|
||
|
||
/** | ||
* Created by Farshid Roohi. | ||
* CustomAdapterRecyclerview | Copyrights 10/8/22. | ||
*/ | ||
|
||
abstract class DiffUtilAdapterRecyclerView<ViewBindingType : ViewBinding, T>( | ||
diffCallback: DiffUtil.ItemCallback<T> | ||
) : ListAdapter<T, BaseViewHolder<ViewBindingType>>(diffCallback) { | ||
|
||
abstract fun initViewBinding(parent: ViewGroup): ViewBindingType | ||
abstract fun bind(binding: ViewBindingType, position: Int, item: T, payloads: MutableList<Any>?) | ||
|
||
override fun onCreateViewHolder( | ||
parent: ViewGroup, | ||
viewType: Int | ||
): BaseViewHolder<ViewBindingType> { | ||
val binding = initViewBinding(parent) | ||
return BaseViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder( | ||
holder: BaseViewHolder<ViewBindingType>, | ||
position: Int, | ||
payloads: MutableList<Any> | ||
) { | ||
bind(holder.binding, position, currentList[position], payloads) | ||
} | ||
|
||
override fun onBindViewHolder(holder: BaseViewHolder<ViewBindingType>, position: Int) { | ||
bind(holder.binding, position, currentList[position], null) | ||
} | ||
|
||
override fun getItemCount(): Int = currentList.size | ||
|
||
fun changeItem(items: ArrayList<T>, element: T, newElement: T) { | ||
val index = items.indexOf(element) | ||
items[index] = newElement | ||
submitList(items.toMutableList()) | ||
} | ||
|
||
fun clear() { | ||
submitList(emptyList()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
customAdapterRecycleView/src/main/java/io/github/farshidroohi/vh/BaseViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.github.farshidroohi.vh | ||
|
||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.viewbinding.ViewBinding | ||
|
||
/** | ||
* Created by Farshid Roohi. | ||
* CustomAdapterRecyclerview | Copyrights 10/8/22. | ||
*/ | ||
|
||
class BaseViewHolder<ViewBindingType : ViewBinding>(val binding: ViewBindingType) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.