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 strings #215

Merged
merged 4 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 72 additions & 16 deletions app/src/main/assets/json/server-config.json

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions app/src/main/java/com/kickstarter/libs/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.support.annotation.Nullable;
import android.util.Patterns;

import java.util.Locale;

public final class StringUtils {
private StringUtils() {}

Expand All @@ -19,6 +21,15 @@ public static boolean isPresent(final @Nullable String str) {
return !isEmpty(str);
}

/**
* Returns a string with only the first character capitalized.
*/
public static @NonNull String sentenceCase(final @NonNull String str) {
return str.length() <= 1
? str.toUpperCase(Locale.getDefault())
: str.substring(0, 1).toUpperCase(Locale.getDefault()) + str.substring(1).toLowerCase(Locale.getDefault());
}

/**
* Returns a string wrapped in parentheses.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;

import butterknife.Bind;
import butterknife.BindString;
import butterknife.ButterKnife;

import static com.kickstarter.libs.rx.transformers.Transformers.observeForUI;
Expand All @@ -28,7 +29,10 @@ public class CreatorDashboardReferrerStatsViewHolder extends KSViewHolder {

protected @Bind(R.id.dashboard_referrer_stats_empty_text_view) TextView emptyTextView;
protected @Bind(R.id.dashboard_referrer_stats_recycler_view) RecyclerView referrerStatsRecyclerView;
protected @Bind(R.id.dashboard_referrer_stats_truncated_text_view) TextView truncatedTextView;
protected @Bind(R.id.dashboard_referrer_title) TextView referrerTitleTextView;

protected @BindString(R.string.Top_pledge_sources) String topPledgeSourcesString;
protected @BindString(R.string.Top_ten_pledge_sources) String topTenPledgeSourcesString;

public CreatorDashboardReferrerStatsViewHolder(final @NonNull View view) {
super(view);
Expand All @@ -50,10 +54,14 @@ public CreatorDashboardReferrerStatsViewHolder(final @NonNull View view) {
.compose(observeForUI())
.subscribe(this::toggleRecyclerViewAndEmptyStateVisibility);

this.viewModel.outputs.referrerStatsTruncatedTextIsGone()
this.viewModel.outputs.referrersTitleIsLimitedCopy()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename to referrersTitleHasTopTen

.compose(bindToLifecycle())
.compose(observeForUI())
.subscribe(gone -> ViewUtils.setGone(this.truncatedTextView, gone));
.subscribe(this::setTitleCopy);
}

private void setTitleCopy(final boolean shouldShowLimitedCopy) {
this.referrerTitleTextView.setText(shouldShowLimitedCopy ? this.topTenPledgeSourcesString : this.topPledgeSourcesString);
}

private void toggleRecyclerViewAndEmptyStateVisibility(final @NonNull Boolean gone) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.widget.TextView;

import com.kickstarter.R;
import com.kickstarter.libs.utils.StringUtils;
import com.kickstarter.libs.utils.ViewUtils;
import com.kickstarter.models.Project;
import com.kickstarter.services.apiresponses.ProjectStatsEnvelope;
Expand All @@ -18,6 +19,7 @@
import java.util.List;

import butterknife.Bind;
import butterknife.BindString;
import butterknife.ButterKnife;
import butterknife.OnClick;

Expand All @@ -31,6 +33,10 @@ public final class CreatorDashboardRewardStatsViewHolder extends KSViewHolder {
protected @Bind(R.id.dashboard_reward_stats_pledged_view) View pledgedColumnView;
protected @Bind(R.id.dashboard_reward_stats_truncated_text_view) TextView truncatedTextView;
protected @Bind(R.id.dashboard_reward_stats_recycler_view) RecyclerView rewardStatsRecyclerView;
protected @Bind(R.id.dashboard_reward_title) TextView rewardsTitleTextView;

protected @BindString(R.string.dashboard_graphs_rewards_top_rewards) String topRewardsString;
protected @BindString(R.string.Top_ten_rewards) String topTenRewardsString;

public CreatorDashboardRewardStatsViewHolder(final @NonNull View view) {
super(view);
Expand All @@ -56,6 +62,16 @@ public CreatorDashboardRewardStatsViewHolder(final @NonNull View view) {
.compose(bindToLifecycle())
.compose(observeForUI())
.subscribe(gone -> ViewUtils.setGone(this.truncatedTextView, gone));

this.viewModel.outputs.rewardsTitleIsLimitedCopy()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this one also.

.compose(bindToLifecycle())
.compose(observeForUI())
.subscribe(this::setTitleCopy);
}

private void setTitleCopy(final boolean shouldShowLimitedCopy) {
final String formattedTopRewards = StringUtils.sentenceCase(this.topRewardsString);
this.rewardsTitleTextView.setText(shouldShowLimitedCopy ? this.topTenRewardsString : formattedTopRewards);
}

private void toggleRecyclerViewAndEmptyStateVisibility(final @NonNull Boolean gone) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ interface Outputs {

/** Emits the current project and the amount pledged via internal referrers **/
Observable<Pair<Project, Float>> projectAndInternalReferrerPledgedAmount();

/** Emits when there are more than 10 referrer stats and title copy should reflect limited list. */
Observable<Boolean> referrersTitleIsLimitedCopy();
}

