idanatz / OneAdapter

A Viewholderless Adapter for RecyclerView, who supports builtin diffing, states (paging, empty...), events (clicking, swiping...), and more.
MIT License
470 stars 45 forks source link

oneadapter.update(model) not working #14

Closed tfaki closed 4 years ago

tfaki commented 4 years ago

not working to undo view

idanatz commented 4 years ago

I just checked the update capabilities on the sample project and it works fine. Please add more information about your problem or this issue will be closed.

tfaki commented 4 years ago

maybe I did wrong, my code is like this ;

private inner class PlaceItemSwipeEvent : SwipeEventHook() { override fun provideHookConfig(): SwipeEventHookConfig = object : SwipeEventHookConfig() { override fun withSwipeDirection() = listOf(SwipeDirection.Left) }

    override fun onSwipe(canvas: Canvas, xAxisOffset: Float, viewBinder: ViewBinder) {

        when {
            xAxisOffset < 0 -> paintSwipeLeft(canvas, xAxisOffset, viewBinder.rootView)
        }
    }

    override fun onSwipeComplete(model: PlaceModel, direction: SwipeDirection, viewBinder: ViewBinder) {

val alert = AlertDialog.Builder(this)

    alert.setTitle("title")
    alert.setCancelable(false);
    alert.setPositiveButton("Yes") { dialogInterface: DialogInterface, i: Int ->
        viewModel.deletePlace(model.placeId)
    alert.setNegativeButton("No") {dialogInterface: DialogInterface, i: Int ->
        oneAdapter.update(model)
    alert.show()

}

}

idanatz commented 4 years ago

This code is fully working with the sample project using SwipeEventHookActivity:

   inner class MessageSwipeHook : SwipeEventHook<MessageModel>() {
        override fun provideHookConfig(): SwipeEventHookConfig = object : SwipeEventHookConfig() {
            override fun withSwipeDirection() = listOf(SwipeDirection.Left)
        }

        override fun onSwipe(canvas: Canvas, xAxisOffset: Float, viewBinder: ViewBinder) {
            when {
                xAxisOffset < 0 -> paintSwipeLeft(canvas, xAxisOffset, viewBinder.rootView)
            }
        }

        override fun onSwipeComplete(model: MessageModel, direction: SwipeDirection, viewBinder: ViewBinder) {
            when (direction) {
                SwipeDirection.Left -> oneAdapter.remove(model)
                SwipeDirection.Right -> {
                    val alert = AlertDialog.Builder(this@SwipeEventHookActivity)
                    alert.setTitle("title")
                    alert.setCancelable(false)
                    alert.setPositiveButton("Yes") { dialogInterface: DialogInterface, i: Int ->
                        oneAdapter.remove(model)
                    }
                    alert.setNegativeButton("No") { dialogInterface: DialogInterface, i: Int ->
                        oneAdapter.update(model)
                    }
                    alert.show()
                }
            }
        }
    }

Just for reference, here is a GIF: gif

tfaki commented 4 years ago

Thanks for your attention, I will do better