Skip to content

Commit

Permalink
Update OneSignal implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jahirfiquitiva committed May 18, 2021
1 parent 2075a10 commit 429c080
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 28 deletions.
8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
/*
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
Expand Down Expand Up @@ -42,6 +44,7 @@ android {
buildToolsVersion Versions.buildTools

defaultConfig {
buildConfigField("String", "ONESIGNAL_APP_ID", "\"$OneSignal.appId\"")
manifestPlaceholders = [
onesignal_app_id : OneSignal.appId,
onesignal_google_project_number: OneSignal.googleProjectNumber
Expand All @@ -67,6 +70,9 @@ android {
}

buildTypes {
buildTypes.each {
it.buildConfigField("String", "ONESIGNAL_APP_ID", "\"$OneSignal.appId\"")
}
release {
debuggable false
zipAlignEnabled true
Expand Down
8 changes: 7 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
-dontwarn okio.**
-dontwarn javax.annotation.**

-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
-keep public final class * extends android.view.AbsSavedState
-keepclassmembers public final class * extends android.view.AbsSavedState { *; }

# Retrofit
-keepattributes Signature, InnerClasses, EnclosingMethod
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
Expand All @@ -52,4 +58,4 @@
-keep,allowobfuscation interface <1>

-dontwarn
-ignorewarnings
-ignorewarnings
10 changes: 2 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,8 @@

<!-- OneSignal Notifications Service -->
<!-- TODO: Remove comment marks to enable
<service
android:name=".NotificationService"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE">
<intent-filter>
<action android:name="com.onesignal.NotificationExtender" />
</intent-filter>
</service>
<meta-data android:name="com.onesignal.NotificationServiceExtension"
android:value="${applicationId}.NotificationServiceExtension" />
-->
</application>
</manifest>
20 changes: 15 additions & 5 deletions app/src/main/kotlin/dev/jahir/blueprint/app/MyApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ import dev.jahir.frames.ui.FramesApplication

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

class MyApplication : FramesApplication() {
override fun onCreate() {
super.onCreate()
// TODO: Remove comment marks to enable
/*
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init()
OneSignal.initWithContext(this);
OneSignal.setAppId(BuildConfig.ONESIGNAL_APP_ID);
OneSignal.setNotificationWillShowInForegroundHandler { notificationReceivedEvent: OSNotificationReceivedEvent ->
notificationReceivedEvent.complete(
if (preferences.notificationsEnabled)
notificationReceivedEvent.notification
else null
)
}
OneSignal.unsubscribeWhenNotificationsAreDisabled(true)
OneSignal.pauseInAppMessages(true)
OneSignal.setLocationShared(false)
*/
}
}
}
12 changes: 0 additions & 12 deletions app/src/main/kotlin/dev/jahir/blueprint/app/NotificationService.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dev.jahir.blueprint.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.extensions.context.color
import dev.jahir.frames.extensions.context.drawable
import dev.jahir.frames.extensions.context.preferences
class NotificationServiceExtension : OSRemoteNotificationReceivedHandler {
override fun remoteNotificationReceived(
context: Context,
notificationReceivedEvent: OSNotificationReceivedEvent
) {
if(!context.preferences.notificationsEnabled) {
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)
}
notificationReceivedEvent.complete(mutableNotification)
}
}
*/
8 changes: 7 additions & 1 deletion library/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
-dontwarn okio.**
-dontwarn javax.annotation.**

-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
-keep public final class * extends android.view.AbsSavedState
-keepclassmembers public final class * extends android.view.AbsSavedState { *; }

# Retrofit
-keepattributes Signature, InnerClasses, EnclosingMethod
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
Expand All @@ -52,4 +58,4 @@
-keep,allowobfuscation interface <1>

-dontwarn
-ignorewarnings
-ignorewarnings

0 comments on commit 429c080

Please sign in to comment.