use of com.kickstarter.libs.utils.ListUtils in project android-oss by kickstarter.
the class ThanksViewModel method relatedProjects.
/**
* Returns a shuffled list of 3 recommended projects, with fallbacks to similar and staff picked projects
* for users with fewer than 3 recommendations.
*/
@NonNull
private Observable<List<Project>> relatedProjects(@NonNull final Project project) {
final DiscoveryParams recommendedParams = DiscoveryParams.builder().backed(-1).recommended(true).perPage(6).build();
final DiscoveryParams similarToParams = DiscoveryParams.builder().backed(-1).similarTo(project).perPage(3).build();
final Category category = project.category();
final DiscoveryParams staffPickParams = DiscoveryParams.builder().category(category == null ? null : category.root()).backed(-1).staffPicks(true).perPage(3).build();
final Observable<Project> recommendedProjects = apiClient.fetchProjects(recommendedParams).retry(2).map(DiscoverEnvelope::projects).map(ListUtils::shuffle).flatMap(Observable::from).take(3);
final Observable<Project> similarToProjects = apiClient.fetchProjects(similarToParams).retry(2).map(DiscoverEnvelope::projects).flatMap(Observable::from);
final Observable<Project> staffPickProjects = apiClient.fetchProjects(staffPickParams).retry(2).map(DiscoverEnvelope::projects).flatMap(Observable::from);
return Observable.concat(recommendedProjects, similarToProjects, staffPickProjects).compose(neverError()).distinct().take(3).toList();
}
Aggregations