-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support to modify notification small icon
- Loading branch information
Showing
4 changed files
with
89 additions
and
2 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
16 changes: 16 additions & 0 deletions
16
...agingpush/src/main/java/io/customer/messagingpush/extensions/ApplicationInfoExtensions.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,16 @@ | ||
package io.customer.messagingpush.extensions | ||
|
||
import android.content.res.Resources | ||
import android.os.Build | ||
import android.os.Bundle | ||
|
||
private val RESOURCE_ID_NULL: Int = | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) Resources.ID_NULL else 0 | ||
|
||
internal fun Bundle.getMetaDataResource(name: String): Int? { | ||
return getInt(name, RESOURCE_ID_NULL).takeUnless { id -> id == RESOURCE_ID_NULL } | ||
} | ||
|
||
internal fun Bundle.getMetaDataString(name: String): String? { | ||
return getString(name, null).takeUnless { value -> value.isNullOrBlank() } | ||
} |
25 changes: 25 additions & 0 deletions
25
messagingpush/src/main/java/io/customer/messagingpush/extensions/ContextExtensions.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,25 @@ | ||
package io.customer.messagingpush.extensions | ||
|
||
import android.content.Context | ||
import android.content.res.Resources | ||
import android.os.Build | ||
import androidx.annotation.ColorInt | ||
import androidx.annotation.ColorRes | ||
import androidx.annotation.DrawableRes | ||
import androidx.core.content.ContextCompat | ||
import io.customer.sdk.CustomerIO | ||
|
||
@DrawableRes | ||
internal fun Context.getDrawableByName(name: String?): Int? = if (name.isNullOrBlank()) null | ||
else resources?.getIdentifier(name, "drawable", packageName)?.takeUnless { id -> | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) id == Resources.ID_NULL | ||
else id == 0 | ||
} | ||
|
||
@ColorInt | ||
internal fun Context.getColorOrNull(@ColorRes id: Int): Int? = try { | ||
ContextCompat.getColor(this, id) | ||
} catch (ex: Resources.NotFoundException) { | ||
CustomerIO.instance().diGraph.logger.error("Invalid resource $id, ${ex.message}") | ||
null | ||
} |
14 changes: 14 additions & 0 deletions
14
messagingpush/src/main/java/io/customer/messagingpush/extensions/StringExtensions.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,14 @@ | ||
/* ktlint-disable filename */ // until this extension file contains 2+ functions in it, we will disable this ktlint rule. | ||
package io.customer.messagingpush.extensions | ||
|
||
import android.graphics.Color | ||
import androidx.annotation.DrawableRes | ||
import io.customer.sdk.CustomerIO | ||
|
||
@DrawableRes | ||
internal fun String.toColorOrNull(): Int? = try { | ||
Color.parseColor(this) | ||
} catch (ex: IllegalArgumentException) { | ||
CustomerIO.instance().diGraph.logger.error("Invalid color string $this, ${ex.message}") | ||
null | ||
} |