![JAR search and dependency download from the Maven repository](/logo.png)
com.urbanairship.api.push.model.notification.ios.IOSDevicePayload Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
The Urban Airship Java client library
/*
* Copyright (c) 2013-2016. Urban Airship and Contributors
*/
package com.urbanairship.api.push.model.notification.ios;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.urbanairship.api.push.model.DeviceType;
import com.urbanairship.api.push.model.PushExpiry;
import com.urbanairship.api.push.model.PushModelObject;
import com.urbanairship.api.push.model.notification.DevicePayloadOverride;
import com.urbanairship.api.push.model.notification.Interactive;
import java.util.Map;
/**
* IOSDevicePayload for iOS specific push messages.
*/
public final class IOSDevicePayload extends PushModelObject implements DevicePayloadOverride {
private final Optional alert;
private final Optional> extra;
private final Optional sound;
private final Optional badge;
private final Optional contentAvailable;
private final Optional expiry;
private final Optional priority;
private final Optional category;
private final Optional interactive;
private final Optional title;
private IOSDevicePayload(Optional alert,
Optional sound,
Optional badge,
Optional contentAvailable,
Optional expiry,
Optional priority,
Optional> extra,
Optional category,
Optional interactive,
Optional title) {
this.alert = alert;
this.sound = sound;
this.badge = badge;
this.contentAvailable = contentAvailable;
this.extra = extra;
this.expiry = expiry;
this.priority = priority;
this.category = category;
this.interactive = interactive;
this.title = title;
}
/**
* Get an IOSPayloadBuilder
* @return IOSPayloadBuilder
*/
public static Builder newBuilder() {
return new Builder();
}
/**
* Get the deviceType.
* @return deviceType
*/
@Override
public DeviceType getDeviceType() {
return DeviceType.IOS;
}
/**
* Get the alert if present.
* @return alert
*/
@Override
public Optional getAlert() {
return alert.isPresent() ? alert.get().getBody() : Optional.absent();
}
/**
* Get the IOSAlertData
* @return IOSAlertData
*/
public Optional getAlertData() {
return alert;
}
/**
* Get the sound file name
* @return sound file name
*/
public Optional getSound() {
return sound;
}
/**
* Get IOSBadgeData
* @return IOSBadgeData
*/
public Optional getBadge() {
return badge;
}
/**
* Get the content available boolean value
* @return content available
*/
public Optional getContentAvailable() {
return contentAvailable;
}
/**
* Get a Map of the extra key value pairs
* @return key value pairs
*/
public Optional> getExtra() {
return extra;
}
/**
* Get the expiry (TTL) if present
* @return expiry value
*/
public Optional getExpiry() {
return expiry;
}
/**
* Get the priority value
* @return priority
*/
public Optional getPriority() {
return priority;
}
/**
* Get the category if present
* @return category
*/
public Optional getCategory() {
return category;
}
/**
* Get the Interactive data if present
* @return interactive
*/
public Optional getInteractive() {
return interactive;
}
/**
* Get the title if present.
* @return title
*/
public Optional getTitle() {
return title;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
IOSDevicePayload that = (IOSDevicePayload)o;
if (alert != null ? !alert.equals(that.alert) : that.alert != null) {
return false;
}
if (extra != null ? !extra.equals(that.extra) : that.extra != null) {
return false;
}
if (sound != null ? !sound.equals(that.sound) : that.sound != null) {
return false;
}
if (badge != null ? !badge.equals(that.badge) : that.badge != null) {
return false;
}
if (contentAvailable != null ? !contentAvailable.equals(that.contentAvailable) : that.contentAvailable != null) {
return false;
}
if (expiry != null ? ! expiry.equals(that.expiry) : that.expiry != null) {
return false;
}
if (priority != null ? ! priority.equals(that.priority) : that.priority != null) {
return false;
}
if (category!= null ? ! category.equals(that.category) : that.category != null) {
return false;
}
if (interactive!= null ? ! interactive.equals(that.interactive) : that.interactive != null) {
return false;
}
if (title!= null ? ! title.equals(that.title) : that.title != null) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = (alert != null ? alert.hashCode() : 0);
result = 31 * result + (extra != null ? extra.hashCode() : 0);
result = 31 * result + (sound != null ? sound.hashCode() : 0);
result = 31 * result + (badge != null ? badge.hashCode() : 0);
result = 31 * result + (contentAvailable != null ? contentAvailable.hashCode() : 0);
result = 31 * result + ( expiry != null ? expiry.hashCode() : 0);
result = 31 * result + (priority != null ? priority.hashCode() : 0);
result = 31 * result + (category != null ? category.hashCode() : 0);
result = 31 * result + (interactive != null ? interactive.hashCode() : 0);
result = 31 * result + (title != null ? title.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "IOSDevicePayload{" +
"alert=" + alert +
", extra=" + extra +
", sound=" + sound +
", badge=" + badge +
", expiry=" + expiry +
", priority" + priority +
", contentAvailable=" + contentAvailable +
", category=" + category +
", interactive=" + interactive +
", title=" + title +
'}';
}
public static class Builder {
private IOSAlertData alert = null;
private String sound = null;
private IOSBadgeData badge = null;
private Boolean contentAvailable = null;
private ImmutableMap.Builder extra = null;
private PushExpiry expiry = null;
private Integer priority = null;
private String category = null;
private Interactive interactive = null;
private String title = null;
private Builder() { }
/**
* Create an IOSAlertData object with the given alert string. This is a
* shortcut for setting an alert data object when no additional iOS
* APNS payload options are needed.
*
* @param alert String alert
* @return Builder
*/
public Builder setAlert(String alert) {
this.alert = IOSAlertData.newBuilder()
.setBody(alert)
.build();
return this;
}
/**
* Set the IOSAlertData object.
* @param alert IOSAlertData
* @return Builder
*/
public Builder setAlert(IOSAlertData alert) {
this.alert = alert;
return this;
}
/**
* Set the filename for the sound. A matching sound file that meets
* Apple requirements needs to reside on the device.
* @param sound Sound file name
* @return Builder
*/
public Builder setSound(String sound) {
this.sound = sound;
return this;
}
/**
* Set the badge data.
* @param badge IOSBadgeData
* @return Builder
*/
public Builder setBadge(IOSBadgeData badge) {
this.badge = badge;
return this;
}
/**
* Set the flag indicating content availability.
* @param value Boolean for content availability.
* @return Builder
*/
public Builder setContentAvailable(boolean value) {
this.contentAvailable = value;
return this;
}
/**
* Set the expiry
* @param value Integer
* @return Integer
**/
public Builder setExpiry(PushExpiry value) {
this.expiry = value;
return this;
}
/**
* Set the priority
* @param value Integer
* @return Integer
**/
public Builder setPriority(int value) {
this.priority = value;
return this;
}
/**
* Add an extra key value pair to the notification payload. Maximum
* payload is 2000 bytes.
* @param key String key
* @param value String value
* @return Builder
*/
public Builder addExtraEntry(String key, String value) {
if (extra == null) {
extra = ImmutableMap.builder();
}
this.extra.put(key, value);
return this;
}
/**
* Add key value pairs to payload. Maximum payload is 2000 bytes.
* @param entries Map of key value pairs
* @return Builder.
*/
public Builder addAllExtraEntries(Map entries) {
if (extra == null) {
extra = ImmutableMap.builder();
}
this.extra.putAll(entries);
return this;
}
/**
* Set the category
* @param value String
* @return String
*/
public Builder setCategory(String value) {
this.category = value;
return this;
}
/**
* Set the Interactive object
* @param value Interactive
* @return Interactive
*/
public Builder setInteractive(Interactive value) {
this.interactive = value;
return this;
}
/**
* Set the title
* @param value String
* @return String
*/
public Builder setTitle(String value) {
this.title = value;
return this;
}
/**
* Build IOSDevicePayload
* @return IOSDevicePayload
*/
public IOSDevicePayload build() {
// Yes, empty payloads are valid (for Passes)
return new IOSDevicePayload(Optional.fromNullable(alert),
Optional.fromNullable(sound),
Optional.fromNullable(badge),
Optional.fromNullable(contentAvailable),
Optional.fromNullable(expiry),
Optional.fromNullable(priority),
extra == null ? Optional.>absent() : Optional.fromNullable(extra.build()),
Optional.fromNullable(category),
Optional.fromNullable(interactive),
Optional.fromNullable(title));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy