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);
}
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();
}
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);
}
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);
}
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);
}
Aggregations