Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creator tools funding #205

Merged
merged 15 commits into from
Jan 29, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.Pair;
import android.view.View;
import android.widget.ProgressBar;
Expand Down Expand Up @@ -91,6 +92,11 @@ public CreatorDashboardHeaderViewHolder(final @NonNull View view, final @Nullabl
.compose(observeForUI())
.subscribe(this.fundedProgressBar::setProgress);

this.viewModel.outputs.progressBarBackground()
.compose(bindToLifecycle())
.compose(observeForUI())
.subscribe(r -> this.fundedProgressBar.setProgressDrawable(ContextCompat.getDrawable(this.context(), r)));

this.viewModel.outputs.projectBackersCountText()
.compose(bindToLifecycle())
.compose(observeForUI())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.support.annotation.NonNull;
import android.util.Pair;

import com.kickstarter.R;
import com.kickstarter.libs.ActivityViewModel;
import com.kickstarter.libs.CurrentUserType;
import com.kickstarter.libs.Environment;
Expand Down Expand Up @@ -47,6 +48,9 @@ interface Outputs {
/** Emits the percentage funded amount for display in the progress bar. */
Observable<Integer> percentageFundedProgress();

/** Emits color of progress bar based on project state. */
Observable<Integer> progressBarBackground();

/** localized count of number of backers */
Observable<String> projectBackersCountText();

Expand Down Expand Up @@ -83,6 +87,11 @@ public ViewModel(final @NonNull Environment environment) {
this.percentageFundedProgress = this.currentProject
.map(p -> ProgressBarUtils.progress(p.percentageFunded()));

this.progressBarBackground = this.currentProject
.map(p -> p.isLive() || p.isStarted() || p.isSubmitted() || p.isSuccessful())
.map(liveStartedSubmittedSuccessful -> liveStartedSubmittedSuccessful ? R.drawable.progress_bar_green_horizontal : R.drawable.progress_bar_grey_horizontal)
.compose(bindToLifecycle());

this.projectBackersCountText = this.currentProject
.map(Project::backersCount)
.map(NumberUtils::format)
Expand Down Expand Up @@ -116,6 +125,7 @@ public ViewModel(final @NonNull Environment environment) {
private final Observable<Boolean> messagesButtonIsGone;
private final Observable<String> percentageFunded;
private final Observable<Integer> percentageFundedProgress;
private final Observable<Integer> progressBarBackground;
private final Observable<String> projectBackersCountText;
private final Observable<String> projectNameTextViewText;
private final Observable<Project> startMessageThreadsActivity;
Expand All @@ -141,10 +151,12 @@ public ViewModel(final @NonNull Environment environment) {
@Override public @NonNull Observable<String> percentageFunded() {
return this.percentageFunded;
}
@Override
public Observable<Integer> percentageFundedProgress() {
@Override public @NonNull Observable<Integer> percentageFundedProgress() {
return this.percentageFundedProgress;
}
@Override public @NonNull Observable<Integer> progressBarBackground() {
return this.progressBarBackground;
}
@Override public @NonNull Observable<String> projectBackersCountText() {
return this.projectBackersCountText;
}
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/drawable/progress_bar_grey_horizontal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<gradient
android:endColor="@color/ksr_grey_400"
android:startColor="@color/ksr_grey_400" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<gradient
android:endColor="@color/ksr_dark_grey_400"
android:startColor="@color/ksr_dark_grey_400" />
</shape>
</clip>
</item>
</layer-list>
12 changes: 7 additions & 5 deletions app/src/main/res/layout/dashboard_funding_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:showDividers="middle|end"
android:divider="@drawable/divider_dark_grey_500_horizontal"
android:orientation="vertical">
android:orientation="vertical"
android:showDividers="middle|end">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -88,9 +88,10 @@
</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="@dimen/grid_5">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -127,7 +128,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/grid_3">
android:paddingBottom="@dimen/grid_3"
android:paddingTop="@dimen/grid_1">

<TextView
android:id="@+id/creator_dashboard_amount_raised"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

<style name="ProgressBar" parent="Base.Widget.AppCompat.ProgressBar">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@drawable/progress_bar_horizontal</item>
<item name="android:progressDrawable">@drawable/progress_bar_green_horizontal</item>
</style>

<style name="Dialog" parent="Theme.AppCompat.Light.Dialog.Alert">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.util.Pair;

import com.kickstarter.KSRobolectricTestCase;
import com.kickstarter.R;
import com.kickstarter.factories.ProjectFactory;
import com.kickstarter.factories.ProjectStatsEnvelopeFactory;
import com.kickstarter.factories.UserFactory;
Expand Down Expand Up @@ -31,6 +32,7 @@ public class CreatorDashboardHeaderHolderViewModelTest extends KSRobolectricTest
private final TestSubscriber<Integer> percentageFundedProgress = new TestSubscriber<>();
private final TestSubscriber<String> projectBackersCountText = new TestSubscriber<>();
private final TestSubscriber<String> projectNameTextViewText = new TestSubscriber<>();
private final TestSubscriber<Integer> progressBarBackground = new TestSubscriber<>();
private final TestSubscriber<String> timeRemainingText = new TestSubscriber<>();
private final TestSubscriber<Project> startMessageThreadsActivity = new TestSubscriber<>();
private final TestSubscriber<Pair<Project, RefTag>> startProjectActivity = new TestSubscriber<>();
Expand All @@ -42,6 +44,7 @@ protected void setUpEnvironment(final @NonNull Environment environment) {
this.vm.outputs.projectNameTextViewText().subscribe(this.projectNameTextViewText);
this.vm.outputs.percentageFunded().subscribe(this.percentageFunded);
this.vm.outputs.percentageFundedProgress().subscribe(this.percentageFundedProgress);
this.vm.outputs.progressBarBackground().subscribe(this.progressBarBackground);
this.vm.outputs.startMessageThreadsActivity().subscribe(this.startMessageThreadsActivity);
this.vm.outputs.startProjectActivity().subscribe(this.startProjectActivity);
this.vm.outputs.timeRemainingText().subscribe(this.timeRemainingText);
Expand Down Expand Up @@ -95,6 +98,62 @@ public void testPercentageFunded() {
this.percentageFundedProgress.assertValues(percentageFundedProgressOutput);
}

@Test
public void testProgressBarBackground_LiveProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_LIVE));
this.progressBarBackground.assertValues(R.drawable.progress_bar_green_horizontal);
}

@Test
public void testProgressBarBackground_SubmittedProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_SUBMITTED));
this.progressBarBackground.assertValues(R.drawable.progress_bar_green_horizontal);
}

@Test
public void testProgressBarBackground_StartedProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_STARTED));
this.progressBarBackground.assertValues(R.drawable.progress_bar_green_horizontal);
}

