I have this `ItemTouchHelper` in a Fragment. Is it...
# android-architecture
I have this
in a Fragment. Is it okay to show the snackbar here directly or should the ViewModel trigger it via an event?
Copy code
ItemTouchHelper(object :
                ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) {
                override fun onMove(
                    recyclerView: RecyclerView,
                    viewHolder: RecyclerView.ViewHolder,
                    target: RecyclerView.ViewHolder
                ): Boolean {
                    return false

                override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
                    val task = taskAdapter.currentList[viewHolder.adapterPosition]

                    Snackbar.make(requireView(), "Task deleted", Snackbar.LENGTH_LONG)
                        .setAction("UNDO") {
I always make my viewmodel emit an event
Reason being, deciding when to show the snackbar is business logic, so it should be up to the viewmodel to show it.
Thank you! I've changed my code as you described!
­čĹŹ 1
Showing hiding a view is more towards presentation logic, so it depends where you're keeping it. It can be view or in viewmodel depending on your design you can keep it. If your keeping presentation logic in vm put it there , if your leaving it in fragment/activity then leave that there, if you have presenters or controllers like Ryan K logic class shift it there
Yea but showing a text message? Isn't this considered business logic?
Text is a string data, ideally it should be coming from a viewmodel, but your viewmodel isn't doing mapping and transformation, that will be responsibility of your domain logic, but deciding it to show or hide should be done by the view controller which is your presentation logic.