Skip to content
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

Add Currently Playing Media Image to MediaServiceData #1074

Merged
merged 3 commits into from
Jul 16, 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
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.smartdevicelink.test.rpc.datatypes;

import com.smartdevicelink.marshal.JsonRPCMarshaller;
import com.smartdevicelink.proxy.rpc.Image;
import com.smartdevicelink.proxy.rpc.MediaServiceData;
import com.smartdevicelink.proxy.rpc.enums.MediaType;
import com.smartdevicelink.test.JsonUtils;
import com.smartdevicelink.test.Test;
import com.smartdevicelink.test.Validator;

import junit.framework.TestCase;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Hashtable;
import java.util.Iterator;

/**
Expand All @@ -28,6 +32,7 @@ public void setUp(){
msg.setMediaTitle(Test.GENERAL_STRING);
msg.setMediaArtist(Test.GENERAL_STRING);
msg.setMediaAlbum(Test.GENERAL_STRING);
msg.setMediaImage(Test.GENERAL_IMAGE);
msg.setPlaylistName(Test.GENERAL_STRING);
msg.setIsExplicit(Test.GENERAL_BOOLEAN);
msg.setTrackPlaybackProgress(Test.GENERAL_INTEGER);
Expand All @@ -47,6 +52,7 @@ public void testRpcValues () {
String mediaTitle = msg.getMediaTitle();
String mediaArtist = msg.getMediaArtist();
String mediaAlbum = msg.getMediaAlbum();
Image mediaImage = msg.getMediaImage();
String playlistName = msg.getPlaylistName();
boolean isExplicit = msg.getIsExplicit();
Integer trackPlaybackProgress = msg.getTrackPlaybackProgress();
Expand All @@ -61,6 +67,7 @@ public void testRpcValues () {
assertEquals(Test.GENERAL_STRING, mediaTitle);
assertEquals(Test.GENERAL_STRING, mediaArtist);
assertEquals(Test.GENERAL_STRING, mediaAlbum);
assertEquals(Test.GENERAL_IMAGE, mediaImage);
assertEquals(Test.GENERAL_STRING, playlistName);
assertEquals(Test.GENERAL_BOOLEAN, isExplicit);
assertEquals(Test.GENERAL_INTEGER, trackPlaybackProgress);
Expand All @@ -78,6 +85,7 @@ public void testRpcValues () {
assertNull(Test.NULL, msg.getMediaTitle());
assertNull(Test.NULL, msg.getMediaArtist());
assertNull(Test.NULL, msg.getMediaAlbum());
assertNull(Test.NULL, msg.getMediaImage());
assertNull(Test.NULL, msg.getPlaylistName());
assertNull(Test.NULL, msg.getIsExplicit());
assertNull(Test.NULL, msg.getTrackPlaybackProgress());
Expand All @@ -96,6 +104,7 @@ public void testJson(){
reference.put(MediaServiceData.KEY_MEDIA_TITLE, Test.GENERAL_STRING);
reference.put(MediaServiceData.KEY_MEDIA_ARTIST, Test.GENERAL_STRING);
reference.put(MediaServiceData.KEY_MEDIA_ALBUM, Test.GENERAL_STRING);
reference.put(MediaServiceData.KEY_MEDIA_IMAGE, Test.GENERAL_IMAGE);
reference.put(MediaServiceData.KEY_PLAYLIST_NAME, Test.GENERAL_STRING);
reference.put(MediaServiceData.KEY_IS_EXPLICIT, Test.GENERAL_BOOLEAN);
reference.put(MediaServiceData.KEY_TRACK_PLAYBACK_PROGRESS, Test.GENERAL_INTEGER);
Expand All @@ -111,7 +120,14 @@ public void testJson(){
Iterator<?> iterator = reference.keys();
while(iterator.hasNext()){
String key = (String) iterator.next();
assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));

if (key.equals(MediaServiceData.KEY_MEDIA_IMAGE)){
JSONObject testEquals = (JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key);
Hashtable<String, Object> hashTest = JsonRPCMarshaller.deserializeJSONObject(testEquals);
assertTrue(Test.TRUE, Validator.validateImage(Test.GENERAL_IMAGE, new Image(hashTest)));
} else {
assertEquals(Test.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
}
}
} catch(JSONException e){
fail(Test.JSON_FAIL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class MediaServiceData extends RPCStruct {
public static final String KEY_MEDIA_TITLE = "mediaTitle";
public static final String KEY_MEDIA_ARTIST = "mediaArtist";
public static final String KEY_MEDIA_ALBUM = "mediaAlbum";
public static final String KEY_MEDIA_IMAGE = "mediaImage";
public static final String KEY_PLAYLIST_NAME = "playlistName";
public static final String KEY_IS_EXPLICIT = "isExplicit";
public static final String KEY_TRACK_PLAYBACK_PROGRESS = "trackPlaybackProgress";
Expand Down Expand Up @@ -138,6 +139,27 @@ public String getMediaAlbum() {
return getString(KEY_MEDIA_ALBUM);
}

/**
* Sets the media image associated with the currently playing media
* Music: The album art of the current track
* Podcast: The podcast or chapter artwork of the current podcast episode
* Audiobook: The book or chapter artwork of the current audiobook
* @param mediaImage
*/
public void setMediaImage(Image mediaImage){
setValue(KEY_MEDIA_IMAGE, mediaImage);
}

/**
* Returns the media image associated with the currently playing media
* Music: The album art of the current track
* Podcast: The podcast or chapter artwork of the current podcast episode
* Audiobook: The book or chapter artwork of the current audiobook
*/
public Image getMediaImage(){
return (Image) getObject(Image.class, KEY_MEDIA_IMAGE);
}

/**
* Music: The name of the playlist or radio station, if the user is playing from a playlist, otherwise, Null
* Podcast: The name of the playlist, if the user is playing from a playlist, otherwise, Null
Expand Down