Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created May 16, 2018 02:24
Show Gist options
  • Save adrianhall/6f0a47fa50dd621bb231febeba7cf852 to your computer and use it in GitHub Desktop.
Save adrianhall/6f0a47fa50dd621bb231febeba7cf852 to your computer and use it in GitHub Desktop.
val adapter = NotesPagedListAdapter {
launchNoteDetailActivity(this@NoteListActivity, it.noteId)
}
viewModel.notes.observe(this, Observer {
it?.let { adapter.submitList(it) }
})
note_list_recyclerview.layoutManager = LinearLayoutManager(this).apply {
orientation = LinearLayoutManager.VERTICAL
}
note_list_recyclerview.adapter = adapter
val itemTouchHelper = ItemTouchHelper(SwipeToDeleteHandler(this) {
it.note?.let { viewModel.deleteNote(it) }
adapter.notifyItemRemoved(it.adapterPosition)
})
itemTouchHelper.attachToRecyclerView(note_list_recyclerview)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment