├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── notification.xml │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── grumpyshoe │ │ │ │ └── modules │ │ │ │ └── pushmanager │ │ │ │ └── sample │ │ │ │ ├── Utils.kt │ │ │ │ ├── NotificationActivity.kt │ │ │ │ ├── MyService.kt │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── grumpyshoe │ │ │ └── modules │ │ │ └── pushmanager │ │ │ └── sample │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── grumpyshoe │ │ └── modules │ │ └── pushmanager │ │ └── sample │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── pushmanager ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ └── fcm.xml │ │ │ ├── drawable-hdpi │ │ │ │ └── baseline_notifications_black.png │ │ │ └── drawable │ │ │ │ └── ic_baseline_notifications_24px.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── grumpyshoe │ │ │ │ └── module │ │ │ │ └── pushmanager │ │ │ │ ├── models │ │ │ │ ├── NotificationLight.kt │ │ │ │ ├── RemoteMessageData.kt │ │ │ │ └── NotificationData.kt │ │ │ │ ├── PushManager.kt │ │ │ │ └── impl │ │ │ │ ├── PushManagerImpl.kt │ │ │ │ └── PushmanagerMessagingService.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── grumpyshoe │ │ │ └── pushmanager │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── grumpyshoe │ │ └── pushmanager │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── CHANGELOG.md ├── gradle.properties ├── LICENSE ├── gradlew.bat ├── gradlew └── README.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':pushmanager' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Pushmanager 3 | 4 | -------------------------------------------------------------------------------- /pushmanager/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Pushmanager 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.iml 2 | **/.gradle 3 | **/local.properties 4 | **/.idea 5 | **/.DS_Store 6 | **/build 7 | **/captures 8 | **/.externalNativeBuild 9 | **/google-services.json 10 | -------------------------------------------------------------------------------- /pushmanager/src/main/res/values/fcm.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | default_channel 4 | -------------------------------------------------------------------------------- /pushmanager/src/main/res/drawable-hdpi/baseline_notifications_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grumpyshoe/android-module-pushmanager/HEAD/pushmanager/src/main/res/drawable-hdpi/baseline_notifications_black.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jan 29 20:45:17 CET 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /pushmanager/src/main/java/com/grumpyshoe/module/pushmanager/models/NotificationLight.kt: -------------------------------------------------------------------------------- 1 | package com.grumpyshoe.module.pushmanager.models 2 | 3 | /** 4 | *

NotificationLight contains all information for handling smartphone-led on incoming message

5 | * 6 | * @since 1.0.0 7 | * @version 1.0.0 8 | * @author grumpyshoe 9 | * 10 | */ 11 | data class NotificationLight(val argb: Int, val onMS: Int, val offMS: Int) -------------------------------------------------------------------------------- /app/src/main/java/com/grumpyshoe/modules/pushmanager/sample/Utils.kt: -------------------------------------------------------------------------------- 1 | package com.grumpyshoe.modules.pushmanager.sample 2 | 3 | import android.content.Context 4 | import android.widget.TextView 5 | import android.widget.Toast 6 | 7 | fun Context.toast(message: String, duration: Int = Toast.LENGTH_SHORT) = Toast.makeText(this, message, duration).show() 8 | fun TextView.onUI(action: (TextView) -> Unit) { 9 | this.post { action(this) } 10 | } -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/grumpyshoe/modules/pushmanager/sample/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.grumpyshoe.modules.pushmanager.sample 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pushmanager/src/test/java/com/grumpyshoe/pushmanager/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.grumpyshoe.pushmanager; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /pushmanager/src/main/res/drawable/ic_baseline_notifications_24px.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/grumpyshoe/modules/pushmanager/sample/NotificationActivity.kt: -------------------------------------------------------------------------------- 1 | package com.grumpyshoe.modules.pushmanager.sample 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import kotlinx.android.synthetic.main.notification.* 6 | 7 | 8 | class NotificationActivity : AppCompatActivity() { 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | setContentView(R.layout.notification) 13 | 14 | notification.text = intent.extras?.getString("type") ?: "param 'type' not found" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /pushmanager/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # Changelog 3 | 4 | ## 1.3.1 5 | 6 | 7 | 8 | ## 1.3.0 9 | 10 | * Bump dependencies to latest version. 11 | 12 | ### BREAKING CHANGES 13 | 14 | * The functions `register` and `unregister` are now suspend functions so you need to use a coroutine context to run this. Example at the sample app. 15 | 16 | 17 | ## 1.2.2 18 | 19 | * Bump dependencies to latest version. 20 | 21 | 22 | ## 1.2.1 23 | 24 | * Make return value for `handleNotificationPayload` nullable. If this method returns _null_ no notification will be generated. 25 | 26 | 27 | ## 1.2.0 28 | 29 | * Change structure of how to implement payload handling 30 | 31 | 32 | ## 1.1.0 33 | 34 | * Change PendingIntent handling and move it's logic to `NotificationData`. -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /pushmanager/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/grumpyshoe/modules/pushmanager/sample/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.grumpyshoe.modules.pushmanager.sample 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.grumpyshoe.modules.pushmanager.sample", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pushmanager/src/androidTest/java/com/grumpyshoe/pushmanager/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.grumpyshoe.pushmanager; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.grumpyshoe.locationmanager.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | 14 | android.useAndroidX=true 15 | # Automatically convert third-party libraries to use AndroidX 16 | android.enableJetifier=true 17 | # Kotlin code style for this project: "official" or "obsolete": 18 | kotlin.code.style=official -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 grumpyshoe 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/notification.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | 8 | android { 9 | compileSdkVersion compile_sdk_version 10 | defaultConfig { 11 | applicationId application_id 12 | minSdkVersion min_sdk_version 13 | targetSdkVersion target_sdk_version 14 | versionCode version_code 15 | versionName version_name 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(include: ['*.jar'], dir: 'libs') 28 | implementation project(':pushmanager') 29 | implementation libs.kotlin 30 | implementation libs.appcompat 31 | implementation libs.constraint_layout 32 | implementation libs.coroutines 33 | testImplementation libs.junit 34 | androidTestImplementation libs.test_runner 35 | androidTestImplementation libs.espresso_core 36 | } 37 | 38 | 39 | apply plugin: 'com.google.gms.google-services' -------------------------------------------------------------------------------- /pushmanager/src/main/java/com/grumpyshoe/module/pushmanager/PushManager.kt: -------------------------------------------------------------------------------- 1 | package com.grumpyshoe.module.pushmanager 2 | 3 | import android.content.Context 4 | import com.grumpyshoe.module.pushmanager.models.NotificationData 5 | import com.grumpyshoe.module.pushmanager.models.RemoteMessageData 6 | 7 | 8 | /** 9 | *

PushManager - interface for easy access to FCM

10 | * 11 | * @version 1.3.0 12 | * @since 1.0.0 13 | * @author grumpyshoe 14 | * 15 | */ 16 | interface PushManager { 17 | 18 | 19 | /** 20 | * register device for cloudmessaging 21 | * 22 | */ 23 | suspend fun register(context: Context, onTokenReceived: (String) -> Unit, onFailure: (Exception?) -> Unit) 24 | 25 | 26 | /** 27 | * delete this Firebase app installation from the Firebase backend 28 | * 29 | */ 30 | suspend fun unregister(context: Context) 31 | 32 | 33 | /** 34 | * subscribe to topic 35 | * 36 | */ 37 | fun subscribeToTopic(topic: String, onSuccess: (() -> Unit)? = null, onFailure: ((Exception?) -> Unit)? = null) 38 | 39 | 40 | /** 41 | * unsubscribe from topic 42 | * 43 | */ 44 | fun unsubscribeFromTopic(topic: String, onSuccess: (() -> Unit)? = null, onFailure: ((Exception?) -> Unit)? = null) 45 | 46 | } -------------------------------------------------------------------------------- /pushmanager/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'maven' 5 | 6 | android { 7 | compileSdkVersion compile_sdk_version 8 | 9 | defaultConfig { 10 | minSdkVersion min_sdk_version 11 | targetSdkVersion target_sdk_version 12 | buildToolsVersion build_tools_version 13 | versionCode version_code 14 | versionName version_name 15 | 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | 27 | } 28 | 29 | dependencies { 30 | implementation fileTree(include: ['*.jar'], dir: 'libs') 31 | implementation libs.kotlin 32 | implementation libs.appcompat 33 | api libs.firebase_core 34 | api libs.firebase_iid 35 | api libs.firebase_messaging 36 | 37 | testImplementation libs.junit 38 | 39 | androidTestImplementation libs.test_runner 40 | androidTestImplementation libs.espresso_core 41 | } 42 | 43 | repositories { 44 | mavenCentral() 45 | google() 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /pushmanager/src/main/java/com/grumpyshoe/module/pushmanager/models/RemoteMessageData.kt: -------------------------------------------------------------------------------- 1 | package com.grumpyshoe.module.pushmanager.models 2 | 3 | import android.net.Uri 4 | 5 | /** 6 | *

RemoteMessageData is a model for holding all notification information that's available from incomming message

7 | * 8 | * @since 1.0.0 9 | * @version 1.0.0 10 | * @author grumpyshoe 11 | * 12 | */ 13 | data class RemoteMessageData( 14 | var tag: String? = null, 15 | var bodyLocalizationKey: String? = null, 16 | var bodyLocalizationArgs: Array? = null, 17 | var title: String? = null, 18 | var body: String? = null, 19 | var clickAction: String? = null, 20 | var color: String? = null, 21 | var icon: String? = null, 22 | var link: Uri? = null, 23 | var sound: String? = null, 24 | var titleLocalizationKey: String? = null, 25 | var titleLocalizationArgs: Array? = null, 26 | var data: MutableMap? = null, 27 | var messageType: String? = null, 28 | var collapseKey: String? = null, 29 | var from: String? = null, 30 | var messageId: String? = null, 31 | var originalPriority: Int? = null, 32 | var priority: Int? = null, 33 | var sentTime: Long? = null, 34 | var to: String? = null, 35 | var ttl: String? = null) -------------------------------------------------------------------------------- /app/src/main/java/com/grumpyshoe/modules/pushmanager/sample/MyService.kt: -------------------------------------------------------------------------------- 1 | package com.grumpyshoe.modules.pushmanager.sample 2 | 3 | import android.app.PendingIntent 4 | import android.content.Context 5 | import android.content.Intent 6 | import android.util.Log 7 | import com.grumpyshoe.module.pushmanager.impl.PushmanagerMessagingService 8 | import com.grumpyshoe.module.pushmanager.models.NotificationData 9 | import com.grumpyshoe.module.pushmanager.models.RemoteMessageData 10 | 11 | class MyService : PushmanagerMessagingService() { 12 | 13 | override fun handleNotificationPayload(context:Context, remoteMessageData: RemoteMessageData): NotificationData? { 14 | Log.d("PushManager", "handlePayload - ${remoteMessageData.title} - ${remoteMessageData.body}") 15 | 16 | // create pending intent 17 | val notificationIntent = Intent(context, NotificationActivity::class.java) 18 | notificationIntent.putExtra("type", remoteMessageData.title ?: "Default Title"+" " 19 | +remoteMessageData.body ?: "Default Message") 20 | notificationIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP 21 | val contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT) 22 | 23 | // create NotificationData containing all necessary information 24 | return NotificationData( 25 | context = context, 26 | title = remoteMessageData.title ?: "Default Title", 27 | message = remoteMessageData.body ?: "Default Message", 28 | channelId = "channel_global_notifications", // needed for SDK >= Android "O" (Oreo) 29 | autoCancel = true, 30 | pendingIntent = contentIntent) 31 | } 32 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /pushmanager/src/main/java/com/grumpyshoe/module/pushmanager/models/NotificationData.kt: -------------------------------------------------------------------------------- 1 | package com.grumpyshoe.module.pushmanager.models 2 | 3 | import android.app.PendingIntent 4 | import android.content.Context 5 | import android.media.RingtoneManager 6 | import android.net.Uri 7 | import com.grumpyshoe.pushmanager.R 8 | 9 | /** 10 | *

NotificationData is a wrapper for creating a custom notification based on a incomming remote message.

11 | * 12 | * @since 1.0.0 13 | * @version 1.0.0 14 | * @author grumpyshoe 15 | * 16 | */ 17 | data class NotificationData(val context: Context, 18 | val title: String, 19 | val message: String, 20 | val soundUri: Uri? = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), 21 | val smallIcon: Int = R.drawable.ic_baseline_notifications_24px, 22 | val autoCancel: Boolean = true, 23 | val channelId: String = context.getString(R.string.default_notification_channel_id), 24 | var color: Int? = null, 25 | val colorize: Boolean = false, 26 | val contentInfo: String? = null, 27 | val category: String? = null, 28 | val light: NotificationLight? = null, 29 | val timeoutAfter: Long? = null, 30 | val subtext: String? = null, 31 | val publicVersion: NotificationData? = null, 32 | val onGoing: Boolean? = null, 33 | val ticker: String? = null, 34 | val useChronometer: Boolean? = null, 35 | val notificationId: Int? = null, 36 | val pendingIntent: PendingIntent? = null, 37 | val notificationType: NotificationType = NotificationType.STACK) 38 | 39 | enum class NotificationType { SINGLE, STACK } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 23 | 24 |