package io.fabianterhorst.fastlayout.converters;

import io.fabianterhorst.fastlayout.annotations.Converter;

/**
 * Created by fabianterhorst on 18.05.16.
 */
@Converter
public class DefaultAttributesConverter extends LayoutConverter {

    @Override
    public LayoutAttribute onConvertLayoutAttributeValue(Object attributeValue, String attributeName) {
        switch (attributeName) {
            case "android:gravity":
                return super.onConvertLayoutAttribute(String.valueOf(attributeValue), "Gravity." + String.valueOf(attributeValue).toUpperCase(), attributeName, false);
            case "android:layout_gravity":
                return onConvertLayoutAttribute(String.valueOf(attributeValue), "Gravity." + String.valueOf(attributeValue).toUpperCase(), attributeName, false);
        }
        return super.onConvertLayoutAttributeValue(attributeValue, attributeName);
    }

    @Override
    public LayoutAttribute onConvertLayoutAttribute(String attributeStartValue, Object attributeValue, String attributeName, boolean isString) {
        switch (attributeName) {
            case "style":
                return new LayoutAttribute(LayoutAttribute.Type.LAYOUT_CONSTRUCTOR_3, attributeValue);
            case "android:layout_gravity":
                return new LayoutAttribute(LayoutAttribute.Type.PARAM, attribute(attributeName.replace("android:layout_", ""), attributeValue));
            case "android:background":
                if (String.valueOf(attributeStartValue).startsWith("R.")) {
                    return new LayoutAttribute(setter("BackgroundResource", attributeStartValue, false));
                }
                break;
            case "android:textSize":
                return new LayoutAttribute(setter("TextSize", "TypedValue.COMPLEX_UNIT_SP," + attributeStartValue.replace("sp", ""), false));
        }
        //Todo : list with all
        if(attributeName.startsWith("android:nextFocus")) {
            return new LayoutAttribute(setter(attributeToName(attributeName) + "Id", attributeStartValue, false));
        }
        return null;
    }
}

@@ -783,32 +783,1036 @@
 teName, false);%0A
+            case %22android:backgroundTintMode%22:%0A                return super.onConvertLayoutAttribute(String.valueOf(attributeValue), %22android.graphics.PorterDuff.Mode.%22 + String.valueOf(attributeValue).toUpperCase(), attributeName, false);%0A            case %22android:accessibilityLiveRegion%22:%0A                return super.onConvertLayoutAttribute(String.valueOf(attributeValue), %22View.ACCESSIBILITY_LIVE_REGION_%22 + String.valueOf(attributeValue).toUpperCase(), attributeName, false);%0A            case %22android:drawingCacheQuality%22:%0A                return super.onConvertLayoutAttribute(String.valueOf(attributeValue), %22View.DRAWING_CACHE_QUALITY_%22 + String.valueOf(attributeValue).toUpperCase(), attributeName, false);%0A            //Todo : viewgroup attribute%0A            case %22android:descendantFocusability%22:%0A                return super.onConvertLayoutAttribute(String.valueOf(attributeValue), %22ViewGroup.FOCUS_%22 + stringToConstant(String.valueOf(attributeValue)).toUpperCase(), attributeName, false);%0A
         %7D%0A      

improve default support