diff --git a/app/build.gradle b/app/build.gradle index 6d144bb..f373c1c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,6 +16,7 @@ android { minifyEnabled false } } + buildToolsVersion '25.0.0' } dependencies { diff --git a/build.gradle b/build.gradle index ebf706b..ecc2f2f 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' + classpath 'com.android.tools.build:gradle:2.3.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0c71e76..4497056 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Apr 10 15:27:10 PDT 2013 +#Mon Sep 18 14:38:39 IST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/library/build.gradle b/library/build.gradle index 92ecb9f..5fe7852 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -15,6 +15,7 @@ android { minifyEnabled false } } + buildToolsVersion '25.0.0' } dependencies { diff --git a/library/src/main/java/com/unnamed/b/atv/model/TreeNode.java b/library/src/main/java/com/unnamed/b/atv/model/TreeNode.java index dbf33f8..3515737 100644 --- a/library/src/main/java/com/unnamed/b/atv/model/TreeNode.java +++ b/library/src/main/java/com/unnamed/b/atv/model/TreeNode.java @@ -53,6 +53,23 @@ public TreeNode addChild(TreeNode childNode) { return this; } + /** + * Adds a child node at give position + * @param childNode + * @param position Fist position is 0. If -1, child is inserted at the end + * @return + */ + public TreeNode addChild(TreeNode childNode, int position) { + childNode.mParent = this; + childNode.mId = generateId(); + + if(position == -1 || position > children.size()) + position = childNode.size(); + + children.add(position, childNode); + return this; + } + public TreeNode addChildren(TreeNode... nodes) { for (TreeNode n : nodes) { addChild(n); diff --git a/library/src/main/java/com/unnamed/b/atv/view/AndroidTreeView.java b/library/src/main/java/com/unnamed/b/atv/view/AndroidTreeView.java index 222a43a..058df2c 100644 --- a/library/src/main/java/com/unnamed/b/atv/view/AndroidTreeView.java +++ b/library/src/main/java/com/unnamed/b/atv/view/AndroidTreeView.java @@ -238,7 +238,7 @@ private void expandNode(final TreeNode node, boolean includeSubnodes) { parentViewHolder.toggle(true); for (final TreeNode n : node.getChildren()) { - addNode(parentViewHolder.getNodeItemsView(), n); + addNode(parentViewHolder.getNodeItemsView(), n, -1); if (n.isExpanded() || includeSubnodes) { expandNode(n, includeSubnodes); @@ -253,10 +253,20 @@ private void expandNode(final TreeNode node, boolean includeSubnodes) { } - private void addNode(ViewGroup container, final TreeNode n) { + /** + * Add the view corresponding to TreeNode to the View Group + * @param container + * @param n + */ + private void addNode(ViewGroup container, final TreeNode n, int index) { final TreeNode.BaseNodeViewHolder viewHolder = getViewHolderForNode(n); final View nodeView = viewHolder.getView(); - container.addView(nodeView); + + if(index == -1) + container.addView(nodeView); + else + container.addView(nodeView, index); + if (mSelectionModeEnabled) { viewHolder.toggleSelectionMode(mSelectionModeEnabled); } @@ -467,11 +477,26 @@ public boolean willChangeBounds() { //----------------------------------------------------------------- //Add / Remove + /** + * Add the node in the end + * @param parent + * @param nodeToAdd + */ public void addNode(TreeNode parent, final TreeNode nodeToAdd) { - parent.addChild(nodeToAdd); + addNode(parent, nodeToAdd, -1); + } + + /** + * Adds the node at given position + * @param parent + * @param nodeToAdd + * @param position if -1, node is add in the last + */ + public void addNode(TreeNode parent, final TreeNode nodeToAdd, int position) { + parent.addChild(nodeToAdd, position); if (parent.isExpanded()) { final TreeNode.BaseNodeViewHolder parentViewHolder = getViewHolderForNode(parent); - addNode(parentViewHolder.getNodeItemsView(), nodeToAdd); + addNode(parentViewHolder.getNodeItemsView(), nodeToAdd, position); } }