Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.RecyclerView
import org.oppia.android.app.profile.ProfileItemViewModel
import java.lang.ref.WeakReference
import javax.inject.Inject
import kotlin.reflect.KClass
Expand Down Expand Up @@ -36,10 +37,23 @@ class BindableAdapter<T : Any> internal constructor(
) : RecyclerView.Adapter<BindableAdapter.BindableViewHolder<T>>() {
private val dataList: MutableList<T> = ArrayList()

// TODO(#170): Introduce support for stable IDs.
init {
setHasStableIds(true)
}

override fun getItemId(position: Int): Long {
val item = dataList[position]
return when (item) {
is ProfileItemViewModel -> item.profile.id.internalId.toLong()
else -> position.toLong()
}
}

/** Sets the data of this adapter. This is expected to be called by Android via data-binding. */
fun setData(newDataList: List<T>) {
if (dataList == newDataList) {
return
}
dataList.clear()
dataList += newDataList
// TODO(#171): Introduce diffing to notify subsets of the view to properly support animations
Expand Down
Loading