diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index d344688..3dc0a58 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -17,7 +17,6 @@
android:theme="@style/AppTheme.Splash">
-
@@ -31,6 +30,14 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/mobiledevpro/app/common/App.kt b/app/src/main/java/com/mobiledevpro/app/common/App.kt
index 5019b8e..5361272 100644
--- a/app/src/main/java/com/mobiledevpro/app/common/App.kt
+++ b/app/src/main/java/com/mobiledevpro/app/common/App.kt
@@ -1,8 +1,12 @@
package com.mobiledevpro.app.common
import android.app.Application
+import android.util.Log
+import com.google.android.gms.tasks.OnCompleteListener
+import com.google.firebase.iid.FirebaseInstanceId
import com.mobiledevpro.app.BuildConfig
import com.mobiledevpro.app.di.*
+import com.mobiledevpro.data.LOG_TAG_DEBUG
import com.testfairy.TestFairy
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
@@ -27,13 +31,13 @@ class App : Application() {
initKoin()
initTimber()
- /*
if (BuildConfig.DEBUG) {
- initStetho()
- initFlipper()
- }
+ // initStetho()
+ // initFlipper()
- */
+ //its only for debug
+ retrieveFirebaseToken()
+ }
//Beta testing (where release is published)
TestFairy.begin(this, "6f9121c053a0dabdfa96dbb31c5c128860c119b3");
@@ -54,6 +58,21 @@ class App : Application() {
dataRemoteModule
)
+ private fun retrieveFirebaseToken() {
+ FirebaseInstanceId.getInstance().instanceId
+ .addOnCompleteListener(OnCompleteListener { task ->
+ if (!task.isSuccessful) {
+ Log.d(LOG_TAG_DEBUG, "retrieveFirebaseToken failed", task.exception)
+ return@OnCompleteListener
+ }
+
+ // Get new Instance ID token
+ val token = task.result?.token
+
+ Log.d(LOG_TAG_DEBUG, "Firebase token: $token")
+ })
+ }
+
/*
private fun initStetho() {
Stetho.initializeWithDefaults(this)
diff --git a/build.gradle b/build.gradle
index abd34a4..6dd9678 100644
--- a/build.gradle
+++ b/build.gradle
@@ -65,6 +65,7 @@ ext {
flipperVersion = '0.33.1'
soloaderVersion = "0.8.2"
testfairyVersion = '1.+@aar'
+ firebaseMessagingVersion = "20.1.4"
deps = [
"multidex" : "androidx.multidex:multidex:$multidexVersion",
@@ -80,6 +81,7 @@ ext {
"firebasePerformance" : "com.google.firebase:firebase-perf:$firebasePerfVersion",
"crashlytics" : "com.google.firebase:firebase-crashlytics:$crashlyticsVersion",
"firebaseAnalytics" : "com.google.firebase:firebase-analytics:$analyticsVersion",
+ "fcm" : "com.google.firebase:firebase-messaging:$firebaseMessagingVersion",
"coreKtx" : "androidx.core:core-ktx:$coreKtxVersion",
"kotlin" : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion",
diff --git a/data-remote/build.gradle b/data-remote/build.gradle
index 8fc8f8e..522b48a 100644
--- a/data-remote/build.gradle
+++ b/data-remote/build.gradle
@@ -9,4 +9,7 @@ dependencies {
implementation deps.retrofitGsonConverter
implementation deps.retrofitRx
implementation deps.okhttpLoggingInterceptor
+
+ //Firebase messaging
+ implementation deps.fcm
}
diff --git a/data-remote/src/main/java/com/mobiledevpro/remote/service/notification/FirebaseMessagingService.kt b/data-remote/src/main/java/com/mobiledevpro/remote/service/notification/FirebaseMessagingService.kt
new file mode 100644
index 0000000..18e8c5c
--- /dev/null
+++ b/data-remote/src/main/java/com/mobiledevpro/remote/service/notification/FirebaseMessagingService.kt
@@ -0,0 +1,67 @@
+package com.mobiledevpro.remote.service.notification
+
+import android.app.NotificationChannel
+import android.app.NotificationManager
+import android.content.Context
+import android.media.RingtoneManager
+import android.os.Build
+import android.util.Log
+import androidx.core.app.NotificationCompat
+import com.google.firebase.messaging.FirebaseMessagingService
+import com.google.firebase.messaging.RemoteMessage
+import com.mobiledevpro.data.LOG_TAG_DEBUG
+import com.mobiledevpro.data.NOTIFICATIONS_CHANNEL_ID_MAIN_NOTIFICATIONS
+import com.mobiledevpro.data.NOTIFICATIONS_CHANNEL_NAME_MAIN_NOTIFICATIONS
+import com.mobiledevpro.remote.R
+
+/**
+ * Class for displaying status bar notifications from Firebase (FCM)
+ *
+ * Created by Dmitriy Chernysh on Mar 31, 2020.
+ *
+ * http://androiddev.pro
+ *
+ */
+class FirebaseMessagingService : FirebaseMessagingService() {
+
+ private var notificationNumber = 0
+
+ override fun onMessageReceived(msg: RemoteMessage) {
+ Log.d(LOG_TAG_DEBUG, "From: ${msg.from}")
+
+ msg.notification?.let {
+ Log.d(LOG_TAG_DEBUG, "Message Notification Title: ${it.title}")
+ Log.d(LOG_TAG_DEBUG, "Message Notification Body: ${it.body}")
+ sendNotification(it.title, it.body)
+ }
+ }
+
+
+ private fun sendNotification(title: String?, messageBody: String?) {
+ if (title == null && messageBody == null) return
+
+ notificationNumber++
+
+ val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
+ val notificationBuilder = NotificationCompat.Builder(this, NOTIFICATIONS_CHANNEL_ID_MAIN_NOTIFICATIONS)
+ .setSmallIcon(R.drawable.ic_notification)
+ .setContentTitle(title ?: "")
+ .setContentText(messageBody ?: "")
+ .setAutoCancel(true)
+ .setSound(defaultSoundUri)
+
+ val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+
+ // Since android Oreo notification channel is needed.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ val channel = NotificationChannel(
+ NOTIFICATIONS_CHANNEL_ID_MAIN_NOTIFICATIONS,
+ NOTIFICATIONS_CHANNEL_NAME_MAIN_NOTIFICATIONS,
+ NotificationManager.IMPORTANCE_DEFAULT)
+ notificationManager.createNotificationChannel(channel)
+ }
+
+ notificationManager.notify(notificationNumber, notificationBuilder.build())
+ }
+
+}
\ No newline at end of file
diff --git a/data/src/main/java/com/mobiledevpro/data/Constants.kt b/data/src/main/java/com/mobiledevpro/data/Constants.kt
index 283f75b..0659433 100644
--- a/data/src/main/java/com/mobiledevpro/data/Constants.kt
+++ b/data/src/main/java/com/mobiledevpro/data/Constants.kt
@@ -6,3 +6,6 @@ package com.mobiledevpro.data
const val LOG_TAG_DEBUG = "app.debug"
const val LOG_TAG_ERROR = "app.error"
+
+const val NOTIFICATIONS_CHANNEL_ID_MAIN_NOTIFICATIONS = "1001"
+const val NOTIFICATIONS_CHANNEL_NAME_MAIN_NOTIFICATIONS = "Main notifications"
\ No newline at end of file
diff --git a/data/src/main/res/drawable-hdpi/ic_notification.png b/data/src/main/res/drawable-hdpi/ic_notification.png
new file mode 100644
index 0000000..e4847d2
Binary files /dev/null and b/data/src/main/res/drawable-hdpi/ic_notification.png differ
diff --git a/data/src/main/res/drawable-mdpi/ic_notification.png b/data/src/main/res/drawable-mdpi/ic_notification.png
new file mode 100644
index 0000000..ac1957e
Binary files /dev/null and b/data/src/main/res/drawable-mdpi/ic_notification.png differ
diff --git a/data/src/main/res/drawable-xhdpi/ic_notification.png b/data/src/main/res/drawable-xhdpi/ic_notification.png
new file mode 100644
index 0000000..589c5d0
Binary files /dev/null and b/data/src/main/res/drawable-xhdpi/ic_notification.png differ
diff --git a/data/src/main/res/drawable-xxhdpi/ic_notification.png b/data/src/main/res/drawable-xxhdpi/ic_notification.png
new file mode 100644
index 0000000..300e3cb
Binary files /dev/null and b/data/src/main/res/drawable-xxhdpi/ic_notification.png differ
diff --git a/data/src/main/res/drawable-xxxhdpi/ic_notification.png b/data/src/main/res/drawable-xxxhdpi/ic_notification.png
new file mode 100644
index 0000000..c1bdc54
Binary files /dev/null and b/data/src/main/res/drawable-xxxhdpi/ic_notification.png differ
diff --git a/data/src/main/res/values/strings.xml b/data/src/main/res/values/strings.xml
index 8f57ace..17621eb 100644
--- a/data/src/main/res/values/strings.xml
+++ b/data/src/main/res/values/strings.xml
@@ -1,3 +1,5 @@
data
+
+