rubensousa / DpadRecyclerView

A RecyclerView built for Android TV with Compose in mind and as a replacement for Leanback's BaseGridView.
https://rubensousa.github.io/DpadRecyclerView/
Apache License 2.0
136 stars 17 forks source link

Drag & Drop Implementation Help #244

Closed fankloano closed 3 months ago

fankloano commented 3 months ago

Hey Ruben,

just tried to implement Drag&Drop with your DragAdapter, so in my current ListAdapter I added:

class TvChannelsAdapter(private val onClickListener: TvChannelsAdapter.OnClickListener, private val onLongClickListener: TvChannelsAdapter.OnLongClickListener) : ListAdapter<TvChannelOB, TvChannelsAdapter.ViewHolder>(
    MANAGE_TVCHANNELS_COMPERATOR),  DpadDragHelper.DragAdapter<TvChannelOB> {

    private val channels = ArrayList<TvChannelOB>()

    override fun getMutableItems(): MutableList<TvChannelOB> = channels

But when I try to implement the DpadDragHelper I am already stuck.

    private val dragHelper = DpadDragHelper(
        adapter = tvChannelsAdapter,
        callback = object : DpadDragHelper.DragCallback {
            override fun onDragStarted(viewHolder: RecyclerView.ViewHolder) {
                // ViewHolder is now being dragged
            }
            override fun onDragStopped() {
                // Dragging was cancelled either by user or programmatically
            }
        }
    )

where tvChannelsAdapter is red-underlined with:

Type mismatch.
Required:
DpadDragHelper.DragAdapter<TypeVariable(T)>
Found:
TvChannelsAdapter?

Ehm sorry, but reading the documentation I can't understand what's the error? I checked also the sample but that's different to the documentation. (I am no experienced developer, maybe that's the reason I don't understand it..... :-) )

rubensousa commented 3 months ago

Looks like you forgot to define the type as non nullable.

rubensousa commented 3 months ago

@fankloano any update here?

fankloano commented 3 months ago

The problem in the question was solved making Tvchannelsadapter non nullable. But I had also problems implementing the other steps, but I had not much time. Will give it a other try next week.

Just as clarification: I call dragHelper.startDrag() (passing the current position of the selected Item as position) when I first press the enter/Center button on an Item, then I can simple move the Item up/down to the wanted position and press enter again - > calls dragHelper.stopDrag() and place the Item on the new position. Is this correct?

rubensousa commented 3 months ago

Is this correct?

Yes, that is correct. Will close the ticket in that case.