Search in sources :

Example 6 with Category

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

the class ChildFilterViewHolder method onBind.

@Override
public void onBind() {
    final Context context = context();
    final Category category = item.params().category();
    if (category != null && category.isRoot()) {
        filterTextView.setText(item.params().filterString(context, ksString));
    } else {
        filterTextView.setText(item.params().filterString(context, ksString));
    }
    if (item.selected()) {
        filterTextView.setTextAppearance(context, R.style.SubheadPrimaryMedium);
        filterTextView.setTextColor(blackColor);
    } else {
        filterTextView.setTextAppearance(context, R.style.SubheadPrimary);
        filterTextView.setTextColor(darkGrayColor);
    }
    filterView.setBackgroundColor(item.selected() ? filterSelectedColor : filterUnselectedColor);
}
Also used : Context(android.content.Context) Category(com.kickstarter.models.Category)

Example 7 with Category

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

the class ThanksViewModel method relatedProjects.

/**
   * Returns a shuffled list of 3 recommended projects, with fallbacks to similar and staff picked projects
   * for users with fewer than 3 recommendations.
   */
@NonNull
private Observable<List<Project>> relatedProjects(@NonNull final Project project) {
    final DiscoveryParams recommendedParams = DiscoveryParams.builder().backed(-1).recommended(true).perPage(6).build();
    final DiscoveryParams similarToParams = DiscoveryParams.builder().backed(-1).similarTo(project).perPage(3).build();
    final Category category = project.category();
    final DiscoveryParams staffPickParams = DiscoveryParams.builder().category(category == null ? null : category.root()).backed(-1).staffPicks(true).perPage(3).build();
    final Observable<Project> recommendedProjects = apiClient.fetchProjects(recommendedParams).retry(2).map(DiscoverEnvelope::projects).map(ListUtils::shuffle).flatMap(Observable::from).take(3);
    final Observable<Project> similarToProjects = apiClient.fetchProjects(similarToParams).retry(2).map(DiscoverEnvelope::projects).flatMap(Observable::from);
    final Observable<Project> staffPickProjects = apiClient.fetchProjects(staffPickParams).retry(2).map(DiscoverEnvelope::projects).flatMap(Observable::from);
    return Observable.concat(recommendedProjects, similarToProjects, staffPickProjects).compose(neverError()).distinct().take(3).toList();
}
Also used : Project(com.kickstarter.models.Project) Category(com.kickstarter.models.Category) DiscoveryParams(com.kickstarter.services.DiscoveryParams) ListUtils(com.kickstarter.libs.utils.ListUtils) Observable(rx.Observable) NonNull(android.support.annotation.NonNull)

Example 8 with Category

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

the class DiscoveryUtils method fillRootCategoryForFeaturedProjects.

/**
   * Given a list of projects and root categories this will determine if the first project is featured
   * and is in need of its root category. If that is the case we will find its root and fill in that
   * data and return a new list of projects.
   */
public static List<Project> fillRootCategoryForFeaturedProjects(@NonNull final List<Project> projects, @NonNull final List<Category> rootCategories) {
    // Guard against no projects
    if (projects.size() == 0) {
        return ListUtils.empty();
    }
    final Project firstProject = projects.get(0);
    // Guard against bad category data on first project
    final Category category = firstProject.category();
    if (category == null) {
        return projects;
    }
    final Long categoryParentId = category.parentId();
    if (categoryParentId == null) {
        return projects;
    }
    // Guard against not needing to find the root category
    if (!projectNeedsRootCategory(firstProject, category)) {
        return projects;
    }
    // Find the root category for the featured project's category
    final Category projectRootCategory = Observable.from(rootCategories).filter(rootCategory -> rootCategory.id() == categoryParentId).take(1).toBlocking().single();
    // Sub in the found root category in our featured project.
    final Category newCategory = category.toBuilder().parent(projectRootCategory).build();
    final Project newProject = firstProject.toBuilder().category(newCategory).build();
    return ListUtils.replaced(projects, 0, newProject);
}
Also used : ColorInt(android.support.annotation.ColorInt) Context(android.content.Context) Category(com.kickstarter.models.Category) List(java.util.List) ColorRes(android.support.annotation.ColorRes) Project(com.kickstarter.models.Project) R(com.kickstarter.R) ContextCompat(android.support.v4.content.ContextCompat) DiscoveryParams(com.kickstarter.services.DiscoveryParams) NonNull(android.support.annotation.NonNull) Nullable(android.support.annotation.Nullable) Observable(rx.Observable) Project(com.kickstarter.models.Project) Category(com.kickstarter.models.Category)

Example 9 with Category

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

the class KoalaUtils method projectProperties.

