-
Notifications
You must be signed in to change notification settings - Fork 3
[FEAT] 알림 센터 API 구현 #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] 알림 센터 API 구현 #141
Changes from all commits
f909028
3fda293
9d1e3bc
18079db
d140dfb
bdbf183
32376cd
0c7a691
c91ad6a
45f541c
42f0b01
7580e37
613a333
ee3788c
cb9b2a5
f7bd19d
28a0187
4d53c6c
c1a877c
e74142c
3ed58f2
e0f2111
2bd7010
5864f8b
0d9f94a
801e8ba
bf47fe1
249c517
c6f40f7
687c179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 클로드의 도움을 받아서 백그라운드 푸시알림일 때 인텐트로 notificationId를 넘기도록 수정했습니다. |
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MainActivity에서 전달받은 알림 데이터를 네비게이션으로 연결하는 로직을 구현했습니다 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,28 +3,94 @@ package com.texthip.thip | |
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.material3.Scaffold | ||
| import android.util.Log | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.navigation.compose.currentBackStackEntryAsState | ||
| import androidx.navigation.compose.rememberNavController | ||
| import com.texthip.thip.data.repository.NotificationRepository | ||
| import com.texthip.thip.ui.navigator.BottomNavigationBar | ||
| import com.texthip.thip.ui.navigator.MainNavHost | ||
| import com.texthip.thip.ui.navigator.extensions.isMainTabRoute | ||
| import com.texthip.thip.ui.navigator.extensions.navigateFromNotification | ||
| import com.texthip.thip.ui.navigator.routes.MainTabRoutes | ||
| import dagger.hilt.EntryPoint | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.android.EntryPointAccessors | ||
| import dagger.hilt.components.SingletonComponent | ||
|
|
||
| @EntryPoint | ||
| @InstallIn(SingletonComponent::class) | ||
| interface MainScreenEntryPoint { | ||
| fun notificationRepository(): NotificationRepository | ||
| } | ||
|
|
||
| @Composable | ||
| fun MainScreen( | ||
| onNavigateToLogin: () -> Unit | ||
| onNavigateToLogin: () -> Unit, | ||
| notificationData: MainActivity.NotificationData? = null | ||
| ) { | ||
| val navController = rememberNavController() | ||
| val navBackStackEntry by navController.currentBackStackEntryAsState() | ||
| val currentDestination = navBackStackEntry?.destination | ||
| var feedReselectionTrigger by remember { mutableStateOf(0) } | ||
| val context = LocalContext.current | ||
|
|
||
| // 처리된 알림 ID 추적 | ||
| var processedNotificationId by remember { mutableStateOf<String?>(null) } | ||
|
|
||
| // 푸시 알림에서 온 경우 알림 읽기 API 호출 및 네비게이션 | ||
| LaunchedEffect(notificationData?.notificationId, notificationData?.fromNotification) { | ||
| val data = notificationData | ||
|
|
||
| // 중복 처리 방지 | ||
| if (data?.notificationId == processedNotificationId) { | ||
| return@LaunchedEffect | ||
| } | ||
|
|
||
| data?.let { notificationData -> | ||
| if (notificationData.fromNotification && notificationData.notificationId != null) { | ||
| try { | ||
| val entryPoint = EntryPointAccessors.fromApplication( | ||
| context.applicationContext, | ||
| MainScreenEntryPoint::class.java | ||
| ) | ||
| val notificationRepository = entryPoint.notificationRepository() | ||
|
|
||
| val notificationId = try { | ||
| notificationData.notificationId.toInt() | ||
| } catch (e: NumberFormatException) { | ||
| Log.e("MainScreen", "Invalid notification ID format: ${notificationData.notificationId}", e) | ||
| return@LaunchedEffect | ||
| } | ||
|
|
||
| val result = notificationRepository.checkNotification(notificationId) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 알림읽기 요청 |
||
|
|
||
| result.onSuccess { response -> | ||
| if (response != null) { | ||
| navController.navigateFromNotification(response) | ||
| notificationRepository.onNotificationReceived() | ||
| processedNotificationId = notificationData.notificationId | ||
| } else { | ||
| Log.w("MainScreen", "Notification check returned null response") | ||
| } | ||
| }.onFailure { exception -> | ||
| Log.e("MainScreen", "Failed to check notification: ${notificationData.notificationId}", exception) | ||
| } | ||
|
|
||
| } catch (e: Exception) { | ||
| Log.e("MainScreen", "Unexpected error processing notification: ${notificationData.notificationId}", e) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| val showBottomBar = currentDestination?.isMainTabRoute() ?: true | ||
|
|
||
|
|
||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 일단 권한이 없어도 전송을 해야됨 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.texthip.thip.data.model.notification.request | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class NotificationCheckRequest( | ||
| @SerialName("notificationId") val notificationId: Int | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.texthip.thip.data.model.notification.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
| import kotlinx.serialization.json.JsonElement | ||
|
|
||
| @Serializable | ||
| data class NotificationCheckResponse( | ||
| @SerialName("route") val route: NotificationRoute, | ||
| @SerialName("params") val params: Map<String, JsonElement> | ||
| ) | ||
|
|
||
| @Serializable | ||
| enum class NotificationRoute { | ||
| @SerialName("FEED_USER") | ||
| FEED_USER, | ||
|
|
||
| @SerialName("FEED_DETAIL") | ||
| FEED_DETAIL, | ||
|
|
||
| @SerialName("ROOM_MAIN") | ||
| ROOM_MAIN, | ||
|
|
||
| @SerialName("ROOM_DETAIL") | ||
| ROOM_DETAIL, | ||
|
|
||
| @SerialName("ROOM_POST_DETAIL") | ||
| ROOM_POST_DETAIL | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.texthip.thip.data.model.notification.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class NotificationListResponse( | ||
| @SerialName("notifications") val notifications: List<NotificationResponse>, | ||
| @SerialName("nextCursor") val nextCursor: String?, | ||
| @SerialName("isLast") val isLast: Boolean | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class NotificationResponse( | ||
| @SerialName("notificationId") val notificationId: Int, | ||
| @SerialName("title") val title: String, | ||
| @SerialName("content") val content: String, | ||
| @SerialName("isChecked") val isChecked: Boolean, | ||
| @SerialName("notificationType") val notificationType: String, | ||
| @SerialName("postDate") val postDate: String | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
FCM 기본 알림 아이콘은 단색 drawable로 지정
mipmap/ic_launcher 대신 단색 drawable을 사용해야 합니다. 상태바/티커 표시 품질을 위해 교체해 주세요.
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" - android:resource="@mipmap/ic_launcher" /> + android:resource="@drawable/ic_notification_small" />ic_notification_small 리소스가 없다면 생성이 필요합니다.
🤖 Prompt for AI Agents