Skip to content

Commit

Permalink
Add colour field to setForegroundOptions (#320)
Browse files Browse the repository at this point in the history
* Change notification icon from an integer to a string in RadarForegroundService and RadarTrackingOptions

* Change notification icon type from integer to string in RadarForegroundService and RadarLocationManager

* fix for test

* bump version and also add toJson field

* added back icon as default

* change val to var

* make calls with unexplicit parameter naming non-breaking

* cahnge back icon int

* added color field and changed tests
  • Loading branch information
KennyHuRadar authored Nov 10, 2023
1 parent 0231cec commit c09eebe
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply plugin: "org.jetbrains.dokka"
apply plugin: 'io.radar.mvnpublish'

ext {
radarVersion = '3.8.14'
radarVersion = '3.8.15'
}

String buildNumber = ".${System.currentTimeMillis()}"
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/main/java/io/radar/sdk/RadarForegroundService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.radar.sdk

import android.app.*
import android.content.Intent
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.os.IBinder
Expand Down Expand Up @@ -57,6 +58,7 @@ class RadarForegroundService : Service() {
val text = extras?.getString("text") ?: "Location tracking started"
var icon = extras?.getInt("icon") ?: 0
var iconString = extras?.getString("iconString") ?: this.applicationInfo.icon.toString()
var iconColor = extras?.getString("iconColor") ?: ""
var smallIcon = resources.getIdentifier(iconString, "drawable", applicationContext.packageName)
if (icon != 0){
smallIcon = resources.getIdentifier(icon.toString(), "drawable", applicationContext.packageName)
Expand All @@ -72,6 +74,9 @@ class RadarForegroundService : Service() {
if (title != null && title.isNotEmpty()) {
builder = builder.setContentTitle(title as CharSequence?)
}
if (iconColor.isNotEmpty()) {
builder.setColor(Color.parseColor(iconColor))
}
try {
extras?.getString("activity")?.let {
val activityClass = Class.forName(it)
Expand Down
1 change: 1 addition & 0 deletions sdk/src/main/java/io/radar/sdk/RadarLocationManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ internal class RadarLocationManager(
.putExtra("text", foregroundService.text)
.putExtra("icon", foregroundService.icon)
.putExtra("iconString", foregroundService.iconString)
.putExtra("iconColor", foregroundService.iconColor)
.putExtra("activity", foregroundService.activity)
logger.d("Starting foreground service with intent | intent = $intent")
context.applicationContext.startForegroundService(intent)
Expand Down
13 changes: 10 additions & 3 deletions sdk/src/main/java/io/radar/sdk/RadarTrackingOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,19 @@ data class RadarTrackingOptions(
* Determines the notification icon, like `R.drawable.ic_your_icon`. Optional, defaults to `applicationContext.applicationInfo.icon`.
*/
val iconString: String? = null,

/**
* Determines the color notification icon. Optional.
*/
val iconColor: String? = null,
) {

companion object {
internal const val KEY_FOREGROUND_SERVICE_TEXT = "text"
internal const val KEY_FOREGROUND_SERVICE_TITLE = "title"
internal const val KEY_FOREGROUND_SERVICE_ICON = "icon"
internal const val KEY_FOREGROUND_SERVICE_ICON_STRING = "iconString"
internal const val KEY_FOREGROUND_SERVICE_ICON_COLOR = "iconColor"
internal const val KEY_FOREGROUND_SERVICE_UPDATES_ONLY = "updatesOnly"
internal const val KEY_FOREGROUND_SERVICE_ACTIVITY = "activity"
internal const val KEY_FOREGROUND_SERVICE_IMPORTANCE = "importance"
Expand All @@ -317,13 +323,13 @@ data class RadarTrackingOptions(
val title = if (obj.isNull(KEY_FOREGROUND_SERVICE_TITLE)) null else obj.optString(KEY_FOREGROUND_SERVICE_TITLE)
val icon = if (obj.isNull(KEY_FOREGROUND_SERVICE_ICON)) null else obj.optInt(KEY_FOREGROUND_SERVICE_ICON)
val iconString = if (obj.isNull(KEY_FOREGROUND_SERVICE_ICON_STRING)) null else obj.optString(KEY_FOREGROUND_SERVICE_ICON_STRING)
val iconColor = if (obj.isNull(KEY_FOREGROUND_SERVICE_ICON_COLOR)) null else obj.optString(KEY_FOREGROUND_SERVICE_ICON_COLOR)
val updatesOnly: Boolean = obj.optBoolean(KEY_FOREGROUND_SERVICE_UPDATES_ONLY)
val activity = if (obj.isNull(KEY_FOREGROUND_SERVICE_ACTIVITY)) null else obj.optString(KEY_FOREGROUND_SERVICE_ACTIVITY)
val importance = if (obj.isNull(KEY_FOREGROUND_SERVICE_IMPORTANCE)) null else obj.optInt(KEY_FOREGROUND_SERVICE_IMPORTANCE)
val id = if (obj.isNull(KEY_FOREGROUND_SERVICE_ID)) null else obj.optInt(KEY_FOREGROUND_SERVICE_ID)
val channelName = if (obj.isNull(KEY_FOREGROUND_SERVICE_CHANNEL_NAME)) null else obj.optString(KEY_FOREGROUND_SERVICE_CHANNEL_NAME)

return RadarTrackingOptionsForegroundService(text, title, icon, updatesOnly, activity, importance, id, channelName, iconString)
return RadarTrackingOptionsForegroundService(text, title, icon, updatesOnly, activity, importance, id, channelName, iconString, iconColor)
}
}

Expand All @@ -333,7 +339,8 @@ data class RadarTrackingOptions(
obj.put(KEY_FOREGROUND_SERVICE_TEXT, text)
obj.put(KEY_FOREGROUND_SERVICE_TITLE, title)
obj.put(KEY_FOREGROUND_SERVICE_ICON, icon)
obj.put(KEY_FOREGROUND_SERVICE_ICON_STRING, iconString)
obj.put(KEY_FOREGROUND_SERVICE_ICON_STRING, iconString)
obj.put(KEY_FOREGROUND_SERVICE_ICON_COLOR, iconColor)
obj.put(KEY_FOREGROUND_SERVICE_ACTIVITY, activity)
obj.put(KEY_FOREGROUND_SERVICE_UPDATES_ONLY, updatesOnly)
obj.put(KEY_FOREGROUND_SERVICE_IMPORTANCE, importance)
Expand Down
10 changes: 6 additions & 4 deletions sdk/src/test/java/io/radar/sdk/RadarTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,12 @@ class RadarTest {
Radar.stopTracking()

Radar.setForegroundServiceOptions(RadarTrackingOptions.RadarTrackingOptionsForegroundService(
"Text",
"Title",
1337,
true
text="Text",
title = "Title",
icon = 1337,
iconString = "test",
updatesOnly = true,
iconColor = "#FF0000"
))

val options = RadarTrackingOptions.EFFICIENT
Expand Down

0 comments on commit c09eebe

Please sign in to comment.