use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ViewPledgeActivity method onCreate.
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_pledge_layout);
ButterKnife.bind(this);
final RewardsItemAdapter rewardsItemAdapter = new RewardsItemAdapter();
rewardsItemRecyclerView.setAdapter(rewardsItemAdapter);
final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
rewardsItemRecyclerView.setLayoutManager(layoutManager);
final Environment environment = environment();
ksString = environment.ksString();
RxView.clicks(projectContextView).compose(bindToLifecycle()).observeOn(mainThread()).subscribe(__ -> viewModel.inputs.projectClicked());
viewModel.outputs.backerNameTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(backerNameTextView::setText);
viewModel.outputs.backerNumberTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(this::setBackerNumberTextViewText);
viewModel.outputs.backingAmountAndDateTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(ad -> setBackingAmountAndDateTextViewText(ad.first, ad.second));
viewModel.outputs.backingStatus().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(this::setBackingStatusTextViewText);
viewModel.outputs.creatorNameTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(this::setCreatorNameTextViewText);
viewModel.outputs.goBack().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(__ -> back());
viewModel.outputs.loadBackerAvatar().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(this::loadBackerAvatar);
viewModel.outputs.loadProjectPhoto().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(url -> Picasso.with(this).load(url).into(projectContextPhotoImageView));
viewModel.outputs.projectNameTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(projectContextProjectNameTextView::setText);
viewModel.outputs.rewardsItems().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(rewardsItemAdapter::rewardsItems);
viewModel.outputs.rewardsItemsAreHidden().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(ViewUtils.setGone(rewardsItemSection));
viewModel.outputs.rewardMinimumAndDescriptionTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(md -> setRewardMinimumAndDescriptionTextViewText(md.first, md.second));
viewModel.outputs.shippingAmountTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(shippingAmountTextView::setText);
viewModel.outputs.shippingLocationTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(shippingLocationTextView::setText);
viewModel.outputs.shippingSectionIsHidden().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(ViewUtils.setGone(shippingSection));
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ActivityFeedViewModelTest method testLoginFlow.
@Test
public void testLoginFlow() {
final ApiClientType apiClient = new MockApiClient();
final CurrentUserType currentUser = new MockCurrentUser();
final Environment environment = environment().toBuilder().apiClient(apiClient).currentUser(currentUser).build();
final ActivityFeedViewModel.ViewModel vm = new ActivityFeedViewModel.ViewModel(environment);
final TestSubscriber<List<Activity>> activities = new TestSubscriber<>();
vm.outputs.activities().subscribe(activities);
final TestSubscriber<Boolean> loggedOutEmptyStateIsVisible = new TestSubscriber<>();
vm.outputs.loggedOutEmptyStateIsVisible().subscribe(loggedOutEmptyStateIsVisible);
final TestSubscriber<Boolean> loggedInEmptyStateIsVisible = new TestSubscriber<>();
vm.outputs.loggedInEmptyStateIsVisible().subscribe(loggedInEmptyStateIsVisible);
final TestSubscriber<Void> goToLogin = new TestSubscriber<>();
vm.outputs.goToLogin().subscribe(goToLogin);
// Empty activity feed with login button should be shown.
loggedOutEmptyStateIsVisible.assertValue(true);
// Login.
vm.inputs.emptyActivityFeedLoginClicked(null);
goToLogin.assertValueCount(1);
currentUser.refresh(UserFactory.user());
// Empty states are not shown when activities emit on successful login.
activities.assertValueCount(1);
loggedOutEmptyStateIsVisible.assertValues(true, false);
loggedInEmptyStateIsVisible.assertValue(false);
}
use of com.kickstarter.libs.Environment 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.libs.Environment 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.libs.Environment in project android-oss by kickstarter.
the class DiscoveryFragmentViewModelTest method testShowHeaderViews.
@Test
public void testShowHeaderViews() {
final CurrentUserType currentUser = new MockCurrentUser();
final Activity activity = ActivityFactory.activity();
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<ActivityEnvelope> fetchActivities() {
return Observable.just(ActivityEnvelopeFactory.activityEnvelope(Collections.singletonList(activity)));
}
};
final MockIntPreference activitySamplePreference = new MockIntPreference(987654321);
final Environment environment = environment().toBuilder().activitySamplePreference(activitySamplePreference).apiClient(apiClient).currentUser(currentUser).build();
final DiscoveryFragmentViewModel vm = new DiscoveryFragmentViewModel(environment);
final TestSubscriber<Activity> activityTest = new TestSubscriber<>();
vm.outputs.activity().subscribe(activityTest);
final TestSubscriber<Boolean> shouldShowOnboardingViewTest = new TestSubscriber<>();
vm.outputs.shouldShowOnboardingView().subscribe(shouldShowOnboardingViewTest);
// Initial home all projects params.
vm.inputs.paramsFromActivity(DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).build());
vm.inputs.rootCategories(CategoryFactory.rootCategories());
// Should show onboarding view.
shouldShowOnboardingViewTest.assertValues(true);
activityTest.assertValue(null);
// Change params. Onboarding view should not be shown.
vm.inputs.paramsFromActivity(DiscoveryParams.builder().build());
shouldShowOnboardingViewTest.assertValues(true, false);
activityTest.assertValues(null, null);
// Login.
currentUser.refresh(UserFactory.user());
// Activity sampler should be shown rather than onboarding view.
shouldShowOnboardingViewTest.assertValues(true, false, false);
activityTest.assertValues(null, null, activity);
// Change params. Activity sampler should not be shown.
vm.inputs.paramsFromActivity(DiscoveryParams.builder().build());
activityTest.assertValues(null, null, activity, null);
}
Aggregations