mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-04-29 22:04:25 +02:00
resolve string refs in plurals
This commit is contained in:
parent
2fac1b2235
commit
c3fdcdd53b
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.reandroid.arsc.value.plurals;
|
||||
|
||||
import com.reandroid.arsc.value.ResConfig;
|
||||
import com.reandroid.arsc.value.ResValueMap;
|
||||
import com.reandroid.arsc.value.ValueType;
|
||||
import com.reandroid.arsc.value.bag.MapBag;
|
||||
@ -50,12 +51,15 @@
|
||||
return PluralsQuantity.valueOf(valueMap);
|
||||
}
|
||||
|
||||
public String getQuantityString(PluralsQuantity quantity) {
|
||||
public String getQuantityString(PluralsQuantity quantity, ResConfig resConfig) {
|
||||
PluralsBagItem item = get(quantity);
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
return item.getQualityString();
|
||||
return item.getQualityString(resConfig);
|
||||
}
|
||||
public String getQuantityString(PluralsQuantity quantity) {
|
||||
return getQuantityString(quantity, null);
|
||||
}
|
||||
|
||||
public void setQuantityString(PluralsQuantity quantity, String str) {
|
||||
|
@ -15,12 +15,14 @@
|
||||
*/
|
||||
package com.reandroid.arsc.value.plurals;
|
||||
|
||||
import com.reandroid.arsc.chunk.TableBlock;
|
||||
import com.reandroid.arsc.item.StringItem;
|
||||
import com.reandroid.arsc.item.TableString;
|
||||
import com.reandroid.arsc.value.ResValueMap;
|
||||
import com.reandroid.arsc.value.ValueType;
|
||||
import com.reandroid.arsc.value.*;
|
||||
import com.reandroid.arsc.value.bag.BagItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PluralsBagItem extends BagItem {
|
||||
private PluralsBagItem(ResValueMap bagItem) {
|
||||
super(bagItem);
|
||||
@ -41,17 +43,49 @@
|
||||
return PluralsQuantity.valueOf(mBagItem);
|
||||
}
|
||||
|
||||
public String getQualityString() {
|
||||
public String getQualityString(ResConfig resConfig) {
|
||||
switch (getValueType()) {
|
||||
case STRING:
|
||||
return getStringValue();
|
||||
case REFERENCE:
|
||||
// TODO: resolve string reference based on language
|
||||
Entry entry = null;
|
||||
if (mBagItem != null) {
|
||||
entry = mBagItem.getEntry();
|
||||
}
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (resConfig == null) {
|
||||
resConfig = entry.getResConfig();
|
||||
}
|
||||
|
||||
Entry stringRes = null;
|
||||
if (resConfig != null) {
|
||||
TableBlock tableBlock = entry.getPackageBlock().getTableBlock();
|
||||
List<Entry> resolvedList = tableBlock.resolveReferenceWithConfig(getValue(), resConfig);
|
||||
if (resolvedList.size() > 0) {
|
||||
stringRes = resolvedList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (stringRes == null) {
|
||||
return null;
|
||||
}
|
||||
ResValue resValue = stringRes.getResValue();
|
||||
if (resValue == null || resValue.getValueType() != ValueType.STRING) {
|
||||
throw new IllegalArgumentException("Not a STR reference: " + formattedRefValue());
|
||||
}
|
||||
return resValue.getValueAsString();
|
||||
default:
|
||||
throw new IllegalArgumentException("Not STR/REFERENCE ValueType=" + getValueType());
|
||||
}
|
||||
}
|
||||
|
||||
private String formattedRefValue() {
|
||||
return String.format("@0x%08x", getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@ -61,7 +95,7 @@
|
||||
if (hasStringValue()) {
|
||||
builder.append(getStringValue());
|
||||
} else {
|
||||
builder.append(String.format("@0x%08x", getValue()));
|
||||
builder.append(formattedRefValue());
|
||||
}
|
||||
builder.append("</item>");
|
||||
return builder.toString();
|
||||
|
Loading…
x
Reference in New Issue
Block a user