use of com.kickstarter.models.Project in project android-oss by kickstarter.
the class KoalaUtils method activityProperties.
@NonNull
public static Map<String, Object> activityProperties(@NonNull final Activity activity, @NonNull final String prefix) {
Map<String, Object> properties = new HashMap<String, Object>() {
{
put("category", activity.category());
}
};
properties = MapUtils.prefixKeys(properties, prefix);
final Project project = activity.project();
if (project != null) {
properties.putAll(projectProperties(project));
final Update update = activity.update();
if (update != null) {
properties.putAll(updateProperties(project, update));
}
}
return properties;
}
use of com.kickstarter.models.Project 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();
}
use of com.kickstarter.models.Project in project android-oss by kickstarter.
the class CommentsViewModelTest method testCommentsViewModel_postCommentError.
@Test
public void testCommentsViewModel_postCommentError() {
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<Comment> postComment(@NonNull final Project project, @NonNull final String body) {
return Observable.error(ApiExceptionFactory.badRequestException());
}
};
final Environment env = environment().toBuilder().apiClient(apiClient).build();
final CommentsViewModel vm = new CommentsViewModel(env);
final TestSubscriber<String> showPostCommentErrorToast = new TestSubscriber<>();
vm.outputs.showPostCommentErrorToast().subscribe(showPostCommentErrorToast);
final TestSubscriber<Void> showCommentPostedToast = new TestSubscriber<>();
vm.outputs.showCommentPostedToast().subscribe(showCommentPostedToast);
// Start the view model with a project.
vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.backedProject()));
// Click the comment button and write a comment.
vm.inputs.commentButtonClicked();
vm.inputs.commentBodyChanged("Mic check mic check.");
// Post comment. Error should be shown. Comment posted toast should not be shown.
vm.inputs.postCommentClicked();
showPostCommentErrorToast.assertValueCount(1);
showCommentPostedToast.assertNoValues();
}
use of com.kickstarter.models.Project in project android-oss by kickstarter.
the class CommentsViewModelTest method testCommentsViewModel_loggedOutShowDialogFlow.
@Test
public void testCommentsViewModel_loggedOutShowDialogFlow() {
final CurrentUserType currentUser = new MockCurrentUser();
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
final CommentsViewModel vm = new CommentsViewModel(environment);
final Project project = ProjectFactory.backedProject();
final TestSubscriber<Pair<Project, Boolean>> showCommentDialogTest = new TestSubscriber<>();
vm.outputs.showCommentDialog().subscribe(showCommentDialogTest);
// Start the view model with a project.
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
// The comment dialog should be hidden from logged out user.
showCommentDialogTest.assertNoValues();
// Login.
currentUser.refresh(UserFactory.user());
vm.inputs.loginSuccess();
// The comment dialog should be shown to backer.
showCommentDialogTest.assertValue(Pair.create(project, true));
}
use of com.kickstarter.models.Project in project android-oss by kickstarter.
the class CommentsViewModelTest method testCommentsViewModel_dismissCommentDialog.
@Test
public void testCommentsViewModel_dismissCommentDialog() {
final CommentsViewModel vm = new CommentsViewModel(environment());
final TestSubscriber<Void> dismissCommentDialogTest = new TestSubscriber<>();
vm.outputs.dismissCommentDialog().subscribe(dismissCommentDialogTest);
final TestSubscriber<Pair<Project, Boolean>> showCommentDialogTest = new TestSubscriber<>();
vm.outputs.showCommentDialog().subscribe(showCommentDialogTest);
final Project project = ProjectFactory.backedProject();
// Start the view model with a project.
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
// The comment dialog should not be shown.
showCommentDialogTest.assertNoValues();
dismissCommentDialogTest.assertNoValues();
// Dismiss the comment dialog.
vm.inputs.commentDialogDismissed();
// The comment dialog should be dismissed.
dismissCommentDialogTest.assertValueCount(1);
showCommentDialogTest.assertValue(null);
}
Aggregations