// Path: mvvm-life-cycle/src/main/java/me/henrytao/mvvmlifecycle/rx/SubscriptionUtils.java
// public class SubscriptionUtils {
// 
//   public static <T> void onComplete(Subscriber<T> subscriber) {
//     if (subscriber != null && !subscriber.isUnsubscribed()) {
//       subscriber.onCompleted();
//     }
//   }
// 
//   public static <T> void onError(Subscriber<T> subscriber, Throwable throwable) {
//     if (subscriber != null && !subscriber.isUnsubscribed()) {
//       subscriber.onError(throwable);
//     }
//   }
// 
//   public static <T> void onNext(Subscriber<T> subscriber, T data) {
//     if (subscriber != null && !subscriber.isUnsubscribed()) {
//       subscriber.onNext(data);
//     }
//   }
// 
//   public static <T> void onNext(Subscriber<T> subscriber) {
//     onNext(subscriber, null);
//   }
// 
//   public static <T> void onNextAndComplete(Subscriber<T> subscriber, T data) {
//     onNext(subscriber, data);
//     onComplete(subscriber);
//   }
// 
//   public static <T> void onNextAndComplete(Subscriber<T> subscriber) {
//     onNextAndComplete(subscriber, null);
//   }
// }
// 
// Path: sample/src/main/java/me/henrytao/mvvmlifecycledemo/data/adapter/LocalAdapter.java
// public interface LocalAdapter {
// 
//   void activeTask(String taskId) throws DataNotFoundException;
// 
//   void completeTask(String taskId) throws DataNotFoundException;
// 
//   Task createTask(String title, String description);
// 
//   Task findTask(String taskId);
// 
//   List<Task> getTasks();
// 
//   Observable<Task> observeTaskCreate();
// 
//   Observable<Task> observeTaskRemove();
// 
//   Observable<Task> observeTaskUpdate();
// 
//   void removeTask(String taskId) throws DataNotFoundException;
// 
//   void updateTask(String taskId, String title, String description) throws DataNotFoundException;
// }
// 
// Path: sample/src/main/java/me/henrytao/mvvmlifecycledemo/data/exception/DataNotFoundException.java
// public class DataNotFoundException extends Exception {
// 
// }
// 
// Path: sample/src/main/java/me/henrytao/mvvmlifecycledemo/data/model/Task.java
// public class Task {
// 
//   private boolean mCompleted;
// 
//   private String mDescription;
// 
//   private String mId;
// 
//   private String mTitle;
// 
//   public Task(String id, String title, String description) {
//     mId = id;
//     mTitle = title;
//     mDescription = description;
//   }
// 
//   protected Task(String id, String title, String description, boolean completed) {
//     mId = id;
//     mTitle = title;
//     mDescription = description;
//     mCompleted = completed;
//   }
// 
//   public Task(String title, String description) {
//     this(UUID.randomUUID().toString(), title, description);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(mId, mTitle, mDescription, mCompleted);
//   }
// 
//   public void active() {
//     mCompleted = false;
//   }
// 
//   public void complete() {
//     mCompleted = true;
//   }
// 
//   public String getDescription() {
//     return mDescription;
//   }
// 
//   public void setDescription(String description) {
//     mDescription = description;
//   }
// 
//   public String getId() {
//     return mId;
//   }
// 
//   public String getTitle() {
//     return mTitle;
//   }
// 
//   public void setTitle(String title) {
//     mTitle = title;
//   }
// 
//   public boolean isActive() {
//     return !isCompleted();
//   }
// 
//   public boolean isCompleted() {
//     return mCompleted;
//   }
// 
//   public void setCompleted(boolean completed) {
//     mCompleted = completed;
//   }
// }


