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

facepile ( •_•) ( •_•)>⌐■-■ (⌐■_■) #181

Merged
merged 9 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from 7 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
25 changes: 20 additions & 5 deletions app/src/main/java/com/kickstarter/libs/utils/SocialUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.kickstarter.R;
import com.kickstarter.libs.KSString;
import com.kickstarter.models.User;

import java.util.Arrays;
import java.util.List;

public final class SocialUtils {
Expand Down Expand Up @@ -131,12 +133,25 @@ public static String friendBackingActivityTitle(final @NonNull Context context,
/**
* Returns a namepile for a list of friends.
*/
public static @NonNull String projectCardFriendNamepile(final @NonNull List<User> friends, final @NonNull KSString ksString) {
final String friendName = friends.size() >= 1 ? friends.get(0).name() : "";
final String secondFriendName = friends.size() >= 2 ? friends.get(1).name() : "";
final String remainingCount = NumberUtils.format(Math.max(0, friends.size() - 2));
public static @NonNull String projectCardFriendNamepile(final Context context, final @NonNull List<User> friends, final @NonNull KSString ksString) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@NonNull Context

final String friendName;
if (friends.size() < 3) {
friendName = friends.size() >= 1 ? friends.get(0).name() : "";
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

this logic makes sense, but is a little hard to read through. maybe it'd be helpful to leave a lil comment here with an example of what friendName would be set here

final String delimiter = context.getString(R.string.project_social_friends_separator).trim() + " ";
final String joinedFriends = TextUtils.join(delimiter, Arrays.asList(friends.get(0).name(), friends.get(1).name()));
friendName = friends.size() == 3 ? joinedFriends.concat(delimiter.trim()) : joinedFriends;
}

final String secondFriendName;
if (friends.size() >= 2) {
secondFriendName = friends.size() == 2 ? friends.get(1).name() : friends.get(2).name();
} else {
secondFriendName = "";
}
final String remainingCount = NumberUtils.format(Math.max(0, friends.size() - 3));

return ksString.format("discovery_baseball_card_social_friends_are_backers", friends.size(),
return ksString.format("discovery_baseball_card_social_friends_are_backers", friends.size() == 3 ? friends.size() - 1 : friends.size(),
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah this is all a bit gnarly but it makes sense! If I have any refactoring ideas I'll chime in.

"friend_name", friendName,
"second_friend_name", secondFriendName,
"remaining_count", remainingCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public final class ProjectCardViewHolder extends KSViewHolder {
protected @Bind(R.id.deadline_countdown_unit) TextView deadlineCountdownUnitTextView;
protected @Bind(R.id.featured) TextView featuredTextView;
protected @Bind(R.id.featured_group) ViewGroup featuredViewGroup;
protected @Bind(R.id.friend_backing_avatar) ImageView friendBackingAvatarImageView;
protected @Bind(R.id.friend_backing_avatar1) ImageView friendBackingAvatarImageView1;
protected @Bind(R.id.friend_backing_avatar2) ImageView friendBackingAvatarImageView2;
protected @Bind(R.id.friend_backing_avatar3) ImageView friendBackingAvatarImageView3;
protected @Bind(R.id.friend_backing_message) TextView friendBackingMessageTextView;
protected @Bind(R.id.friend_backing_group) ViewGroup friendBackingViewGroup;
protected @Bind(R.id.funding_successful_date_text_view) TextView fundingSuccessfulTextViewDate;
Expand Down Expand Up @@ -118,10 +120,30 @@ public ProjectCardViewHolder(final @NonNull View view, final @NonNull Delegate d
.compose(observeForUI())
.subscribe(ViewUtils.setGone(this.featuredViewGroup));

this.viewModel.outputs.friendAvatarUrl()
this.viewModel.outputs.friendAvatar2IsHidden()
Copy link
Contributor

Choose a reason for hiding this comment

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

can rename these outputs from IsHidden to IsGone to more properly reflect what's happening in the view!

.compose(bindToLifecycle())
.compose(observeForUI())
.subscribe(this::setFriendAvatarUrl);
.subscribe(hidden -> ViewUtils.setGone(this.friendBackingAvatarImageView2, hidden));

this.viewModel.outputs.friendAvatar3IsHidden()
.compose(bindToLifecycle())
.compose(observeForUI())
.subscribe(hidden -> ViewUtils.setGone(this.friendBackingAvatarImageView3, hidden));

this.viewModel.outputs.friendAvatarUrl1()
.compose(bindToLifecycle())
.compose(observeForUI())
.subscribe(url -> setFriendAvatarUrl(url, this.friendBackingAvatarImageView1));

this.viewModel.outputs.friendAvatarUrl2()
.compose(bindToLifecycle())
.compose(observeForUI())
.subscribe(url -> setFriendAvatarUrl(url, this.friendBackingAvatarImageView2));

this.viewModel.outputs.friendAvatarUrl3()
.compose(bindToLifecycle())
.compose(observeForUI())
.subscribe(url -> setFriendAvatarUrl(url, this.friendBackingAvatarImageView3));

this.viewModel.outputs.friendBackingViewIsHidden()
.compose(bindToLifecycle())
Expand All @@ -132,7 +154,7 @@ public ProjectCardViewHolder(final @NonNull View view, final @NonNull Delegate d
.compose(bindToLifecycle())
.compose(observeForUI())
.subscribe(friends ->
this.friendBackingMessageTextView.setText(SocialUtils.projectCardFriendNamepile(friends, this.ksString))
this.friendBackingMessageTextView.setText(SocialUtils.projectCardFriendNamepile(context(), friends, this.ksString))
);

this.viewModel.outputs.fundingUnsuccessfulViewGroupIsGone()
Expand Down Expand Up @@ -282,10 +304,10 @@ private void setDeadlineCountdownText(final @NonNull Project project) {
this.deadlineCountdownUnitTextView.setText(ProjectUtils.deadlineCountdownDetail(project, context(), this.ksString));
}

private void setFriendAvatarUrl(final @NonNull String avatarUrl) {
private void setFriendAvatarUrl(final @NonNull String avatarUrl, final @NonNull ImageView imageView) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice nice

Picasso.with(context()).load(avatarUrl)
.transform(new CircleTransformation())
.into(this.friendBackingAvatarImageView);
.into(imageView);
}

private void setDefaultTopPadding(final boolean setDefaultPadding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public void setSocialView() {
.transform(new CircleTransformation())
.into(this.projectSocialImageView);

this.projectSocialTextView.setText(SocialUtils.projectCardFriendNamepile(this.project.friends(), this.ksString));
this.projectSocialTextView.setText(SocialUtils.projectCardFriendNamepile(context(), this.project.friends(), this.ksString));

} else {
this.projectSocialViewGroup.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ interface Outputs {
Observable<String> deadlineCountdownText();
Observable<Boolean> featuredViewGroupIsGone();
Observable<List<User>> friendsForNamepile();
Observable<String> friendAvatarUrl();
Observable<Boolean> friendAvatar2IsHidden();
Observable<Boolean> friendAvatar3IsHidden();
Observable<String> friendAvatarUrl1();
Observable<String> friendAvatarUrl2();
Observable<String> friendAvatarUrl3();
Observable<Boolean> imageIsInvisible();
Observable<Boolean> friendBackingViewIsHidden();
Observable<Boolean> fundingUnsuccessfulViewGroupIsGone();
Expand Down Expand Up @@ -89,11 +93,33 @@ public ViewModel(final @NonNull Environment environment) {
this.featuredViewGroupIsGone = this.project
.map(p -> ProjectUtils.metadataForProject(p) != ProjectUtils.Metadata.CATEGORY_FEATURED);

this.friendAvatarUrl = this.project
this.friendAvatarUrl1 = this.project
.filter(Project::isFriendBacking)
.map(Project::friends)
.map(friends -> friends.get(0).avatar().small());

this.friendAvatarUrl2 = this.project
.filter(Project::isFriendBacking)
.map(Project::friends)
.filter(friends -> friends.size() > 1)
.map(friends -> friends.get(1).avatar().small());

this.friendAvatarUrl3 = this.project
.filter(Project::isFriendBacking)
.map(Project::friends)
.filter(friends -> friends.size() > 2)
.map(friends -> friends.get(2).avatar().small());

this.friendAvatar2IsHidden = this.project
.map(Project::friends)
.map(friends -> friends != null && friends.size() > 1)
.map(BooleanUtils::negate);

this.friendAvatar3IsHidden = this.project
.map(Project::friends)
.map(friends -> friends != null && friends.size() > 2)
.map(BooleanUtils::negate);

this.friendBackingViewIsHidden = this.project
.map(Project::isFriendBacking)
.map(BooleanUtils::negate);
Expand Down Expand Up @@ -188,7 +214,11 @@ public ViewModel(final @NonNull Environment environment) {
private final Observable<Boolean> backingViewGroupIsGone;
private final Observable<String> deadlineCountdownText;
private final Observable<Boolean> featuredViewGroupIsGone;
private final Observable<String> friendAvatarUrl;
private final Observable<Boolean> friendAvatar2IsHidden;
private final Observable<Boolean> friendAvatar3IsHidden;
private final Observable<String> friendAvatarUrl1;
private final Observable<String> friendAvatarUrl2;
private final Observable<String> friendAvatarUrl3;
private final Observable<Boolean> friendBackingViewIsHidden;
private final Observable<List<User>> friendsForNamepile;
private final Observable<Boolean> fundingSuccessfulViewGroupIsGone;
Expand Down Expand Up @@ -235,8 +265,20 @@ public ViewModel(final @NonNull Environment environment) {
@Override public @NonNull Observable<Boolean> featuredViewGroupIsGone() {
return this.featuredViewGroupIsGone;
}
@Override public @NonNull Observable<String> friendAvatarUrl() {
return this.friendAvatarUrl;
@Override public @NonNull Observable<Boolean> friendAvatar2IsHidden() {
return this.friendAvatar2IsHidden;
}
@Override public @NonNull Observable<Boolean> friendAvatar3IsHidden() {
return this.friendAvatar3IsHidden;
}
@Override public @NonNull Observable<String> friendAvatarUrl1() {
return this.friendAvatarUrl1;
}
@Override public @NonNull Observable<String> friendAvatarUrl2() {
return this.friendAvatarUrl2;
}
@Override public @NonNull Observable<String> friendAvatarUrl3() {
return this.friendAvatarUrl3;
}
@Override public @NonNull Observable<Boolean> friendBackingViewIsHidden() {
return this.friendBackingViewIsHidden;
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/oval_white.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="@color/white" />
</shape>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/oval_white_stroke.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="2dp"
android:color="@color/white" />
</shape>
102 changes: 40 additions & 62 deletions app/src/main/res/layout-land/project_card_view.xml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/project_card_view_group"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/project_card_view_group"
android:layout_height="wrap_content"
android:layout_width="match_parent">
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.CardView
android:id="@+id/project_card_view"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@color/transparent"
card_view:cardPreventCornerOverlap="false"
card_view:cardElevation="@dimen/card_no_elevation"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="0dp"
android:foreground="@drawable/click_indicator_light"
android:focusable="true"
android:layout_marginStart="@dimen/card_margin_x"
android:layout_marginBottom="@dimen/project_card_margin_bottom"
android:layout_marginEnd="@dimen/card_margin_x"
android:layout_marginStart="@dimen/card_margin_x"
android:layout_marginTop="@dimen/project_card_margin_top"
android:layout_marginBottom="@dimen/project_card_margin_bottom">
android:focusable="true"
android:foreground="@drawable/click_indicator_light"
card_view:cardBackgroundColor="@color/transparent"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="@dimen/card_no_elevation"
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true">

<LinearLayout
android:id="@+id/land_card_view_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rect_white_grey_stroke"
android:orientation="horizontal"
android:padding="@dimen/grid_5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="InconsistentLayout">

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<include
layout="@layout/project_card_photo_view"
android:id="@+id/project_card_photo"
android:layout_marginTop="@dimen/grid_1"
android:layout_marginBottom="@dimen/grid_2"
layout="@layout/project_card_photo_view"
android:layout_width="@dimen/project_card_photo_landscape_width"
android:layout_height="@dimen/project_card_photo_landscape_height"
android:layout_width="@dimen/project_card_photo_landscape_width"/>
android:layout_marginBottom="@dimen/grid_2"
android:layout_marginTop="@dimen/grid_1" />

<include
layout="@layout/project_metadata_view" />
Expand All @@ -51,76 +51,54 @@

<LinearLayout
android:id="@+id/project_card_info"
android:orientation="vertical"
android:layout_marginStart="@dimen/grid_5"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/grid_5"
android:orientation="vertical">

<TextView
android:id="@+id/name_and_blurb_text_view"
style="@style/TextPrimary"
android:textSize="@dimen/headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/grid_4"
android:maxLines="3"
android:lines="3"
android:ellipsize="end"
tools:text="Project name here: some description"/>
android:lines="3"
android:maxLines="3"
android:paddingBottom="@dimen/grid_4"
android:textSize="@dimen/headline"
tools:text="Project name here: some description" />

<ProgressBar
style="@style/ProgressBar"
android:id="@+id/percentage_funded"
style="@style/ProgressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/progress_bar_min_height"
android:progress="50" />

<include layout="@layout/project_state_view"
android:layout_height="wrap_content"
<include
android:id="@+id/project_state_view_group"
layout="@layout/project_state_view"
android:layout_width="wrap_content"
android:layout_marginTop="@dimen/grid_2"
android:id="@+id/project_state_view_group"/>
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/grid_2" />

<include layout="@layout/project_card_stats_view"
android:layout_marginTop="@dimen/grid_4"
<include
layout="@layout/project_card_stats_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/grid_4" />

</LinearLayout>

</LinearLayout>

</android.support.v7.widget.CardView>

<LinearLayout
android:id="@+id/friend_backing_group"
android:layout_below="@id/project_card_view"
android:visibility="gone"
android:layout_marginBottom="@dimen/grid_2"
android:layout_marginStart="@dimen/grid_4"
android:layout_marginEnd="@dimen/grid_5"
android:orientation="horizontal"
<include
layout="@layout/friend_row_backing_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/friend_backing_avatar"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/grid_1"
android:layout_width="@dimen/grid_4"
android:layout_height="@dimen/grid_4"
tools:ignore="ContentDescription"
tools:background="@color/ksr_cobalt_500"/>

<TextView
android:id="@+id/friend_backing_message"
style="@style/Caption1PrimaryMedium"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Dancing Hot Dog, Frank, and 1 more are backers."/>

</LinearLayout>
android:layout_height="wrap_content"
android:layout_below="@id/project_card_view" />

</RelativeLayout>
Loading