Search in sources :

Example 6 with Update

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

the class CommentsViewModelTest method testCommentsViewModel_EmptyState.

@Test
public void testCommentsViewModel_EmptyState() {
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<CommentsEnvelope> fetchComments(@NonNull final Update update) {
            return Observable.empty();
        }
    };
    final Environment env = environment().toBuilder().apiClient(apiClient).build();
    final CommentsViewModel vm = new CommentsViewModel(env);
    final TestSubscriber<CommentsData> commentsData = new TestSubscriber<>();
    vm.outputs.commentsData().subscribe(commentsData);
    // Start the view model with an update.
    vm.intent(new Intent().putExtra(IntentKey.UPDATE, UpdateFactory.update()));
    // Only Viewed Comments event should fire.
    koalaTest.assertValues(KoalaEvent.VIEWED_COMMENTS);
    commentsData.assertNoValues();
}
Also used : CommentsEnvelope(com.kickstarter.services.apiresponses.CommentsEnvelope) CommentsData(com.kickstarter.ui.adapters.data.CommentsData) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Update(com.kickstarter.models.Update) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 7 with Update

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

the class ProjectUpdateViewHolder 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;
    }
    final Update update = activity().update();
    if (update == null) {
        return;
    }
    final DateTime publishedAt = ObjectUtils.coalesce(update.publishedAt(), new DateTime());
    projectNameTextView.setText(project.name());
    Picasso.with(context).load(photo.little()).into(projectPhotoImageView);
    timestampTextView.setText(DateTimeUtils.relative(context, ksString, publishedAt));
    updateBodyTextView.setText(update.truncatedBody());
    updateSequenceTextView.setText(ksString.format(projectUpdateCountString, "update_count", String.valueOf(update.sequence())));
    updateTitleTextView.setText(update.title());
}
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) DateTime(org.joda.time.DateTime)

Example 8 with Update

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

the class PushNotifications method fetchUpdateWithEnvelope.

@Nullable
private Observable<Pair<PushNotificationEnvelope, Update>> fetchUpdateWithEnvelope(@NonNull final PushNotificationEnvelope envelope) {
    final Activity activity = envelope.activity();
    if (activity == null) {
        return null;
    }
    final Long updateId = activity.updateId();
    if (updateId == null) {
        return null;
    }
    final Long projectId = activity.projectId();
    if (projectId == null) {
        return null;
    }
    final String projectParam = ObjectUtils.toString(projectId);
    final String updateParam = ObjectUtils.toString(updateId);
    final Observable<Update> update = client.fetchUpdate(projectParam, updateParam).compose(Transformers.neverError());
    return Observable.just(envelope).compose(Transformers.combineLatestPair(update));
}
Also used : ProjectActivity(com.kickstarter.ui.activities.ProjectActivity) Activity(com.kickstarter.models.pushdata.Activity) WebViewActivity(com.kickstarter.ui.activities.WebViewActivity) Update(com.kickstarter.models.Update) Nullable(android.support.annotation.Nullable)

Example 9 with Update

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

the class KoalaUtils method activityProperties.

@NonNull
public static Map<String, Object> activityProperties(@NonNull final Activity activity, @NonNull final String prefix) {
    Map<String, Object> properties = new HashMap<String, Object>() {

        {
            put("category", activity.category());
        }
    };
    properties = MapUtils.prefixKeys(properties, prefix);
    final Project project = activity.project();
    if (project != null) {
        properties.putAll(projectProperties(project));
        final Update update = activity.update();
        if (update != null) {
            properties.putAll(updateProperties(project, update));
        }
    }
    return properties;
}
Also used : Project(com.kickstarter.models.Project) HashMap(java.util.HashMap) Update(com.kickstarter.models.Update) NonNull(android.support.annotation.NonNull)

Example 10 with Update

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

the class UpdateViewModelTest method testUpdateViewModel_LoadsWebViewUrl.

@Test
public void testUpdateViewModel_LoadsWebViewUrl() {
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment());
    final Update update = UpdateFactory.update();
    final String anotherUpdateUrl = "https://kck.str/projects/param/param/posts/next-id";
    final Request anotherUpdateRequest = new Request.Builder().url(anotherUpdateUrl).build();
    final TestSubscriber<String> webViewUrl = new TestSubscriber<>();
    vm.outputs.webViewUrl().subscribe(webViewUrl);
    // Start the intent with a project and update.
    vm.intent(defaultIntent);
    // Initial update's url emits.
    webViewUrl.assertValues(update.urls().web().update());
    // Make a request for another update.
    vm.inputs.goToUpdateRequest(anotherUpdateRequest);
    // New update url emits.
    webViewUrl.assertValues(update.urls().web().update(), anotherUpdateUrl);
}
Also used : Request(okhttp3.Request) TestSubscriber(rx.observers.TestSubscriber) Update(com.kickstarter.models.Update) Test(org.junit.Test)

Aggregations

Update (com.kickstarter.models.Update)12 Test (org.junit.Test)8 TestSubscriber (rx.observers.TestSubscriber)8 Intent (android.content.Intent)7 Project (com.kickstarter.models.Project)5 Request (okhttp3.Request)5 NonNull (android.support.annotation.NonNull)4 Environment (com.kickstarter.libs.Environment)3 ApiClientType (com.kickstarter.services.ApiClientType)3 MockApiClient (com.kickstarter.services.MockApiClient)3 Context (android.content.Context)2 Photo (com.kickstarter.models.Photo)2 User (com.kickstarter.models.User)2 Nullable (android.support.annotation.Nullable)1 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)1 ProjectFactory (com.kickstarter.factories.ProjectFactory)1 UpdateFactory (com.kickstarter.factories.UpdateFactory)1 KoalaEvent (com.kickstarter.libs.KoalaEvent)1 NumberUtils (com.kickstarter.libs.utils.NumberUtils)1 Activity (com.kickstarter.models.pushdata.Activity)1