@NonNull
public static Map<String, Object> projectProperties(@NonNull final Project project, @Nullable final User loggedInUser, @NonNull final String prefix) {
    final Map<String, Object> properties = new HashMap<String, Object>() {

        {
            put("backers_count", project.backersCount());
            put("country", project.country());
            put("currency", project.currency());
            put("goal", project.goal());
            put("pid", project.id());
            put("name", project.name());
            put("state", project.state());
            put("update_count", project.updatesCount());
            put("comments_count", project.commentsCount());
            put("pledged", project.pledged());
            put("percent_raised", project.percentageFunded() / 100.0f);
            put("has_video", project.video() != null);
            put("hours_remaining", ProjectUtils.timeInSecondsUntilDeadline(project) / 60.0f / 60.0f);
            // TODO: Implement `duration`
            // put("duration", project.duration());
            final Category category = project.category();
            if (category != null) {
                put("category", category.name());
                final Category parent = category.parent();
                if (parent != null) {
                    put("parent_category", parent.name());
                }
            }
            final Location location = project.location();
            if (location != null) {
                put("location", location.name());
            }
            putAll(userProperties(project.creator(), "creator_"));
            if (loggedInUser != null) {
                put("user_is_project_creator", ProjectUtils.userIsCreator(project, loggedInUser));
                put("user_is_backer", project.isBacking());
                put("user_has_starred", project.isStarred());
            }
        }
    };
    return MapUtils.prefixKeys(properties, prefix);
}
Also used : Category(com.kickstarter.models.Category) HashMap(java.util.HashMap) Location(com.kickstarter.models.Location) NonNull(android.support.annotation.NonNull)

Example 10 with Category

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

the class DiscoveryViewModelTest method testRootCategoriesEmitWithPosition.

@Test
public void testRootCategoriesEmitWithPosition() {
    final DiscoveryViewModel vm = new DiscoveryViewModel(environment());
    final TestSubscriber<List<Category>> rootCategories = new TestSubscriber<>();
    final TestSubscriber<Integer> position = new TestSubscriber<>();
    vm.outputs.rootCategoriesAndPosition().map(cp -> cp.first).subscribe(rootCategories);
    vm.outputs.rootCategoriesAndPosition().map(cp -> cp.second).subscribe(position);
    // Start initial activity.
    vm.intent(new Intent(Intent.ACTION_MAIN));
    // Initial HOME page selected.
    vm.inputs.discoveryPagerAdapterSetPrimaryPage(null, 0);
    // Root categories should emit for the initial HOME sort position.
    rootCategories.assertValueCount(1);
    position.assertValues(0);
    // Select POPULAR sort position.
    vm.inputs.discoveryPagerAdapterSetPrimaryPage(null, 1);
    // Root categories should emit for the POPULAR sort position.
    rootCategories.assertValueCount(2);
    position.assertValues(0, 1);
    // Select ART category from the drawer.
    vm.inputs.childFilterViewHolderRowClick(null, NavigationDrawerData.Section.Row.builder().params(DiscoveryParams.builder().category(CategoryFactory.artCategory()).build()).build());
    // Root categories should not emit again for the same position.
    rootCategories.assertValueCount(2);
    position.assertValues(0, 1);
}
Also used : Transformers(com.kickstarter.libs.rx.transformers.Transformers) Category(com.kickstarter.models.Category) Arrays(java.util.Arrays) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) CategoryFactory(com.kickstarter.factories.CategoryFactory) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Intent(android.content.Intent) Test(org.junit.Test) UserFactory(com.kickstarter.factories.UserFactory) DiscoveryUtils(com.kickstarter.libs.utils.DiscoveryUtils) KSRobolectricTestCase(com.kickstarter.KSRobolectricTestCase) InternalBuildEnvelope(com.kickstarter.services.apiresponses.InternalBuildEnvelope) List(java.util.List) TestSubscriber(rx.observers.TestSubscriber) Environment(com.kickstarter.libs.Environment) NavigationDrawerData(com.kickstarter.ui.adapters.data.NavigationDrawerData) InternalBuildEnvelopeFactory(com.kickstarter.factories.InternalBuildEnvelopeFactory) TestSubscriber(rx.observers.TestSubscriber) List(java.util.List) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

Category (com.kickstarter.models.Category)11 DiscoveryParams (com.kickstarter.services.DiscoveryParams)6 Project (com.kickstarter.models.Project)4 List (java.util.List)4 Test (org.junit.Test)4 TestSubscriber (rx.observers.TestSubscriber)4 Context (android.content.Context)3 Intent (android.content.Intent)3 NonNull (android.support.annotation.NonNull)3 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)3 CategoryFactory (com.kickstarter.factories.CategoryFactory)3 UserFactory (com.kickstarter.factories.UserFactory)3 Environment (com.kickstarter.libs.Environment)3 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)3 Photo (com.kickstarter.models.Photo)3 Arrays (java.util.Arrays)3 InternalBuildEnvelopeFactory (com.kickstarter.factories.InternalBuildEnvelopeFactory)2 Transformers (com.kickstarter.libs.rx.transformers.Transformers)2 CircleTransformation (com.kickstarter.libs.transformations.CircleTransformation)2 DiscoveryUtils (com.kickstarter.libs.utils.DiscoveryUtils)2