package com.seatgeek.sixpack.android;

import android.graphics.Color;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.seatgeek.sixpack.Alternative;
import com.seatgeek.sixpack.Experiment;
import com.seatgeek.sixpack.OnParticipationFailure;
import com.seatgeek.sixpack.OnParticipationSuccess;
import com.seatgeek.sixpack.ParticipatingExperiment;

import javax.inject.Inject;
import javax.inject.Named;

import butterknife.ButterKnife;
import butterknife.InjectView;


public class SixpackActivity extends ActionBarActivity {
    @Inject @Named(SixpackModule.BUTTON_COLOR) Experiment buttonColor;

    @InjectView(R.id.colorful_button) Button colorfulButton;

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ((SixpackApplication) getApplication()).inject(this);

        setContentView(R.layout.activity_sixpack);
        ButterKnife.inject(this);

        buttonColor.participate(
                new OnParticipationSuccess() {
                    @Override public void onParticipation(ParticipatingExperiment experiment, Alternative selectedAlternative) {
                        if (SixpackModule.BUTTON_COLOR_RED.equals(selectedAlternative.getName())) {
                            colorfulButton.setBackgroundColor(Color.RED);
                        } else if (SixpackModule.BUTTON_COLOR_BLUE.equals(selectedAlternative.getName())) {
                            colorfulButton.setBackgroundColor(Color.BLUE);
                        }
                        colorfulButton.setVisibility(View.VISIBLE);
                    }
                },
                new OnParticipationFailure() {
                    @Override public void onParticipationFailed(Experiment experiment, Throwable error) {
                        colorfulButton.setBackgroundColor(Color.RED);
                        colorfulButton.setVisibility(View.VISIBLE);
                    }
                }
        );
    }
}

@@ -193,16 +193,45 @@
 .Button;
+%0Aimport android.widget.Toast;
 %0A%0Aimport
@@ -293,16 +293,25 @@
 sixpack.
+Converted
 Experime
@@ -314,16 +314,148 @@
 riment;%0A
+import com.seatgeek.sixpack.Experiment;%0Aimport com.seatgeek.sixpack.OnConvertFailure;%0Aimport com.seatgeek.sixpack.OnConvertSuccess;%0A
 import c
@@ -1315,16 +1315,22 @@
 ipation(
+final 
 Particip
@@ -1767,32 +1767,1301 @@
               %7D%0A
+%0A                        colorfulButton.setOnClickListener(new View.OnClickListener() %7B%0A                            @Override%0A                            public void onClick(View v) %7B%0A                                v.setOnClickListener(null);%0A                                %0A                                experiment.convert(%0A                                        new OnConvertSuccess() %7B%0A                                            @Override%0A                                            public void onConverted(ConvertedExperiment convertedExperiment) %7B%0A                                                Toast.makeText(SixpackActivity.this, %22Converted!%22, Toast.LENGTH_SHORT).show();%0A                                            %7D%0A                                        %7D,%0A                                        new OnConvertFailure() %7B%0A                                            @Override%0A                                            public void onConvertFailure(ParticipatingExperiment experiment, Throwable error) %7B%0A                                                // uhhhh, retry?%0A                                            %7D%0A                                        %7D%0A                                );%0A                            %7D%0A                        %7D);%0A%0A
                 

Convert our Android users when they click thier button.