Skip to content

Commit

Permalink
API call to filter by book type
Browse files Browse the repository at this point in the history
  • Loading branch information
anas-ambri committed Jan 28, 2016
1 parent 597347a commit 83d196f
Showing 1 changed file with 28 additions and 0 deletions.
Expand Up @@ -3,6 +3,9 @@
import com.google.gson.Gson;
import com.verybadalloc.designlib.model.Book;

import java.util.ArrayList;
import java.util.List;

/**
* Created by aambri on 15-06-06.
*/
Expand All @@ -26,4 +29,29 @@ public void onFailure(String reason) {
}
});
}

public static void getBooksOfType(final String type, final DataCallback<Book[]> callback) {

DataFetcher.getBooks(new DataCallback<Book[]>() {
@Override
public void onSuccess(Book[] data) {
if (!type.equalsIgnoreCase("All")) {
List<Book> newList = new ArrayList<Book>(data.length);
for (Book b : data) {
if (b.type.equalsIgnoreCase(type)) {
newList.add(b);
}
}
callback.onSuccess(newList.toArray(new Book[newList.size()]));
} else {
callback.onSuccess(data);
}
}

@Override
public void onFailure(String reason) {
callback.onFailure(reason);
}
});
}
}

0 comments on commit 83d196f

Please sign in to comment.