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

Commit fcbf46e7 authored by George Mount's avatar George Mount Committed by Android (Google) Code Review
Browse files

Merge "Merge implementation into base class for single implementations."

parents bc81292a 0dbcee1f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public class ProcessExpressions extends ProcessDataBinding.ProcessingStep {
        CompilerChef compilerChef = CompilerChef.createChef(resourceBundle, getWriter());
        if (compilerChef.hasAnythingToGenerate()) {
            compilerChef.addBRVariables(mProcessBindable);
            compilerChef.writeViewBinderInterfaces();
            compilerChef.writeViewBinderInterfaces(forLibraryModule);
            if (!forLibraryModule) {
                compilerChef.writeDbrFile();
                compilerChef.writeViewBinders();
+3 −3
Original line number Diff line number Diff line
@@ -74,14 +74,14 @@ public class CompilerChef {
        ensureDataBinder();
        for (LayoutBinder layoutBinder : mDataBinder.mLayoutBinders) {
            for (String variableName : layoutBinder.getUserDefinedVariables().keySet()) {
                bindables.addVariable(variableName, layoutBinder.getInterfaceName());
                bindables.addVariable(variableName, layoutBinder.getClassName());
            }
        }
    }
    
    public void writeViewBinderInterfaces() {
    public void writeViewBinderInterfaces(boolean isLibrary) {
        ensureDataBinder();
        mDataBinder.writerBinderInterfaces();
        mDataBinder.writerBaseClasses(isLibrary);
    }

    public void writeViewBinders() {
+12 −9
Original line number Diff line number Diff line
@@ -47,23 +47,26 @@ public class DataBinder {
        return mLayoutBinders;
    }
    
    public void writerBinderInterfaces() {
    public void writerBaseClasses(boolean isLibrary) {
        Set<String> writtenFiles = new HashSet<String>();
        for (LayoutBinder layoutBinder : mLayoutBinders) {
            String interfaceName = layoutBinder.getInterfaceName();
            if (writtenFiles.contains(interfaceName)) {
            if (isLibrary || layoutBinder.hasVariations()) {
                String className = layoutBinder.getClassName();
                if (writtenFiles.contains(className)) {
                    continue;
                }
            mFileWriter.writeToFile(layoutBinder.getPackage() + "." + interfaceName,
                    layoutBinder.writeViewBinderInterface());
            writtenFiles.add(interfaceName);
                mFileWriter.writeToFile(layoutBinder.getPackage() + "." + className,
                        layoutBinder.writeViewBinderBaseClass());
                writtenFiles.add(className);
            }
        }
    }
    
    public void writeBinders() {
        for (LayoutBinder layoutBinder : mLayoutBinders) {
            L.d("writing data binder %s", layoutBinder.getClassName());
            mFileWriter.writeToFile(layoutBinder.getPackage() + "." + layoutBinder.getClassName(),
            String className = layoutBinder.getImplementationName();
            L.d("writing data binder %s", className);
            mFileWriter.writeToFile(layoutBinder.getPackage() + "." + className,
                    layoutBinder.writeViewBinder());
        }
    }
+11 −8
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ public class LayoutBinder {
        }
    }

    public String writeViewBinderInterface() {
    public String writeViewBinderBaseClass() {
        ensureWriter();
        return mWriter.writeBaseClass();
    }
@@ -190,7 +190,8 @@ public class LayoutBinder {
        return mBundle.getFileName();
    }

    public String getClassName() {
    public String getImplementationName() {
        if (hasVariations()) {
            final String suffix;
            if (hasVariations()) {
                suffix = mBundle.getConfigName();
@@ -198,10 +199,12 @@ public class LayoutBinder {
                suffix = "";
            }
            return mBaseClassName + suffix + "Impl";

        } else {
            return mBaseClassName;
        }
    }
    
    public String getInterfaceName() {
    public String getClassName() {
        return mBaseClassName;
    }

+2 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ class DataBinderWriter(val pkg: String, val projectPackage: String, val classNam
                            layoutBinders.groupBy{it.getLayoutname()}.forEach {
                                tab("case ${it.value.first!!.getModulePackage()}.R.layout.${it.value.first!!.getLayoutname()}:") {
                                    if (it.value.size() == 1) {
                                        tab("return new ${it.value.first!!.getPackage()}.${it.value.first!!.getClassName()}(view);")
                                        tab("return ${it.value.first!!.getPackage()}.${it.value.first!!.getImplementationName()}.bind(view);")
                                    } else {
                                        // we should check the tag to decide which layout we need to inflate
                                        tab("{") {
@@ -36,7 +36,7 @@ class DataBinderWriter(val pkg: String, val projectPackage: String, val classNam
                                            it.value.forEach {
                                                // TODO don't use strings. not necessary
                                                tab("if (tag.equals(String.valueOf(${it.getId()}))) {") {
                                                    tab("return new ${it.getPackage()}.${it.getClassName()}(view);")
                                                    tab("return new ${it.getPackage()}.${it.getImplementationName()}(view);")
                                                } tab("}")
                                            }
                                        }tab("}")
Loading