package com.kickstarter.libs;

import android.os.Bundle;

import rx.subjects.PublishSubject;

public class Presenter<ViewType> {
  protected final PublishSubject<ViewType> viewSubject = PublishSubject.create();

  protected void onCreate(Bundle savedInstanceState) {
    viewSubject.onNext(null);
  }

  protected void onResume(ViewType view) {
    viewSubject.onNext(view);
  }

  protected void onPause() {
    viewSubject.onNext(null);
  }

  protected void onDestroy() {
    viewSubject.onCompleted();
  }

  public void save(Bundle state) {
    // TODO
  }

}

@@ -51,16 +51,92 @@
 undle;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport rx.Subscription;%0A
 import r
@@ -162,16 +162,16 @@
 ubject;%0A
-
 %0Apublic 
@@ -279,16 +279,88 @@
 reate();
+%0A  protected final List%3CSubscription%3E subscriptions = new ArrayList%3C%3E();
 %0A%0A  prot
@@ -612,24 +612,119 @@
 Destroy() %7B%0A
+    for (Subscription subscription : subscriptions) %7B%0A      subscription.unsubscribe();%0A    %7D%0A%0A
     viewSubj
@@ -794,15 +794,14 @@
 // TODO%0A
+
   %7D%0A
-%0A
 %7D%0A

Add subscriptions, unsubscribe to all when presenter is destroyed