android: optimize code
This commit is contained in:
parent
f1f16f719a
commit
83f24e0eb3
@ -151,7 +151,7 @@ public class NestedSliderNode extends GroupNode<ViewPager> implements ViewPager.
|
|||||||
JSObject model = getSubModel(id);
|
JSObject model = getSubModel(id);
|
||||||
String type = model.getProperty("type").asString().value();
|
String type = model.getProperty("type").asString().value();
|
||||||
if (idx < mChildNodes.size()) {
|
if (idx < mChildNodes.size()) {
|
||||||
ViewNode oldNode = mChildNodes.get(idx);
|
ViewNode<?> oldNode = mChildNodes.get(idx);
|
||||||
if (id.equals(oldNode.getId())) {
|
if (id.equals(oldNode.getId())) {
|
||||||
//The same,skip
|
//The same,skip
|
||||||
} else {
|
} else {
|
||||||
@ -164,7 +164,7 @@ public class NestedSliderNode extends GroupNode<ViewPager> implements ViewPager.
|
|||||||
//Replace this view
|
//Replace this view
|
||||||
mChildNodes.remove(idx);
|
mChildNodes.remove(idx);
|
||||||
slideItems.remove(oldNode.getNodeView());
|
slideItems.remove(oldNode.getNodeView());
|
||||||
ViewNode newNode = ViewNode.create(getDoricContext(), type);
|
ViewNode<?> newNode = ViewNode.create(getDoricContext(), type);
|
||||||
newNode.setId(id);
|
newNode.setId(id);
|
||||||
newNode.init(this);
|
newNode.init(this);
|
||||||
newNode.blend(model.getProperty("props").asObject());
|
newNode.blend(model.getProperty("props").asObject());
|
||||||
@ -175,7 +175,7 @@ public class NestedSliderNode extends GroupNode<ViewPager> implements ViewPager.
|
|||||||
//Find in remain nodes
|
//Find in remain nodes
|
||||||
int position = -1;
|
int position = -1;
|
||||||
for (int start = idx + 1; start < mChildNodes.size(); start++) {
|
for (int start = idx + 1; start < mChildNodes.size(); start++) {
|
||||||
ViewNode node = mChildNodes.get(start);
|
ViewNode<?> node = mChildNodes.get(start);
|
||||||
if (id.equals(node.getId())) {
|
if (id.equals(node.getId())) {
|
||||||
//Found
|
//Found
|
||||||
position = start;
|
position = start;
|
||||||
@ -184,8 +184,8 @@ public class NestedSliderNode extends GroupNode<ViewPager> implements ViewPager.
|
|||||||
}
|
}
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
//Found swap idx,position
|
//Found swap idx,position
|
||||||
ViewNode reused = mChildNodes.remove(position);
|
ViewNode<?> reused = mChildNodes.remove(position);
|
||||||
ViewNode abandoned = mChildNodes.remove(idx);
|
ViewNode<?> abandoned = mChildNodes.remove(idx);
|
||||||
mChildNodes.set(idx, reused);
|
mChildNodes.set(idx, reused);
|
||||||
mChildNodes.set(position, abandoned);
|
mChildNodes.set(position, abandoned);
|
||||||
//View swap index
|
//View swap index
|
||||||
@ -195,7 +195,7 @@ public class NestedSliderNode extends GroupNode<ViewPager> implements ViewPager.
|
|||||||
slideItems.add(position, abandoned.getNodeView());
|
slideItems.add(position, abandoned.getNodeView());
|
||||||
} else {
|
} else {
|
||||||
//Not found,insert
|
//Not found,insert
|
||||||
ViewNode newNode = ViewNode.create(getDoricContext(), type);
|
ViewNode<?> newNode = ViewNode.create(getDoricContext(), type);
|
||||||
newNode.setId(id);
|
newNode.setId(id);
|
||||||
newNode.init(this);
|
newNode.init(this);
|
||||||
newNode.blend(model.getProperty("props").asObject());
|
newNode.blend(model.getProperty("props").asObject());
|
||||||
|
Reference in New Issue
Block a user