AmrDeveloper / TreeView

Multi roots TreeView :palm_tree: implementation for Android Platform with a lot of options and customization
https://amrdeveloper.github.io/TreeView/
MIT License
174 stars 23 forks source link

Child nodes have incorrect level/depth #7

Closed pavelreiter closed 1 year ago

pavelreiter commented 1 year ago

Describe the bug Child nodes have incorrect depth if they tree is constructed from bottom up with more then 3 levels. Sample tree:

graph TD
0_lvl_0-->0-0_lvl_1
0-0_lvl_1-->0-0-0_lvl_2
0-0_lvl_1-->0-0-1_lvl_2
0-0-0_lvl_2-->0-0-0-0_lvl_3
0-0-0_lvl_2-->0-0-0-1_lvl_3

Actual levels of nodes (ignore incorrect parent of 0-0-0-0 and 0-0-0-1):

graph TD
0_lvl_0-->0-0_lvl_1
0-0_lvl_1-->0-0-0_lvl_2
0-0_lvl_1-->0-0-1_lvl_2
0-0_lvl_1-->0-0-0-0_lvl_2
0-0_lvl_1-->0-0-0-1_lvl_2

Problem is caused by the fact that node level update is done only for first level of children when node is added as child to another node, but it should be done recursively.

Easy solution would be to update child levels whenever node level is changed via setLevel.

To Reproduce Steps to reproduce the behavior:

  1. Create 4 level treenode hierarchy.
  2. Check node level of 4th level leaf node.
  3. Reported level should be 3 but will be 2.

Expected behavior When adding node as child all it's children should have level updated recursively. Also when setting node level via setLevel all it's children level should be recursively updated.

Screenshots N/A

Smartphone (please complete the following information):

Additional context N/A

AmrDeveloper commented 1 year ago

Hello @pavelreiter,

Thank you for clean reporting and suggesting solutions, I fixed it now and created unit tests up to 4 levels,

I published now a hox fix release for this issue with version 1.1.2

Thank you, Amr Hesham

pavelreiter commented 1 year ago

@AmrDeveloper Thank you for quick fix