All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.frankiesardo.icepick.annotation.IcicleViewWriter Maven / Gradle / Ivy

There is a newer version: 2.3.6
Show newest version
package com.github.frankiesardo.icepick.annotation;

import java.io.Writer;

class IcicleViewWriter extends IcicleWriter {

    static final String SUPER_SUFFIX = "\"$$SUPER$$\"";

    public IcicleViewWriter(Writer writer, String suffix) {
        super(writer, suffix);
    }

    @Override
    protected String makeSaveInstanceStateStart(String className, String parentFqcn) {
        return "  public static android.os.Parcelable saveInstanceState(" + className + " target, android.os.Parcelable state) {\n" +
                "    android.os.Bundle outState = new android.os.Bundle();\n" +
                "    android.os.Parcelable superState = " + makeSaveSuperStateCall(parentFqcn) + ";\n" +
                "    outState.putParcelable(" + BASE_KEY + " + " + SUPER_SUFFIX + ", superState);\n";
    }

    private String makeSaveSuperStateCall(String parentFqcn) {
        return parentFqcn != null ? parentFqcn + suffix + ".saveInstanceState(target, state)" : "state";
    }

    @Override
    protected String makeSaveInstanceStateEnd() {
        return "    return outState;\n";
    }

    @Override
    protected String makeRestoreInstanceStateStart(String className) {
        return "  public static android.os.Parcelable restoreInstanceState(" + className + " target, android.os.Parcelable state) {\n" +
                "    android.os.Bundle savedInstanceState = (android.os.Bundle) state;\n" +
                "    android.os.Parcelable superState = savedInstanceState.getParcelable(" + BASE_KEY + " + " + SUPER_SUFFIX + ");\n";
    }

    @Override
    protected String makeRestoreInstanceStateEnd(String parentFqcn) {
        return "    return " + (parentFqcn != null ? parentFqcn + suffix + ".restoreInstanceState(target, superState)" : "superState") + ";\n";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy