Skip to content

Commit

Permalink
fix: update OneSignal implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jahirfiquitiva committed Jan 3, 2024
1 parent bbcfdba commit fa1f9d7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

-keep class dev.jahir.frames.** { *; }

-keep class androidx.core.app.CoreComponentFactory { *; }
-keep class com.google.**
-keep class autovalue.shaded.com.google.**
-keep class com.android.vending.billing.**
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/kotlin/dev/jahir/frames/app/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dev.jahir.frames.app

import dev.jahir.frames.ui.FramesApplication

// TODO: Remove comment marks to enable
// import com.onesignal.OneSignal
// import com.onesignal.OSNotificationReceivedEvent
// import com.onesignal.OneSignal
// import dev.jahir.frames.extensions.context.preferences
import dev.jahir.frames.ui.FramesApplication

class MyApplication : FramesApplication(BuildConfig.ONESIGNAL_APP_ID) {
override fun onCreate() {
Expand All @@ -26,6 +25,6 @@ class MyApplication : FramesApplication(BuildConfig.ONESIGNAL_APP_ID) {
OneSignal.unsubscribeWhenNotificationsAreDisabled(true)
OneSignal.pauseInAppMessages(true)
OneSignal.setLocationShared(false)
*/
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@ package dev.jahir.frames.app

/* TODO: Remove comment marks to enable
import android.content.Context
import androidx.core.app.NotificationCompat
import com.onesignal.OSNotificationReceivedEvent
import com.onesignal.OneSignal.OSRemoteNotificationReceivedHandler
import dev.jahir.frames.R
import dev.jahir.frames.extensions.context.color
import dev.jahir.frames.extensions.context.drawable
import dev.jahir.frames.extensions.context.preferences
import dev.jahir.frames.extensions.context.hasNotificationsPermission
import dev.jahir.frames.extensions.context.preferences
class NotificationServiceExtension : OSRemoteNotificationReceivedHandler {
override fun remoteNotificationReceived(
context: Context,
notificationReceivedEvent: OSNotificationReceivedEvent
) {
if(!context.preferences.notificationsEnabled || !context.hasNotificationsPermission) {
if (!context.preferences.notificationsEnabled || !context.hasNotificationsPermission) {
notificationReceivedEvent.complete(null)
return
}
val notification = notificationReceivedEvent.notification
val mutableNotification = notification.mutableCopy()
mutableNotification.setExtender { builder: NotificationCompat.Builder ->
builder.color = context.color(R.color.accent)
builder.setSmallIcon(R.drawable.ic_notification)
mutableNotification.setExtender { extender ->
extender.apply {
color = context.color(R.color.accent)
setSmallIcon(R.drawable.ic_notification)
}
}
notificationReceivedEvent.complete(mutableNotification)
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Versions {
const val ksp = "$kotlin-1.0.16"

// OneSignal
const val oneSignal = "4.8.6"
const val oneSignal = "4.8.7"

// App
const val minSdk = 21
Expand Down
1 change: 1 addition & 0 deletions library/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

-keep class dev.jahir.frames.** { *; }

-keep class androidx.core.app.CoreComponentFactory { *; }
-keep class com.google.**
-keep class autovalue.shaded.com.google.**
-keep class com.android.vending.billing.**
Expand Down

0 comments on commit fa1f9d7

Please sign in to comment.