Search in sources :

Example 26 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class RewardViewHolder method bindData.

@Override
@SuppressWarnings("unchecked")
public void bindData(@Nullable final Object data) throws Exception {
    final Pair<Project, Reward> projectAndReward = requireNonNull((Pair<Project, Reward>) data);
    final Project project = requireNonNull(projectAndReward.first, Project.class);
    final Reward reward = requireNonNull(projectAndReward.second, Reward.class);
    viewModel.inputs.projectAndReward(project, reward);
}
Also used : Project(com.kickstarter.models.Project) Reward(com.kickstarter.models.Reward)

Example 27 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class ActivitySampleProjectViewHolder method onBind.

public void onBind() {
    final Context context = context();
    final Project project = activity.project();
    if (project != null) {
        final Photo photo = project.photo();
        if (photo != null) {
            Picasso.with(context).load(photo.little()).into(activityImageView);
        }
        activityTitleTextView.setText(project.name());
        switch(activity.category()) {
            case Activity.CATEGORY_FAILURE:
                activitySubtitleTextView.setText(categoryFailureString);
                break;
            case Activity.CATEGORY_CANCELLATION:
                activitySubtitleTextView.setText(categoryCancellationString);
                break;
            case Activity.CATEGORY_LAUNCH:
                final User user = activity.user();
                if (user != null) {
                    activitySubtitleTextView.setText(ksString.format(categoryLaunchString, "user_name", user.name()));
                }
                break;
            case Activity.CATEGORY_SUCCESS:
                activitySubtitleTextView.setText(categorySuccessString);
                break;
            case Activity.CATEGORY_UPDATE:
                final Update update = activity.update();
                if (update != null) {
                    activitySubtitleTextView.setText(ksString.format(categoryUpdateString, "update_number", String.valueOf(update.sequence()), "update_title", update.title()));
                }
                break;
            default:
                break;
        }
    }
}
Also used : Context(android.content.Context) Project(com.kickstarter.models.Project) User(com.kickstarter.models.User) Photo(com.kickstarter.models.Photo) Update(com.kickstarter.models.Update)

Example 28 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class FriendBackingViewHolder method onBind.

@Override
public void onBind() {
    final Context context = context();
    final User activityUser = activity().user();
    if (activityUser == null) {
        return;
    }
    final Project activityProject = activity().project();
    if (activityProject == null) {
        return;
    }
    final User projectCreator = activityProject.creator();
    if (projectCreator == null) {
        return;
    }
    final Category projectCategory = activityProject.category();
    if (projectCategory == null) {
        return;
    }
    final Photo projectPhoto = activityProject.photo();
    if (projectPhoto == null) {
        return;
    }
    Picasso.with(context).load(activityUser.avatar().small()).transform(new CircleTransformation()).into(avatarImageView);
    creatorNameTextView.setText(ksString.format(projectByCreatorString, "creator_name", projectCreator.name()));
    projectNameTextView.setText(activityProject.name());
    Picasso.with(context).load(projectPhoto.little()).into(projectPhotoImageView);
    titleTextView.setText(SocialUtils.friendBackingActivityTitle(context, activityUser.name(), projectCategory.rootId(), ksString));
}
Also used : Context(android.content.Context) Project(com.kickstarter.models.Project) CircleTransformation(com.kickstarter.libs.transformations.CircleTransformation) User(com.kickstarter.models.User) Category(com.kickstarter.models.Category) Photo(com.kickstarter.models.Photo)

Example 29 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class ProjectStateChangedPositiveViewHolder method onBind.

@Override
public void onBind() {
    final Context context = context();
    final Project project = activity().project();
    if (project == null) {
        return;
    }
    final User user = activity().user();
    if (user == null) {
        return;
    }
    final Photo photo = project.photo();
    if (photo == null) {
        return;
    }
    switch(activity().category()) {
        case Activity.CATEGORY_LAUNCH:
            final DateTime launchedAt = coalesce(project.launchedAt(), new DateTime());
            cardView.setCardBackgroundColor(blueDarken10Color);
            leftStatFirstTextView.setText(ksCurrency.format(project.goal(), project));
            leftStatSecondTextView.setText(goalString);
            rightStatFirstTextView.setText(launchedString);
            rightStatSecondTextView.setText(DateTimeUtils.mediumDate(launchedAt));
            titleTextView.setText(ksString.format(creatorLaunchedProjectString, "creator_name", user.name(), "project_name", project.name()));
            break;
        case Activity.CATEGORY_SUCCESS:
            cardView.setCardBackgroundColor(greenDarken10Color);
            leftStatFirstTextView.setText(ksCurrency.format(project.pledged(), project));
            leftStatSecondTextView.setText(ksString.format(pledgedOfGoalString, "goal", ksCurrency.format(project.goal(), project, true)));
            rightStatFirstTextView.setText(fundedString);
            rightStatSecondTextView.setText(DateTimeUtils.mediumDate(activity().createdAt()));
            titleTextView.setText(ksString.format(projectSuccessfullyFundedString, "project_name", project.name()));
            break;
        default:
            cardView.setCardBackgroundColor(greenDarken10Color);
            leftStatFirstTextView.setText("");
            leftStatSecondTextView.setText("");
            rightStatFirstTextView.setText("");
            rightStatSecondTextView.setText("");
            titleTextView.setText("");
    }
    // TODO: Switch to "You launched a project" if current user launched
    //return context.getString(R.string.creator_launched_a_project, activity.user().name(), activity.project().name());
    Picasso.with(context).load(photo.full()).into(projectPhotoImageView);
}
Also used : Context(android.content.Context) Project(com.kickstarter.models.Project) User(com.kickstarter.models.User) Photo(com.kickstarter.models.Photo) DateTime(org.joda.time.DateTime)

Example 30 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class KSCurrencyTest method testFormatCurrency_roundsDown.

public void testFormatCurrency_roundsDown() {
    final KSCurrency currency = createKSCurrency("US");
    final Project project = ProjectFactory.project();
    assertEquals("$100", currency.format(100.4f, project));
    assertEquals("$100", currency.format(100.5f, project));
    assertEquals("$101", currency.format(101.5f, project));
    assertEquals("$100", currency.format(100.9f, project));
}
Also used : Project(com.kickstarter.models.Project) KSCurrency(com.kickstarter.libs.KSCurrency)

Aggregations

Project (com.kickstarter.models.Project)85 Test (org.junit.Test)68 Intent (android.content.Intent)36 TestSubscriber (rx.observers.TestSubscriber)33 Environment (com.kickstarter.libs.Environment)19 Reward (com.kickstarter.models.Reward)19 User (com.kickstarter.models.User)14 Pair (android.util.Pair)12 CurrentUserType (com.kickstarter.libs.CurrentUserType)12 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)12 NonNull (android.support.annotation.NonNull)9 MockBooleanPreference (com.kickstarter.libs.preferences.MockBooleanPreference)8 MockApiClient (com.kickstarter.services.MockApiClient)7 Context (android.content.Context)6 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)6 ProjectFactory (com.kickstarter.factories.ProjectFactory)6 UserFactory (com.kickstarter.factories.UserFactory)5 KoalaEvent (com.kickstarter.libs.KoalaEvent)5 Photo (com.kickstarter.models.Photo)5 Update (com.kickstarter.models.Update)5