package com.khmelenko.lab.travisclient.converter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;

import com.khmelenko.lab.travisclient.R;
import com.khmelenko.lab.travisclient.TravisApp;

/**
 * Provides methods for processing build states
 *
 * @author Dmytro Khmelenko
 */
public final class BuildStateHelper {

    /**
     * Gets the color according to the build state
     *
     * @param state Build state
     * @return Color
     */
    public static int getBuildColor(String state) {
        Context context = TravisApp.getAppContext();

        int color = ContextCompat.getColor(context, R.color.secondary_text);
        switch (state) {
            case "created":
            case "started":
                color = ContextCompat.getColor(context, R.color.build_state_started);
                break;
            case "passed":
                color = ContextCompat.getColor(context, R.color.build_state_passed);
                break;
            case "canceled":
            case "failed":
            case "errored":
                color = ContextCompat.getColor(context, R.color.build_state_failed);
                break;
        }

        return color;
    }

    public static int getBuildBackground(String state) {
        Context context = TravisApp.getAppContext();

        int color = ContextCompat.getColor(context, android.R.color.transparent);
        switch (state) {
            case "created":
            case "started":
                color = ContextCompat.getColor(context, R.color.build_state_started_bg);
                break;
            case "passed":
                color = ContextCompat.getColor(context, R.color.build_state_passed_bg);
                break;
            case "canceled":
            case "failed":
            case "errored":
                color = ContextCompat.getColor(context, R.color.build_state_failed_bg);
                break;
        }

        return color;
    }

    /**
     * Gets the image drawable according to the build state
     *
     * @param state Build state
     * @return Image drawable
     */
    public static
    @Nullable
    Drawable getBuildImage(String state) {
        Context context = TravisApp.getAppContext();

        Drawable drawable = null;
        switch (state) {
            case "created":
            case "started":
                drawable = ContextCompat.getDrawable(context, R.drawable.build_state_started);
                break;
            case "passed":
                drawable = ContextCompat.getDrawable(context, R.drawable.build_state_passed);
                break;
            case "canceled":
            case "errored":
                drawable = ContextCompat.getDrawable(context, R.drawable.build_state_errored);
                break;
            case "failed":
                drawable = ContextCompat.getDrawable(context, R.drawable.build_state_failed);
                break;
        }

        return drawable;
    }

    /**
     * Checks whether the state passed or not
     *
     * @param state State
     * @return True, if state is passed. False otherwise
     */
    public static boolean isPassed(@NonNull String state) {
        boolean passed = state.equals("passed");
        return passed;
    }

    /**
     * Checks whether the build is in progress or not
     *
     * @param state State
     * @return True, if the build is in progress state. False otherwise
     */
    public static boolean isInProgress(@NonNull String state) {
        boolean inProgress = state.equals("created") || state.equals("started");
        return inProgress;
    }
}

@@ -473,24 +473,377 @@
 lper %7B%0A%0A
+    private static final String STATE_CREATED = %22created%22;%0A    private static final String STATE_STARTED = %22started%22;%0A    private static final String STATE_PASSED = %22passed%22;%0A    private static final String STATE_CANCELED = %22canceled%22;%0A    private static final String STATE_FAILED = %22failed%22;%0A    private static final String STATE_ERRORED = %22errored%22;%0A%0A
     /**%0A
      * G
@@ -826,32 +826,32 @@
 ored%22;%0A%0A    /**%0A
-
      * Gets the 
@@ -1174,33 +1174,37 @@
        case 
-%22created%22
+STATE_CREATED
 :%0A          
@@ -1206,33 +1206,37 @@
        case 
-%22started%22
+STATE_STARTED
 :%0A          
@@ -1347,32 +1347,36 @@
        case 
-%22passed%22
+STATE_PASSED
 :%0A          
@@ -1486,34 +1486,38 @@
        case 
-%22canceled%22
+STATE_CANCELED
 :%0A          
@@ -1519,32 +1519,36 @@
        case 
-%22failed%22
+STATE_FAILED
 :%0A          
@@ -1550,33 +1550,37 @@
        case 
-%22errored%22
+STATE_ERRORED
 :%0A          
@@ -1948,33 +1948,37 @@
        case 
-%22created%22
+STATE_CREATED
 :%0A          
@@ -1980,33 +1980,37 @@
        case 
-%22started%22
+STATE_STARTED
 :%0A          
@@ -2124,32 +2124,36 @@
        case 
-%22passed%22
+STATE_PASSED
 :%0A          
@@ -2266,34 +2266,38 @@
        case 
-%22canceled%22
+STATE_CANCELED
 :%0A          
@@ -2299,32 +2299,36 @@
        case 
-%22failed%22
+STATE_FAILED
 :%0A          
@@ -2330,33 +2330,37 @@
        case 
-%22errored%22
+STATE_ERRORED
 :%0A          
@@ -2850,25 +2850,29 @@
    case 
-%22created%22
+STATE_CREATED
 :%0A      
@@ -2882,25 +2882,29 @@
    case 
-%22started%22
+STATE_STARTED
 :%0A      
@@ -3032,24 +3032,28 @@
    case 
-%22passed%22
+STATE_PASSED
 :%0A      
@@ -3180,26 +3180,30 @@
    case 
-%22canceled%22
+STATE_CANCELED
 :%0A      
@@ -3213,25 +3213,29 @@
    case 
-%22errored%22
+STATE_ERRORED
 :%0A      
@@ -3363,24 +3363,28 @@
    case 
-%22failed%22
+STATE_FAILED
 :%0A      
@@ -3787,24 +3787,28 @@
 .equals(
-%22passed%22
+STATE_PASSED
 );%0A     
@@ -4113,25 +4113,29 @@
 .equals(
-%22created%22
+STATE_CREATED
 ) %7C%7C sta
@@ -4144,25 +4144,29 @@
 .equals(
-%22started%22
+STATE_STARTED
 );%0A     

Move build states to constant values