@Test
public void testProgressBarBackground_SuccessfulProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_SUCCESSFUL));
this.progressBarBackground.assertValues(R.drawable.progress_bar_green_horizontal);
}

@Test
public void testProgressBarBackground_FailedProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_FAILED));
this.progressBarBackground.assertValues(R.drawable.progress_bar_grey_horizontal);
}

@Test
public void testProgressBarBackground_CanceledProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_CANCELED));
this.progressBarBackground.assertValues(R.drawable.progress_bar_grey_horizontal);
}

@Test
public void testProgressBarBackground_SuspendedProject() {
setUpEnvironment(environment());

this.vm.inputs.projectAndStats(getProjectAndStats(Project.STATE_SUSPENDED));
this.progressBarBackground.assertValues(R.drawable.progress_bar_grey_horizontal);
}

@Test
public void testStartMessagesActivity() {
final User creator = UserFactory.creator();
Expand Down Expand Up @@ -132,4 +191,11 @@ public void testTimeRemainingText() {
this.vm.inputs.projectAndStats(Pair.create(project, projectStatsEnvelope));
this.timeRemainingText.assertValues(NumberUtils.format(deadlineVal));
}

private Pair<Project, ProjectStatsEnvelope> getProjectAndStats(final String state) {
final ProjectStatsEnvelope projectStatsEnvelope = ProjectStatsEnvelopeFactory.projectStatsEnvelope();

final Project project = ProjectFactory.project().toBuilder().state(state).build();
return Pair.create(project, projectStatsEnvelope);
}
}