auto initialise entries

This commit is contained in:
REAndroid 2023-04-29 18:02:40 +02:00
parent 793f3dd3a9
commit 17a9e18fd2
4 changed files with 46 additions and 14 deletions

View File

@ -19,6 +19,8 @@ import com.reandroid.arsc.item.IntegerItem;
import com.reandroid.arsc.pool.SpecStringPool;
import com.reandroid.arsc.pool.TableStringPool;
import com.reandroid.arsc.value.Entry;
import com.reandroid.arsc.value.ResValue;
import com.reandroid.arsc.value.ValueType;
import com.reandroid.json.JSONConvert;
import com.reandroid.json.JSONArray;
import com.reandroid.json.JSONObject;
@ -75,12 +77,22 @@ public class EntryArray extends OffsetBlockArray<Entry> implements JSONConvert<J
}
clearChildes();
}
public boolean hasComplexEntry(){
Entry first = iterator(true).next();
if(first==null){
public Boolean hasComplexEntry(){
Iterator<Entry> itr = iterator(true);
while (itr.hasNext()){
Entry entry = itr.next();
if(entry.isComplex()){
return true;
}
ResValue resValue = entry.getResValue();
ValueType valueType = resValue.getValueType();
if(valueType == null || valueType == ValueType.REFERENCE
|| valueType == ValueType.NULL){
continue;
}
return false;
}
return first.isComplex();
return null;
}
public boolean isEmpty(){
return !iterator(true).hasNext();

View File

@ -16,7 +16,6 @@
package com.reandroid.arsc.array;
import com.reandroid.arsc.chunk.ChunkType;
import com.reandroid.arsc.base.Block;
import com.reandroid.arsc.base.BlockArray;
import com.reandroid.arsc.chunk.SpecBlock;
import com.reandroid.arsc.chunk.TypeBlock;
@ -32,17 +31,29 @@ import com.reandroid.json.JSONArray;
import com.reandroid.json.JSONObject;
import java.io.IOException;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.*;
public class TypeBlockArray extends BlockArray<TypeBlock>
implements JSONConvert<JSONArray>, Comparator<TypeBlock> {
private byte mTypeId;
private Boolean mHasComplexEntry;
public TypeBlockArray(){
super();
}
public Boolean hasComplexEntry(){
if(mHasComplexEntry != null){
return mHasComplexEntry;
}
for(TypeBlock typeBlock : listItems(true)){
Boolean hasComplex = typeBlock.getEntryArray().hasComplexEntry();
if(hasComplex != null){
mHasComplexEntry = hasComplex;
}
}
return mHasComplexEntry;
}
public void destroy(){
for(TypeBlock typeBlock:listItems()){
if(typeBlock!=null){

View File

@ -18,12 +18,8 @@ package com.reandroid.arsc.chunk;
import com.reandroid.arsc.array.EntryArray;
import com.reandroid.arsc.array.OffsetArray;
import com.reandroid.arsc.array.SparseOffsetsArray;
import com.reandroid.arsc.base.Block;
import com.reandroid.arsc.container.SpecTypePair;
import com.reandroid.arsc.group.EntryGroup;
import com.reandroid.arsc.header.TypeHeader;
import com.reandroid.arsc.io.BlockLoad;
import com.reandroid.arsc.io.BlockReader;
import com.reandroid.arsc.item.*;
import com.reandroid.arsc.pool.SpecStringPool;
import com.reandroid.arsc.pool.TableStringPool;
@ -199,7 +195,10 @@ public class TypeBlock extends Chunk<TypeHeader>
.getSpecStringPool().getOrCreate(name);
entry = getOrCreateEntry((short) id);
if(entry.isNull()){
entry.ensureComplex(getEntryArray().hasComplexEntry());
Boolean hasComplex = hasComplexEntry();
if(hasComplex != null){
entry.ensureComplex(hasComplex);
}
}
entry.setSpecReference(specString.getIndex());
return entry;
@ -216,6 +215,13 @@ public class TypeBlock extends Chunk<TypeHeader>
public Entry getEntry(String entryName){
return getEntryArray().getEntry(entryName);
}
public Boolean hasComplexEntry(){
SpecTypePair specTypePair = getParentSpecTypePair();
if(specTypePair != null){
return specTypePair.hasComplexEntry();
}
return null;
}
public ResConfig getResConfig(){
return getHeaderBlock().getConfig();
}

View File

@ -57,6 +57,9 @@ public class SpecTypePair extends BlockContainer<Block>
this(new SpecBlock(), new TypeBlockArray());
}
public Boolean hasComplexEntry(){
return getTypeBlockArray().hasComplexEntry();
}
public void linkTableStringsInternal(TableStringPool tableStringPool){
for(TypeBlock typeBlock:listTypeBlocks()){
typeBlock.linkTableStringsInternal(tableStringPool);