Skip to content

Instantly share code, notes, and snippets.

@VictorAlbertos
Created November 17, 2020 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VictorAlbertos/50945e7bb8bdeda2114e2a5492b274e2 to your computer and use it in GitHub Desktop.
Save VictorAlbertos/50945e7bb8bdeda2114e2a5492b274e2 to your computer and use it in GitHub Desktop.
class SampleFragment : Fragment(R.layout.sample_fragment) {
private val viewModel: SampleViewModel by viewModels()
private val sampleAdapter by lazy { SampleAdapter(viewModel) }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val rvItems = view.findViewById<RecyclerView>(R.id.rvItems)
rvItems.layoutManager = LinearLayoutManager(context)
view.findViewById<View>(R.id.btInsertHeaderItem).setOnClickListener {
viewModel.onViewEvent(SampleViewEvents.InsertItemHeader)
}
view.findViewById<View>(R.id.btInsertFooterItem).setOnClickListener {
viewModel.onViewEvent(SampleViewEvents.InsertItemFooter)
}
viewModel.pagingDataViewStates.observe(viewLifecycleOwner, Observer { pagingData ->
sampleAdapter.submitData(viewLifecycleOwner.lifecycle, pagingData)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment