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

Selection disable other clicks #29

Closed NoahReyson closed 3 years ago

NoahReyson commented 3 years ago

Hi,

When I set a SelectionState in a Module with selectionTrigger set to Click, it disable any other click event that could happend on the module view.

I know for sure the issue is from the SelectionState because it works properly if I set to 'false' the 'enable' property in the SelectionState config.

Is it an expected behavior, is there a workaround ?

Thanks

btw: when a SelectionState is set in a module, the onBind method of that module is never called. So the onBind method of the SelectionState must contain all of the binding. If that's the expected bahavior, please precise it in the Readme, cost me some time.

idanatz commented 3 years ago

Hi,

When the selection module is configured as a single click and a click hook (or any other click capturing code) is configured, there is a conflict in how the click should be handled. What are you expecting to happen? both the click listener and the click selection should be triggered? one of them? it's confusing and ambiguous. If you need a way to start selection with a single click (let's say on an ImageView inside the view holder) and configure a click hook on the entire ViewHolder, you could set a click listener on the ImageView and call: oneAdapter.modules.itemSelectionModule?.actions?.startSelection() (implemented in the sample project under ItemSelectionModuleActivity) in order to start the selection in reaction to a specific part of the ViewHolder being clicked.

Regarding the onBind, in my project sample, in ItemSelectionModuleActivity, the onBind function is defined on the ItemModule and not in the SelectionState and gets called as expected on every onBindViewHolder. (btw, that's a DSL issue, there is no onBind function on SelectionState, you are overriding the one from ItemModule) I tried to move the onBind logic from the ItemModule down to the SelectionState and it's working the same (not surprising, it's overriding the same function as I explained) So I don't quite understand the issue, can you explain more and supply code example?

NoahReyson commented 3 years ago

Hi,

Actually I need the opposite of your example. I have a small ImageView inside my view holder. When I click on the image, I want my click listener to be triggered (only it). When I click anywhere else, I want the click selection to be triggered. Currently, only the click selection is triggered, ignoring my custom listener, no matter when I click.

Regarding the onBind, I understand better. If the Selection onBind override the ItemModule onBind, it's perfectly normal that the content of the ItemModule onBind was never called.

In the sample ItemSelectionModuleActivity, you use the onSelected method when a click happens but in my case I need to change the ViewHolder so I need the onBind method to be called again. I though I could call the ItemModule onBind to init the ViewHolder and then only the Selection onBind to apply the changes when selected/unselected.

Anyway, I understood the behavior so no problem.

idanatz commented 3 years ago

That's exactly the issue, its ambiguous. If you look at Gmail for example, when you click on the ImageView - a selection is starting, not a click listener that will take you to your mail. what you need is custom behavior.

  1. Add a clickEventHook to your ItemModule to capture clicks on the root view with your logic
  2. if any of your views above the root (other than the ImageView) are clickable, make them propagate the click to the root by adding these lines to XML: (only when needed) android:clickable="false" android:focusable="false"
  3. add a click listener on your ImageView and start selection manually
  4. set the SelectionState trigger to be long-click to not interfere with the above.

currently, there is no way to just enable selection without any trigger (basically relying on the manual trigger) will try to add it in the next version.

Hope it helps

idanatz commented 3 years ago

v2.0.1 is out with a new selection trigger: Manual So you can mark items to never trigger selection, they will only respond to selection clicks after you call the startSelection() function on the selectionModule