Skip to content

Commit 17c34e2

Browse files
authored
[MERGE] #372 -> develop
[REFACTOR/#372] λ„€λΉ„κ²Œμ΄μ…˜ ꡬ쑰 μˆ˜μ •
2 parents 167008e + c49309a commit 17c34e2

36 files changed

Lines changed: 332 additions & 99 deletions

File tree

β€Žcore/firebase/build.gradle.ktsβ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import com.terning.build_logic.extension.setNamespace
22

3-
43
plugins {
54
alias(libs.plugins.terning.library)
65
}
@@ -10,8 +9,14 @@ android {
109
}
1110

1211
dependencies {
12+
//core
13+
implementation(projects.core.navigator)
14+
implementation(projects.core.local)
15+
16+
// timber
1317
implementation(libs.timber)
1418

19+
// firebase
1520
implementation(platform(libs.firebase.bom))
1621
implementation(libs.firebase.analytics)
1722
implementation(libs.firebase.messaging)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package com.terning.core.firebase.remoteconfig.messageservice
2+
3+
import android.app.NotificationChannel
4+
import android.app.NotificationManager
5+
import android.app.PendingIntent
6+
import android.content.Intent
7+
import androidx.core.app.NotificationCompat
8+
import androidx.core.app.NotificationManagerCompat
9+
import androidx.core.content.getSystemService
10+
import androidx.core.net.toUri
11+
import com.google.firebase.messaging.FirebaseMessagingService
12+
import com.google.firebase.messaging.RemoteMessage
13+
import com.terning.core.firebase.R
14+
import com.terning.core.local.TerningDataStore
15+
import com.terning.navigator.NavigatorProvider
16+
import dagger.hilt.android.AndroidEntryPoint
17+
import timber.log.Timber
18+
import java.util.Random
19+
import javax.inject.Inject
20+
21+
@AndroidEntryPoint
22+
class TerningMessagingService : FirebaseMessagingService() {
23+
24+
@Inject
25+
lateinit var terningDataStore: TerningDataStore
26+
27+
@Inject
28+
lateinit var navigatorProvider: NavigatorProvider
29+
30+
override fun onNewToken(token: String) {
31+
super.onNewToken(token)
32+
33+
Timber.tag("okhttp").d("ON NEW TOKEN")
34+
}
35+
36+
override fun handleIntent(intent: Intent?) {
37+
super.handleIntent(intent)
38+
39+
if (intent?.getStringExtra(TITLE)?.isEmpty() == true) return
40+
41+
val title = intent?.getStringExtra(TITLE).orEmpty()
42+
val body = intent?.getStringExtra(BODY).orEmpty()
43+
val type = intent?.getStringExtra(TYPE).orEmpty()
44+
45+
sendNotification(title = title, body = body, type = type)
46+
}
47+
48+
override fun onMessageReceived(message: RemoteMessage) {
49+
super.onMessageReceived(message)
50+
51+
if (message.data.isEmpty())
52+
// TODO: 쑰건 μΆ”κ°€ by 이유빈 -> || !terningDataStore.alarmAvailable
53+
return
54+
55+
val title = message.data[TITLE].orEmpty()
56+
val body = message.data[BODY].orEmpty()
57+
val type = message.data[TYPE].orEmpty()
58+
59+
sendNotification(title = title, body = body, type = type)
60+
}
61+
62+
private fun sendNotification(title: String, body: String, type: String) {
63+
val notifyId = Random().nextInt()
64+
val intent = navigatorProvider.getMainActivityIntent(deeplink = type).apply {
65+
action = Intent.ACTION_VIEW
66+
data = type.toUri()
67+
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
68+
}
69+
val pendingIntent = PendingIntent.getActivity(
70+
this@TerningMessagingService,
71+
notifyId,
72+
intent,
73+
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_MUTABLE
74+
)
75+
val channelId: String = CHANNEL_ID
76+
val notificationBuilder =
77+
NotificationCompat.Builder(this, channelId).apply {
78+
setSmallIcon(R.mipmap.ic_terning_launcher)
79+
setContentTitle(title)
80+
setContentText(body)
81+
setPriority(NotificationManagerCompat.IMPORTANCE_HIGH)
82+
setContentIntent(pendingIntent)
83+
}
84+
85+
getSystemService<NotificationManager>()?.run {
86+
createNotificationChannel(
87+
NotificationChannel(
88+
channelId,
89+
channelId,
90+
NotificationManager.IMPORTANCE_HIGH,
91+
),
92+
)
93+
notify(notifyId, notificationBuilder.build())
94+
}
95+
}
96+
97+
companion object {
98+
private const val CHANNEL_ID: String = "terning"
99+
private const val TITLE: String = "title"
100+
private const val BODY: String = "body"
101+
private const val TYPE: String = "type"
102+
}
103+
}
1.93 KB
Loading
1.4 KB
Loading
2.72 KB
Loading
4.29 KB
Loading
5.98 KB
Loading

β€Žcore/navigator/.gitignoreβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import com.terning.build_logic.extension.setNamespace
2+
3+
plugins {
4+
alias(libs.plugins.terning.library)
5+
}
6+
7+
android {
8+
setNamespace("core.navigator")
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
</manifest>

0 commit comments

Comments
Β (0)