-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setNotificationsOptions end point (#321)
* make notification take same custom icon and background as foreground service * implemented new radarnotificationsoptions class with usage in creating notifications and tests * cleanup * make name singular and formatting changes * changed comments * add punctioation to comment * spacing formatting
- Loading branch information
1 parent
c09eebe
commit 00dc134
Showing
7 changed files
with
214 additions
and
7 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
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
93 changes: 93 additions & 0 deletions
93
sdk/src/main/java/io/radar/sdk/RadarNotificationOptions.kt
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,93 @@ | ||
package io.radar.sdk | ||
|
||
import org.json.JSONObject | ||
import java.util.Date | ||
|
||
/** | ||
* An options class used to configure local notifications. | ||
* | ||
* @see [](https://radar.com/documentation/sdk/android) | ||
*/ | ||
data class RadarNotificationOptions( | ||
/** | ||
* Determines the name of the asset to be used for notifications. Optional, defaults to app icon. | ||
*/ | ||
val iconString: String? = null, | ||
|
||
/** | ||
* Determines the background color of used for notifications. Optional. | ||
*/ | ||
val iconColor: String? = null, | ||
|
||
/** | ||
* Determines the name of the asset to be used for forgroundService notifications. Optional, defaults to iconString. | ||
*/ | ||
val foregroundServiceIconString: String? = null, | ||
|
||
/** | ||
* Determines the name of the asset to be used for forgroundService notifications. Optional, defaults to iconString. | ||
*/ | ||
val foregroundServiceIconColor: String? = null, | ||
|
||
/** | ||
* Determines the name of the asset to be used for event notifications. Optional, defaults to iconString. | ||
*/ | ||
val eventIconString:String? = null, | ||
|
||
/** | ||
* Determines the name of the asset to be used for event notifications. Optional, defaults to iconString. | ||
*/ | ||
val eventIconColor: String? = null, | ||
) { | ||
|
||
companion object { | ||
|
||
internal const val KEY_ICON_STRING = "iconString" | ||
internal const val KEY_ICON_COLOR = "iconColor" | ||
internal const val KEY_FOREGROUNDSERVICE_ICON_STRING = "foregroundServiceIconString" | ||
internal const val KEY_FOREGROUNDSERVICE_ICON_COLOR = "foregroundServiceIconColor" | ||
internal const val KEY_EVENT_ICON_STRING = "eventIconString" | ||
internal const val KEY_EVENT_ICON_COLOR = "eventIconColor" | ||
|
||
|
||
@JvmStatic | ||
fun fromJson(obj: JSONObject): RadarNotificationOptions { | ||
val iconString = if (obj.isNull(KEY_ICON_STRING)) null else obj.optString(KEY_ICON_STRING) | ||
val iconColor = if (obj.isNull(KEY_ICON_COLOR)) null else obj.optString(KEY_ICON_COLOR) | ||
val foregroundServiceIconString = if (obj.isNull(KEY_FOREGROUNDSERVICE_ICON_STRING)) null else obj.optString(KEY_FOREGROUNDSERVICE_ICON_STRING) | ||
val foregroundServiceIconColor = if (obj.isNull(KEY_FOREGROUNDSERVICE_ICON_COLOR)) null else obj.optString(KEY_FOREGROUNDSERVICE_ICON_COLOR) | ||
val eventIconString = if (obj.isNull(KEY_EVENT_ICON_STRING)) null else obj.optString(KEY_EVENT_ICON_STRING) | ||
val eventIconColor = if (obj.isNull(KEY_EVENT_ICON_COLOR)) null else obj.optString(KEY_EVENT_ICON_COLOR) | ||
|
||
return RadarNotificationOptions(iconString, iconColor, foregroundServiceIconString, foregroundServiceIconColor, eventIconString, eventIconColor) | ||
} | ||
} | ||
|
||
fun toJson(): JSONObject { | ||
val obj = JSONObject() | ||
obj.put(KEY_ICON_STRING, iconString) | ||
obj.put(KEY_ICON_COLOR, iconColor) | ||
obj.put(KEY_FOREGROUNDSERVICE_ICON_STRING, foregroundServiceIconString) | ||
obj.put(KEY_FOREGROUNDSERVICE_ICON_COLOR, foregroundServiceIconColor) | ||
obj.put(KEY_EVENT_ICON_STRING, eventIconString) | ||
obj.put(KEY_EVENT_ICON_COLOR, eventIconColor) | ||
return obj | ||
} | ||
|
||
fun getForegroundServiceIcon(): String? { | ||
return foregroundServiceIconString ?: iconString | ||
} | ||
|
||
fun getForegroundServiceColor(): String? { | ||
return foregroundServiceIconColor ?: iconColor | ||
} | ||
|
||
fun getEventIcon(): String? { | ||
return eventIconString ?: iconString | ||
} | ||
|
||
fun getEventColor(): String? { | ||
return eventIconColor ?: iconColor | ||
} | ||
|
||
} |
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