Search in sources :

Example 41 with Project

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);
}
Also used : CookieStore(java.net.CookieStore) Project(com.kickstarter.models.Project) RefTag(com.kickstarter.libs.RefTag) HttpCookie(java.net.HttpCookie) CookieManager(java.net.CookieManager) Test(org.junit.Test)

Example 42 with Project

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);
}
Also used : Project(com.kickstarter.models.Project) HttpCookie(java.net.HttpCookie) CookieManager(java.net.CookieManager) Test(org.junit.Test)

Example 43 with Project

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());
}
Also used : Project(com.kickstarter.models.Project) ObjectUtils(com.kickstarter.libs.utils.ObjectUtils) NonNull(android.support.annotation.NonNull)

Example 44 with Project

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())));
    }
}
Also used : Context(android.content.Context) Project(com.kickstarter.models.Project) CircleTransformation(com.kickstarter.libs.transformations.CircleTransformation) User(com.kickstarter.models.User)

Example 45 with Project

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

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