import java.util.List;
import me.henrytao.mvvmlifecycle.rx.SubscriptionUtils;
import me.henrytao.mvvmlifecycledemo.data.adapter.LocalAdapter;
import me.henrytao.mvvmlifecycledemo.data.exception.DataNotFoundException;
import me.henrytao.mvvmlifecycledemo.data.model.Task;
import rx.Observable;
      } catch (Exception e) {
        SubscriptionUtils.onError(subscriber, e);
      }
    });
  }

  public Observable<Void> complete(String taskId) {
    return Observable.create(subscriber -> {
      try {
        mLocalAdapter.completeTask(taskId);
        SubscriptionUtils.onNextAndComplete(subscriber);
      } catch (Exception e) {
        SubscriptionUtils.onError(subscriber, e);
      }
    });
  }

  public Observable<Task> create(String title, String description) {
    return Observable.create(subscriber -> {
      Task task = mLocalAdapter.createTask(title, description);
      SubscriptionUtils.onNextAndComplete(subscriber, task);
    });
  }

  public Observable<Task> find(String taskId) {
    return Observable.create(subscriber -> {
      Task task = mLocalAdapter.findTask(taskId);
      if (task != null) {
        SubscriptionUtils.onNextAndComplete(subscriber, task);
      } else {
// Path: mvvm-life-cycle/src/main/java/me/henrytao/mvvmlifecycle/rx/SubscriptionUtils.java
// public class SubscriptionUtils {
// 
//   public static <T> void onComplete(Subscriber<T> subscriber) {
//     if (subscriber != null && !subscriber.isUnsubscribed()) {
//       subscriber.onCompleted();
//     }
//   }
// 
//   public static <T> void onError(Subscriber<T> subscriber, Throwable throwable) {
//     if (subscriber != null && !subscriber.isUnsubscribed()) {
//       subscriber.onError(throwable);
//     }
//   }
// 
//   public static <T> void onNext(Subscriber<T> subscriber, T data) {
//     if (subscriber != null && !subscriber.isUnsubscribed()) {
//       subscriber.onNext(data);
//     }
//   }
// 
//   public static <T> void onNext(Subscriber<T> subscriber) {
//     onNext(subscriber, null);
//   }
// 
//   public static <T> void onNextAndComplete(Subscriber<T> subscriber, T data) {
//     onNext(subscriber, data);
//     onComplete(subscriber);
//   }
// 
//   public static <T> void onNextAndComplete(Subscriber<T> subscriber) {
//     onNextAndComplete(subscriber, null);
//   }
// }
// 
// Path: sample/src/main/java/me/henrytao/mvvmlifecycledemo/data/adapter/LocalAdapter.java
// public interface LocalAdapter {
// 
//   void activeTask(String taskId) throws DataNotFoundException;
// 
//   void completeTask(String taskId) throws DataNotFoundException;
// 
//   Task createTask(String title, String description);
// 
//   Task findTask(String taskId);
// 
//   List<Task> getTasks();
// 
//   Observable<Task> observeTaskCreate();
// 
//   Observable<Task> observeTaskRemove();
// 
//   Observable<Task> observeTaskUpdate();
// 
//   void removeTask(String taskId) throws DataNotFoundException;
// 
//   void updateTask(String taskId, String title, String description) throws DataNotFoundException;
// }
// 
// Path: sample/src/main/java/me/henrytao/mvvmlifecycledemo/data/exception/DataNotFoundException.java
// public class DataNotFoundException extends Exception {
// 
// }
// 
// Path: sample/src/main/java/me/henrytao/mvvmlifecycledemo/data/model/Task.java
// public class Task {
// 
//   private boolean mCompleted;
// 
//   private String mDescription;
// 
//   private String mId;
// 
//   private String mTitle;
// 
//   public Task(String id, String title, String description) {
//     mId = id;
//     mTitle = title;
//     mDescription = description;
//   }
// 
//   protected Task(String id, String title, String description, boolean completed) {
//     mId = id;
//     mTitle = title;
//     mDescription = description;
//     mCompleted = completed;
//   }
// 
//   public Task(String title, String description) {
//     this(UUID.randomUUID().toString(), title, description);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(mId, mTitle, mDescription, mCompleted);
//   }
// 
//   public void active() {
//     mCompleted = false;
//   }
// 
//   public void complete() {
//     mCompleted = true;
//   }
// 
//   public String getDescription() {
//     return mDescription;
//   }
// 
//   public void setDescription(String description) {
//     mDescription = description;
//   }
// 
//   public String getId() {
//     return mId;
//   }
// 
//   public String getTitle() {
//     return mTitle;
//   }
// 
//   public void setTitle(String title) {
//     mTitle = title;
//   }
// 
//   public boolean isActive() {
//     return !isCompleted();
//   }
// 
//   public boolean isCompleted() {
//     return mCompleted;
//   }
// 
//   public void setCompleted(boolean completed) {
//     mCompleted = completed;
//   }
// }


// Path: sample/src/main/java/me/henrytao/mvvmlifecycledemo/data/service/TaskService.java
import java.util.List;
import me.henrytao.mvvmlifecycle.rx.SubscriptionUtils;
import me.henrytao.mvvmlifecycledemo.data.adapter.LocalAdapter;
import me.henrytao.mvvmlifecycledemo.data.exception.DataNotFoundException;
import me.henrytao.mvvmlifecycledemo.data.model.Task;
import rx.Observable;

      } catch (Exception e) {
        SubscriptionUtils.onError(subscriber, e);
      }
    });
  }

  public Observable<Void> complete(String taskId) {
    return Observable.create(subscriber -> {
      try {
        mLocalAdapter.completeTask(taskId);
        SubscriptionUtils.onNextAndComplete(subscriber);
      } catch (Exception e) {
        SubscriptionUtils.onError(subscriber, e);
      }
    });
  }

  public Observable<Task> create(String title, String description) {
    return Observable.create(subscriber -> {
      Task task = mLocalAdapter.createTask(title, description);
      SubscriptionUtils.onNextAndComplete(subscriber, task);
    });
  }

  public Observable<Task> find(String taskId) {
    return Observable.create(subscriber -> {
      Task task = mLocalAdapter.findTask(taskId);
      if (task != null) {
        SubscriptionUtils.onNextAndComplete(subscriber, task);
      } else {
        SubscriptionUtils.onError(subscriber, new DataNotFoundException());