Skip to content

Commit

Permalink
Fire App Builder v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
creeld committed Apr 14, 2017
1 parent 9ee53af commit 2d000b4
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 83 deletions.
4 changes: 2 additions & 2 deletions Application/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ android {
applicationId "com.amazon.android.calypso"
minSdkVersion 21
targetSdkVersion 23
versionCode 6
versionName "1.0.2"
versionCode 7
versionName "1.0.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,34 +194,41 @@ public static void trackContentDetailsAction(Content content, int actionId) {


/**
* Track that the given content started/resumed playback.
* Track that the given content started or resumed playback.
*
* @param content Content that started/resumed playback.
* @param duration Total duration of the content.
* @param content Content that started/resumed playback.
* @param duration Total duration of the content.
* @param currentPosition The current playback position.
*/
public static void trackContentStarted(Content content, long duration) {
public static void trackPlaybackStarted(Content content, long duration, long currentPosition) {

Map<String, Object> attributes = getBasicAnalyticsAttributesForContent(content);
attributes.putAll(getDetailedContentAttributes(content));

// Get Content extras
attributes.putAll(ExtraContentAttributes.getExtraAttributes(content.getExtras()));
attributes.put(AnalyticsTags.ATTRIBUTE_VIDEO_DURATION, duration);
attributes.put(AnalyticsTags.ATTRIBUTE_VIDEO_CURRENT_POSITION, currentPosition);

sendAnalytics(AnalyticsTags.ACTION_PLAYBACK_STARTED, attributes);
}

/**
* Tracks the ending of a content.
* Tracks that a content's playback finished. This could be that the content was played to
* completion or that the player was exited.
*
* @param content Content to track.
* @param duration The duration for which the content was played.
* @param content Content to track.
* @param startingPosition The position that this playback session started at.
* @param currentPosition The current playback position.
*/
public static void trackContentFinished(Content content, long duration) {
public static void trackPlaybackFinished(Content content, long startingPosition,
long currentPosition) {

// Get the attributes for the selected movie.
Map<String, Object> attributes = getBasicAnalyticsAttributesForContent(content);
attributes.put(AnalyticsTags.ATTRIBUTE_VIDEO_SECONDS_WATCHED, duration);
attributes.put(AnalyticsTags.ATTRIBUTE_VIDEO_SECONDS_WATCHED,
currentPosition - startingPosition);
attributes.put(AnalyticsTags.ATTRIBUTE_VIDEO_CURRENT_POSITION, currentPosition);

sendAnalytics(AnalyticsTags.ACTION_PLAYBACK_FINISHED, attributes);
}
Expand All @@ -242,13 +249,14 @@ public static void trackPurchaseResult(String sku, boolean purchaseResult) {
}

/**
* Tracks playback actions of the content.
* Tracks when users interact with the playback controls of the player.
*
* @param action Action taken on this content.
* @param content Content on which the action was taken.
* @param currentPosition Current position in the content playback that the ad finished.
*/
public static void trackContentAction(String action, Content content, long currentPosition) {
public static void trackPlaybackControlAction(String action, Content content,
long currentPosition) {

// Get the attributes for the selected content.
Map<String, Object> attributes = getBasicAnalyticsAttributesForContent(content);
Expand Down Expand Up @@ -357,15 +365,15 @@ public static void trackAppEntry() {
/**
* Tracks requests received from launcher to play content
*
* @param contentId contentId of the content requested to be played
* @param content content corresponding to the contentId
* @param contentId contentId of the content requested to be played
* @param content content corresponding to the contentId
* @param requestSource Source of request, it could be Catalog integration or Recommendations
*/
public static void trackLauncherRequest(String contentId, Content content,
String requestSource) {

HashMap<String, Object> attributes = new HashMap<>();
if(requestSource != null) {
if (requestSource != null) {
attributes.put(AnalyticsTags.ATTRIBUTE_REQUEST_SOURCE, requestSource);
}
if (content != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
Expand Down Expand Up @@ -180,14 +181,15 @@ public void testMapToModel() throws Exception {
* Tests the {@link ContentContainerTranslator#mapToModel(Map, Recipe)} method with a bad
* recipe.
*/
@Test(expected = AModelTranslator.TranslationException.class)
@Test
public void testMapToModelWithBadRecipe() throws Exception {

Recipe badRecipe = Recipe.newInstance(FileHelper.readFile(InstrumentationRegistry
.getContext(),
"BadContainerRecipe.json"));

mTranslator.mapToModel(createValidMap(), badRecipe);
ContentContainer container = mTranslator.mapToModel(createValidMap(), badRecipe);
assertNull("ContentContainer should be null", container);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

import com.amazon.android.model.content.Content;
import com.amazon.android.recipe.Recipe;
import com.amazon.android.model.AModelTranslator;
import com.amazon.android.utils.FileHelper;

import org.json.JSONException;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -33,6 +31,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
Expand Down Expand Up @@ -321,60 +320,69 @@ public void testMapToModel() throws Exception {
* Tests the {@link ContentTranslator#mapToModel(Map, Recipe)} with a recipe that's missing the
* title field.
*/
@Test(expected = AModelTranslator.TranslationException.class)
@Test
public void testMapToModelWithBadRecipeTitle() throws Exception {

Recipe badRecipe = Recipe.newInstance(getBadContentRecipeJsonString("title"));

mContentTranslator.mapToModel(createValidMap(), badRecipe);
Content content = mContentTranslator.mapToModel(createValidMap(), badRecipe);
assertNull("Content should be null due to bad translation", content);

}

/**
* Tests the {@link ContentTranslator#mapToModel(Map, Recipe)} with a recipe that's missing the
* description field.
*/
@Test(expected = AModelTranslator.TranslationException.class)
@Test
public void testMapToModelWithBadRecipeDescription() throws Exception {

Recipe badRecipe = Recipe.newInstance(getBadContentRecipeJsonString("description"));

mContentTranslator.mapToModel(createValidMap(), badRecipe);
Content content = mContentTranslator.mapToModel(createValidMap(), badRecipe);
assertNull("Content should be null due to bad translation", content);

}

/**
* Tests the {@link ContentTranslator#mapToModel(Map, Recipe)} with a recipe that's missing the
* url field.
*/
@Test(expected = AModelTranslator.TranslationException.class)
@Test
public void testMapToModelWithBadRecipeUrl() throws Exception {

Recipe badRecipe = Recipe.newInstance(getBadContentRecipeJsonString("url"));

mContentTranslator.mapToModel(createValidMap(), badRecipe);
Content content = mContentTranslator.mapToModel(createValidMap(), badRecipe);
assertNull("Content should be null due to bad translation", content);
}

/**
* Tests the {@link ContentTranslator#mapToModel(Map, Recipe)} with a recipe that's missing the
* cardImageUrl field.
*/
@Test(expected = AModelTranslator.TranslationException.class)
@Test
public void testMapToModelWithBadRecipeCardImageUrl() throws Exception {

Recipe badRecipe = Recipe.newInstance(getBadContentRecipeJsonString("cardImageUrl"));

mContentTranslator.mapToModel(createValidMap(), badRecipe);
Content content = mContentTranslator.mapToModel(createValidMap(), badRecipe);
assertNull("Content should be null due to bad translation", content);

}

/**
* Tests the {@link ContentTranslator#mapToModel(Map, Recipe)} with a recipe that's missing the
* backgroundImageUrl field.
*/
@Test(expected = AModelTranslator.TranslationException.class)
@Test
public void testMapToModelWithBadRecipeBackgroundImageUrl() throws Exception {

Recipe badRecipe = Recipe.newInstance(getBadContentRecipeJsonString("backgroundImageUrl"));

mContentTranslator.mapToModel(createValidMap(), badRecipe);
Content content = mContentTranslator.mapToModel(createValidMap(), badRecipe);
assertNull("Content should be null due to bad translation", content);

}

/**
Expand Down Expand Up @@ -447,13 +455,15 @@ private String getBadContentRecipeJsonString(String skipMatchItem, String extraM
* Tests the {@link ContentTranslator#mapToModel(Map, Recipe)} with a bad map argument. The map
* is missing the title field so the model should not be valid at the end of translation.
*/
@Test(expected = AModelTranslator.TranslationException.class)
@Test
public void testMapToModelWithBadMap() throws Exception {

Map<String, Object> map = createValidMap();
map.remove("title");

mContentTranslator.mapToModel(map, mGoodRecipe);
Content content = mContentTranslator.mapToModel(map, mGoodRecipe);
assertNull("Content should be null due to bad translation", content);

}

/**
Expand Down
Loading

0 comments on commit 2d000b4

Please sign in to comment.