Skip to content

Instantly share code, notes, and snippets.

@EudyContreras
Last active April 15, 2020 19:22
Show Gist options
  • Save EudyContreras/fe931164d0da5fd0d7156f1f4a3b611e to your computer and use it in GitHub Desktop.
Save EudyContreras/fe931164d0da5fd0d7156f1f4a3b611e to your computer and use it in GitHub Desktop.
private val dummyData = arrayOfNulls<DemoData>(DUMMY_ENTRY_COUNT)
val items: LiveData<Resource<List<DemoData?>?>> = repository.getDemoData().map {
if (it.loading) {
Resource.Loading(dummyData.toList())
} else it
}
val itemBinding: ItemBinding<DemoData> = { data, position ->
when (data) {
is DemoData.A -> R.layout.list_item_a
is DemoData.B -> R.layout.list_item_b
else -> if (position % 2 == 0) { R.layout.list_item_a } else R.layout.list_item_b
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment