Skip to content

Commit

Permalink
Diff util improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshpaliyal committed Oct 3, 2021
1 parent d78f448 commit 841554f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ class MainActivity : AppCompatActivity() {
MultipleViewTypeActivity.start(this)
}

binding.btnPaginationListing.setOnClickListener {
PaginationListingActivity.start(this)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.Observer
import com.techpaliyal.androidkotlinmvvm.R
import com.techpaliyal.androidkotlinmvvm.databinding.ActivityListingBinding
import com.techpaliyal.androidkotlinmvvm.extensions.setupPagination
import com.techpaliyal.androidkotlinmvvm.listeners.BasicListener
import com.techpaliyal.androidkotlinmvvm.listeners.UsersListener
import com.techpaliyal.androidkotlinmvvm.model.UserModel
import com.techpaliyal.androidkotlinmvvm.ui.view_model.LoadingListingViewModel
import com.techpaliyal.androidkotlinmvvm.ui.view_model.initViewModel
Expand Down Expand Up @@ -44,7 +46,11 @@ class PaginationListingActivity : AppCompatActivity() {
resourceLoading = R.layout.item_user_shimmer,
defaultLoadingItems = 5,
loaderFooter = R.layout.item_loading_more,
mListener = object : BasicListener<UserModel> {
mListener = object : UsersListener {
override fun onLikeClicked(binding: ViewDataBinding, model: UserModel) {

}

override fun onClick(model: UserModel) {
Toast.makeText(this@PaginationListingActivity, model.name, Toast.LENGTH_SHORT)
.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.Observer
import com.techpaliyal.androidkotlinmvvm.R
import com.techpaliyal.androidkotlinmvvm.databinding.ActivityListingBinding
import com.techpaliyal.androidkotlinmvvm.listeners.BasicListener
import com.techpaliyal.androidkotlinmvvm.listeners.UsersListener
import com.techpaliyal.androidkotlinmvvm.model.UserModel
import com.techpaliyal.androidkotlinmvvm.ui.view_model.LoadingListingViewModel
import com.techpaliyal.androidkotlinmvvm.ui.view_model.initViewModel
Expand Down Expand Up @@ -44,7 +46,11 @@ class ShimmerListingActivity : AppCompatActivity() {
null,
content = UniversalAdapterViewType.Content(
R.layout.item_user,
listener = object : BasicListener<UserModel> {
listener = object : UsersListener {
override fun onLikeClicked(binding: ViewDataBinding, model: UserModel) {

}

override fun onClick(model: UserModel) {
Toast.makeText(this@ShimmerListingActivity, model.name, Toast.LENGTH_SHORT)
.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ class ContentListAdapter<T>(
DiffUtil.ItemCallback<T>() {
override fun areItemsTheSame(oldItem: T, newItem: T): Boolean {
return if (oldItem is BaseDiffUtil && newItem is BaseDiffUtil) {
oldItem.getDiffId() == newItem.getDiffId()
oldItem.getDiffId()?.equals(newItem.getDiffId())
} else {
oldItem.hashCode() == newItem.hashCode()
}
oldItem?.hashCode()?.equals(newItem?.hashCode())
} ?: false
}

override fun areContentsTheSame(oldItem: T, newItem: T): Boolean {
return if (oldItem is BaseDiffUtil && newItem is BaseDiffUtil) {
oldItem.getDiffBody() == newItem.getDiffBody()
oldItem.getDiffBody()?.equals(newItem.getDiffBody())
} else {
oldItem.hashCode() == newItem.hashCode()
}
oldItem?.toString()?.equals(newItem?.toString())
} ?: false
}

}).build()) {
Expand Down

0 comments on commit 841554f

Please sign in to comment.