diff --git a/app/build.gradle b/app/build.gradle index c07b8b9eb..b4450eeff 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,9 @@ /* buildscript { repositories { - maven { url 'https://plugins.gradle.org/m2/' } + google() + mavenCentral() + gradlePluginPortal() } dependencies { @@ -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 @@ -67,6 +70,9 @@ android { } buildTypes { + buildTypes.each { + it.buildConfigField("String", "ONESIGNAL_APP_ID", "\"$OneSignal.appId\"") + } release { debuggable false zipAlignEnabled true diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 25d65e5d4..83635918a 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -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 @@ -52,4 +58,4 @@ -keep,allowobfuscation interface <1> -dontwarn --ignorewarnings \ No newline at end of file +-ignorewarnings diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 338a556b3..08285ecba 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -278,14 +278,8 @@ diff --git a/app/src/main/kotlin/dev/jahir/blueprint/app/MyApplication.kt b/app/src/main/kotlin/dev/jahir/blueprint/app/MyApplication.kt index a5b2e0a43..72f952358 100644 --- a/app/src/main/kotlin/dev/jahir/blueprint/app/MyApplication.kt +++ b/app/src/main/kotlin/dev/jahir/blueprint/app/MyApplication.kt @@ -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) */ } -} \ No newline at end of file +} diff --git a/app/src/main/kotlin/dev/jahir/blueprint/app/NotificationService.kt b/app/src/main/kotlin/dev/jahir/blueprint/app/NotificationService.kt deleted file mode 100644 index 9df6d4974..000000000 --- a/app/src/main/kotlin/dev/jahir/blueprint/app/NotificationService.kt +++ /dev/null @@ -1,12 +0,0 @@ -package dev.jahir.blueprint.app - -/* TODO: Remove comment marks to enable -import com.onesignal.NotificationExtenderService -import com.onesignal.OSNotificationReceivedResult -import dev.jahir.frames.extensions.context.preferences - -class NotificationService : NotificationExtenderService() { - override fun onNotificationProcessing(notification: OSNotificationReceivedResult?): Boolean = - !preferences.notificationsEnabled -} -*/ \ No newline at end of file diff --git a/app/src/main/kotlin/dev/jahir/blueprint/app/NotificationServiceExtension.kt b/app/src/main/kotlin/dev/jahir/blueprint/app/NotificationServiceExtension.kt new file mode 100644 index 000000000..92ac3145e --- /dev/null +++ b/app/src/main/kotlin/dev/jahir/blueprint/app/NotificationServiceExtension.kt @@ -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) + } +} +*/ diff --git a/library/proguard-rules.pro b/library/proguard-rules.pro index 25d65e5d4..83635918a 100644 --- a/library/proguard-rules.pro +++ b/library/proguard-rules.pro @@ -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 @@ -52,4 +58,4 @@ -keep,allowobfuscation interface <1> -dontwarn --ignorewarnings \ No newline at end of file +-ignorewarnings