mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-05-02 07:04:27 +02:00
sort ResXmlElement
This commit is contained in:
parent
71437db825
commit
3bfa17aeb6
@ -32,7 +32,8 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ResXmlElement extends ResXmlNode implements JSONConvert<JSONObject> {
|
public class ResXmlElement extends ResXmlNode implements JSONConvert<JSONObject>,
|
||||||
|
Comparator<ResXmlNode> {
|
||||||
private final BlockList<ResXmlStartNamespace> mStartNamespaceList;
|
private final BlockList<ResXmlStartNamespace> mStartNamespaceList;
|
||||||
private final SingleBlockContainer<ResXmlStartElement> mStartElementContainer;
|
private final SingleBlockContainer<ResXmlStartElement> mStartElementContainer;
|
||||||
private final BlockList<ResXmlNode> mBody;
|
private final BlockList<ResXmlNode> mBody;
|
||||||
@ -52,6 +53,31 @@
|
|||||||
addChild(3, mEndElementContainer);
|
addChild(3, mEndElementContainer);
|
||||||
addChild(4, mEndNamespaceList);
|
addChild(4, mEndNamespaceList);
|
||||||
}
|
}
|
||||||
|
public void changeIndex(ResXmlElement element, int index){
|
||||||
|
int i = 0;
|
||||||
|
for(ResXmlNode xmlNode:mBody.getChildes()){
|
||||||
|
if(i == index){
|
||||||
|
element.setIndex(i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if(xmlNode==element){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
xmlNode.setIndex(i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
mBody.sort(this);
|
||||||
|
}
|
||||||
|
public int indexOf(ResXmlElement element){
|
||||||
|
int index = 0;
|
||||||
|
for(ResXmlNode xmlNode:mBody.getChildes()){
|
||||||
|
if(xmlNode==element){
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
public void setAttributesUnitSize(int size, boolean setToAll){
|
public void setAttributesUnitSize(int size, boolean setToAll){
|
||||||
ResXmlStartElement startElement = getStartElement();
|
ResXmlStartElement startElement = getStartElement();
|
||||||
startElement.setAttributesUnitSize(size);
|
startElement.setAttributesUnitSize(size);
|
||||||
@ -849,6 +875,10 @@
|
|||||||
return xmlElement;
|
return xmlElement;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
public int compare(ResXmlNode node1, ResXmlNode node2) {
|
||||||
|
return Integer.compare(node1.getIndex(), node2.getIndex());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
ResXmlStartElement start = getStartElement();
|
ResXmlStartElement start = getStartElement();
|
||||||
if(start!=null){
|
if(start!=null){
|
||||||
|
@ -23,6 +23,7 @@ import com.reandroid.arsc.io.BlockReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BlockList<T extends Block> extends Block {
|
public class BlockList<T extends Block> extends Block {
|
||||||
@ -31,6 +32,9 @@ public class BlockList<T extends Block> extends Block {
|
|||||||
super();
|
super();
|
||||||
mItems=new ArrayList<>();
|
mItems=new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
public void sort(Comparator<T> comparator){
|
||||||
|
mItems.sort(comparator);
|
||||||
|
}
|
||||||
public boolean remove(T item){
|
public boolean remove(T item){
|
||||||
if(item!=null){
|
if(item!=null){
|
||||||
item.setParent(null);
|
item.setParent(null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user