package com.plumb.example.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;

import com.jakewharton.rxbinding.widget.RxSeekBar;
import com.plumb.example.viewmodel.ColorPickerViewModel;
import com.plumb.plumb.R;

import plumb.Plumbing;
import plumb.annotation.In;
import plumb.annotation.Out;
import plumb.annotation.Plumbed;
import rx.Observable;
import rx.functions.Action1;
import rx.subjects.BehaviorSubject;
import rx.subscriptions.CompositeSubscription;

@Plumbed(ColorPickerViewModel.class)
public class ColorPickerView extends RelativeLayout {

    public ImageView colorView;

    public ColorPickerViewModel viewModel = new ColorPickerViewModel();

    @Out("red")
    public Observable<Integer> red;
    @Out("green")
    public Observable<Integer> green;
    @Out("blue")
    public Observable<Integer> blue;

    @In("color")
    public BehaviorSubject<Integer> color = BehaviorSubject.create();

    private CompositeSubscription subscriptions = new CompositeSubscription();

    public ColorPickerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public ColorPickerView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        colorView = (ImageView) findViewById(R.id.target);
        SeekBar redSeekBar = (SeekBar) findViewById(R.id.red_seek_bar);
        SeekBar greenSeekBar = (SeekBar) findViewById(R.id.green_seek_bar);
        SeekBar blueSeekBar = (SeekBar) findViewById(R.id.blue_seek_bar);

        red = RxSeekBar.changes(redSeekBar);
        green = RxSeekBar.changes(greenSeekBar);
        blue = RxSeekBar.changes(blueSeekBar);

        //(color) -> { colorView.setBackgroundColor(color) }
        subscriptions.add(color.subscribe(new Action1<Integer>() {
            @Override
            public void call(Integer color) {
                colorView.setBackgroundColor(color);
            }
        }));
        Plumbing.plumb(this, viewModel);
    }

    @Override
    public void onDetachedFromWindow() {
        subscriptions.unsubscribe();
        Plumbing.demolish(this);
        super.onDetachedFromWindow();
    }
}

@@ -77,90 +77,24 @@
 oid.
-graphics.Color;%0Aimport android.util.AttributeSet;%0Aimport android.widget.FrameLayou
+util.AttributeSe
 t;%0Ai
@@ -194,17 +194,16 @@
 eekBar;%0A
-%0A
 import c
@@ -328,17 +328,16 @@
 lumb.R;%0A
-%0A
 import p
@@ -789,20 +789,16 @@
 t(%22red%22)
-%0A   
  public 
@@ -839,20 +839,16 @@
 %22green%22)
-%0A   
  public 
@@ -890,20 +890,16 @@
 (%22blue%22)
-%0A   
  public 
@@ -941,20 +941,16 @@
 %22color%22)
-%0A   
  public 
@@ -1334,36 +1334,32 @@
 %7D%0A%0A    @Override
-%0A   
  public void onA
@@ -1987,28 +1987,16 @@
 Override
-%0A           
  public 
@@ -2163,20 +2163,16 @@
 Override
-%0A   
  public 

Format ColorPickerView