Last active
March 23, 2022 04:59
-
-
Save adisiji/f5fcfb315e948b84021155c4c579736e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.PointF | |
import android.util.Log | |
import android.view.LayoutInflater | |
import android.view.ViewGroup | |
import androidx.recyclerview.widget.DiffUtil | |
import androidx.recyclerview.widget.ListAdapter | |
import com.neobyte.tutorialscreen.databinding.CardPlaceBinding | |
import com.neobyte.tutorialscreen.model.Place | |
class PlaceAdapter(private val listener: PlaceListener) : | |
ListAdapter<Place, PlaceViewHolder>(DIFF_CALLBACK) { | |
companion object { | |
private val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Place>() { | |
override fun areItemsTheSame(oldItem: Place, newItem: Place) = | |
oldItem.name == newItem.name | |
override fun areContentsTheSame(oldItem: Place, newItem: Place) = | |
oldItem == newItem | |
} | |
private const val FIRST_CARD = 0 | |
private const val OTHER_CARD = 1 | |
} | |
override fun getItemViewType(position: Int) = | |
if (position == 0) FIRST_CARD else OTHER_CARD | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaceViewHolder { | |
val layoutInflater = LayoutInflater.from(parent.context) | |
val itemBinding = CardPlaceBinding.inflate(layoutInflater, parent, false) | |
return PlaceViewHolder(itemBinding) | |
} | |
override fun onBindViewHolder(holder: PlaceViewHolder, position: Int) { | |
getItem(position)?.let { | |
holder.bind(it) | |
} | |
} | |
} | |
interface PlaceListener { | |
fun firstPosition(topLeft: PointF, bottomRight: PointF) | |
fun onClick() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment