{"action":"created","issue":{"url":"https://api.github.com/repos/bmelnychuk/AndroidTreeView/issues/7","labels_url":"https://api.github.com/repos/bmelnychuk/AndroidTreeView/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/bmelnychuk/AndroidTreeView/issues/7/comments","events_url":"https://api.github.com/repos/bmelnychuk/AndroidTreeView/issues/7/events","html_url":"https://github.com/bmelnychuk/AndroidTreeView/issues/7","id":63020373,"number":7,"title":"restore state issue","user":{"login":"fahimk","id":857824,"avatar_url":"https://avatars.githubusercontent.com/u/857824?v=3","gravatar_id":"","url":"https://api.github.com/users/fahimk","html_url":"https://github.com/fahimk","followers_url":"https://api.github.com/users/fahimk/followers","following_url":"https://api.github.com/users/fahimk/following{/other_user}","gists_url":"https://api.github.com/users/fahimk/gists{/gist_id}","starred_url":"https://api.github.com/users/fahimk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fahimk/subscriptions","organizations_url":"https://api.github.com/users/fahimk/orgs","repos_url":"https://api.github.com/users/fahimk/repos","events_url":"https://api.github.com/users/fahimk/events{/privacy}","received_events_url":"https://api.github.com/users/fahimk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-19T15:37:28Z","updated_at":"2015-03-21T18:48:26Z","closed_at":null,"body":"Right now on restoring the code takes the selected nodes and puts them in a hashset\r\n\r\n```final Set<String> openNodes = new HashSet<>(Arrays.asList(openNodesArray));```\r\n\r\nSo if you have 1;0:0;2;0:0 gives you HashSet {1, 0:0, 2}\r\nbut if you have 1;0:0;2 that gives you the same HashSet {1, 0:0, 2}\r\n\r\nThere is data loss here because there is no indication which 0:0 is selected \r\n\r\nTo see this in practice go to \"Custom Holder Example\"\r\nopen \"My Profile\" -> Social\r\nopen \"Bruce Wayne\" -> Social\r\nopen \"Barry Allen\" -> Social; open \"Barry Allen\" -> Places\r\nrotate the device\r\nAll the places nodes are expanded.\r\n\r\nI have a solution which looks like this and writes the tree with DFS as a string\r\n```\r\n    private void getSaveState(TreeNode root, StringBuilder sBuilder) {\r\n        for (TreeNode node : root.getChildren()) {\r\n            if (node.isExpanded()) {\r\n                sBuilder.append(NODE_EXPANDED);\r\n            }\r\n            else {\r\n                sBuilder.append(NODE_COLLAPSED);\r\n            }\r\n            getSaveState(node, sBuilder);\r\n        }\r\n    }\r\n\r\n    public String getSaveState() {\r\n        final StringBuilder builder = new StringBuilder();\r\n        getSaveState(mRoot, builder);\r\n        return builder.toString();\r\n    }\r\n```\r\nLet me know what you think of this solution, and I'll make a pull request with the changes."},"comment":{"url":"https://api.github.com/repos/bmelnychuk/AndroidTreeView/issues/comments/84419760","html_url":"https://github.com/bmelnychuk/AndroidTreeView/issues/7#issuecomment-84419760","issue_url":"https://api.github.com/repos/bmelnychuk/AndroidTreeView/issues/7","id":84419760,"user":{"login":"bmelnychuk","id":4201475,"avatar_url":"https://avatars.githubusercontent.com/u/4201475?v=3","gravatar_id":"","url":"https://api.github.com/users/bmelnychuk","html_url":"https://github.com/bmelnychuk","followers_url":"https://api.github.com/users/bmelnychuk/followers","following_url":"https://api.github.com/users/bmelnychuk/following{/other_user}","gists_url":"https://api.github.com/users/bmelnychuk/gists{/gist_id}","starred_url":"https://api.github.com/users/bmelnychuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmelnychuk/subscriptions","organizations_url":"https://api.github.com/users/bmelnychuk/orgs","repos_url":"https://api.github.com/users/bmelnychuk/repos","events_url":"https://api.github.com/users/bmelnychuk/events{/privacy}","received_events_url":"https://api.github.com/users/bmelnychuk/received_events","type":"User","site_admin":false},"created_at":"2015-03-21T18:48:26Z","updated_at":"2015-03-21T18:48:26Z","body":"Your code looks good. But I found small problem in my code: I used `path.append(mId);` (the same id all the time) instead of `path.append(node.getId());` and I think that solved the issue. Let me know if it works for you"}}