use of com.kickstarter.models.Project in project android-oss by kickstarter.
the class RefTagUtilsTest method testStoredCookieRefTagForProject.
@Test
public void testStoredCookieRefTagForProject() {
final CookieManager cookieManager = new CookieManager();
final CookieStore cookieStore = cookieManager.getCookieStore();
final Project project = ProjectFactory.project();
final RefTag refTag = RefTag.recommended();
// set the cookie and retrieve the ref tag
cookieStore.add(null, new HttpCookie("ref_" + project.id(), refTag.tag() + "%3F" + SystemUtils.secondsSinceEpoch()));
final RefTag retrievedRefTag = RefTagUtils.storedCookieRefTagForProject(project, cookieManager, sharedPreferences);
assertNotNull(retrievedRefTag);
assertEquals(refTag, retrievedRefTag);
}
use of com.kickstarter.models.Project in project android-oss by kickstarter.
the class RefTagUtilsTest method testFindRefTagCookieForProject_WhenCookieDoesNotExist.
@Test
public void testFindRefTagCookieForProject_WhenCookieDoesNotExist() {
final CookieManager cookieManager = new CookieManager();
final Project project = ProjectFactory.project();
// retrieve the cookie
final HttpCookie cookie = RefTagUtils.findRefTagCookieForProject(project, cookieManager, sharedPreferences);
assertNull(cookie);
}
use of com.kickstarter.models.Project in project android-oss by kickstarter.
the class ProjectIntentMapper method project.
/**
* Returns an observable of projects retrieved from intent data. May hit the API if the intent only contains a project
* param rather than a parceled project.
*/
@NonNull
public static Observable<Project> project(@NonNull final Intent intent, @NonNull final ApiClientType client) {
final Project intentProject = projectFromIntent(intent);
final Observable<Project> projectFromParceledProject = intentProject == null ? Observable.empty() : Observable.just(intentProject).flatMap(client::fetchProject).startWith(intentProject).retry(3);
final Observable<Project> projectFromParceledParam = Observable.just(paramFromIntent(intent)).filter(ObjectUtils::isNotNull).flatMap(client::fetchProject).retry(3);
return projectFromParceledProject.mergeWith(projectFromParceledParam).compose(Transformers.neverError());
}
use of com.kickstarter.models.Project in project android-oss by kickstarter.
the class ActivitySampleFriendBackingViewHolder method onBind.
public void onBind() {
final Context context = context();
final User user = activity.user();
final Project project = activity.project();
if (user != null && project != null) {
activityTitleTextView.setVisibility(View.GONE);
Picasso.with(context).load(user.avatar().small()).transform(new CircleTransformation()).into(activityImageView);
activitySubtitleTextView.setText(Html.fromHtml(ksString.format(categoryBackingString, "friend_name", user.name(), "project_name", project.name(), "creator_name", project.creator().name())));
}
}
use of com.kickstarter.models.Project 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);
}
Aggregations