From 137060a4063ef7869942be613d94a27ee8e2ad74 Mon Sep 17 00:00:00 2001 From: amirisback Date: Mon, 25 Mar 2024 05:44:59 +0700 Subject: [PATCH 1/4] update: develop diff util --- .../sample/issue/AnswerIssueActivity.kt | 8 + .../JavaNoAdapterMultiViewActivity.java | 20 ++ .../simple/JavaNoAdapterActivity.java | 10 + .../java/usingadapter/JavaSampleActivity.java | 10 + .../sample/kotlin/FrogoRvExtActivity.kt | 8 + .../KotlinNoAdapterMultiVewActivity.kt | 16 ++ .../progress/KotlinProgressActivity.kt | 8 + .../shimmer/KotlinShimmerActivity.kt | 8 + .../simple/KotlinNoAdapterActivity.kt | 43 ++++- .../nested/KotlinNestedActivity.kt | 8 + .../nested/KotlinSimpleNestedActivity.kt | 8 + .../simple/KotlinSampleActivity.kt | 14 ++ .../recycler/core/BaseRecyclerViewAdapter.kt | 154 +++++++++++++++ .../recycler/core/BaseRecyclerViewHolder.kt | 22 +++ .../recycler/core/FrogoBindingAdapter.kt | 3 +- .../frogobox/recycler/core/FrogoBuilderRv.kt | 8 + .../recycler/core/FrogoBuilderRvBinding.kt | 8 + .../recycler/core/FrogoDiffUtilCallback.kt | 24 +++ .../core/FrogoRecyclerBindingAdapter.kt | 137 ++------------ .../core/FrogoRecyclerBindingHolder.kt | 2 +- .../core/FrogoRecyclerBindingListener.kt | 2 +- .../recycler/core/FrogoRecyclerViewAdapter.kt | 176 ++++-------------- .../recycler/core/FrogoRecyclerViewHolder.kt | 16 +- .../core/FrogoRecyclerViewListener.kt | 4 +- .../frogobox/recycler/core/FrogoRvModel.kt | 15 ++ .../frogobox/recycler/core/FrogoSingleRv.kt | 8 + .../recycler/core/FrogoSingleRvBinding.kt | 8 + .../frogobox/recycler/core/FrogoSingleSrv.kt | 15 ++ .../recycler/core/FrogoViewAdapter.kt | 3 +- .../frogobox/recycler/core/FrogoViewHolder.kt | 3 +- .../recycler/core/IFrogoBindingAdapter.kt | 5 +- .../frogobox/recycler/core/IFrogoBuilderRv.kt | 4 +- .../recycler/core/IFrogoBuilderRvBinding.kt | 4 +- .../recycler/core/IFrogoLayoutManager.kt | 17 +- .../frogobox/recycler/core/IFrogoSingleRv.kt | 22 +-- .../recycler/core/IFrogoSingleRvBinding.kt | 16 +- .../recycler/core/IFrogoViewAdapter.kt | 7 +- .../recycler/core/IFrogoViewHolder.kt | 3 +- .../recycler/ext/FrogoRecyclerViewExt.kt | 2 +- .../recycler/widget/FrogoStyleComponent.kt | 3 +- .../recycler/widget/IFrogoRecyclerView.kt | 13 +- 41 files changed, 545 insertions(+), 320 deletions(-) create mode 100644 frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewAdapter.kt create mode 100644 frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewHolder.kt create mode 100644 frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoDiffUtilCallback.kt create mode 100644 frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRvModel.kt diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/issue/AnswerIssueActivity.kt b/app/src/main/java/com/frogobox/apprecycler/sample/issue/AnswerIssueActivity.kt index f47f898..04fe8c6 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/issue/AnswerIssueActivity.kt +++ b/app/src/main/java/com/frogobox/apprecycler/sample/issue/AnswerIssueActivity.kt @@ -46,6 +46,14 @@ class AnswerIssueActivity : BaseActivity() { ) } + override fun areContentsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem == newItem + } + + override fun areItemsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem.name == newItem.name + } + override fun setupInitComponent( binding: ItemAnswerIssueBinding, data: ExampleModel, diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/java/noadapter/multiview/JavaNoAdapterMultiViewActivity.java b/app/src/main/java/com/frogobox/apprecycler/sample/java/noadapter/multiview/JavaNoAdapterMultiViewActivity.java index 56f59c6..6bbdcc6 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/java/noadapter/multiview/JavaNoAdapterMultiViewActivity.java +++ b/app/src/main/java/com/frogobox/apprecycler/sample/java/noadapter/multiview/JavaNoAdapterMultiViewActivity.java @@ -65,6 +65,16 @@ private static IFrogoViewHolder secondCallback() { private FrogoRecyclerViewListener firstListenerType() { return new FrogoRecyclerViewListener<>() { + @Override + public boolean areContentsTheSame(ExampleModel oldItem, ExampleModel newItem) { + return oldItem == newItem; + } + + @Override + public boolean areItemsTheSame(ExampleModel oldItem, ExampleModel newItem) { + return oldItem.getName().equals(newItem.getName()); + } + @Override public void onItemLongClicked(@NonNull View view, ExampleModel data, int position, @NonNull FrogoRecyclerNotifyListener notifyListener) { showToast(data.getName() + " First"); @@ -79,6 +89,16 @@ public void onItemClicked(@NonNull View view, ExampleModel data, int position, @ private FrogoRecyclerViewListener secondListenerType() { return new FrogoRecyclerViewListener<>() { + @Override + public boolean areContentsTheSame(ExampleModel oldItem, ExampleModel newItem) { + return oldItem == newItem; + } + + @Override + public boolean areItemsTheSame(ExampleModel oldItem, ExampleModel newItem) { + return oldItem.getName().equals(newItem.getName()); + } + @Override public void onItemLongClicked(@NonNull View view, ExampleModel data, int position, @NonNull FrogoRecyclerNotifyListener notifyListener) { showToast(data.getName() + " Second"); diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/java/noadapter/simple/JavaNoAdapterActivity.java b/app/src/main/java/com/frogobox/apprecycler/sample/java/noadapter/simple/JavaNoAdapterActivity.java index 27a9c0b..5323577 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/java/noadapter/simple/JavaNoAdapterActivity.java +++ b/app/src/main/java/com/frogobox/apprecycler/sample/java/noadapter/simple/JavaNoAdapterActivity.java @@ -45,6 +45,16 @@ private ArrayList listData() { private void setupFrogoRecyclerView() { IFrogoViewAdapter frogoViewAdapterCallback = new IFrogoViewAdapter() { + @Override + public boolean areContentsTheSame(ExampleModel oldItem, ExampleModel newItem) { + return oldItem == newItem; + } + + @Override + public boolean areItemsTheSame(ExampleModel oldItem, ExampleModel newItem) { + return oldItem.getName().equals(newItem.getName()); + } + @Override public void onItemLongClicked(@NonNull View view, ExampleModel data, int position, @NonNull FrogoRecyclerNotifyListener notifyListener) { // setup item long clicked on frogo recycler view diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/java/usingadapter/JavaSampleActivity.java b/app/src/main/java/com/frogobox/apprecycler/sample/java/usingadapter/JavaSampleActivity.java index 5896684..b8d9d60 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/java/usingadapter/JavaSampleActivity.java +++ b/app/src/main/java/com/frogobox/apprecycler/sample/java/usingadapter/JavaSampleActivity.java @@ -45,6 +45,16 @@ private ArrayList listData() { private void setupAdapter() { JavaSampleViewAdapter adapter = new JavaSampleViewAdapter(); adapter.setupRequirement(R.layout.frogo_rv_list_type_1, listData(), new FrogoRecyclerViewListener() { + @Override + public boolean areContentsTheSame(ExampleModel oldItem, ExampleModel newItem) { + return oldItem == newItem; + } + + @Override + public boolean areItemsTheSame(ExampleModel oldItem, ExampleModel newItem) { + return oldItem.getName().equals(newItem.getName()); + } + @Override public void onItemLongClicked(@NonNull View view, ExampleModel data, int position, @NonNull FrogoRecyclerNotifyListener notifyListener) { Toast.makeText(JavaSampleActivity.this, data.getName(), Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/FrogoRvExtActivity.kt b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/FrogoRvExtActivity.kt index 1060a6a..6fe67bc 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/FrogoRvExtActivity.kt +++ b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/FrogoRvExtActivity.kt @@ -111,6 +111,14 @@ class FrogoRvExtActivity : BaseActivity() { // setup item long clicked on frogo recycler view FLog.d("Clicked on Position : $position") } + + override fun areItemsTheSame(oldItem: Article, newItem: Article): Boolean { + return oldItem.title == newItem.title + } + + override fun areContentsTheSame(oldItem: Article, newItem: Article): Boolean { + return oldItem == newItem + } } binding.rv.injector
() diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/multiview/KotlinNoAdapterMultiVewActivity.kt b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/multiview/KotlinNoAdapterMultiVewActivity.kt index 1f0944e..2b19717 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/multiview/KotlinNoAdapterMultiVewActivity.kt +++ b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/multiview/KotlinNoAdapterMultiVewActivity.kt @@ -76,6 +76,14 @@ class KotlinNoAdapterMultiVewActivity : BaseActivity ) { showToast("LAYOUT TYPE 1") } + + override fun areItemsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem.name == newItem.name + } + + override fun areContentsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem == newItem + } } } @@ -98,6 +106,14 @@ class KotlinNoAdapterMultiVewActivity : BaseActivity ) { showToast("LAYOUT TYPE 2") } + + override fun areItemsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem.name == newItem.name + } + + override fun areContentsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem == newItem + } } } diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/progress/KotlinProgressActivity.kt b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/progress/KotlinProgressActivity.kt index 2f01f7b..8e818ea 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/progress/KotlinProgressActivity.kt +++ b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/progress/KotlinProgressActivity.kt @@ -64,6 +64,14 @@ class KotlinProgressActivity : BaseActivity() { // setup item long clicked on frogo recycler view data.title?.let { showToast(it) } } + + override fun areItemsTheSame(oldItem: Article, newItem: Article): Boolean { + return oldItem.title == newItem.title + } + + override fun areContentsTheSame(oldItem: Article, newItem: Article): Boolean { + return oldItem == newItem + } } binding.rvProgress.defineRecyclerView
() diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/shimmer/KotlinShimmerActivity.kt b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/shimmer/KotlinShimmerActivity.kt index 930ade8..2d28a78 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/shimmer/KotlinShimmerActivity.kt +++ b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/shimmer/KotlinShimmerActivity.kt @@ -64,6 +64,14 @@ class KotlinShimmerActivity : BaseActivity() { // setup item long clicked on frogo recycler view data.title?.let { showToast(it) } } + + override fun areItemsTheSame(oldItem: Article, newItem: Article): Boolean { + return oldItem.title == newItem.title + } + + override fun areContentsTheSame(oldItem: Article, newItem: Article): Boolean { + return oldItem == newItem + } } binding.rvShimmer.defineRecyclerView
() diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/simple/KotlinNoAdapterActivity.kt b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/simple/KotlinNoAdapterActivity.kt index dbf6b32..7b919ce 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/simple/KotlinNoAdapterActivity.kt +++ b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/noadapter/simple/KotlinNoAdapterActivity.kt @@ -8,13 +8,18 @@ import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.frogobox.apprecycler.core.BaseActivity -import com.frogobox.ui.databinding.FrogoRvListType1Binding -import com.frogobox.ui.R -import com.frogobox.recycler.core.* import com.frogobox.apprecycler.databinding.ActivityBaseBinding import com.frogobox.apprecycler.model.ExampleModel import com.frogobox.apprecycler.util.Constant import com.frogobox.apprecycler.util.FLog +import com.frogobox.recycler.core.FrogoLayoutManager +import com.frogobox.recycler.core.FrogoRecyclerNotifyListener +import com.frogobox.recycler.core.IFrogoBindingAdapter +import com.frogobox.recycler.core.IFrogoBuilderRv +import com.frogobox.recycler.core.IFrogoBuilderRvBinding +import com.frogobox.recycler.core.IFrogoViewAdapter +import com.frogobox.ui.R +import com.frogobox.ui.databinding.FrogoRvListType1Binding class KotlinNoAdapterActivity : BaseActivity() { @@ -87,6 +92,14 @@ class KotlinNoAdapterActivity : BaseActivity() { FLog.d("Clicked on Position : $position") showToast(data.name) } + + override fun areItemsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem.name == newItem.name + } + + override fun areContentsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem == newItem + } } binding.frogoRecyclerView.injector() @@ -118,6 +131,14 @@ class KotlinNoAdapterActivity : BaseActivity() { ) } + override fun areContentsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem == newItem + } + + override fun areItemsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem.name == newItem.name + } + override fun onItemClicked( binding: FrogoRvListType1Binding, data: ExampleModel, @@ -170,6 +191,14 @@ class KotlinNoAdapterActivity : BaseActivity() { return FrogoLayoutManager.linearLayoutVertical(context) } + override fun areContentsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem == newItem + } + + override fun areItemsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem.name == newItem.name + } + override fun setupInitComponent( view: View, data: ExampleModel, @@ -234,6 +263,14 @@ class KotlinNoAdapterActivity : BaseActivity() { ) } + override fun areContentsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem == newItem + } + + override fun areItemsTheSame(oldItem: ExampleModel, newItem: ExampleModel): Boolean { + return oldItem.name == newItem.name + } + override fun onItemClicked( binding: FrogoRvListType1Binding, data: ExampleModel, diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/nested/KotlinNestedActivity.kt b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/nested/KotlinNestedActivity.kt index 52c55c1..081e8ba 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/nested/KotlinNestedActivity.kt +++ b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/nested/KotlinNestedActivity.kt @@ -114,6 +114,14 @@ class KotlinNestedActivity : BaseActivity() { ) { showToast("Long Click : $data") } + + override fun areItemsTheSame(oldItem: Article, newItem: Article): Boolean { + return oldItem.title == newItem.title + } + + override fun areContentsTheSame(oldItem: Article, newItem: Article): Boolean { + return oldItem == newItem + } } } diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/nested/KotlinSimpleNestedActivity.kt b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/nested/KotlinSimpleNestedActivity.kt index 0385bb3..24dafad 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/nested/KotlinSimpleNestedActivity.kt +++ b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/nested/KotlinSimpleNestedActivity.kt @@ -65,6 +65,14 @@ class KotlinSimpleNestedActivity : BaseActivity() { ) { showToast("Long Click : $data") } + + override fun areItemsTheSame(oldItem: Int, newItem: Int): Boolean { + return oldItem == newItem + } + + override fun areContentsTheSame(oldItem: Int, newItem: Int): Boolean { + return oldItem == newItem + } } } diff --git a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/simple/KotlinSampleActivity.kt b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/simple/KotlinSampleActivity.kt index 8b33912..47d2835 100644 --- a/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/simple/KotlinSampleActivity.kt +++ b/app/src/main/java/com/frogobox/apprecycler/sample/kotlin/usingadapter/simple/KotlinSampleActivity.kt @@ -48,6 +48,20 @@ class KotlinSampleActivity : BaseActivity() { ) { Toast.makeText(this@KotlinSampleActivity, data.name, Toast.LENGTH_SHORT).show() } + + override fun areItemsTheSame( + oldItem: ExampleModel, + newItem: ExampleModel + ): Boolean { + return oldItem.name == newItem.name + } + + override fun areContentsTheSame( + oldItem: ExampleModel, + newItem: ExampleModel + ): Boolean { + return oldItem == newItem + } } ) adapter.setupEmptyView(R.layout.frogo_container_empty_view) // With Custom View diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewAdapter.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewAdapter.kt new file mode 100644 index 0000000..22100f0 --- /dev/null +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewAdapter.kt @@ -0,0 +1,154 @@ +package com.frogobox.recycler.core + +import androidx.recyclerview.widget.AsyncListDiffer +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.RecyclerView + +/** + * Created by faisalamircs on 25/03/2024 + * ----------------------------------------- + * Name : Muhammad Faisal Amir + * E-mail : faisalamircs@gmail.com + * Github : github.com/amirisback + * ----------------------------------------- + */ + + +abstract class BaseRecyclerViewAdapter> : RecyclerView.Adapter() { + + /** + * Base Of Core FrogoRecyclerViewHolder + */ + + protected var notifyListener = object : FrogoRecyclerNotifyListener { + + override fun frogoNotifyData(): MutableList { + 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, positionStart: Int, payload: Any) { + innerFrogoNotifyItemRangeChanged(data, positionStart, payload) + } + + override fun frogoNotifyItemRangeChanged(data: List, positionStart: Int) { + innerFrogoNotifyItemRangeChanged(data, positionStart) + } + + override fun frogoNotifyItemRangeInserted(data: List, positionStart: Int) { + innerFrogoNotifyItemRangeInserted(data, positionStart) + } + + override fun frogoNotifyItemRangeRemoved(positionStart: Int, itemCount: Int) { + innerFrogoNotifyItemRangeRemoved(positionStart, itemCount) + } + + override fun frogoNotifyItemRemoved(position: Int) { + innerFrogoNotifyItemRemoved(position) + } + + } + + protected val asyncListDiffer = AsyncListDiffer(this, object : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: T & Any, newItem: T & Any): Boolean { + return adapterAreItemsTheSame(oldItem, newItem) + } + + override fun areContentsTheSame(oldItem: T & Any, newItem: T & Any): Boolean { + return adapterAreContentsTheSame(oldItem, newItem) + } + }) + + open fun adapterAreItemsTheSame(oldItem: T & Any, newItem: T & Any): Boolean { + return false + } + + open fun adapterAreContentsTheSame(oldItem: T & Any, newItem: T & Any): Boolean { + return false + } + + // Notify Data List + fun innerFrogoNotifyData(): MutableList { + return asyncListDiffer.currentList + } + + // Notify Data Set Changed + fun innerFrogoNotifyDataSetChanged() { + notifyDataSetChanged() + } + + // Notify Data Item Changed + fun innerFrogoNotifyItemChanged(data: T, position: Int, payload: Any) { + asyncListDiffer.currentList[position] = data + notifyItemChanged(position, payload) + } + + // Notify Data Item Changed + fun innerFrogoNotifyItemChanged(data: T, position: Int) { + asyncListDiffer.currentList[position] = data + notifyItemChanged(position) + } + + // Notify Data Item Inserted + fun innerFrogoNotifyItemInserted(data: T, position: Int) { + asyncListDiffer.currentList.add(position, data) + notifyItemInserted(position) + } + + // Notify Data Item Moved + fun innerFrogoNotifyItemMoved(data: T, fromPosition: Int, toPosition: Int) { + asyncListDiffer.currentList.removeAt(fromPosition) + asyncListDiffer.currentList.add(toPosition, data) + notifyItemMoved(fromPosition, toPosition) + } + + // Notify Data Item Range Changed + fun innerFrogoNotifyItemRangeChanged(data: List, positionStart: Int, payload: Any) { + asyncListDiffer.currentList.addAll(positionStart, data) + notifyItemRangeChanged(positionStart, data.size, payload) + } + + // Notify Data Item Range Changed + fun innerFrogoNotifyItemRangeChanged(data: List, positionStart: Int) { + asyncListDiffer.currentList.addAll(positionStart, data) + notifyItemRangeChanged(positionStart, data.size) + } + + // Notify Data Item Range Inserted + fun innerFrogoNotifyItemRangeInserted(data: List, positionStart: Int) { + asyncListDiffer.currentList.addAll(positionStart, data) + notifyItemRangeChanged(positionStart, data.size) + } + + // Notify Data Item Range Removed + fun innerFrogoNotifyItemRangeRemoved(positionStart: Int, itemCount: Int) { + asyncListDiffer.currentList.subList(positionStart, (positionStart + itemCount)).clear() + notifyItemRangeRemoved(positionStart, itemCount) + } + + // Notify Data Item Removed + fun innerFrogoNotifyItemRemoved(position: Int) { + asyncListDiffer.currentList.removeAt(position) + notifyItemRemoved(position) + } + +} \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewHolder.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewHolder.kt new file mode 100644 index 0000000..f02afc5 --- /dev/null +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewHolder.kt @@ -0,0 +1,22 @@ +package com.frogobox.recycler.core + +import android.view.View +import androidx.recyclerview.widget.RecyclerView + +/** + * Created by faisalamircs on 25/03/2024 + * ----------------------------------------- + * Name : Muhammad Faisal Amir + * E-mail : faisalamircs@gmail.com + * Github : github.com/amirisback + * ----------------------------------------- + */ + + +abstract class BaseRecyclerViewHolder(view: View) : RecyclerView.ViewHolder(view) { + + /** + * Base Of Core FrogoRecyclerViewHolder + */ + +} \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBindingAdapter.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBindingAdapter.kt index 96c411c..9e4a8d3 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBindingAdapter.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBindingAdapter.kt @@ -3,7 +3,7 @@ package com.frogobox.recycler.core import android.view.ViewGroup import androidx.viewbinding.ViewBinding -/* +/** * Created by Faisal Amir * ========================================= * FrogoRecyclerViewAdapter @@ -18,6 +18,7 @@ import androidx.viewbinding.ViewBinding * com.frogobox.recycler.content * */ + class FrogoBindingAdapter : FrogoRecyclerBindingAdapter() { private var frogoViewHolderCallback: IFrogoBindingHolder? = null diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBuilderRv.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBuilderRv.kt index 7609bc1..696d2cb 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBuilderRv.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBuilderRv.kt @@ -61,6 +61,14 @@ class FrogoBuilderRv : FrogoBuilderRvBase() { ) { viewListener.onItemLongClicked(view, data, position, notifyListener) } + + override fun areItemsTheSame(oldItem: T, newItem: T): Boolean { + return viewListener.areItemsTheSame(oldItem, newItem) + } + + override fun areContentsTheSame(oldItem: T, newItem: T): Boolean { + return viewListener.areContentsTheSame(oldItem, newItem) + } }) if (viewListener.setupEmptyView() != null) { diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBuilderRvBinding.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBuilderRvBinding.kt index 173ba0c..9e7cd55 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBuilderRvBinding.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoBuilderRvBinding.kt @@ -66,6 +66,14 @@ class FrogoBuilderRvBinding : FrogoBuilderRvBase() { ) { bindingListener.onItemLongClicked(binding, data, position, notifyListener) } + + override fun areItemsTheSame(oldItem: T, newItem: T): Boolean { + return bindingListener.areItemsTheSame(oldItem, newItem) + } + + override fun areContentsTheSame(oldItem: T, newItem: T): Boolean { + return bindingListener.areContentsTheSame(oldItem, newItem) + } }) frogoRecyclerView.adapter = frogoBindingAdapter diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoDiffUtilCallback.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoDiffUtilCallback.kt new file mode 100644 index 0000000..31bfe2c --- /dev/null +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoDiffUtilCallback.kt @@ -0,0 +1,24 @@ +package com.frogobox.recycler.core + +/** + * Created by faisalamircs on 25/03/2024 + * ----------------------------------------- + * Name : Muhammad Faisal Amir + * E-mail : faisalamircs@gmail.com + * Github : github.com/amirisback + * ----------------------------------------- + */ + + +interface FrogoDiffUtilCallback { + + // DiffUtils -------------------------------- + + fun areItemsTheSame(oldItem: T, newItem: T): Boolean + + + fun areContentsTheSame(oldItem: T, newItem: T): Boolean + + // DiffUtils -------------------------------- + +} \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingAdapter.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingAdapter.kt index 59e5110..b9b1f99 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingAdapter.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingAdapter.kt @@ -1,9 +1,11 @@ package com.frogobox.recycler.core +import androidx.recyclerview.widget.AsyncListDiffer +import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding -/* +/** * Created by Faisal Amir * ========================================= * FrogoRecyclerViewAdapter @@ -18,140 +20,33 @@ import androidx.viewbinding.ViewBinding * com.frogobox.recycler.base * */ -abstract class FrogoRecyclerBindingAdapter : - RecyclerView.Adapter>() { - protected var bindingListener: FrogoRecyclerBindingListener? = null - - protected var notifyListener = object : FrogoRecyclerNotifyListener { - - override fun frogoNotifyData(): MutableList { - 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) - } +abstract class FrogoRecyclerBindingAdapter : BaseRecyclerViewAdapter>() { - override fun frogoNotifyItemMoved(data: T, fromPosition: Int, toPosition: Int) { - innerFrogoNotifyItemMoved(data, fromPosition, toPosition) - } - - override fun frogoNotifyItemRangeChanged(data: List, positionStart: Int, payload: Any) { - innerFrogoNotifyItemRangeChanged(data, positionStart, payload) - } - - override fun frogoNotifyItemRangeChanged(data: List, positionStart: Int) { - innerFrogoNotifyItemRangeChanged(data, positionStart) - } - - override fun frogoNotifyItemRangeInserted(data: List, positionStart: Int) { - innerFrogoNotifyItemRangeInserted(data, positionStart) - } - - override fun frogoNotifyItemRangeRemoved(positionStart: Int, itemCount: Int) { - innerFrogoNotifyItemRangeRemoved(positionStart, itemCount) - } + protected var bindingListener: FrogoRecyclerBindingListener? = null - override fun frogoNotifyItemRemoved(position: Int) { - innerFrogoNotifyItemRemoved(position) - } + override fun adapterAreContentsTheSame(oldItem: T & Any, newItem: T & Any): Boolean { + return bindingListener?.areContentsTheSame(oldItem, newItem) ?: false + } + override fun adapterAreItemsTheSame(oldItem: T & Any, newItem: T & Any): Boolean { + return bindingListener?.areItemsTheSame(oldItem, newItem) ?: false } - protected val listData = mutableListOf() override fun getItemCount(): Int { - return listData.size + return asyncListDiffer.currentList.size } override fun onBindViewHolder(holder: FrogoRecyclerBindingHolder, position: Int) { - holder.bindItem(listData[position], position, bindingListener, notifyListener) - } - - - // Notify Data List - fun innerFrogoNotifyData(): MutableList { - return listData - } - - // Notify Data Set Changed - fun innerFrogoNotifyDataSetChanged() { - notifyDataSetChanged() - } - - // Notify Data Item Changed - fun innerFrogoNotifyItemChanged(data: T, position: Int, payload: Any) { - listData[position] = data - notifyItemChanged(position, payload) - } - - // Notify Data Item Changed - fun innerFrogoNotifyItemChanged(data: T, position: Int) { - listData[position] = data - notifyItemChanged(position) - } - - // Notify Data Item Inserted - fun innerFrogoNotifyItemInserted(data: T, position: Int) { - listData.add(position, data) - notifyItemInserted(position) - } - - // Notify Data Item Moved - fun innerFrogoNotifyItemMoved(data: T, fromPosition: Int, toPosition: Int) { - listData.removeAt(fromPosition) - listData.add(toPosition, data) - notifyItemMoved(fromPosition, toPosition) - } - - // Notify Data Item Range Changed - fun innerFrogoNotifyItemRangeChanged(data: List, positionStart: Int, payload: Any) { - listData.addAll(positionStart, data) - notifyItemRangeChanged(positionStart, data.size, payload) - } - - // Notify Data Item Range Changed - fun innerFrogoNotifyItemRangeChanged(data: List, positionStart: Int) { - listData.addAll(positionStart, data) - notifyItemRangeChanged(positionStart, data.size) - } - - // Notify Data Item Range Inserted - fun innerFrogoNotifyItemRangeInserted(data: List, positionStart: Int) { - listData.addAll(positionStart, data) - notifyItemRangeChanged(positionStart, data.size) - } - - // Notify Data Item Range Removed - fun innerFrogoNotifyItemRangeRemoved(positionStart: Int, itemCount: Int) { - listData.subList(positionStart, (positionStart + itemCount)).clear() - notifyItemRangeRemoved(positionStart, itemCount) - } - - // Notify Data Item Removed - fun innerFrogoNotifyItemRemoved(position: Int) { - listData.removeAt(position) - notifyItemRemoved(position) + holder.bindItem(asyncListDiffer.currentList[position], position, bindingListener, notifyListener) } fun setupData(data: List?) { - this.listData.clear() + this.asyncListDiffer.currentList.clear() if (data != null) { - this.listData.addAll(data) + this.asyncListDiffer.submitList(data) } } @@ -170,10 +65,10 @@ abstract class FrogoRecyclerBindingAdapter : this.bindingListener = bindingListener } - this.listData.clear() + this.asyncListDiffer.currentList.clear() if (data != null) { - this.listData.addAll(data) + this.asyncListDiffer.submitList(data) } } diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingHolder.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingHolder.kt index eeb7488..744f057 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingHolder.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingHolder.kt @@ -22,7 +22,7 @@ import androidx.viewbinding.ViewBinding * */ abstract class FrogoRecyclerBindingHolder(private val binding: VB) : - RecyclerView.ViewHolder(binding.root) { + BaseRecyclerViewHolder(binding.root) { abstract fun initComponent( binding: VB, diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingListener.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingListener.kt index 0c89c65..a068879 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingListener.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingListener.kt @@ -16,7 +16,7 @@ import androidx.viewbinding.ViewBinding * */ -interface FrogoRecyclerBindingListener { +interface FrogoRecyclerBindingListener : FrogoDiffUtilCallback { // on itemview set on click listener fun onItemClicked( diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewAdapter.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewAdapter.kt index 2b9b133..0442c7a 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewAdapter.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewAdapter.kt @@ -3,10 +3,12 @@ package com.frogobox.recycler.core import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.recyclerview.widget.AsyncListDiffer +import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import com.frogobox.recycler.R -/* +/** * Created by Faisal Amir * ========================================= * FrogoRecyclerViewAdapter @@ -21,8 +23,8 @@ import com.frogobox.recycler.R * com.frogobox.recycler.base * */ -abstract class FrogoRecyclerViewAdapter : - RecyclerView.Adapter>() { + +abstract class FrogoRecyclerViewAdapter : BaseRecyclerViewAdapter>() { var hasEmptyView = false var hasMultiHolder = false @@ -30,59 +32,10 @@ abstract class FrogoRecyclerViewAdapter : protected var viewListener: FrogoRecyclerViewListener? = null - protected var notifyListener = object : FrogoRecyclerNotifyListener { - - override fun frogoNotifyData(): MutableList { - 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, positionStart: Int, payload: Any) { - innerFrogoNotifyItemRangeChanged(data, positionStart, payload) - } - - override fun frogoNotifyItemRangeChanged(data: List, positionStart: Int) { - innerFrogoNotifyItemRangeChanged(data, positionStart) - } - - override fun frogoNotifyItemRangeInserted(data: List, positionStart: Int) { - innerFrogoNotifyItemRangeInserted(data, positionStart) - } - - override fun frogoNotifyItemRangeRemoved(positionStart: Int, itemCount: Int) { - innerFrogoNotifyItemRangeRemoved(positionStart, itemCount) - } - - override fun frogoNotifyItemRemoved(position: Int) { - innerFrogoNotifyItemRemoved(position) - } - - } - protected val listPosition = HashMap() protected val sharedPool = RecyclerView.RecycledViewPool() protected val frogoHolder = mutableListOf>() - protected val listData = mutableListOf() protected val listDataNested = mutableListOf>() protected var listCount = 0 @@ -90,6 +43,14 @@ abstract class FrogoRecyclerViewAdapter : protected var customLayoutRestId: Int = 0 protected var emptyLayoutResId: Int = R.layout.frogo_rv_container_empty_view + override fun adapterAreContentsTheSame(oldItem: T & Any, newItem: T & Any): Boolean { + return viewListener?.areContentsTheSame(oldItem, newItem) ?: false + } + + override fun adapterAreItemsTheSame(oldItem: T & Any, newItem: T & Any): Boolean { + return viewListener?.areItemsTheSame(oldItem, newItem) ?: false + } + fun bindNestedHolder() { } // component view @@ -112,14 +73,14 @@ abstract class FrogoRecyclerViewAdapter : } } else { if (hasEmptyView) { - listCount = if (listData.size == 0) { + listCount = if (asyncListDiffer.currentList.size == 0) { 1 } else { - listData.size + asyncListDiffer.currentList.size } listCount } else { - listData.size + asyncListDiffer.currentList.size } } } @@ -149,11 +110,11 @@ abstract class FrogoRecyclerViewAdapter : } } else { if (hasEmptyView) { - if (listData.size != 0) { - holder.bindItem(listData[position], position, viewListener, notifyListener) + if (asyncListDiffer.currentList.size != 0) { + holder.bindItem(asyncListDiffer.currentList[position], position, viewListener, notifyListener) } } else { - holder.bindItem(listData[position], position, viewListener, notifyListener) + holder.bindItem(asyncListDiffer.currentList[position], position, viewListener, notifyListener) } } } @@ -181,72 +142,7 @@ abstract class FrogoRecyclerViewAdapter : super.onViewRecycled(holder) } - // Notify Data List - fun innerFrogoNotifyData(): MutableList { - return listData - } - - // Notify Data Set Changed - fun innerFrogoNotifyDataSetChanged() { - notifyDataSetChanged() - } - - // Notify Data Item Changed - fun innerFrogoNotifyItemChanged(data: T, position: Int, payload: Any) { - listData[position] = data - notifyItemChanged(position, payload) - } - - // Notify Data Item Changed - fun innerFrogoNotifyItemChanged(data: T, position: Int) { - listData[position] = data - notifyItemChanged(position) - } - - // Notify Data Item Inserted - fun innerFrogoNotifyItemInserted(data: T, position: Int) { - listData.add(position, data) - notifyItemInserted(position) - } - - // Notify Data Item Moved - fun innerFrogoNotifyItemMoved(data: T, fromPosition: Int, toPosition: Int) { - listData.removeAt(fromPosition) - listData.add(toPosition, data) - notifyItemMoved(fromPosition, toPosition) - } - - // Notify Data Item Range Changed - fun innerFrogoNotifyItemRangeChanged(data: List, positionStart: Int, payload: Any) { - listData.addAll(positionStart, data) - notifyItemRangeChanged(positionStart, data.size, payload) - } - - // Notify Data Item Range Changed - fun innerFrogoNotifyItemRangeChanged(data: List, positionStart: Int) { - listData.addAll(positionStart, data) - notifyItemRangeChanged(positionStart, data.size) - } - - // Notify Data Item Range Inserted - fun innerFrogoNotifyItemRangeInserted(data: List, positionStart: Int) { - listData.addAll(positionStart, data) - notifyItemRangeChanged(positionStart, data.size) - } - - // Notify Data Item Range Removed - fun innerFrogoNotifyItemRangeRemoved(positionStart: Int, itemCount: Int) { - listData.subList(positionStart, (positionStart + itemCount)).clear() - notifyItemRangeRemoved(positionStart, itemCount) - } - - // Notify Data Item Removed - fun innerFrogoNotifyItemRemoved(position: Int) { - listData.removeAt(position) - notifyItemRemoved(position) - } - - fun layoutHandling() { + open fun layoutHandling() { if (hasMultiHolder) { if (customLayoutRestId != 0) { layoutRv = if (frogoHolder.isNotEmpty()) { @@ -257,7 +153,7 @@ abstract class FrogoRecyclerViewAdapter : } } else { if (customLayoutRestId != 0) { - layoutRv = if (listData.isNotEmpty()) { + layoutRv = if (asyncListDiffer.currentList.isNotEmpty()) { customLayoutRestId } else { emptyLayoutResId @@ -266,25 +162,25 @@ abstract class FrogoRecyclerViewAdapter : } } - fun viewLayout(parent: ViewGroup): View { + open fun viewLayout(parent: ViewGroup): View { return LayoutInflater.from(parent.context).inflate(layoutRv, parent, false) } - fun viewLayout(parent: ViewGroup, layoutResId: Int): View { + open fun viewLayout(parent: ViewGroup, layoutResId: Int): View { customLayoutRestId = layoutResId layoutHandling() return LayoutInflater.from(parent.context).inflate(layoutRv, parent, false) } - fun setupNestedView() { + open fun setupNestedView() { hasNestedView = true } - fun setupMultiHolder() { + open fun setupMultiHolder() { hasMultiHolder = true } - fun setupEmptyView(emptyView: Int?) { + open fun setupEmptyView(emptyView: Int?) { hasEmptyView = true if (emptyView != null) { emptyLayoutResId = emptyView @@ -292,7 +188,7 @@ abstract class FrogoRecyclerViewAdapter : layoutHandling() } - fun setupDataNested(data: List>?) { + open fun setupDataNested(data: List>?) { this.listDataNested.clear() if (data != null) { @@ -300,25 +196,25 @@ abstract class FrogoRecyclerViewAdapter : } } - fun setupData(data: List?) { - this.listData.clear() + open fun setupData(data: List?) { + this.asyncListDiffer.currentList.clear() if (data != null) { - this.listData.addAll(data) + this.asyncListDiffer.submitList(data) } } - fun setupListener(listener: FrogoRecyclerViewListener?) { + open fun setupListener(listener: FrogoRecyclerViewListener?) { if (listener != null) { viewListener = listener } } - fun setupCustomLayout(customViewId: Int) { + open fun setupCustomLayout(customViewId: Int) { customLayoutRestId = customViewId } - fun setupRequirement( + open fun setupRequirement( customViewId: Int, data: List?, listener: FrogoRecyclerViewListener? @@ -328,17 +224,17 @@ abstract class FrogoRecyclerViewAdapter : viewListener = listener } - this.listData.clear() + this.asyncListDiffer.currentList.clear() if (data != null) { - this.listData.addAll(data) + this.asyncListDiffer.submitList(data) } customLayoutRestId = customViewId layoutHandling() } - fun setupRequirement(viewHolder: List>) { + open fun setupRequirement(viewHolder: List>) { frogoHolder.addAll(viewHolder) } diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewHolder.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewHolder.kt index 3ab40a0..4a845ea 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewHolder.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewHolder.kt @@ -21,15 +21,19 @@ import androidx.recyclerview.widget.RecyclerView * com.frogobox.frogoviewadapter * */ -abstract class FrogoRecyclerViewHolder(view: View) : RecyclerView.ViewHolder(view) { +abstract class FrogoRecyclerViewHolder(view: View) : BaseRecyclerViewHolder(view) { - abstract fun initComponent(data: T, position: Int, notifyListener: FrogoRecyclerNotifyListener) // component view + abstract fun initComponent( + data: T, + position: Int, + notifyListener: FrogoRecyclerNotifyListener + ) // component view - fun getLinearLayoutManager(recyclerView: RecyclerView): LinearLayoutManager { + open fun getLinearLayoutManager(recyclerView: RecyclerView): LinearLayoutManager { return recyclerView.layoutManager as LinearLayoutManager } - fun bindItem( + open fun bindItem( data: T?, position: Int, viewListener: FrogoRecyclerViewListener?, @@ -37,11 +41,11 @@ abstract class FrogoRecyclerViewHolder(view: View) : RecyclerView.ViewHolder( ) { if (data != null) { onItemViewClicked(data, position, viewListener, notifyListener) - initComponent(data, position,notifyListener) + initComponent(data, position, notifyListener) } } - private fun onItemViewClicked( + open fun onItemViewClicked( data: T?, position: Int, viewListener: FrogoRecyclerViewListener?, diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewListener.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewListener.kt index 09f2468..26e6757 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewListener.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewListener.kt @@ -19,7 +19,7 @@ import android.view.View * com.frogobox.frogoviewadapter * */ -interface FrogoRecyclerViewListener { +interface FrogoRecyclerViewListener : FrogoDiffUtilCallback { // on itemview set on click listener fun onItemClicked(view: View, data: T, position: Int, notifyListener: FrogoRecyclerNotifyListener) @@ -30,6 +30,6 @@ interface FrogoRecyclerViewListener { data: T, position: Int, notifyListener: FrogoRecyclerNotifyListener - ) + ) {} } \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRvModel.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRvModel.kt new file mode 100644 index 0000000..b887db9 --- /dev/null +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRvModel.kt @@ -0,0 +1,15 @@ +package com.frogobox.recycler.core + +/** + * Created by faisalamircs on 25/03/2024 + * ----------------------------------------- + * Name : Muhammad Faisal Amir + * E-mail : faisalamircs@gmail.com + * Github : github.com/amirisback + * ----------------------------------------- + */ + + +data class FrogoRvModel( + val id: Int +) diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt index 42621ad..d74c9d3 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt @@ -141,6 +141,14 @@ open class FrogoSingleRv : FrogoSingleRvBase(), IFrogoSingleRv { ) { frogoAdapterCallback.onItemLongClicked(view, data, position, notifyListener) } + + override fun areItemsTheSame(oldItem: T, newItem: T): Boolean { + return frogoAdapterCallback.areItemsTheSame(oldItem, newItem) + } + + override fun areContentsTheSame(oldItem: T, newItem: T): Boolean { + return frogoAdapterCallback.areContentsTheSame(oldItem, newItem) + } }) frogoViewAdapter.setupEmptyView(emptyViewId) diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBinding.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBinding.kt index bc88efe..9c2ba54 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBinding.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBinding.kt @@ -120,6 +120,14 @@ open class FrogoSingleRvBinding : FrogoSingleRvBase(), ) { frogoAdapterCallback.onItemLongClicked(binding, data, position, notifyListener) } + + override fun areItemsTheSame(oldItem: T, newItem: T): Boolean { + return frogoAdapterCallback.areItemsTheSame(oldItem, newItem) + } + + override fun areContentsTheSame(oldItem: T, newItem: T): Boolean { + return frogoAdapterCallback.areContentsTheSame(oldItem, newItem) + } }) } diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleSrv.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleSrv.kt index a1188bb..7091dd6 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleSrv.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleSrv.kt @@ -62,6 +62,14 @@ class FrogoSingleSrv : FrogoSingleRv() { position: Int, notifyListener: FrogoRecyclerNotifyListener ) {} + + override fun areItemsTheSame(oldItem: String, newItem: String): Boolean { + return oldItem.hashCode() == newItem.hashCode() + } + + override fun areContentsTheSame(oldItem: String, newItem: String): Boolean { + return oldItem == newItem + } } srvFrogoViewAdapter = FrogoViewAdapter() @@ -95,6 +103,13 @@ class FrogoSingleSrv : FrogoSingleRv() { ) { srvFrogoAdapterCallback.onItemLongClicked(view, data, position, notifyListener) } + override fun areItemsTheSame(oldItem: String, newItem: String): Boolean { + return oldItem.hashCode() == newItem.hashCode() + } + + override fun areContentsTheSame(oldItem: String, newItem: String): Boolean { + return oldItem == newItem + } }) srvFrogoViewAdapter.setupEmptyView(emptyViewId) diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoViewAdapter.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoViewAdapter.kt index d2eb5af..cd77798 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoViewAdapter.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoViewAdapter.kt @@ -3,7 +3,7 @@ package com.frogobox.recycler.core import android.view.View import android.view.ViewGroup -/* +/** * Created by Faisal Amir * ========================================= * FrogoRecyclerViewAdapter @@ -18,6 +18,7 @@ import android.view.ViewGroup * com.frogobox.recycler.content * */ + class FrogoViewAdapter : FrogoRecyclerViewAdapter() { private var frogoViewHolderCallback: IFrogoViewHolder? = null diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoViewHolder.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoViewHolder.kt index f3dacc2..f368c20 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoViewHolder.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoViewHolder.kt @@ -2,7 +2,7 @@ package com.frogobox.recycler.core import android.view.View -/* +/** * Created by Faisal Amir * ========================================= * FrogoRecyclerViewAdapter @@ -17,6 +17,7 @@ import android.view.View * com.frogobox.recycler * */ + class FrogoViewHolder(view: View, private val frogoViewHolderCallback: IFrogoViewHolder?) : FrogoRecyclerViewHolder(view) { diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBindingAdapter.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBindingAdapter.kt index 40743fc..7dfe0ef 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBindingAdapter.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBindingAdapter.kt @@ -18,7 +18,7 @@ import androidx.viewbinding.ViewBinding * com.frogobox.recycler.callback * */ -interface IFrogoBindingAdapter { +interface IFrogoBindingAdapter : FrogoDiffUtilCallback { // Setup View Binding fun setViewBinding(parent: ViewGroup): VB @@ -45,6 +45,7 @@ interface IFrogoBindingAdapter { data: T, position: Int, notifyListener: FrogoRecyclerNotifyListener - ) + ) { + } } \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBuilderRv.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBuilderRv.kt index 7fc4b44..deee866 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBuilderRv.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBuilderRv.kt @@ -16,7 +16,7 @@ import androidx.recyclerview.widget.RecyclerView * All rights reserved * */ -interface IFrogoBuilderRv { +interface IFrogoBuilderRv : FrogoDiffUtilCallback { // Setup data FrogoRecyclerView fun setupData(): List @@ -52,6 +52,6 @@ interface IFrogoBuilderRv { data: T, position: Int, notifyListener: FrogoRecyclerNotifyListener - ) + ) {} } \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBuilderRvBinding.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBuilderRvBinding.kt index f0dcbe8..9dd0499 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBuilderRvBinding.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoBuilderRvBinding.kt @@ -17,7 +17,7 @@ import androidx.viewbinding.ViewBinding * All rights reserved * */ -interface IFrogoBuilderRvBinding { +interface IFrogoBuilderRvBinding : FrogoDiffUtilCallback { // Setup data FrogoRecyclerView fun setupData(): List @@ -50,6 +50,6 @@ interface IFrogoBuilderRvBinding { data: T, position: Int, notifyListener: FrogoRecyclerNotifyListener - ) + ) {} } \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoLayoutManager.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoLayoutManager.kt index fdaecbb..fbb8e06 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoLayoutManager.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoLayoutManager.kt @@ -1,7 +1,10 @@ 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.RecyclerView +import androidx.recyclerview.widget.StaggeredGridLayoutManager /* * Created by faisalamir on 23/07/21 @@ -21,24 +24,24 @@ interface IFrogoLayoutManager { fun linearLayoutVertical( context: Context, - reverseLayout: Boolean, - stackFromEnd: Boolean + reverseLayout: Boolean = false, + stackFromEnd: Boolean = false ): RecyclerView.LayoutManager fun linearLayoutHorizontal(context: Context): RecyclerView.LayoutManager fun linearLayoutHorizontal( context: Context, - reverseLayout: Boolean, - stackFromEnd: Boolean + reverseLayout: Boolean = false, + stackFromEnd: Boolean = false ): RecyclerView.LayoutManager fun dividerItemVertical(context: Context): DividerItemDecoration fun dividerItemHorizontal(context: Context): DividerItemDecoration - fun staggeredGridLayout(spanCount: Int): StaggeredGridLayoutManager + fun staggeredGridLayout(spanCount: Int = 1): StaggeredGridLayoutManager - fun gridLayout(context: Context, spanCount: Int): GridLayoutManager + fun gridLayout(context: Context, spanCount: Int = 1): GridLayoutManager } \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRv.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRv.kt index 31bf458..5f0a6ba 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRv.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRv.kt @@ -24,30 +24,30 @@ interface IFrogoSingleRv { fun initSingleton(frogoRecyclerView: RecyclerView): FrogoSingleRv // Create Linear Vertical Layout Manager - fun createLayoutLinearVertical(dividerItem: Boolean): FrogoSingleRv + fun createLayoutLinearVertical(dividerItem: Boolean = false): FrogoSingleRv // Create Linear Vertical Layout Manager From End fun createLayoutLinearVertical( - dividerItem: Boolean, - reverseLayout: Boolean, - stackFromEnd: Boolean + dividerItem: Boolean = false, + reverseLayout: Boolean = false, + stackFromEnd: Boolean = false ): FrogoSingleRv // Create Linear Horizontal Layout Manager - fun createLayoutLinearHorizontal(dividerItem: Boolean): FrogoSingleRv + fun createLayoutLinearHorizontal(dividerItem: Boolean = false): FrogoSingleRv // Create Linear Horizontal Layout Manager From End fun createLayoutLinearHorizontal( - dividerItem: Boolean, - reverseLayout: Boolean, - stackFromEnd: Boolean + dividerItem: Boolean = false, + reverseLayout: Boolean = false, + stackFromEnd: Boolean = false ): FrogoSingleRv // Create Staggered Grid Layout Manager - fun createLayoutStaggeredGrid(spanCount: Int): FrogoSingleRv + fun createLayoutStaggeredGrid(spanCount: Int = 1): FrogoSingleRv // Create Grid Layout Manager - fun createLayoutGrid(spanCount: Int): FrogoSingleRv + fun createLayoutGrid(spanCount: Int = 1): FrogoSingleRv // Adding Data for RecyclerView fun addData(listData: List): FrogoSingleRv @@ -59,7 +59,7 @@ interface IFrogoSingleRv { fun addCustomView(customViewInt: Int): FrogoSingleRv // Adding Empty View layout if data is Empty - fun addEmptyView(emptyViewInt: Int?): FrogoSingleRv + fun addEmptyView(emptyViewInt: Int? = null): FrogoSingleRv // Adding Callback for adapter fun addCallback(frogoViewAdapterCallback: IFrogoViewAdapter): FrogoSingleRv diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRvBinding.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRvBinding.kt index a360bbe..ceb6db7 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRvBinding.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRvBinding.kt @@ -24,17 +24,17 @@ interface IFrogoSingleRvBinding { fun initSingleton(frogoRecyclerView: RecyclerView): FrogoSingleRvBinding // Create Linear Vertical Layout Manager - fun createLayoutLinearVertical(dividerItem: Boolean): FrogoSingleRvBinding + fun createLayoutLinearVertical(dividerItem: Boolean= false): FrogoSingleRvBinding // Create Linear Vertical Layout Manager From End fun createLayoutLinearVertical( - dividerItem: Boolean, - reverseLayout: Boolean, - stackFromEnd: Boolean + dividerItem: Boolean = false, + reverseLayout: Boolean = false, + stackFromEnd: Boolean = false ): FrogoSingleRvBinding // Create Linear Horizontal Layout Manager - fun createLayoutLinearHorizontal(dividerItem: Boolean): FrogoSingleRvBinding + fun createLayoutLinearHorizontal(dividerItem: Boolean = false): FrogoSingleRvBinding // Create Linear Horizontal Layout Manager From End fun createLayoutLinearHorizontal( @@ -44,10 +44,10 @@ interface IFrogoSingleRvBinding { ): FrogoSingleRvBinding // Create Staggered Grid Layout Manager - fun createLayoutStaggeredGrid(spanCount: Int): FrogoSingleRvBinding + fun createLayoutStaggeredGrid(spanCount: Int = 1): FrogoSingleRvBinding // Create Grid Layout Manager - fun createLayoutGrid(spanCount: Int): FrogoSingleRvBinding + fun createLayoutGrid(spanCount: Int = 1): FrogoSingleRvBinding // Adding Data for RecyclerView fun addData(listData: List): FrogoSingleRvBinding @@ -61,7 +61,7 @@ interface IFrogoSingleRvBinding { // --------------------------------------------------------------------------------------------- // Notify Data List - fun frogoNotifyData() : MutableList + fun frogoNotifyData(): MutableList // Notify Data Set Changed fun frogoNotifyDataSetChanged() diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoViewAdapter.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoViewAdapter.kt index 19760dc..9f7c31c 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoViewAdapter.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoViewAdapter.kt @@ -2,7 +2,7 @@ package com.frogobox.recycler.core import android.view.View -/* +/** * Created by Faisal Amir * ========================================= * FrogoRecyclerViewAdapter @@ -17,7 +17,8 @@ import android.view.View * com.frogobox.recycler.callback * */ -interface IFrogoViewAdapter { + +interface IFrogoViewAdapter : FrogoDiffUtilCallback { // Setup Init Component on ViewHolder fun setupInitComponent( @@ -41,6 +42,6 @@ interface IFrogoViewAdapter { data: T, position: Int, notifyListener: FrogoRecyclerNotifyListener - ) + ) {} } \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoViewHolder.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoViewHolder.kt index 06443dd..00af3df 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoViewHolder.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoViewHolder.kt @@ -2,7 +2,7 @@ package com.frogobox.recycler.core import android.view.View -/* +/** * Created by Faisal Amir * ========================================= * FrogoRecyclerViewAdapter @@ -17,6 +17,7 @@ import android.view.View * com.frogobox.recycler.callback * */ + interface IFrogoViewHolder { // Setup Init Component on ViewHolder diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt index f344680..1ae6a87 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt @@ -5,7 +5,7 @@ import androidx.viewbinding.ViewBinding import com.frogobox.recycler.core.* -/* +/** * Created by faisalamir on 12/04/22 * FrogoRecyclerView * ----------------------------------------- diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoStyleComponent.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoStyleComponent.kt index 1b1a39c..0cef05c 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoStyleComponent.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoStyleComponent.kt @@ -5,7 +5,7 @@ import android.view.View import android.widget.ProgressBar import com.frogobox.recycler.R -/* +/** * Created by faisalamir on 09/05/21 * FrogoRecyclerView * ----------------------------------------- @@ -17,6 +17,7 @@ import com.frogobox.recycler.R * All rights reserved * */ + object FrogoStyleComponent : IFrogoStyleComponent { override fun setupComponentFrogoRecyclerView( diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/IFrogoRecyclerView.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/IFrogoRecyclerView.kt index ed915ad..7284e02 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/IFrogoRecyclerView.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/IFrogoRecyclerView.kt @@ -1,7 +1,10 @@ package com.frogobox.recycler.widget import androidx.viewbinding.ViewBinding -import com.frogobox.recycler.core.* +import com.frogobox.recycler.core.FrogoSingleRv +import com.frogobox.recycler.core.FrogoSingleRvBinding +import com.frogobox.recycler.core.IFrogoBuilderRv +import com.frogobox.recycler.core.IFrogoBuilderRvBinding /** * Created by Faisal Amir @@ -24,16 +27,16 @@ import com.frogobox.recycler.core.* interface IFrogoRecyclerView { // Setup linear vertical recycler view - fun isViewLinearVertical(dividerItem: Boolean) + fun isViewLinearVertical(dividerItem: Boolean = false) // Setup linear horizontal recycler view - fun isViewLinearHorizontal(dividerItem: Boolean) + fun isViewLinearHorizontal(dividerItem: Boolean = false) // Setup staggered grid recycler view - fun isViewStaggeredGrid(spanCount: Int) + fun isViewStaggeredGrid(spanCount: Int = 1) // Setup grid recycler view - fun isViewGrid(spanCount: Int) + fun isViewGrid(spanCount: Int = 1) // Setup SingletonRclass fun injector(): FrogoSingleRv From c6e5449fd9fe5fe7fc87703c4935fb2b2f81c73b Mon Sep 17 00:00:00 2001 From: amirisback Date: Mon, 25 Mar 2024 05:54:20 +0700 Subject: [PATCH 2/4] update: develop diff util --- ...ter.kt => CoreFrogoRecyclerViewAdapter.kt} | 2 +- ...lder.kt => CoreFrogoRecyclerViewHolder.kt} | 2 +- .../core/FrogoRecyclerBindingAdapter.kt | 5 +--- .../core/FrogoRecyclerBindingHolder.kt | 2 +- .../recycler/core/FrogoRecyclerViewAdapter.kt | 4 +-- .../recycler/core/FrogoRecyclerViewHolder.kt | 3 ++- .../recycler/ext/FrogoRecyclerViewExt.kt | 27 +++++++++++++++++-- .../recycler/widget/FrogoRecyclerView.kt | 17 ++++++++++++ .../recycler/widget/IFrogoRecyclerView.kt | 11 ++++++++ 9 files changed, 60 insertions(+), 13 deletions(-) rename frogorecyclerview/src/main/java/com/frogobox/recycler/core/{BaseRecyclerViewAdapter.kt => CoreFrogoRecyclerViewAdapter.kt} (97%) rename frogorecyclerview/src/main/java/com/frogobox/recycler/core/{BaseRecyclerViewHolder.kt => CoreFrogoRecyclerViewHolder.kt} (82%) diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewAdapter.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/CoreFrogoRecyclerViewAdapter.kt similarity index 97% rename from frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewAdapter.kt rename to frogorecyclerview/src/main/java/com/frogobox/recycler/core/CoreFrogoRecyclerViewAdapter.kt index 22100f0..12a4d56 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewAdapter.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/CoreFrogoRecyclerViewAdapter.kt @@ -14,7 +14,7 @@ import androidx.recyclerview.widget.RecyclerView */ -abstract class BaseRecyclerViewAdapter> : RecyclerView.Adapter() { +abstract class CoreFrogoRecyclerViewAdapter> : RecyclerView.Adapter() { /** * Base Of Core FrogoRecyclerViewHolder diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewHolder.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/CoreFrogoRecyclerViewHolder.kt similarity index 82% rename from frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewHolder.kt rename to frogorecyclerview/src/main/java/com/frogobox/recycler/core/CoreFrogoRecyclerViewHolder.kt index f02afc5..154a3fb 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/BaseRecyclerViewHolder.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/CoreFrogoRecyclerViewHolder.kt @@ -13,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView */ -abstract class BaseRecyclerViewHolder(view: View) : RecyclerView.ViewHolder(view) { +abstract class CoreFrogoRecyclerViewHolder(view: View) : RecyclerView.ViewHolder(view) { /** * Base Of Core FrogoRecyclerViewHolder diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingAdapter.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingAdapter.kt index b9b1f99..dc801c7 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingAdapter.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingAdapter.kt @@ -1,8 +1,5 @@ package com.frogobox.recycler.core -import androidx.recyclerview.widget.AsyncListDiffer -import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding /** @@ -21,7 +18,7 @@ import androidx.viewbinding.ViewBinding * */ -abstract class FrogoRecyclerBindingAdapter : BaseRecyclerViewAdapter>() { +abstract class FrogoRecyclerBindingAdapter : CoreFrogoRecyclerViewAdapter>() { protected var bindingListener: FrogoRecyclerBindingListener? = null diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingHolder.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingHolder.kt index 744f057..cfcc4e0 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingHolder.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerBindingHolder.kt @@ -22,7 +22,7 @@ import androidx.viewbinding.ViewBinding * */ abstract class FrogoRecyclerBindingHolder(private val binding: VB) : - BaseRecyclerViewHolder(binding.root) { + CoreFrogoRecyclerViewHolder(binding.root) { abstract fun initComponent( binding: VB, diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewAdapter.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewAdapter.kt index 0442c7a..6cf863d 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewAdapter.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewAdapter.kt @@ -3,8 +3,6 @@ package com.frogobox.recycler.core import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.recyclerview.widget.AsyncListDiffer -import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import com.frogobox.recycler.R @@ -24,7 +22,7 @@ import com.frogobox.recycler.R * */ -abstract class FrogoRecyclerViewAdapter : BaseRecyclerViewAdapter>() { +abstract class FrogoRecyclerViewAdapter : CoreFrogoRecyclerViewAdapter>() { var hasEmptyView = false var hasMultiHolder = false diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewHolder.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewHolder.kt index 4a845ea..4f9403a 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewHolder.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRecyclerViewHolder.kt @@ -21,7 +21,8 @@ import androidx.recyclerview.widget.RecyclerView * com.frogobox.frogoviewadapter * */ -abstract class FrogoRecyclerViewHolder(view: View) : BaseRecyclerViewHolder(view) { + +abstract class FrogoRecyclerViewHolder(view: View) : CoreFrogoRecyclerViewHolder(view) { abstract fun initComponent( data: T, diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt index 1ae6a87..10299bf 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt @@ -2,7 +2,14 @@ package com.frogobox.recycler.ext import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding -import com.frogobox.recycler.core.* +import com.frogobox.recycler.core.FrogoBindingAdapter +import com.frogobox.recycler.core.FrogoBuilderRv +import com.frogobox.recycler.core.FrogoBuilderRvBinding +import com.frogobox.recycler.core.FrogoSingleRv +import com.frogobox.recycler.core.FrogoSingleRvBinding +import com.frogobox.recycler.core.FrogoViewAdapter +import com.frogobox.recycler.core.IFrogoBuilderRv +import com.frogobox.recycler.core.IFrogoBuilderRvBinding /** @@ -13,7 +20,7 @@ import com.frogobox.recycler.core.* * E-mail : faisalamircs@gmail.com * Github : github.com/amirisback * ----------------------------------------- - * Copyright (C) 2022 Frogobox Media Inc. + * Copyright (C) 2022 Frogobox Media Inc. * All rights reserved * */ @@ -32,4 +39,20 @@ fun RecyclerView.builder(listener: IFrogoBuilderRv) { fun RecyclerView.builderBinding(listener: IFrogoBuilderRvBinding) { return FrogoBuilderRvBinding().initBuilder(this).builder(listener) +} + +fun RecyclerView.getAdapterExt(): FrogoViewAdapter { + return this.adapter as FrogoViewAdapter +} + +fun RecyclerView.setupData(data: List) { + this.getAdapterExt().setupData(data) +} + +fun RecyclerView.getAdapterBindingExt(): FrogoBindingAdapter { + return this.adapter as FrogoBindingAdapter +} + +fun RecyclerView.setupDataBinding(data: List) { + this.getAdapterBindingExt().setupData(data) } \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoRecyclerView.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoRecyclerView.kt index 5eb751a..bcbc44a 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoRecyclerView.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoRecyclerView.kt @@ -80,4 +80,21 @@ class FrogoRecyclerView : RecyclerView, return FrogoBuilderRvBinding().initBuilder(this).builder(listener) } + override fun getAdapterExt(): FrogoViewAdapter { + return this.adapter as FrogoViewAdapter + } + + override fun setupData(data: List) { + this.getAdapterExt().setupData(data) + } + + override fun getAdapterBindingExt(): FrogoBindingAdapter { + return this.adapter as FrogoBindingAdapter + } + + override fun setupDataBinding(data: List) { + this.getAdapterBindingExt().setupData(data) + } + + } \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/IFrogoRecyclerView.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/IFrogoRecyclerView.kt index 7284e02..e959505 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/IFrogoRecyclerView.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/IFrogoRecyclerView.kt @@ -1,8 +1,11 @@ package com.frogobox.recycler.widget +import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding +import com.frogobox.recycler.core.FrogoBindingAdapter import com.frogobox.recycler.core.FrogoSingleRv import com.frogobox.recycler.core.FrogoSingleRvBinding +import com.frogobox.recycler.core.FrogoViewAdapter import com.frogobox.recycler.core.IFrogoBuilderRv import com.frogobox.recycler.core.IFrogoBuilderRvBinding @@ -50,4 +53,12 @@ interface IFrogoRecyclerView { // Setup Builder Binding fun builderBinding(listener: IFrogoBuilderRvBinding) + fun getAdapterExt(): FrogoViewAdapter + + fun setupData(data: List) + + fun getAdapterBindingExt(): FrogoBindingAdapter + + fun setupDataBinding(data: List) + } \ No newline at end of file From 7a6b1585b0f279fc365848982f082fdbd14baa74 Mon Sep 17 00:00:00 2001 From: amirisback Date: Mon, 25 Mar 2024 05:58:45 +0700 Subject: [PATCH 3/4] update: develop diff util --- .../src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt | 3 ++- .../com/frogobox/recycler/widget/FrogoProgressRecyclerView.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt index d74c9d3..2330bde 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt @@ -5,7 +5,7 @@ import androidx.recyclerview.widget.RecyclerView import com.frogobox.recycler.R -/* +/** * Created by Faisal Amir * ========================================= * RecyclerViewAdapter @@ -20,6 +20,7 @@ import com.frogobox.recycler.R * com.frogobox.recycler * */ + open class FrogoSingleRv : FrogoSingleRvBase(), IFrogoSingleRv { protected lateinit var frogoRecycleView: RecyclerView diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoProgressRecyclerView.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoProgressRecyclerView.kt index 276274f..be5e9c4 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoProgressRecyclerView.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/widget/FrogoProgressRecyclerView.kt @@ -11,7 +11,7 @@ import com.frogobox.recycler.widget.FrogoStyleComponent.setupComponentFrogoRecyc import com.frogobox.recycler.databinding.WidgetFrogoProgressRecyclerviewBinding import com.frogobox.recycler.widget.FrogoStyleComponent.setupComponentProgressBar -/* +/** * Created by Faisal Amir on 17/02/2021 * FrogoRecyclerView Source Code * ----------------------------------------- @@ -23,6 +23,7 @@ import com.frogobox.recycler.widget.FrogoStyleComponent.setupComponentProgressBa * All rights reserved * */ + class FrogoProgressRecyclerView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, From abeed2779d4c16f65d59b8d16054112b9ff7c22a Mon Sep 17 00:00:00 2001 From: amirisback Date: Mon, 25 Mar 2024 06:32:59 +0700 Subject: [PATCH 4/4] add: FlexBox UI --- buildSrc/build.gradle.kts | 2 +- frogorecyclerview/build.gradle.kts | 1 + .../recycler/core/FrogoLayoutManager.kt | 11 ++- .../frogobox/recycler/core/FrogoRvConstant.kt | 4 +- .../frogobox/recycler/core/FrogoSingleRv.kt | 7 +- .../recycler/core/FrogoSingleRvBase.kt | 26 ++++- .../recycler/core/FrogoSingleRvBinding.kt | 10 +- .../recycler/core/IFrogoLayoutManager.kt | 9 ++ .../com/frogobox/recycler/core/IFrogoRv.kt | 34 +++++++ .../frogobox/recycler/core/IFrogoRvBinding.kt | 26 +++++ ...IFrogoSingleRv.kt => IFrogoRvSingleton.kt} | 54 +++++------ .../recycler/core/IFrogoSingleRvBinding.kt | 96 ------------------- .../recycler/ext/FrogoRecyclerViewExt.kt | 52 +++++++++- 13 files changed, 195 insertions(+), 137 deletions(-) create mode 100644 frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoRv.kt create mode 100644 frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoRvBinding.kt rename frogorecyclerview/src/main/java/com/frogobox/recycler/core/{IFrogoSingleRv.kt => IFrogoRvSingleton.kt} (68%) delete mode 100644 frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRvBinding.kt diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 397bb99..668e066 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -12,6 +12,6 @@ repositories { dependencies{ // library frogo-build-src - implementation("com.github.frogobox:open-build-src:3.0.0") + implementation("com.github.frogobox:open-build-src:3.0.2") } \ No newline at end of file diff --git a/frogorecyclerview/build.gradle.kts b/frogorecyclerview/build.gradle.kts index 4316725..dd5725e 100644 --- a/frogorecyclerview/build.gradle.kts +++ b/frogorecyclerview/build.gradle.kts @@ -63,6 +63,7 @@ android { dependencies { api(Androidx.recyclerview) + api("com.google.android.flexbox:flexbox:3.0.0") } afterEvaluate { diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoLayoutManager.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoLayoutManager.kt index 5ca2afe..7a72be0 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoLayoutManager.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoLayoutManager.kt @@ -2,8 +2,9 @@ package com.frogobox.recycler.core import android.content.Context import androidx.recyclerview.widget.* +import com.google.android.flexbox.FlexboxLayoutManager -/* +/** * Created by faisalamir on 23/07/21 * FrogoRecyclerView * ----------------------------------------- @@ -15,6 +16,7 @@ import androidx.recyclerview.widget.* * All rights reserved * */ + object FrogoLayoutManager : IFrogoLayoutManager { override fun linearLayoutVertical(context: Context): RecyclerView.LayoutManager { @@ -68,4 +70,11 @@ object FrogoLayoutManager : IFrogoLayoutManager { return GridLayoutManager(context, spanCount) } + override fun flexboxLayout(context: Context, flexDirection: Int, justifyContent: Int): FlexboxLayoutManager { + return FlexboxLayoutManager(context).apply { + this.flexDirection = flexDirection + this.justifyContent = justifyContent + } + } + } \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRvConstant.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRvConstant.kt index 4364a7d..165baa8 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRvConstant.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoRvConstant.kt @@ -1,6 +1,6 @@ package com.frogobox.recycler.core -/* +/** * Created by Faisal Amir * ========================================= * FrogoRecyclerViewAdapter @@ -15,6 +15,7 @@ package com.frogobox.recycler.core * com.frogobox.recycler.util * */ + object FrogoRvConstant { const val OPTION_HOLDER_FIRST = 0 @@ -26,6 +27,7 @@ object FrogoRvConstant { const val LAYOUT_LINEAR_HORIZONTAL_REVERSE = "LAYOUT_LINEAR_HORIZONTAL_REVERSE" const val LAYOUT_STAGGERED_GRID = "LAYOUT_STAGGERED_GRID" const val LAYOUT_GRID = "LAYOUT_GRID" + const val LAYOUT_FLEXBOX = "LAYOUT_FLEXBOX" const val FROGO_ADAPTER_R_CLASS = "FROGO_ADAPTER_R_CLASS" const val FROGO_ADAPTER_VIEW_BINDING = "FROGO_ADAPTER_VIEW_BINDING" diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt index 2330bde..39e7817 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRv.kt @@ -21,7 +21,7 @@ import com.frogobox.recycler.R * */ -open class FrogoSingleRv : FrogoSingleRvBase(), IFrogoSingleRv { +open class FrogoSingleRv : FrogoSingleRvBase(), IFrogoRv { protected lateinit var frogoRecycleView: RecyclerView protected lateinit var frogoAdapterCallback: IFrogoViewAdapter @@ -76,6 +76,11 @@ open class FrogoSingleRv : FrogoSingleRvBase(), IFrogoSingleRv { return this } + override fun createLayoutFlexBox(flexDirection: Int, justifyContent: Int): FrogoSingleRv { + baseCreateLayoutFlexBox(flexDirection, justifyContent) + return this + } + override fun addData(listData: List): FrogoSingleRv { this.listData.addAll(listData) return this diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBase.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBase.kt index 45f4f56..df4f313 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBase.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBase.kt @@ -2,12 +2,15 @@ package com.frogobox.recycler.core import androidx.recyclerview.widget.RecyclerView import com.frogobox.recycler.core.FrogoLayoutManager.dividerItemVertical +import com.frogobox.recycler.core.FrogoLayoutManager.flexboxLayout import com.frogobox.recycler.core.FrogoLayoutManager.gridLayout import com.frogobox.recycler.core.FrogoLayoutManager.linearLayoutHorizontal import com.frogobox.recycler.core.FrogoLayoutManager.linearLayoutVertical import com.frogobox.recycler.core.FrogoLayoutManager.staggeredGridLayout +import com.google.android.flexbox.FlexDirection +import com.google.android.flexbox.JustifyContent -/* +/** * Created by faisalamir on 31/05/21 * RecyclerView * ----------------------------------------- @@ -19,6 +22,7 @@ import com.frogobox.recycler.core.FrogoLayoutManager.staggeredGridLayout * All rights reserved * */ + abstract class FrogoSingleRvBase { protected val listDataFH = mutableListOf>() @@ -29,6 +33,8 @@ abstract class FrogoSingleRvBase { protected var optionDividerItem = false protected var optionReverseLayout = false protected var optionStackFromEnd = false + protected var flexDirection: Int = FlexDirection.ROW + protected var justifyContent: Int = JustifyContent.FLEX_START protected fun baseCreateLayoutLinearVertical(dividerItem: Boolean) { optionLayoutManager = FrogoRvConstant.LAYOUT_LINEAR_VERTICAL @@ -72,17 +78,23 @@ abstract class FrogoSingleRvBase { layoutSpanCount = spanCount } - protected fun setupLayoutManager(frogoRV: RecyclerView) { + protected fun baseCreateLayoutFlexBox(flexDirection: Int, justifyContent: Int) { + optionLayoutManager = FrogoRvConstant.LAYOUT_FLEXBOX + this.flexDirection = flexDirection + this.justifyContent = justifyContent + } + + protected fun setupLayoutManager(rv: RecyclerView) { - val context = frogoRV.context + val context = rv.context if (listData.isNotEmpty() || listDataFH.isNotEmpty()) { if (optionDividerItem) { - frogoRV.addItemDecoration(dividerItemVertical(context)) + rv.addItemDecoration(dividerItemVertical(context)) } - frogoRV.layoutManager = when (optionLayoutManager) { + rv.layoutManager = when (optionLayoutManager) { FrogoRvConstant.LAYOUT_LINEAR_VERTICAL -> { linearLayoutVertical(context) } @@ -107,6 +119,10 @@ abstract class FrogoSingleRvBase { staggeredGridLayout(layoutSpanCount) } + FrogoRvConstant.LAYOUT_FLEXBOX -> { + flexboxLayout(context, flexDirection, justifyContent) + } + else -> { linearLayoutVertical(context) } diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBinding.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBinding.kt index 9c2ba54..8f21053 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBinding.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/FrogoSingleRvBinding.kt @@ -20,7 +20,7 @@ import androidx.viewbinding.ViewBinding * */ open class FrogoSingleRvBinding : FrogoSingleRvBase(), - IFrogoSingleRvBinding { + IFrogoRvBinding { protected lateinit var frogoRecycleView: RecyclerView protected lateinit var frogoAdapterCallback: IFrogoBindingAdapter @@ -72,6 +72,14 @@ open class FrogoSingleRvBinding : FrogoSingleRvBase(), return this } + override fun createLayoutFlexBox( + flexDirection: Int, + justifyContent: Int + ): FrogoSingleRvBinding { + baseCreateLayoutFlexBox(flexDirection, justifyContent) + return this + } + override fun addData(listData: List): FrogoSingleRvBinding { this.listData.addAll(listData) return this diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoLayoutManager.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoLayoutManager.kt index fbb8e06..14e2b93 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoLayoutManager.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoLayoutManager.kt @@ -5,6 +5,9 @@ import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.StaggeredGridLayoutManager +import com.google.android.flexbox.FlexDirection +import com.google.android.flexbox.FlexboxLayoutManager +import com.google.android.flexbox.JustifyContent /* * Created by faisalamir on 23/07/21 @@ -44,4 +47,10 @@ interface IFrogoLayoutManager { fun gridLayout(context: Context, spanCount: Int = 1): GridLayoutManager + fun flexboxLayout( + context: Context, + flexDirection: Int = FlexDirection.ROW, + justifyContent: Int = JustifyContent.FLEX_START + ) : FlexboxLayoutManager + } \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoRv.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoRv.kt new file mode 100644 index 0000000..0d28876 --- /dev/null +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoRv.kt @@ -0,0 +1,34 @@ +package com.frogobox.recycler.core + + +/** + * Created by Faisal Amir + * ========================================= + * FrogoRecyclerViewAdapter + * Copyright (C) 27/04/2020. + * All rights reserved + * ----------------------------------------- + * Name : Muhammad Faisal Amir + * E-mail : faisalamircs@gmail.com + * Github : github.com/amirisback + * ----------------------------------------- + * FrogoBox Inc + * com.frogobox.recycler.util + * + */ + +interface IFrogoRv : IFrogoRvSingleton { + + // Adding Data with object ViewHolder + fun addDataFH(listDataFH: List>): FrogoSingleRv + + // Adding Custom View for RecyclerView + fun addCustomView(customViewInt: Int): FrogoSingleRv + + // Adding Empty View layout if data is Empty + fun addEmptyView(emptyViewInt: Int? = null): FrogoSingleRv + + // Adding Callback for adapter + fun addCallback(frogoViewAdapterCallback: IFrogoViewAdapter): FrogoSingleRv + +} \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoRvBinding.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoRvBinding.kt new file mode 100644 index 0000000..0c432dd --- /dev/null +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoRvBinding.kt @@ -0,0 +1,26 @@ +package com.frogobox.recycler.core + +import androidx.viewbinding.ViewBinding + +/** + * Created by Faisal Amir + * ========================================= + * FrogoRecyclerViewAdapter + * Copyright (C) 27/04/2020. + * All rights reserved + * ----------------------------------------- + * Name : Muhammad Faisal Amir + * E-mail : faisalamircs@gmail.com + * Github : github.com/amirisback + * ----------------------------------------- + * FrogoBox Inc + * com.frogobox.recycler.util + * + */ + +interface IFrogoRvBinding : IFrogoRvSingleton { + + // Adding Callback for adapter + fun addCallback(frogoViewAdapterCallback: IFrogoBindingAdapter): FrogoSingleRvBinding + +} \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRv.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoRvSingleton.kt similarity index 68% rename from frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRv.kt rename to frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoRvSingleton.kt index 5f0a6ba..3303cc2 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRv.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoRvSingleton.kt @@ -1,13 +1,14 @@ package com.frogobox.recycler.core import androidx.recyclerview.widget.RecyclerView +import com.google.android.flexbox.FlexDirection +import com.google.android.flexbox.JustifyContent - -/* +/** * Created by Faisal Amir * ========================================= * FrogoRecyclerViewAdapter - * Copyright (C) 27/04/2020. + * Copyright (C) 27/04/2020. * All rights reserved * ----------------------------------------- * Name : Muhammad Faisal Amir @@ -16,61 +17,54 @@ import androidx.recyclerview.widget.RecyclerView * ----------------------------------------- * FrogoBox Inc * com.frogobox.recycler.util - * + * */ -interface IFrogoSingleRv { + +interface IFrogoRvSingleton { // Init FrogoRecyclerView - fun initSingleton(frogoRecyclerView: RecyclerView): FrogoSingleRv - + fun initSingleton(frogoRecyclerView: RecyclerView): IFrogoRvSingleton + // Create Linear Vertical Layout Manager - fun createLayoutLinearVertical(dividerItem: Boolean = false): FrogoSingleRv + fun createLayoutLinearVertical(dividerItem: Boolean = false): IFrogoRvSingleton // Create Linear Vertical Layout Manager From End fun createLayoutLinearVertical( dividerItem: Boolean = false, reverseLayout: Boolean = false, stackFromEnd: Boolean = false - ): FrogoSingleRv + ): IFrogoRvSingleton // Create Linear Horizontal Layout Manager - fun createLayoutLinearHorizontal(dividerItem: Boolean = false): FrogoSingleRv + fun createLayoutLinearHorizontal(dividerItem: Boolean = false): IFrogoRvSingleton // Create Linear Horizontal Layout Manager From End fun createLayoutLinearHorizontal( dividerItem: Boolean = false, reverseLayout: Boolean = false, stackFromEnd: Boolean = false - ): FrogoSingleRv + ): IFrogoRvSingleton // Create Staggered Grid Layout Manager - fun createLayoutStaggeredGrid(spanCount: Int = 1): FrogoSingleRv + fun createLayoutStaggeredGrid(spanCount: Int = 1): IFrogoRvSingleton // Create Grid Layout Manager - fun createLayoutGrid(spanCount: Int = 1): FrogoSingleRv - - // Adding Data for RecyclerView - fun addData(listData: List): FrogoSingleRv + fun createLayoutGrid(spanCount: Int = 1): IFrogoRvSingleton - // Adding Data with object ViewHolder - fun addDataFH(listDataFH: List>): FrogoSingleRv + // Create FlexBox Layout Manager + fun createLayoutFlexBox( + flexDirection: Int = FlexDirection.ROW, + justifyContent: Int = JustifyContent.FLEX_START + ): IFrogoRvSingleton - // Adding Custom View for RecyclerView - fun addCustomView(customViewInt: Int): FrogoSingleRv - - // Adding Empty View layout if data is Empty - fun addEmptyView(emptyViewInt: Int? = null): FrogoSingleRv - - // Adding Callback for adapter - fun addCallback(frogoViewAdapterCallback: IFrogoViewAdapter): FrogoSingleRv + // Adding Data for RecyclerView + fun addData(listData: List): IFrogoRvSingleton // Build this FrogoRecyclerView - fun build(): FrogoSingleRv - - // --------------------------------------------------------------------------------------------- + fun build(): IFrogoRvSingleton // Notify Data List - fun frogoNotifyData() : MutableList + fun frogoNotifyData(): MutableList // Notify Data Set Changed fun frogoNotifyDataSetChanged() diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRvBinding.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRvBinding.kt deleted file mode 100644 index ceb6db7..0000000 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/core/IFrogoSingleRvBinding.kt +++ /dev/null @@ -1,96 +0,0 @@ -package com.frogobox.recycler.core - -import androidx.recyclerview.widget.RecyclerView -import androidx.viewbinding.ViewBinding - -/* - * Created by Faisal Amir - * ========================================= - * FrogoRecyclerViewAdapter - * Copyright (C) 27/04/2020. - * All rights reserved - * ----------------------------------------- - * Name : Muhammad Faisal Amir - * E-mail : faisalamircs@gmail.com - * Github : github.com/amirisback - * ----------------------------------------- - * FrogoBox Inc - * com.frogobox.recycler.util - * - */ -interface IFrogoSingleRvBinding { - - // Init FrogoRecyclerView - fun initSingleton(frogoRecyclerView: RecyclerView): FrogoSingleRvBinding - - // Create Linear Vertical Layout Manager - fun createLayoutLinearVertical(dividerItem: Boolean= false): FrogoSingleRvBinding - - // Create Linear Vertical Layout Manager From End - fun createLayoutLinearVertical( - dividerItem: Boolean = false, - reverseLayout: Boolean = false, - stackFromEnd: Boolean = false - ): FrogoSingleRvBinding - - // Create Linear Horizontal Layout Manager - fun createLayoutLinearHorizontal(dividerItem: Boolean = false): FrogoSingleRvBinding - - // Create Linear Horizontal Layout Manager From End - fun createLayoutLinearHorizontal( - dividerItem: Boolean, - reverseLayout: Boolean, - stackFromEnd: Boolean - ): FrogoSingleRvBinding - - // Create Staggered Grid Layout Manager - fun createLayoutStaggeredGrid(spanCount: Int = 1): FrogoSingleRvBinding - - // Create Grid Layout Manager - fun createLayoutGrid(spanCount: Int = 1): FrogoSingleRvBinding - - // Adding Data for RecyclerView - fun addData(listData: List): FrogoSingleRvBinding - - // Adding Callback for adapter - fun addCallback(frogoViewAdapterCallback: IFrogoBindingAdapter): FrogoSingleRvBinding - - // Build this FrogoRecyclerView - fun build(): FrogoSingleRvBinding - - // --------------------------------------------------------------------------------------------- - - // Notify Data List - fun frogoNotifyData(): MutableList - - // Notify Data Set Changed - fun frogoNotifyDataSetChanged() - - // Notify Data Item Changed - fun frogoNotifyItemChanged(data: T, position: Int, payload: Any) - - // Notify Data Item Changed - fun frogoNotifyItemChanged(data: T, position: Int) - - // Notify Data Item Inserted - fun frogoNotifyItemInserted(data: T, position: Int) - - // Notify Data Item Moved - fun frogoNotifyItemMoved(data: T, fromPosition: Int, toPosition: Int) - - // Notify Data Item Range Changed - fun frogoNotifyItemRangeChanged(data: List, positionStart: Int, payload: Any) - - // Notify Data Item Range Changed - fun frogoNotifyItemRangeChanged(data: List, positionStart: Int) - - // Notify Data Item Range Inserted - fun frogoNotifyItemRangeInserted(data: List, positionStart: Int) - - // Notify Data Item Range Removed - fun frogoNotifyItemRangeRemoved(positionStart: Int, itemCount: Int) - - // Notify Data Item Removed - fun frogoNotifyItemRemoved(position: Int) - -} \ No newline at end of file diff --git a/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt b/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt index 10299bf..bcfa9fb 100644 --- a/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt +++ b/frogorecyclerview/src/main/java/com/frogobox/recycler/ext/FrogoRecyclerViewExt.kt @@ -1,5 +1,7 @@ package com.frogobox.recycler.ext +import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding import com.frogobox.recycler.core.FrogoBindingAdapter @@ -55,4 +57,52 @@ fun RecyclerView.getAdapterBindingExt(): FrogoBindingAdapt fun RecyclerView.setupDataBinding(data: List) { this.getAdapterBindingExt().setupData(data) -} \ No newline at end of file +} + +fun RecyclerView.addOnBottomScrollListener(onBottomReached: () -> Unit = {}) { + addOnScrollListener(object : RecyclerView.OnScrollListener() { + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + super.onScrolled(recyclerView, dx, dy) + (recyclerView.layoutManager as? LinearLayoutManager)?.let { + if (dy >= 0) { + val visibleItemCount = it.childCount + val totalItemCount = it.itemCount + val pastVisibleItems = it.findFirstVisibleItemPosition() + if (visibleItemCount + pastVisibleItems >= totalItemCount) { + onBottomReached() + } + } + } + + (recyclerView.layoutManager as? GridLayoutManager)?.let { + if (dy >= 0) { + val visibleItemCount = it.childCount + val totalItemCount = it.itemCount + val pastVisibleItems = it.findFirstVisibleItemPosition() + if (visibleItemCount + pastVisibleItems >= totalItemCount) { + onBottomReached() + } + } + } + } + }) +} + +fun RecyclerView.addOnTopScrollListener(onTopReached: () -> Unit = {}) { + addOnScrollListener(object : RecyclerView.OnScrollListener() { + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + super.onScrolled(recyclerView, dx, dy) + (recyclerView.layoutManager as? LinearLayoutManager)?.let { + if (dy <= 0) { + + val visibleItemCount = it.childCount + val totalItemCount = it.itemCount + val pastVisibleItems = it.findFirstVisibleItemPosition() + if (visibleItemCount + pastVisibleItems >= totalItemCount) { + onTopReached() + } + } + } + } + }) +}