final class ViewModel extends ActivityViewModel<CreatorDashboardReferrerBreakdownViewHolder> implements Inputs, Outputs {
Expand Down Expand Up @@ -194,6 +197,12 @@ public ViewModel(final @NonNull Environment environment) {

this.pledgedViaInternalLayoutIsGone = this.internalReferrerPledgedAmount
.map(amount -> amount <= 0f);

referrerStats
.map(rs -> rs.size() > 10)
.distinctUntilChanged()
.compose(bindToLifecycle())
.subscribe(this.referrersTitleIsLimitedCopy);
}

public final Inputs inputs = this;
Expand All @@ -220,6 +229,7 @@ public ViewModel(final @NonNull Environment environment) {
private final Observable<Pair<Project, Float>> projectAndCustomReferrerPledgedAmount;
private final Observable<Pair<Project, Float>> projectAndExternalReferrerPledgedAmount;
private final Observable<Pair<Project, Float>> projectAndInternalReferrerPledgedAmount;
private final PublishSubject<Boolean> referrersTitleIsLimitedCopy = PublishSubject.create();

@Override
public void projectAndStatsInput(final @NonNull Pair<Project, ProjectStatsEnvelope> projectAndStats) {
Expand Down Expand Up @@ -291,6 +301,8 @@ public void projectAndStatsInput(final @NonNull Pair<Project, ProjectStatsEnvelo
public @NonNull Observable<Pair<Project, Float>> projectAndInternalReferrerPledgedAmount() {
return this.projectAndInternalReferrerPledgedAmount;
}

@Override public @NonNull Observable<Boolean> referrersTitleIsLimitedCopy() {
return this.referrersTitleIsLimitedCopy;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ interface Outputs {
/** Emits when there are no referrer stats. */
Observable<Boolean> referrerStatsListIsGone();

/** Emits when there are more than 10 referrer stats. */
Observable<Boolean> referrerStatsTruncatedTextIsGone();
/** Emits when there are more than 10 referrer stats and title copy should reflect limited list. */
Observable<Boolean> referrersTitleIsLimitedCopy();
}

final class ViewModel extends ActivityViewModel<CreatorDashboardReferrerStatsViewHolder> implements Inputs, Outputs {
Expand All @@ -62,10 +62,10 @@ public ViewModel(final @NonNull Environment environment) {
.subscribe(this.referrerStatsListIsGone);

sortedReferrerStats
.map(pr -> pr.size() <= 10)
.map(rs -> rs.size() > 10)
.distinctUntilChanged()
.compose(bindToLifecycle())
.subscribe(this.referrerStatsTruncatedTextIsGone);
.subscribe(this.referrersTitleIsLimitedCopy);
}

final private class OrderByBackersReferrerStatsComparator implements Comparator<ProjectStatsEnvelope.ReferrerStats> {
Expand All @@ -89,7 +89,7 @@ public int compare(final @NonNull ProjectStatsEnvelope.ReferrerStats o1, final @

private final Observable<Pair<Project, List<ProjectStatsEnvelope.ReferrerStats>>> projectAndReferrerStats;
private final PublishSubject<Boolean> referrerStatsListIsGone = PublishSubject.create();
private final PublishSubject<Boolean> referrerStatsTruncatedTextIsGone = PublishSubject.create();
private final PublishSubject<Boolean> referrersTitleIsLimitedCopy = PublishSubject.create();

@Override
public void projectAndReferrerStatsInput(final @NonNull Pair<Project, List<ProjectStatsEnvelope.ReferrerStats>> projectAndReferrerStats) {
Expand All @@ -101,8 +101,8 @@ public void projectAndReferrerStatsInput(final @NonNull Pair<Project, List<Proje
@Override public @NonNull Observable<Boolean> referrerStatsListIsGone() {
return this.referrerStatsListIsGone;
}
@Override public @NonNull Observable<Boolean> referrerStatsTruncatedTextIsGone() {
return this.referrerStatsTruncatedTextIsGone;
@Override public @NonNull Observable<Boolean> referrersTitleIsLimitedCopy() {
return this.referrersTitleIsLimitedCopy;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ interface Outputs {

/** Emits when there are more than 10 reward stats. */
Observable<Boolean> rewardsStatsTruncatedTextIsGone();

/** Emits when there are more than 10 reward stats and title copy should reflect limited list. */
Observable<Boolean> rewardsTitleIsLimitedCopy();
}

final class ViewModel extends ActivityViewModel<CreatorDashboardRewardStatsViewHolder> implements Inputs, Outputs {
Expand All @@ -65,10 +68,16 @@ public ViewModel(final @NonNull Environment environment) {
.subscribe(this.rewardsStatsListIsGone);

sortedRewardStats
.map(pr -> pr.size() <= 10)
.map(rs -> rs.size() <= 10)
.distinctUntilChanged()
.compose(bindToLifecycle())
.subscribe(this.rewardsStatsTruncatedTextIsGone);

sortedRewardStats
.map(rs -> rs.size() > 10)
.distinctUntilChanged()
.compose(bindToLifecycle())
.subscribe(this.rewardsTitleIsLimitedCopy);
}

final private class OrderByPledgedRewardStatsComparator implements Comparator<ProjectStatsEnvelope.RewardStats> {
Expand All @@ -94,6 +103,7 @@ public int compare(final ProjectStatsEnvelope.RewardStats o1, final ProjectStats
private final Observable<Pair<Project, List<ProjectStatsEnvelope.RewardStats>>> projectAndRewardStats;
private final PublishSubject<Boolean> rewardsStatsListIsGone = PublishSubject.create();
private final PublishSubject<Boolean> rewardsStatsTruncatedTextIsGone = PublishSubject.create();
private final PublishSubject<Boolean> rewardsTitleIsLimitedCopy = PublishSubject.create();

@Override
public void pledgedColumnTitleClicked() {
Expand All @@ -113,5 +123,9 @@ public void projectAndRewardStatsInput(final @NonNull Pair<Project, List<Project
@Override public @NonNull Observable<Boolean> rewardsStatsTruncatedTextIsGone() {
return this.rewardsStatsTruncatedTextIsGone;
}
@Override
public Observable<Boolean> rewardsTitleIsLimitedCopy() {
return this.rewardsTitleIsLimitedCopy;
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/dashboard_funding_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:gravity="center_vertical"
android:text="@string/dashboard_buttons_project"
android:text="@string/View_project"
android:textColor="@color/ksr_soft_black"
android:textSize="@dimen/callout" />

Expand Down
12 changes: 7 additions & 5 deletions app/src/main/res/layout/dashboard_referrer_breakdown_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
android:layout_height="wrap_content"
android:divider="@drawable/divider_dark_grey_500_horizontal"
android:orientation="vertical"
android:showDividers="beginning">
android:showDividers="beginning"
android:visibility="gone">

<TextView
style="@style/Title2"
Expand All @@ -15,7 +16,8 @@
android:layout_marginTop="@dimen/grid_7"
android:paddingEnd="@dimen/grid_2"
android:paddingStart="@dimen/grid_2"
android:text="@string/dashboard_graphs_referrers_title_referrers" />
android:text="@string/How_backers_found_your_project"
android:visibility="gone" />

<LinearLayout
android:id="@+id/referrer_breakdown_chart_layout"
Expand Down Expand Up @@ -74,7 +76,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/dashboard_graphs_referrers_pledged_via_kickstarter" />
android:text="@string/via_kickstarter" />

</LinearLayout>

Expand Down Expand Up @@ -118,7 +120,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dashboard_graphs_referrers_pledged_via_external" />
android:text="@string/via_external" />

</LinearLayout>

Expand Down Expand Up @@ -163,7 +165,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dashboard_graphs_referrers_pledged_via_custom" />
android:text="@string/via_custom" />

</LinearLayout>
</LinearLayout>
Expand Down
43 changes: 24 additions & 19 deletions app/src/main/res/layout/dashboard_referrer_stats_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingStart="@dimen/grid_2"
android:paddingEnd="@dimen/grid_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/grid_5"
android:layout_marginTop="@dimen/grid_1"
android:divider="@drawable/divider_dark_grey_500_horizontal"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:showDividers="beginning">

<TextView
android:id="@+id/dashboard_referrer_title"
style="@style/Title2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/grid_7"
android:paddingEnd="@dimen/grid_2"
android:paddingStart="@dimen/grid_2"
android:text="@string/Top_pledge_sources" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/grid_1"
android:divider="@drawable/divider_dark_grey_500_horizontal"
android:showDividers="middle"
android:orientation="vertical">
android:orientation="vertical"
android:paddingEnd="@dimen/grid_2"
android:paddingStart="@dimen/grid_2"
android:showDividers="middle">

<LinearLayout
style="@style/CreatorDashboardTableRowContainer">
Expand Down Expand Up @@ -48,9 +60,9 @@
android:text="@string/dashboard_graphs_funding_backers" />

<TextView
style="@style/CreatorDashboardTableRowText"
android:layout_width="0dp"
android:layout_weight="3"
style="@style/CreatorDashboardTableRowText"
android:text="@string/dashboard_graphs_referrers_source" />

</LinearLayout>
Expand All @@ -59,24 +71,17 @@
android:id="@+id/dashboard_referrer_stats_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/dashboard_referrer_stats_row_view"/>
tools:listitem="@layout/dashboard_referrer_stats_row_view" />

</LinearLayout>

<TextView
android:id="@+id/dashboard_referrer_stats_empty_text_view"
android:paddingTop="@dimen/grid_10"
android:paddingBottom="@dimen/grid_10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
tools:text="Sorry, no stats yet!\n
You don’t have any backings"/>

<TextView
style="@style/BodyPrimary"
android:id="@+id/dashboard_referrer_stats_truncated_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Limited to the top 10 rewards."/>
android:paddingBottom="@dimen/grid_10"
android:paddingTop="@dimen/grid_10"
android:text="@string/Data_will_appear_here_once" />

</LinearLayout>
Loading