|  | @@ -0,0 +1,122 @@
 | 
	
		
			
			|  | 1 | +package com.reactnativenavigation.params.parsers;
 | 
	
		
			
			|  | 2 | +
 | 
	
		
			
			|  | 3 | +import android.os.Bundle;
 | 
	
		
			
			|  | 4 | +import android.support.annotation.NonNull;
 | 
	
		
			
			|  | 5 | +import android.support.annotation.Nullable;
 | 
	
		
			
			|  | 6 | +
 | 
	
		
			
			|  | 7 | +import com.reactnativenavigation.params.StyleParams;
 | 
	
		
			
			|  | 8 | +
 | 
	
		
			
			|  | 9 | +public class StyleParamsParser {
 | 
	
		
			
			|  | 10 | +    private static StyleParams appStyle;
 | 
	
		
			
			|  | 11 | +    private Bundle params;
 | 
	
		
			
			|  | 12 | +
 | 
	
		
			
			|  | 13 | +    public static void setAppStyle(Bundle params) {
 | 
	
		
			
			|  | 14 | +        StyleParamsParser.appStyle = new StyleParamsParser(params.getBundle("appStyle")).parse();
 | 
	
		
			
			|  | 15 | +    }
 | 
	
		
			
			|  | 16 | +
 | 
	
		
			
			|  | 17 | +    public StyleParamsParser(Bundle params) {
 | 
	
		
			
			|  | 18 | +        this.params = params;
 | 
	
		
			
			|  | 19 | +    }
 | 
	
		
			
			|  | 20 | +
 | 
	
		
			
			|  | 21 | +    public StyleParams parse() {
 | 
	
		
			
			|  | 22 | +        StyleParams result = new StyleParams();
 | 
	
		
			
			|  | 23 | +        if (params == null) {
 | 
	
		
			
			|  | 24 | +            return result;
 | 
	
		
			
			|  | 25 | +        }
 | 
	
		
			
			|  | 26 | +
 | 
	
		
			
			|  | 27 | +        result.statusBarColor = getColor("statusBarColor", getDefaultStatusBarColor());
 | 
	
		
			
			|  | 28 | +
 | 
	
		
			
			|  | 29 | +        result.topBarColor = getColor("topBarColor", getDefaultTopBarColor());
 | 
	
		
			
			|  | 30 | +        result.titleBarHidden = getBoolean("titleBarHidden", isDefaultTopBarHidden());
 | 
	
		
			
			|  | 31 | +        result.titleBarTitleColor = getColor("titleBarTitleColor", getDefaultTitleBarColor());
 | 
	
		
			
			|  | 32 | +        result.backButtonHidden = getBoolean("backButtonHidden", isDefaultBackButtonHidden());
 | 
	
		
			
			|  | 33 | +        result.topTabsHidden = getBoolean("topTabsHidden", isDefaultTopTabsHidden());
 | 
	
		
			
			|  | 34 | +
 | 
	
		
			
			|  | 35 | +        result.drawScreenBelowTopBar = params.getBoolean("drawBelowTopBar", isDefaultScreenBelowTopBar());
 | 
	
		
			
			|  | 36 | +
 | 
	
		
			
			|  | 37 | +        result.bottomTabsHidden = getBoolean("bottomTabsHidden", isDefaultBottomTabsHidden());
 | 
	
		
			
			|  | 38 | +        result.bottomTabsHiddenOnScroll =
 | 
	
		
			
			|  | 39 | +                getBoolean("bottomTabsHiddenOnScroll", isDefaultBottomTabsHiddenOnScroll());
 | 
	
		
			
			|  | 40 | +        result.bottomTabsColor = getColor("bottomTabsColor", getDefaultBottomTabsColor());
 | 
	
		
			
			|  | 41 | +        result.bottomTabsButtonColor = getColor("bottomTabsButtonColor", getDefaultBottomTabsButtonColor());
 | 
	
		
			
			|  | 42 | +        result.selectedBottomTabsButtonColor =
 | 
	
		
			
			|  | 43 | +                getColor("selectedBottomTabsButtonColor", getDefaultSelectedBottomTabsButtonColor());
 | 
	
		
			
			|  | 44 | +
 | 
	
		
			
			|  | 45 | +        result.navigationBarColor = getColor("navigationBarColor", getDefaultNavigationColor());
 | 
	
		
			
			|  | 46 | +
 | 
	
		
			
			|  | 47 | +        return result;
 | 
	
		
			
			|  | 48 | +    }
 | 
	
		
			
			|  | 49 | +
 | 
	
		
			
			|  | 50 | +    @Nullable
 | 
	
		
			
			|  | 51 | +    private StyleParams.Color getDefaultNavigationColor() {
 | 
	
		
			
			|  | 52 | +        return appStyle == null ? new StyleParams.Color(-1) : appStyle.navigationBarColor;
 | 
	
		
			
			|  | 53 | +    }
 | 
	
		
			
			|  | 54 | +
 | 
	
		
			
			|  | 55 | +    @Nullable
 | 
	
		
			
			|  | 56 | +    private StyleParams.Color getDefaultSelectedBottomTabsButtonColor() {
 | 
	
		
			
			|  | 57 | +        return appStyle == null ? new StyleParams.Color(-1) : appStyle.selectedBottomTabsButtonColor;
 | 
	
		
			
			|  | 58 | +    }
 | 
	
		
			
			|  | 59 | +
 | 
	
		
			
			|  | 60 | +    @Nullable
 | 
	
		
			
			|  | 61 | +    private StyleParams.Color getDefaultBottomTabsButtonColor() {
 | 
	
		
			
			|  | 62 | +        return appStyle == null ? new StyleParams.Color(-1) : appStyle.bottomTabsButtonColor;
 | 
	
		
			
			|  | 63 | +    }
 | 
	
		
			
			|  | 64 | +
 | 
	
		
			
			|  | 65 | +    @Nullable
 | 
	
		
			
			|  | 66 | +    private StyleParams.Color getDefaultBottomTabsColor() {
 | 
	
		
			
			|  | 67 | +        return appStyle == null ? new StyleParams.Color(-1) : appStyle.bottomTabsColor;
 | 
	
		
			
			|  | 68 | +    }
 | 
	
		
			
			|  | 69 | +
 | 
	
		
			
			|  | 70 | +    private boolean isDefaultBottomTabsHiddenOnScroll() {
 | 
	
		
			
			|  | 71 | +        return appStyle != null && appStyle.bottomTabsHiddenOnScroll;
 | 
	
		
			
			|  | 72 | +    }
 | 
	
		
			
			|  | 73 | +
 | 
	
		
			
			|  | 74 | +    private boolean isDefaultBottomTabsHidden() {
 | 
	
		
			
			|  | 75 | +        return appStyle != null && appStyle.bottomTabsHidden;
 | 
	
		
			
			|  | 76 | +    }
 | 
	
		
			
			|  | 77 | +
 | 
	
		
			
			|  | 78 | +    private boolean isDefaultScreenBelowTopBar() {
 | 
	
		
			
			|  | 79 | +        return appStyle == null || appStyle.drawScreenBelowTopBar;
 | 
	
		
			
			|  | 80 | +    }
 | 
	
		
			
			|  | 81 | +
 | 
	
		
			
			|  | 82 | +    private boolean isDefaultTopTabsHidden() {
 | 
	
		
			
			|  | 83 | +        return appStyle != null && appStyle.topTabsHidden;
 | 
	
		
			
			|  | 84 | +    }
 | 
	
		
			
			|  | 85 | +
 | 
	
		
			
			|  | 86 | +    private boolean isDefaultBackButtonHidden() {
 | 
	
		
			
			|  | 87 | +        return appStyle != null && appStyle.backButtonHidden;
 | 
	
		
			
			|  | 88 | +    }
 | 
	
		
			
			|  | 89 | +
 | 
	
		
			
			|  | 90 | +    @Nullable
 | 
	
		
			
			|  | 91 | +    private StyleParams.Color getDefaultTitleBarColor() {
 | 
	
		
			
			|  | 92 | +        return appStyle == null ? new StyleParams.Color(-1) : appStyle.titleBarTitleColor;
 | 
	
		
			
			|  | 93 | +    }
 | 
	
		
			
			|  | 94 | +
 | 
	
		
			
			|  | 95 | +    private boolean isDefaultTopBarHidden() {
 | 
	
		
			
			|  | 96 | +        return appStyle != null && appStyle.titleBarHidden;
 | 
	
		
			
			|  | 97 | +    }
 | 
	
		
			
			|  | 98 | +
 | 
	
		
			
			|  | 99 | +    @Nullable
 | 
	
		
			
			|  | 100 | +    private StyleParams.Color getDefaultTopBarColor() {
 | 
	
		
			
			|  | 101 | +        return appStyle == null ? new StyleParams.Color(-1) : appStyle.topBarColor;
 | 
	
		
			
			|  | 102 | +    }
 | 
	
		
			
			|  | 103 | +
 | 
	
		
			
			|  | 104 | +    @Nullable
 | 
	
		
			
			|  | 105 | +    private StyleParams.Color getDefaultStatusBarColor() {
 | 
	
		
			
			|  | 106 | +        return appStyle == null ? new StyleParams.Color(-1) : appStyle.statusBarColor;
 | 
	
		
			
			|  | 107 | +    }
 | 
	
		
			
			|  | 108 | +
 | 
	
		
			
			|  | 109 | +    private boolean getBoolean(String titleBarHidden, boolean defaultValue) {
 | 
	
		
			
			|  | 110 | +        return params.containsKey(titleBarHidden) ? params.getBoolean(titleBarHidden) : defaultValue;
 | 
	
		
			
			|  | 111 | +    }
 | 
	
		
			
			|  | 112 | +
 | 
	
		
			
			|  | 113 | +    @NonNull
 | 
	
		
			
			|  | 114 | +    private StyleParams.Color getColor(String key, StyleParams.Color defaultColor) {
 | 
	
		
			
			|  | 115 | +        StyleParams.Color color = new StyleParams.Color(ColorParser.parse(params.getString(key)));
 | 
	
		
			
			|  | 116 | +        if (color.hasColor()) {
 | 
	
		
			
			|  | 117 | +            return color;
 | 
	
		
			
			|  | 118 | +        } else {
 | 
	
		
			
			|  | 119 | +            return defaultColor.hasColor() ? defaultColor : color;
 | 
	
		
			
			|  | 120 | +        }
 | 
	
		
			
			|  | 121 | +    }
 | 
	
		
			
			|  | 122 | +}
 |