-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from Project-Unifest/develop
release v1.1.0
- Loading branch information
Showing
289 changed files
with
8,752 additions
and
3,098 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,3 +62,5 @@ secrets.properties | |
/app/release/* | ||
|
||
/app/google-services.json | ||
|
||
.kotlin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/kotlin/com/unifest/android/initializer/FirebaseMessagingInitializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.unifest.android.initializer | ||
|
||
import android.content.Context | ||
import androidx.startup.Initializer | ||
import com.google.firebase.messaging.FirebaseMessaging | ||
import timber.log.Timber | ||
|
||
class FirebaseMessagingInitializer : Initializer<Unit> { | ||
override fun create(context: Context) { | ||
FirebaseMessaging.getInstance().subscribeToTopic("2") | ||
.addOnCompleteListener { task -> | ||
if (task.isSuccessful) { | ||
Timber.d("Subscribed to topic successfully") | ||
} else { | ||
Timber.e("Failed to subscribe to topic") | ||
} | ||
} | ||
} | ||
|
||
override fun dependencies(): List<Class<out Initializer<*>>> { | ||
return emptyList() | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
app/src/main/kotlin/com/unifest/android/service/UnifestFirebaseMessagingService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.unifest.android.service | ||
|
||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Build | ||
import androidx.core.app.NotificationCompat | ||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
import com.unifest.android.core.designsystem.R as designR | ||
import com.unifest.android.feature.main.MainActivity | ||
import timber.log.Timber | ||
|
||
class UnifestFirebaseMessagingService : FirebaseMessagingService() { | ||
override fun onMessageReceived(remoteMessage: RemoteMessage) { | ||
super.onMessageReceived(remoteMessage) | ||
if (remoteMessage.notification != null) { | ||
sendNotification(remoteMessage) | ||
} | ||
} | ||
|
||
private fun sendNotification(remoteMessage: RemoteMessage) { | ||
val requestCode = System.currentTimeMillis().toInt() | ||
|
||
val intent = Intent(this, MainActivity::class.java).apply { | ||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).also { | ||
if (remoteMessage.data["boothId"] != null) { | ||
if (remoteMessage.data["waitingId"] != null) { | ||
Timber.tag("UnifestFirebaseMessagingService").d("waitingId: ${remoteMessage.data["waitingId"]}") | ||
putExtra("navigate_to_waiting", true) | ||
putExtra("waitingId", remoteMessage.data["waitingId"]) | ||
} else { | ||
Timber.tag("UnifestFirebaseMessagingService").d("boothId: ${remoteMessage.data["boothId"]}") | ||
putExtra("navigate_to_booth", true) | ||
putExtra("boothId", remoteMessage.data["boothId"]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
val pendingIntentFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE | ||
} else { | ||
PendingIntent.FLAG_UPDATE_CURRENT | ||
} | ||
val pendingIntent = PendingIntent.getActivity(this, requestCode, intent, pendingIntentFlags) | ||
|
||
val channelId = CHANNEL_ID | ||
|
||
val notificationBuilder = NotificationCompat.Builder(this, channelId) | ||
.setSmallIcon(designR.mipmap.ic_launcher) | ||
.setContentTitle(remoteMessage.notification?.title.toString()) | ||
.setContentText(remoteMessage.notification?.body.toString()) | ||
.setAutoCancel(true) | ||
.setContentIntent(pendingIntent) | ||
|
||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
|
||
val channel = NotificationChannel(channelId, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH) | ||
notificationManager.createNotificationChannel(channel) | ||
|
||
notificationManager.notify(requestCode, notificationBuilder.build()) | ||
} | ||
|
||
override fun onNewToken(token: String) { | ||
Timber.d("Refreshed token: $token") | ||
} | ||
|
||
companion object { | ||
private const val CHANNEL_ID = "unifest" | ||
private const val CHANNEL_NAME = "unifest_notification" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.