Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ec064df authored by George Mount's avatar George Mount
Browse files

Use layout path for the tag on bound layout roots.

Change-Id: I6bda5d5716e749251b27c112865da066ba908509
parent 266aa36b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ public class ProcessExpressions extends ProcessDataBinding.ProcessingStep {
                try {
                    final ResourceBundle.LayoutFileBundle bundle
                            = (ResourceBundle.LayoutFileBundle) mUnmarshaller.unmarshal(is);
                    resourceBundle.addLayoutBundle(bundle, bundle.getLayoutId());
                    resourceBundle.addLayoutBundle(bundle);
                    L.d("loaded layout info file %s", bundle);
                } finally {
                    IOUtils.closeQuietly(is);
+2 −3
Original line number Diff line number Diff line
@@ -202,12 +202,11 @@ public class LayoutBinder {
        return mBaseClassName;
    }

    public int getId() {
        return mBundle.getLayoutId();
    public String getTag() {
        return mBundle.getDirectory() + "/" + mBundle.getFileName();
    }

    public boolean hasVariations() {
        return mBundle.hasVariations();
    }

}
+2 −4
Original line number Diff line number Diff line
@@ -98,13 +98,11 @@ public class LayoutXmlProcessor {
            return false;
        }
        LayoutFileParser layoutFileParser = new LayoutFileParser();
        int layoutId = 0;
        for (File xmlFile : getLayoutFiles(mResources)) {
            final ResourceBundle.LayoutFileBundle bindingLayout = layoutFileParser
                    .parseXml(xmlFile, mResourceBundle.getAppPackage(), layoutId);
                    .parseXml(xmlFile, mResourceBundle.getAppPackage());
            if (bindingLayout != null && !bindingLayout.isEmpty()) {
                mResourceBundle.addLayoutBundle(bindingLayout, layoutId);
                layoutId++;
                mResourceBundle.addLayoutBundle(bindingLayout);
            }
        }
        mProcessingComplete = true;
+5 −4
Original line number Diff line number Diff line
@@ -55,10 +55,12 @@ public class LayoutFileParser {
    private static final String XPATH_MERGE_TAG = "/merge";
    final String LAYOUT_PREFIX = "@layout/";

    public ResourceBundle.LayoutFileBundle parseXml(File xml, String pkg, int layoutId)
    public ResourceBundle.LayoutFileBundle parseXml(File xml, String pkg)
            throws ParserConfigurationException, IOException, SAXException,
            XPathExpressionException {
        File original = stripFileAndGetOriginal(xml, "" + layoutId);
        final String xmlNoExtension = ParserHelper.INSTANCE$.stripExtension(xml.getName());
        final String newTag = xml.getParentFile().getName() + '/' + xmlNoExtension;
        File original = stripFileAndGetOriginal(xml, newTag);
        if (original == null) {
            L.d("assuming the file is the original for %s", xml.getAbsoluteFile());
            original = xml;
@@ -66,8 +68,7 @@ public class LayoutFileParser {
        L.d("parsing file %s", xml.getAbsolutePath());

        ResourceBundle.LayoutFileBundle bundle = new ResourceBundle.LayoutFileBundle(
                ParserHelper.INSTANCE$.stripExtension(xml.getName()), layoutId,
                xml.getParentFile().getName(), pkg);
                xmlNoExtension, xml.getParentFile().getName(), pkg);

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        final DocumentBuilder builder = factory.newDocumentBuilder();
+2 −12
Original line number Diff line number Diff line
@@ -53,12 +53,11 @@ public class ResourceBundle implements Serializable {
        mAppPackage = appPackage;
    }

    public void addLayoutBundle(LayoutFileBundle bundle, int layoutId) {
    public void addLayoutBundle(LayoutFileBundle bundle) {
        Preconditions.checkArgument(bundle.mFileName != null, "File bundle must have a name");
        if (!mLayoutBundles.containsKey(bundle.mFileName)) {
            mLayoutBundles.put(bundle.mFileName, new ArrayList<LayoutFileBundle>());
        }
        bundle.mLayoutId = layoutId;
        final List<LayoutFileBundle> bundles = mLayoutBundles.get(bundle.mFileName);
        for (LayoutFileBundle existing : bundles) {
            if (existing.equals(bundle)) {
@@ -211,8 +210,6 @@ public class ResourceBundle implements Serializable {
    @XmlAccessorType(XmlAccessType.NONE)
    @XmlRootElement(name="Layout")
    public static class LayoutFileBundle implements Serializable {
        @XmlAttribute(name="layoutId", required = true)
        public int mLayoutId;
        @XmlAttribute(name="layout", required = true)
        public String mFileName;
        @XmlAttribute(name="modulePackage", required = true)
@@ -239,10 +236,8 @@ public class ResourceBundle implements Serializable {
        public LayoutFileBundle() {
        }

        public LayoutFileBundle(String fileName, int layoutId, String directory,
                String modulePackage) {
        public LayoutFileBundle(String fileName, String directory, String modulePackage) {
            mFileName = fileName;
            mLayoutId = layoutId;
            mDirectory = directory;
            mModulePackage = modulePackage;
        }
@@ -276,10 +271,6 @@ public class ResourceBundle implements Serializable {
            return null;
        }

        public int getLayoutId() {
            return mLayoutId;
        }

        public String getFileName() {
            return mFileName;
        }
@@ -351,7 +342,6 @@ public class ResourceBundle implements Serializable {
                    ", mConfigName='" + mConfigName + '\'' +
                    ", mModulePackage='" + mModulePackage + '\'' +
                    ", mFileName='" + mFileName + '\'' +
                    ", mLayoutId=" + mLayoutId +
                    '}';
        }

Loading