Skip to content

Commit

Permalink
Merge pull request #59 from amirisback/develop/diffutil
Browse files Browse the repository at this point in the history
Add DiffUtil Callback
  • Loading branch information
amirisback authored Mar 24, 2024
2 parents 56da3c5 + abeed27 commit 5c5b1e6
Show file tree
Hide file tree
Showing 50 changed files with 780 additions and 448 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class AnswerIssueActivity : BaseActivity<ActivityAnswerIssueBinding>() {
)
}

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ private static IFrogoViewHolder<ExampleModel> secondCallback() {

private FrogoRecyclerViewListener<ExampleModel> 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<ExampleModel> notifyListener) {
showToast(data.getName() + " First");
Expand All @@ -79,6 +89,16 @@ public void onItemClicked(@NonNull View view, ExampleModel data, int position, @

private FrogoRecyclerViewListener<ExampleModel> 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<ExampleModel> notifyListener) {
showToast(data.getName() + " Second");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ private ArrayList<ExampleModel> listData() {
private void setupFrogoRecyclerView() {

IFrogoViewAdapter frogoViewAdapterCallback = new IFrogoViewAdapter<ExampleModel>() {
@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<ExampleModel> notifyListener) {
// setup item long clicked on frogo recycler view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ private ArrayList<ExampleModel> listData() {
private void setupAdapter() {
JavaSampleViewAdapter adapter = new JavaSampleViewAdapter();
adapter.setupRequirement(R.layout.frogo_rv_list_type_1, listData(), new FrogoRecyclerViewListener<ExampleModel>() {
@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<ExampleModel> notifyListener) {
Toast.makeText(JavaSampleActivity.this, data.getName(), Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ class FrogoRvExtActivity : BaseActivity<ActivityFrogoRvExtBinding>() {
// 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<Article>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class KotlinNoAdapterMultiVewActivity : BaseActivity<ActivityFrogoRvGridBinding>
) {
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
}
}
}

Expand All @@ -98,6 +106,14 @@ class KotlinNoAdapterMultiVewActivity : BaseActivity<ActivityFrogoRvGridBinding>
) {
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
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ class KotlinProgressActivity : BaseActivity<ActivityKotlinProgressBinding>() {
// 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<Article>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ class KotlinShimmerActivity : BaseActivity<ActivityKotlinShimmerBinding>() {
// 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<Article>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActivityBaseBinding>() {

Expand Down Expand Up @@ -87,6 +92,14 @@ class KotlinNoAdapterActivity : BaseActivity<ActivityBaseBinding>() {
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<ExampleModel>()
Expand Down Expand Up @@ -118,6 +131,14 @@ class KotlinNoAdapterActivity : BaseActivity<ActivityBaseBinding>() {
)
}

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,
Expand Down Expand Up @@ -170,6 +191,14 @@ class KotlinNoAdapterActivity : BaseActivity<ActivityBaseBinding>() {
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,
Expand Down Expand Up @@ -234,6 +263,14 @@ class KotlinNoAdapterActivity : BaseActivity<ActivityBaseBinding>() {
)
}

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ class KotlinNestedActivity : BaseActivity<ActivityFrogoRvGridBinding>() {
) {
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
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ class KotlinSimpleNestedActivity : BaseActivity<ActivityFrogoRvGridBinding>() {
) {
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
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ class KotlinSampleActivity : BaseActivity<ActivityFrogoRvListBinding>() {
) {
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
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

}
1 change: 1 addition & 0 deletions frogorecyclerview/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ android {

dependencies {
api(Androidx.recyclerview)
api("com.google.android.flexbox:flexbox:3.0.0")
}

afterEvaluate {
Expand Down
Loading

0 comments on commit 5c5b1e6

Please sign in to comment.