Skip to content

Commit

Permalink
cleaning up my mess
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Sharat committed Mar 1, 2017
1 parent 143ca0f commit f8d7151
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

/**
* IncludeParser
* <p>
* TODO: merge the attributes into the included layout
* </p>
*
* @author aditya.sharat
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public class ParseHelper {
private static final String TEXT_ALIGNMENT_VIEW_END = "viewEnd";


private static final String ATTR_START_LITERAL = "?";
private static final String TWEEN_LOCAL_RESOURCE_STR = "@anim/";

private static final String DRAWABLE_STR = "drawable";
Expand Down Expand Up @@ -269,7 +268,7 @@ public static int parseVisibility(@Nullable Value value) {
return returnValue == null ? View.VISIBLE : returnValue;
}

public static Primitive getVisibilty(int visibility) {
public static Primitive getVisibility(int visibility) {
Primitive value = sVisibilityMap.get(visibility);
return null != value ? value : sVisibilityMap.get(View.GONE);
}
Expand Down Expand Up @@ -329,10 +328,6 @@ public static int parseTextStyle(String attributeValue) {
return typeface;
}

public static boolean isLocalAttribute(String value) {
return value.startsWith(ATTR_START_LITERAL);
}

public static boolean isTweenAnimationResource(String attributeValue) {
return attributeValue.startsWith(TWEEN_LOCAL_RESOURCE_STR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusAndroidView(context);
}

Expand Down Expand Up @@ -363,7 +364,7 @@ public void handleStyleResource(V view, StyleResource style) {
@Override
public Value compile(@Nullable Value value, Context context) {
int visibility = ParseHelper.parseVisibility(value);
return ParseHelper.getVisibilty(visibility);
return ParseHelper.getVisibility(visibility);
}
});
addAttributeProcessor(Attributes.View.Id, new StringAttributeProcessor<V>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusButton(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusCheckBox(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusEditText(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusAspectRatioFrameLayout(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusHorizontalProgressBar(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusHorizontalScrollView(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusImageButton(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusImageView(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusLinearLayout(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusProgressBar(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusFixedRatingBar(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusRelativeLayout(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusScrollView(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusTextView(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusAspectRatioFrameLayout(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public String getParentType() {

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data,
@Nullable ViewGroup parent, int dataIndex) {
return new ProteusWebView(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,9 @@

public abstract class BooleanAttributeProcessor<V extends View> extends AttributeProcessor<V> {

public static final String BOOLEAN_RESOURCE_PREFIX = "@bool/";

public static final Primitive TRUE = new Primitive(true);
public static final Primitive FALSE = new Primitive(false);

public static boolean isLocalBooleanResource(String value) {
return value.startsWith(BOOLEAN_RESOURCE_PREFIX);
}

@Override
public void handleValue(V view, Value value) {
if (value.isPrimitive() && value.getAsPrimitive().isBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import android.support.annotation.Nullable;
import android.view.View;

import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Primitive;
import com.flipkart.android.proteus.value.Resource;
Expand All @@ -40,24 +38,14 @@ public abstract class StringAttributeProcessor<V extends View> extends Attribute

public static final String EMPTY_STRING = "";
public static final Primitive EMPTY = new Primitive(EMPTY_STRING);
private static final String STRING_RESOURCE_PREFIX = "@string/";

public static boolean isLocalStringResource(String value) {
return value.startsWith(STRING_RESOURCE_PREFIX);
}

/**
* @param view View
* @param value
*/
@Override
public void handleValue(V view, Value value) {
String string = value.getAsString();
if (ParseHelper.isLocalAttribute(string) || isLocalStringResource(string)) {
process(view, precompile(value, view.getContext(), ((ProteusContext) view.getContext()).getFormatterManager()));
} else {
setString(view, string);
}
setString(view, value.getAsString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
import com.flipkart.android.proteus.value.Value;

/**
* Use this as the base processor for references like @anim
* TweenAnimationResourceProcessor
* <p>
* TODO: implement precompiling animation blocks
* </p>
*
* @author yasirmhd
*/
public abstract class TweenAnimationResourceProcessor<V extends View> extends AttributeProcessor<V> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

/**
* ColorValue
* TODO: fix the color state list to consume color resources and style attributes.
*
* @author aditya.sharat
*/
Expand Down Expand Up @@ -183,10 +182,6 @@ public static boolean isColor(String color) {
return color.startsWith(COLOR_PREFIX_LITERAL);
}

public static boolean isLocalColorResource(String attributeValue) {
return attributeValue.startsWith(COLOR_RESOURCE_PREFIX);
}

private static HashMap<String, Integer> getAttributesMap() {
if (null == sAttributesMap) {
synchronized (Color.class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public class Dimension extends Value {
public static final String FILL_PARENT = "fill_parent";
public static final String WRAP_CONTENT = "wrap_content";

public static final String PREFIX_DIMENSION = "@dimen/";

public static final String SUFFIX_PX = "px";
public static final String SUFFIX_DP = "dp";
public static final String SUFFIX_SP = "sp";
Expand Down Expand Up @@ -128,10 +126,6 @@ public static float apply(String dimension, Context context) {
return Dimension.valueOf(dimension, context).apply(context);
}

public static boolean isLocalDimensionResource(String value) {
return value.startsWith(PREFIX_DIMENSION);
}

public float apply(Context context) {
double result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
*/
public abstract class DrawableValue extends Value {

private static final String PREFIX_DRAWABLE = "@drawable/";

private static final String TYPE = "type";
private static final String CHILDREN = "children";

Expand All @@ -74,10 +72,6 @@ public abstract class DrawableValue extends Value {
private static final String TYPE_SOLID = "solid";
private static final String TYPE_STROKE = "stroke";

public static boolean isLocalDrawableResource(String value) {
return value.startsWith(PREFIX_DRAWABLE);
}

@Nullable
public static DrawableValue valueOf(String value, Context context) {
if (Color.isColor(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,12 @@ public Array getAsArray(String memberName) {
* @param memberName name of the member being requested.
* @return the ObjectValue corresponding to the specified member.
*/
@Nullable
public ObjectValue getAsObject(String memberName) {
return (ObjectValue) members.get(memberName);
if (isObject(memberName)) {
return (ObjectValue) members.get(memberName);
}
return null;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.util.LruCache;

import com.flipkart.android.proteus.ProteusConstants;
import com.flipkart.android.proteus.parser.ParseHelper;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -53,9 +52,6 @@ private StyleResource() {
}

private StyleResource(String value, Context context) throws IllegalArgumentException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException {
if (!ParseHelper.isLocalAttribute(value)) {
throw new IllegalArgumentException(value + " is not a valid style attribute");
}
String[] tokens = value.substring(1, value.length()).split(":");
String style = tokens[0];
String attr = tokens[1];
Expand Down

0 comments on commit f8d7151

Please sign in to comment.