Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #163 from mazook/master
Browse files Browse the repository at this point in the history
Add support for content_available field
  • Loading branch information
kroikie committed Jan 29, 2016
2 parents 56361a5 + 9287ee4 commit 2fec73a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public final class Constants {
*/
public static final String PARAM_PRIORITY = "priority";

/**
* Parameter used to set the content available (iOS only)
*/
public static final String PARAM_CONTENT_AVAILABLE = "content_available";

/**
* Value used to set message priority to normal.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ public final class Message implements Serializable {
private final Boolean dryRun;
private final String restrictedPackageName;
private final String priority;
private final Boolean contentAvailable;
private final Notification notification;


public enum Priority {
NORMAL, HIGH
}
Expand All @@ -83,6 +85,7 @@ public static final class Builder {
private Boolean dryRun;
private String restrictedPackageName;
private String priority;
private Boolean contentAvailable;
private Notification notification;

public Builder() {
Expand Down Expand Up @@ -160,6 +163,14 @@ public Builder notification(Notification value) {
return this;
}

/**
* Sets the contentAvailable property
*/
public Builder contentAvailable(Boolean value){
contentAvailable = value;
return this;
}

public Message build() {
return new Message(this);
}
Expand All @@ -174,6 +185,7 @@ private Message(Builder builder) {
dryRun = builder.dryRun;
restrictedPackageName = builder.restrictedPackageName;
priority = builder.priority;
contentAvailable = builder.contentAvailable;
notification = builder.notification;
}

Expand Down Expand Up @@ -219,6 +231,13 @@ public String getPriority() {
return priority;
}

/**
* Gets the contentAvailable value
*/
public Boolean getContentAvailable() {
return contentAvailable;
}

/**
* Gets the payload data, which is immutable.
*/
Expand All @@ -239,6 +258,9 @@ public String toString() {
if (priority != null) {
builder.append("priority=").append(priority).append(", ");
}
if (contentAvailable != null){
builder.append("contentAvailable=").append(contentAvailable).append(", ");
}
if (collapseKey != null) {
builder.append("collapseKey=").append(collapseKey).append(", ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static com.google.android.gcm.server.Constants.PARAM_DELAY_WHILE_IDLE;
import static com.google.android.gcm.server.Constants.PARAM_DRY_RUN;
import static com.google.android.gcm.server.Constants.PARAM_PRIORITY;
import static com.google.android.gcm.server.Constants.PARAM_CONTENT_AVAILABLE;
import static com.google.android.gcm.server.Constants.PARAM_RESTRICTED_PACKAGE_NAME;
import static com.google.android.gcm.server.Constants.PARAM_TIME_TO_LIVE;
import static com.google.android.gcm.server.Constants.TOKEN_CANONICAL_REG_ID;
Expand Down Expand Up @@ -456,6 +457,7 @@ private void messageToMap(Message message, Map<Object, Object> mapRequest) {
return;
}
setJsonField(mapRequest, PARAM_PRIORITY, message.getPriority());
setJsonField(mapRequest, PARAM_CONTENT_AVAILABLE, message.getContentAvailable());
setJsonField(mapRequest, PARAM_TIME_TO_LIVE, message.getTimeToLive());
setJsonField(mapRequest, PARAM_COLLAPSE_KEY, message.getCollapseKey());
setJsonField(mapRequest, PARAM_RESTRICTED_PACKAGE_NAME, message.getRestrictedPackageName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void testRequiredParameters() {
public void testOptionalParameters() {
Message message = new Message.Builder()
.priority(Message.Priority.HIGH)
.contentAvailable(true)
.collapseKey("108")
.delayWhileIdle(true)
.timeToLive(42)
Expand All @@ -59,6 +60,7 @@ public void testOptionalParameters() {
.notification(new Notification.Builder("my").build())
.build();
assertEquals("high", message.getPriority());
assertTrue(message.getContentAvailable());
assertEquals("108", message.getCollapseKey());
assertTrue(message.isDelayWhileIdle());
assertEquals(42, message.getTimeToLive().intValue());
Expand All @@ -70,6 +72,7 @@ public void testOptionalParameters() {
assertEquals("v2", data.get("k2"));
String toString = message.toString();
assertTrue(toString.contains("priority=high"));
assertTrue(toString.contains("contentAvailable=true"));
assertTrue(toString.contains("collapseKey=108"));
assertTrue(toString.contains("timeToLive=42"));
assertTrue(toString.contains("delayWhileIdle=true"));
Expand Down

0 comments on commit 2fec73a

Please sign in to comment.