8000 [🔗] NT-342 Adding ref tag when sharing updates by eoji · Pull Request #622 · kickstarter/android-oss · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[🔗] NT-342 Adding ref tag when sharing updates #622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/java/com/kickstarter/libs/RefTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ public static RefTag from(final @NonNull String tag) {
public static @NonNull RefTag update() {
return new AutoParcel_RefTag("update");
}

public static @NonNull RefTag updateShare() {
return new AutoParcel_RefTag("android_update_share");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,16 @@ private void startProjectActivity(final @NonNull Project project, final @NonNull
startActivityWithTransition(intent, R.anim.slide_in_right, R.anim.fade_out_slide_out_left);
}

private void startShareIntent(final @NonNull Update update) {
private void startShareIntent(final @NonNull Pair<Update, String> updateAndShareUrl) {
final Update update = updateAndShareUrl.first;
final String shareUrl = updateAndShareUrl.second;
final String shareMessage = this.ksString.format(this.shareUpdateCountString, "update_count", NumberUtils.format(update.sequence()))
+ ": " + update.title();

final Intent intent = new Intent(Intent.ACTION_SEND)
.setType("text/plain")
.putExtra(Intent.EXTRA_TEXT, shareMessage + " " + update.urls().web().update());
startActivity(intent);
.putExtra(Intent.EXTRA_TEXT, shareMessage + " " + shareUrl);
startActivity(Intent.createChooser(intent, getString(R.string.Share_update)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.kickstarter.libs.KoalaContext;
import com.kickstarter.libs.RefTag;
import com.kickstarter.libs.utils.NumberUtils;
import com.kickstarter.libs.utils.UrlUtils;
import com.kickstarter.models.Project;
import com.kickstarter.models.Update;
import com.kickstarter.services.ApiClientType;
Expand Down Expand Up @@ -44,7 +45,7 @@ interface Inputs {

interface Outputs {
/** Emits when we should start the share intent to show the share sheet. */
Observable<Update> startShareIntent();
Observable<Pair<Update, String>> startShareIntent();

/** Emits an update to start the comments activity with. */
Observable<Update> startCommentsActivity();
Expand Down Expand Up @@ -96,6 +97,7 @@ public ViewModel(final @NonNull Environment environment) {

currentUpdate
.compose(takeWhen(this.shareButtonClicked))
.map(update -> Pair.create(update, UrlUtils.INSTANCE.appendRefTag(update.urls().web().update(), RefTag.updateShare().tag())))
.compose(bindToLifecycle())
.subscribe(this.startShareIntent::onNext);

Expand Down Expand Up @@ -139,7 +141,7 @@ public ViewModel(final @NonNull Environment environment) {
private final PublishSubject<Request> goToUpdateRequest = PublishSubject.create();
private final PublishSubject<Void> shareButtonClicked = PublishSubject.create();

private final PublishSubject<Update> startShareIntent = PublishSubject.create();
private final PublishSubject<Pair<Update, String>> startShareIntent = PublishSubject.create();
private final PublishSubject<Update> startCommentsActivity = PublishSubject.create();
private final PublishSubject<Pair<Project, RefTag>> startProjectActivity = PublishSubject.create();
private final BehaviorSubject<String> updateSequence = BehaviorSubject.create();
Expand All @@ -164,7 +166,7 @@ public ViewModel(final @NonNull Environment environment) {
this.shareButtonClicked.onNext(null);
}

@Override public Observable<Update> startShareIntent() {
@Override public Observable<Pair<Update, String>> startShareIntent() {
return this.startShareIntent;
}
@Override public @NonNull Observable<Update> startCommentsActivity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.kickstarter.viewmodels;

import android.content.Intent;
import android.util.Pair;

import com.kickstarter.KSRobolectricTestCase;
import com.kickstarter.libs.Environment;
import com.kickstarter.libs.KoalaEvent;
import com.kickstarter.libs.utils.NumberUtils;
import com.kickstarter.mock.factories.ProjectFactory;
import com.kickstarter.mock.factories.UpdateFactory;
import com.kickstarter.mock.factories.UserFactory;
import com.kickstarter.mock.services.MockApiClient;
import com.kickstarter.models.Project;
import com.kickstarter.models.Update;
import com.kickstarter.models.User;
import com.kickst B5C8 arter.services.ApiClientType;
import com.kickstarter.ui.IntentKey;

Expand Down Expand Up @@ -144,9 +147,25 @@ public void testUpdateViewModel_StartProjectActivity() {
public void testUpdateViewModel_StartShareIntent() {
final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment());

final Update update = UpdateFactory.update();
final User creator = UserFactory.creator().toBuilder().id(278438049).build();
final Project project = ProjectFactory.project().toBuilder().creator(creator).build();
final String updatesUrl = "https://www.kck.str/projects/" + project.creator().param() + "/" + project.param() + "/posts";

final int id = 15;

final Update.Urls.Web web = Update.Urls.Web.builder()
.update(updatesUrl + "/" + id)
.likes(updatesUrl + "/likes")
.build();

final Update update = UpdateFactory.update()
.toBuilder()
.id(id)
.projectId(project.id())
.urls(Update.Urls.builder().web(web).build())
.build();

final TestSubscriber<Update> startShareIntent = new TestSubscriber<>();
final TestSubscriber<Pair<Update, String>> startShareIntent = new TestSubscriber<>();
vm.outputs.startShareIntent().subscribe(startShareIntent);

// Start the intent with a project and update.
Expand All @@ -156,7 +175,9 @@ public void testUpdateViewModel_StartShareIntent() {
);
vm.inputs.shareIconButtonClicked();

startShareIntent.assertValues(update);
final String expectedShareUrl = "https://www.kck.str/projects/" + project.creator().param() +
"/" + project.param() + "/posts/" + id + "?ref=android_update_share";
startShareIntent.assertValue(Pair.create(update, expectedShareUrl));
}

@Test
Expand Down
0