Skip to content

Commit

Permalink
2nd pass of discovery and project refresh (#249)
Browse files Browse the repository at this point in the history
* second pass of discovery and project refresh
  • Loading branch information
eoji committed Nov 10, 2017
1 parent b0f1d9c commit 0b42c40
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 171 deletions.
18 changes: 18 additions & 0 deletions app/src/main/java/com/kickstarter/libs/utils/ProjectUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;

Expand Down Expand Up @@ -97,6 +98,19 @@ public static boolean isProjectNamePunctuated(final @NonNull String name) {
return lastChar.matches(".*\\p{Punct}");
}

public static @Nullable Metadata metadataForProject(final @NonNull Project project) {
if (project.isBacking()) {
return Metadata.BACKING;
} else if (project.isStarred()) {
return Metadata.SAVING;
} else if (project.isPotdToday()) {
return Metadata.POTD;
} else if (project.isFeaturedToday()) {
return Metadata.CATEGORY_FEATURED;
}
return null;
}

/**
* Returns 16:9 height relative to input width.
*/
Expand Down Expand Up @@ -144,4 +158,8 @@ public static boolean userIsCreator(final @NonNull Project project, final @NonNu
public static boolean isUSUserViewingNonUSProject(final @NonNull String userCountry, final @NonNull String projectCountry) {
return I18nUtils.isCountryUS(userCountry) && !I18nUtils.isCountryUS(projectCountry);
}

public enum Metadata {
BACKING, SAVING, POTD, CATEGORY_FEATURED
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.text.TextUtils;
import android.util.Pair;
Expand All @@ -13,7 +14,6 @@
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

Expand Down Expand Up @@ -65,9 +65,8 @@ public final class ProjectViewHolder extends KSViewHolder {
private Project project;

protected @Bind(R.id.avatar) ImageView avatarImageView;
protected @Bind(R.id.avatar_name) TextView avatarNameTextView;
protected @Bind(R.id.backers_count) TextView backersCountTextView;
protected @Bind(R.id.backer_label) LinearLayout backerLabelLinearLayout;
protected @Bind(R.id.backing_group) ViewGroup backingViewGroup;
protected @Bind(R.id.back_project_button) @Nullable Button backProjectButton;
protected @Bind(R.id.blurb_view) ViewGroup blurbViewGroup;
protected @Bind(R.id.blurb) TextView blurbTextView;
Expand All @@ -76,6 +75,8 @@ public final class ProjectViewHolder extends KSViewHolder {
protected @Bind(R.id.creator_name) TextView creatorNameTextView;
protected @Bind(R.id.deadline_countdown_text_view) TextView deadlineCountdownTextView;
protected @Bind(R.id.deadline_countdown_unit_text_view) TextView deadlineCountdownUnitTextView;
protected @Bind(R.id.featured) TextView featuredTextView;
protected @Bind(R.id.featured_group) ViewGroup featuredViewGroup;
protected @Bind(R.id.project_disclaimer_text_view) TextView projectDisclaimerTextView;
protected @Bind(R.id.goal) TextView goalTextView;
protected @Bind(R.id.land_overlay_text) @Nullable ViewGroup landOverlayTextViewGroup;
Expand All @@ -86,7 +87,9 @@ public final class ProjectViewHolder extends KSViewHolder {
protected @Bind(R.id.project_photo) ImageView photoImageView;
protected @Bind(R.id.play_button_overlay) ImageButton playButton;
protected @Bind(R.id.pledged) TextView pledgedTextView;
protected @Bind(R.id.project_metadata_view_group) ViewGroup projectMetadataViewGroup;
protected @Bind(R.id.project_name) TextView projectNameTextView;
protected @Bind(R.id.potd_view_group) ViewGroup potdViewGroup;
protected @Bind(R.id.project_social_image) ImageView projectSocialImageView;
protected @Bind(R.id.project_social_text) TextView projectSocialTextView;
protected @Bind(R.id.project_stats_view) ViewGroup projectStatsViewGroup;
Expand All @@ -112,6 +115,7 @@ public final class ProjectViewHolder extends KSViewHolder {
protected @BindString(R.string.project_creator_by_creator_html) String byCreatorString;
protected @BindString(R.string.discovery_baseball_card_blurb_read_more) String blurbReadMoreString;
protected @BindString(R.string.discovery_baseball_card_stats_convert_from_pledged_of_goal) String convertedFromString;
protected @BindString(R.string.discovery_baseball_card_metadata_featured_project) String featuredInString;
protected @BindString(R.string.project_disclaimer_goal_not_reached) String projectDisclaimerGoalNotReachedString;
protected @BindString(R.string.project_disclaimer_goal_reached) String projectDisclaimerGoalReachedString;
protected @BindString(R.string.project_status_funding_canceled) String fundingCanceledString;
Expand Down Expand Up @@ -180,11 +184,6 @@ public void onBind() {
this.blurbTextView.setText(Html.fromHtml(TextUtils.htmlEncode(this.project.blurb())));
this.creatorNameTextView.setText(Html.fromHtml(this.ksString.format(this.byCreatorString,
"creator_name", TextUtils.htmlEncode(this.project.creator().name()))));
if (this.project.isBacking()) {
this.backerLabelLinearLayout.setVisibility(View.VISIBLE);
} else {
this.backerLabelLinearLayout.setVisibility(View.GONE);
}
this.projectNameTextView.setText(this.project.name());
final Category category = this.project.category();
if (category != null) {
Expand All @@ -204,7 +203,6 @@ public void onBind() {
.medium())
.transform(new CircleTransformation())
.into(this.avatarImageView);
this.avatarNameTextView.setText(this.project.creator().name());
final Integer updatesCount = this.project.updatesCount();
this.updatesCountTextView.setText(updatesCount != null ? NumberUtils.format(updatesCount) : null);
final Integer commentsCount = this.project.commentsCount();
Expand All @@ -215,6 +213,7 @@ public void onBind() {
setLandscapeOverlayText();
setPledgedOfGoalView();
setProjectDisclaimerView();
setProjectMetadataLozenge();
setProjectSocialClick();
setProjectStateView();
setSocialView();
Expand Down Expand Up @@ -335,6 +334,25 @@ public void setProjectDisclaimerView() {
}
}

private void setProjectMetadataLozenge() {
final ProjectUtils.Metadata metadata = ProjectUtils.metadataForProject(this.project);
if (metadata == ProjectUtils.Metadata.BACKING) {
this.projectMetadataViewGroup.setBackground(ContextCompat.getDrawable(this.context, R.drawable.rect_green_grey_stroke));
this.backingViewGroup.setVisibility(View.VISIBLE);
} else if (metadata == ProjectUtils.Metadata.POTD) {
this.potdViewGroup.setVisibility(View.VISIBLE);
} else if (metadata == ProjectUtils.Metadata.CATEGORY_FEATURED) {
this.featuredViewGroup.setVisibility(View.VISIBLE);
final Category category = this.project.category();
if (category != null && category.root() != null) {
final String rootCategory = category.root().name();
this.featuredTextView.setText(this.ksString.format(this.featuredInString, "category_name", rootCategory));
}
} else {
this.projectMetadataViewGroup.setVisibility(View.GONE);
}
}

public void setProjectSocialClick() {
if (this.project.isFriendBacking()) {
if (this.project.friends().size() > 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Pair;

import com.kickstarter.R;
Expand Down Expand Up @@ -79,14 +78,14 @@ public ViewModel(final @NonNull Environment environment) {
.map(NumberUtils::format);

this.backingViewGroupIsGone = this.project
.map(p -> metadataForProject(p) != Metadata.BACKING);
.map(p -> ProjectUtils.metadataForProject(p) != ProjectUtils.Metadata.BACKING);

this.deadlineCountdownText = this.project
.map(ProjectUtils::deadlineCountdownValue)
.map(NumberUtils::format);

this.featuredViewGroupIsGone = this.project
.map(p -> metadataForProject(p) != Metadata.CATEGORY_FEATURED);
.map(p -> ProjectUtils.metadataForProject(p) != ProjectUtils.Metadata.CATEGORY_FEATURED);

this.friendAvatarUrl = this.project
.filter(Project::isFriendBacking)
Expand Down Expand Up @@ -115,10 +114,10 @@ public ViewModel(final @NonNull Environment environment) {
.map(ObjectUtils::isNull);

this.metadataViewGroupIsGone = this.project
.map(p -> metadataForProject(p) == null);
.map(p -> ProjectUtils.metadataForProject(p) == null);

this.metadataViewGroupBackground = this.backingViewGroupIsGone
.map(gone -> gone ? R.drawable.rect_white_grey_stroke : R.drawable.rect_green_700);
.map(gone -> gone ? R.drawable.rect_white_grey_stroke : R.drawable.rect_green_grey_stroke);

this.nameAndBlurbText = this.project
.map(p -> Pair.create(p.name(), p.blurb()));
Expand All @@ -141,7 +140,7 @@ public ViewModel(final @NonNull Environment environment) {
.map(p -> p.photo() == null ? null : p.photo().full());

this.potdViewGroupIsGone = this.project
.map(p -> metadataForProject(p) != Metadata.POTD);
.map(p -> ProjectUtils.metadataForProject(p) != ProjectUtils.Metadata.POTD);

this.projectCanceledAt = this.project
.filter(p -> p.state().equals(Project.STATE_CANCELED))
Expand Down Expand Up @@ -180,7 +179,7 @@ public ViewModel(final @NonNull Environment environment) {
this.setDefaultTopPadding = this.metadataViewGroupIsGone;

this.savedViewGroupIsGone = this.project
.map(p -> metadataForProject(p) != Metadata.SAVING);
.map(p -> ProjectUtils.metadataForProject(p) != ProjectUtils.Metadata.SAVING);
}

private final PublishSubject<Project> project = PublishSubject.create();
Expand Down Expand Up @@ -319,22 +318,5 @@ public Observable<Pair<String, String>> nameAndBlurbText() {
@Override public @NonNull Observable<Boolean> fundingSuccessfulViewGroupIsGone() {
return this.fundingSuccessfulViewGroupIsGone;
}

private enum Metadata {
BACKING, SAVING, POTD, CATEGORY_FEATURED
}

private static @Nullable Metadata metadataForProject(final @NonNull Project project) {
if (project.isBacking()) {
return Metadata.BACKING;
} else if (project.isStarred()) {
return Metadata.SAVING;
} else if (project.isPotdToday()) {
return Metadata.POTD;
} else if (project.isFeaturedToday()) {
return Metadata.CATEGORY_FEATURED;
}
return null;
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/arrow_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#282828"
android:pathData="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z" />
</vector>
4 changes: 0 additions & 4 deletions app/src/main/res/drawable/rect_green_700.xml

This file was deleted.

13 changes: 13 additions & 0 deletions app/src/main/res/drawable/rect_green_grey_stroke.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/ksr_grey_500" />
<solid android:color="@color/ksr_green_700" />
<padding
android:bottom="1.5dp"
android:left="1.5dp"
android:right="1.5dp"
android:top="1.5dp" />
</shape>
2 changes: 0 additions & 2 deletions app/src/main/res/layout-land/project_main_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@

</LinearLayout>

<include layout="@layout/horizontal_line_0_5dp_view" />

<include layout="@layout/project_creator_info" />

</LinearLayout>
Loading

0 comments on commit 0b42c40

Please sign in to comment.