TreeView icon indicating copy to clipboard operation
TreeView copied to clipboard

Node can't be reselected

Open pavelreiter opened this issue 2 years ago • 4 comments

Describe the bug Node can't be selected again if it was selected and then unselected. Issue appears to be here https://github.com/AmrDeveloper/TreeView/blob/b86994b4ecacc7fab4ee4002f3b7ec6099a01634/treeview/src/main/java/com/amrdeveloper/treeview/TreeViewAdapter.java#L126 The previously selected node is always set as unselected even if the newly selected node is the same. I propose following change:

if (currentNode == currentSelectedNode) {
  currentSelectedNode.setSelected(!currentSelectedNode.isSelected());
} else {
  if (currentSelectedNode != null) currentSelectedNode.setSelected(false);
  currentSelectedNode = currentNode;
}

To Reproduce Steps to reproduce the behavior:

  1. Create tree with at least one node
  2. Click on the same node 3 times
  3. The node state is unselected

Expected behavior If user is clicking on the same node it's state should switch between selected/unselected

Screenshots N/A

Smartphone (please complete the following information):

  • Device: API 28 Emulator

Additional context Workaround for this issue is to click on different node, thus breaking the loop which is keeping the node in unset state.

pavelreiter avatar Feb 24 '23 15:02 pavelreiter

Hello @pavelreiter,

Thank you for the report and suggestion I checked your solution and worked well, if you like you can make a PR with this solution if you want to work on it, if not I will add it and make a hot fix release

Thank you, Amr Hesham

AmrDeveloper avatar Feb 24 '23 20:02 AmrDeveloper

I am away from laptop, so if you would be so kind hotfix would be great.

Thank you, Pavel Reiter.

Dne pá 24. 2. 2023 21:35 uživatel Amr Hesham @.***> napsal:

Hello @pavelreiter https://github.com/pavelreiter,

Thank you for the report and suggestion I checked your solution and worked well, if you like you can make a PR with this solution if you want to work on it, if not I will add it and make a hot fix release

Thank you, Amr Hesham

— Reply to this email directly, view it on GitHub https://github.com/AmrDeveloper/TreeView/issues/8#issuecomment-1444435678, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABADLTMRD2BE5P3F7VGSCQLWZELQVANCNFSM6AAAAAAVHB3SC4 . You are receiving this because you were mentioned.Message ID: @.***>

pavelreiter avatar Feb 25 '23 07:02 pavelreiter

Thank you @pavelreiter again, i commit the solution and will make hot fix release today

AmrDeveloper avatar Feb 25 '23 09:02 AmrDeveloper

It is released now in version 1.1.3

AmrDeveloper avatar Feb 25 '23 10:02 AmrDeveloper