package com.getbase.android.db.loaders;

import com.getbase.android.db.provider.ProviderAction;
import com.getbase.android.db.provider.Query;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.support.v4.content.Loader;

import java.util.List;

public class CursorLoaderBuilder {

  public static CursorLoaderBuilder forUri(Uri uri) {
    return new CursorLoaderBuilder(uri);
  }

  private final Query query;
  private final List<Uri> notificationUris = Lists.newArrayList();

  private CursorLoaderBuilder(Uri uri) {
    this.query = ProviderAction.query(uri);
  }

  public CursorLoaderBuilder projection(String... projection) {
    query.projection(projection);
    return this;
  }

  public CursorLoaderBuilder where(String selection, Object... selectionArgs) {
    query.where(selection, selectionArgs);
    return this;
  }

  public CursorLoaderBuilder orderBy(String orderBy) {
    query.orderBy(orderBy);
    return this;
  }

  public CursorLoaderBuilder addNotificationUri(Uri uri) {
    notificationUris.add(uri);
    return this;
  }

  public <Out> TransformedRowLoaderBuilder<Out> transformRow(Function<Cursor, Out> rowTransformer) {
    return new TransformedRowLoaderBuilder<Out>(query.getQueryData(), ImmutableList.copyOf(notificationUris), rowTransformer);
  }

  public <Out> TransformedLoaderBuilder<Out> transform(Function<Cursor, Out> transformer) {
    return new TransformedLoaderBuilder<Out>(query.getQueryData(), ImmutableList.copyOf(notificationUris), transformer);
  }

  public Loader<Cursor> build(Context context) {
    return new ComposedCursorLoader<Cursor>(
        context,
        query.getQueryData(),
        ImmutableList.copyOf(notificationUris),
        Functions.<Cursor>identity()
    );
  }
}

@@ -436,16 +436,45 @@
 oader;%0A%0A
+import java.util.Collection;%0A
 import j
@@ -1069,32 +1069,177 @@
 turn this;%0A  %7D%0A%0A
+  public %3CT%3E CursorLoaderBuilder whereIn(String column, Collection%3CT%3E collection) %7B%0A    query.whereIn(column, collection);%0A    return this;%0A  %7D%0A%0A
   public CursorL

Add CursorLoaderBuilder.whereIn() API