-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from apptentive/branch_5.6.0
Release 5.6.0
- Loading branch information
Showing
26 changed files
with
721 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# 2020-09-28 - v5.6.0 | ||
|
||
#### Improvements | ||
|
||
* Google Play In-App Review support. | ||
|
||
# 2020-09-04 - v5.5.4 | ||
|
||
#### Fixes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
205 changes: 205 additions & 0 deletions
205
...om/apptentive/android/sdk/module/engagement/InAppRatingDialogInteractionLauncherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
package com.apptentive.android.sdk.module.engagement; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.apptentive.android.sdk.InstrumentationTestCaseBase; | ||
import com.apptentive.android.sdk.external.Engagement; | ||
import com.apptentive.android.sdk.external.InAppReviewListener; | ||
import com.apptentive.android.sdk.external.InAppReviewManager; | ||
import com.apptentive.android.sdk.external.InAppReviewManagerFactory; | ||
import com.apptentive.android.sdk.module.engagement.interaction.model.InAppRatingDialogInteraction; | ||
import com.apptentive.android.sdk.module.engagement.interaction.model.Interaction; | ||
import com.apptentive.android.sdk.util.Callback; | ||
import com.apptentive.android.sdk.util.StringUtils; | ||
|
||
import junit.framework.AssertionFailedError; | ||
|
||
import org.json.JSONException; | ||
import org.junit.Test; | ||
|
||
import java.util.Map; | ||
|
||
public class InAppRatingDialogInteractionLauncherTest extends InstrumentationTestCaseBase { | ||
private static final String FALLBACK_INTERACTION_ID = "1234567"; | ||
|
||
private static final String JSON = "{'type':'InAppRatingDialog','version':1,'configuration':{'not_shown_interaction': '" + FALLBACK_INTERACTION_ID + "'},'display_type':null,'id':'58eebbf2127096704e0000d0'}"; | ||
private static final String JSON_MISSING_FALLBACK = "{'type':'InAppRatingDialog','version':1,'configuration':{'not_shown_interaction': '0000000'},'display_type':null,'id':'58eebbf2127096704e0000d0'}"; | ||
private static final String JSON_NO_FALLBACK = "{'type':'InAppRatingDialog','version':1,'configuration':{},'display_type':null,'id':'58eebbf2127096704e0000d0'}"; | ||
|
||
//region In-App Review supported | ||
|
||
@Test | ||
public void testInAppReviewSupportedLaunchSucceed() { | ||
InAppRatingDialogInteractionLauncher launcher = createLauncher(MockInAppReviewManager.successful()); | ||
launcher.launch(getContext(), createInteraction(JSON)); | ||
|
||
assertResult( | ||
"engage=InAppRatingDialog#request", | ||
"engage=InAppRatingDialog#shown" | ||
); | ||
} | ||
|
||
@Test | ||
public void testInAppReviewSupportedLaunchFailed() { | ||
InAppRatingDialogInteractionLauncher launcher = createLauncher(MockInAppReviewManager.failed("Something went wrong")); | ||
launcher.launch(getContext(), createInteraction(JSON)); | ||
|
||
assertResult( | ||
"engage=InAppRatingDialog#request", | ||
"engage=InAppRatingDialog#not_shown data='cause':'Something went wrong'" | ||
); | ||
} | ||
|
||
//endregion | ||
|
||
//region In-App Review unsupported | ||
|
||
@Test | ||
public void testInAppReviewUnsupportedWithFallbackAction() { | ||
InAppRatingDialogInteractionLauncher launcher = createLauncher(MockInAppReviewManager.unsupported()); | ||
launcher.launch(getContext(), createInteraction(JSON)); | ||
|
||
assertResult( | ||
"engage=InAppRatingDialog#request", | ||
"engage=InAppRatingDialog#not_supported", | ||
"launch=1234567", // fallback interaction | ||
"engage=InAppRatingDialog#launch" | ||
); | ||
} | ||
|
||
@Test | ||
public void testInAppReviewUnsupportedWithNoFallbackAction() { | ||
InAppRatingDialogInteractionLauncher launcher = createLauncher(MockInAppReviewManager.unsupported()); | ||
launcher.launch(getContext(), createInteraction(JSON_NO_FALLBACK)); | ||
|
||
assertResult( | ||
"engage=InAppRatingDialog#request", | ||
"engage=InAppRatingDialog#not_supported" | ||
); | ||
} | ||
|
||
@Test | ||
public void testInAppReviewUnsupportedWithMissingFallbackAction() { | ||
InAppRatingDialogInteractionLauncher launcher = createLauncher(MockInAppReviewManager.unsupported()); | ||
launcher.launch(getContext(), createInteraction(JSON_MISSING_FALLBACK)); | ||
|
||
assertResult( | ||
"engage=InAppRatingDialog#request", | ||
"engage=InAppRatingDialog#not_supported" | ||
); | ||
} | ||
|
||
//endregion | ||
|
||
//region Helpers | ||
|
||
private InAppRatingDialogInteraction createInteraction(String json) { | ||
try { | ||
return new InAppRatingDialogInteraction(json.replace("'", "\"")); | ||
} catch (JSONException e) { | ||
throw new AssertionFailedError(e.getMessage()); | ||
} | ||
} | ||
|
||
private InAppRatingDialogInteractionLauncher createLauncher(InAppReviewManager manager) { | ||
Engagement engagement = new Engagement() { | ||
@Override | ||
public void engageInternal(Context context, Interaction interaction, String eventName, @Nullable Map<String, Object> data) { | ||
String event = interaction.getType() + "#" + eventName; | ||
if (data != null) { | ||
addResult("engage=%s data=%s", event, StringUtils.toString(data)); | ||
} else { | ||
addResult("engage=%s", event); | ||
} | ||
} | ||
|
||
@Override | ||
public void launchInteraction(Context context, String interactionId, Callback<Boolean> callback) { | ||
if (FALLBACK_INTERACTION_ID.equals(interactionId)) { | ||
addResult("launch=%s", interactionId); | ||
callback.onFinish(Boolean.TRUE); | ||
} else { | ||
callback.onFinish(Boolean.FALSE); | ||
} | ||
} | ||
}; | ||
|
||
return new InAppRatingDialogInteractionLauncher(new MockInAppReviewManagerFactory(manager), engagement); | ||
} | ||
|
||
//endregion | ||
|
||
//region Mocks | ||
|
||
private static class MockInAppReviewManager implements InAppReviewManager { | ||
private final String errorMessage; | ||
private final boolean supported; | ||
|
||
private MockInAppReviewManager(boolean supported, String errorMessage) { | ||
this.errorMessage = errorMessage; | ||
this.supported = supported; | ||
} | ||
|
||
public static InAppReviewManager successful() { | ||
return new MockInAppReviewManager(true, null); | ||
} | ||
|
||
public static InAppReviewManager failed(String errorMessage) { | ||
return new MockInAppReviewManager(true, errorMessage); | ||
} | ||
|
||
public static InAppReviewManager unsupported() { | ||
return new MockInAppReviewManager(false, null); | ||
} | ||
|
||
@Override | ||
public void launchReview(@NonNull Context context, InAppReviewListener callback) { | ||
if (supported) { | ||
if (errorMessage != null) { | ||
callback.onReviewFlowFailed(errorMessage); | ||
} else { | ||
callback.onReviewFlowComplete(); | ||
} | ||
} else { | ||
throw new AssertionFailedError("Should not get there"); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isInAppReviewSupported() { | ||
return supported; | ||
} | ||
} | ||
|
||
private static class MockInAppReviewManagerFactory implements InAppReviewManagerFactory { | ||
private final InAppReviewManager manager; | ||
|
||
private MockInAppReviewManagerFactory(InAppReviewManager manager) { | ||
this.manager = manager; | ||
} | ||
|
||
@Override | ||
public InAppReviewManager createReviewManager(@NonNull Context context) { | ||
return manager; | ||
} | ||
} | ||
|
||
private static class MockInteraction extends Interaction { | ||
public static Interaction create(String json) { | ||
try { | ||
return new MockInteraction(json); | ||
} catch (JSONException e) { | ||
throw new AssertionFailedError(e.getMessage()); | ||
} | ||
} | ||
|
||
private MockInteraction(String json) throws JSONException { | ||
super(json); | ||
} | ||
} | ||
|
||
//endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,6 @@ public enum ApptentiveLogTag { | |
TROUBLESHOOT, | ||
ADVERTISER_ID, | ||
PARTNERS, | ||
SECURITY | ||
SECURITY, | ||
IN_APP_REVIEW | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
apptentive/src/main/java/com/apptentive/android/sdk/external/DefaultEngagement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.apptentive.android.sdk.external; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.apptentive.android.sdk.ApptentiveLog; | ||
import com.apptentive.android.sdk.ApptentiveLogTag; | ||
import com.apptentive.android.sdk.conversation.Conversation; | ||
import com.apptentive.android.sdk.conversation.ConversationDispatchTask; | ||
import com.apptentive.android.sdk.module.engagement.EngagementModule; | ||
import com.apptentive.android.sdk.module.engagement.interaction.model.Interaction; | ||
import com.apptentive.android.sdk.util.Callback; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.Map; | ||
|
||
import static com.apptentive.android.sdk.ApptentiveHelper.dispatchConversationTask; | ||
|
||
public class DefaultEngagement implements Engagement { | ||
@Override | ||
public void engageInternal(final Context context, final Interaction interaction, final String eventName, @Nullable final Map<String, Object> data) { | ||
dispatchConversationTask(new ConversationDispatchTask() { | ||
@Override | ||
protected boolean execute(Conversation conversation) { | ||
String jsonData = createJsonData(data); | ||
return EngagementModule.engageInternal(context, conversation, interaction, eventName, jsonData); | ||
} | ||
}, "engage event '" + eventName + "'"); | ||
} | ||
|
||
@Override | ||
public void launchInteraction(final Context context, final String interactionId, final Callback<Boolean> callback) { | ||
dispatchConversationTask(new ConversationDispatchTask() { | ||
@Override | ||
protected boolean execute(Conversation conversation) { | ||
Interaction interaction = getInteraction(conversation); | ||
if (interaction != null) { | ||
EngagementModule.launchInteraction(context, conversation, interaction); | ||
callback.onFinish(Boolean.TRUE); | ||
} else { | ||
callback.onFinish(Boolean.FALSE); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private @Nullable Interaction getInteraction(Conversation conversation) { | ||
try { | ||
return conversation.getInteraction(interactionId); | ||
} catch (JSONException e) { | ||
ApptentiveLog.e(ApptentiveLogTag.CONVERSATION, e, "Unable to get interaction '%s'", interactionId); | ||
} | ||
return null; | ||
} | ||
}, "launch interaction '" + interactionId + "'"); | ||
} | ||
|
||
private static String createJsonData(Map<String, Object> data) { | ||
if (data != null && data.size() > 0) { | ||
return new JSONObject(data).toString(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.