Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {

defaultConfig {
versionCode = 21
versionName = "1.2.6"
versionName = "1.2.7"
targetSdk = 35

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
20 changes: 2 additions & 18 deletions app/src/main/java/com/idle/care/CareApplication.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.idle.care

import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import com.appsflyer.AppsFlyerLib
import com.appsflyer.attribution.AppsFlyerRequestListener
import com.idle.care.notification.NotificationHandler.Companion.BACKGROUND_CHANNEL
import com.idle.care.notification.NotificationHandler.Companion.BACKGROUND_DESCRIPTION
import com.idle.care.notification.NotificationService.Companion.initNotification
import com.idle.domain.model.error.ErrorHelper
import com.kakao.sdk.common.KakaoSdk
import dagger.hilt.android.HiltAndroidApp
Expand All @@ -22,24 +19,11 @@ class CareApplication : Application() {
override fun onCreate() {
super.onCreate()

initNotification()
initNotification(this)
initKakao()
initAppsFlyer()
}

private fun initNotification() {
val channel =
NotificationChannel(
BACKGROUND_CHANNEL,
BACKGROUND_CHANNEL,
NotificationManager.IMPORTANCE_DEFAULT
)
channel.description = BACKGROUND_DESCRIPTION

val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}

private fun initKakao() {
KakaoSdk.init(this, BuildConfig.KAKAO_APP_KEY)
}
Expand Down
21 changes: 0 additions & 21 deletions app/src/main/java/com/idle/care/di/AppModule.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package com.idle.care.notification

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.idle.designsystem.binding.R
import com.idle.domain.model.error.ErrorHelper
import com.idle.domain.repositorry.ProfileRepository
import com.idle.domain.repositorry.TokenRepository
import com.idle.presentation.MainActivity
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
Expand All @@ -23,12 +32,13 @@ class NotificationService : FirebaseMessagingService() {
@Inject
lateinit var profileRepository: ProfileRepository

@Inject
lateinit var notificationHandler: NotificationHandler

@Inject
lateinit var errorHelper: ErrorHelper

private val notificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager


private val coroutineExceptionHandler = CoroutineExceptionHandler { _, throwable ->
errorHelper.logError(throwable)
}
Expand Down Expand Up @@ -56,15 +66,68 @@ class NotificationService : FirebaseMessagingService() {
val body = message.notification?.body ?: ""
val data = message.data

notificationHandler.deliverNotification(
deliverNotification(
title = title,
body = body,
data = data,
)
}

internal fun deliverNotification(
title: String,
body: String,
data: Map<String, String>
) {
val intent = Intent(this, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
}

if (data.isNotEmpty()) {
data.forEach { (key, value) ->
intent.putExtra(key, value)
}
}

val pendingIntent = PendingIntent.getActivity(
this,
0,
intent,
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)

val builder = NotificationCompat.Builder(this, BACKGROUND_CHANNEL)
.setSmallIcon(com.idle.care.R.drawable.ic_notification_icon)
.setColor(ContextCompat.getColor(this, R.color.orange_500))
.setContentTitle(title)
.setContentText(body)
.setContentIntent(pendingIntent)
.setAutoCancel(true)

notificationManager.notify(System.currentTimeMillis().toInt(), builder.build())
}

override fun onDestroy() {
super.onDestroy()
scope.cancel()
}

companion object {
private const val BACKGROUND_CHANNEL = "백그라운드 알림"
private const val BACKGROUND_DESCRIPTION =
"센터장 : 공고 지원자 확인, 요양보호사 : 희망 공고가 게시되었을 때의 알림을 받을 수 있는 채널입니다."

fun initNotification(context: Context) {
val channel =
NotificationChannel(
BACKGROUND_CHANNEL,
BACKGROUND_CHANNEL,
NotificationManager.IMPORTANCE_DEFAULT
)
channel.description = BACKGROUND_DESCRIPTION

val notificationManager =
context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.idle.network.model.chat.ReadMessageRequest
import com.idle.network.model.chat.SendMessageRequest
import com.idle.network.source.ChatDataSource
import com.idle.network.util.MAX_RETRY_ATTEMPTS
import com.idle.network.util.calculateBackoffTime
import com.idle.network.util.calculateRetryTime
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
Expand Down Expand Up @@ -174,6 +174,7 @@ class ChatRepositoryImpl @Inject constructor(
}
localChatDataSource.insertMessage(message, userId)
}

is ReadMessage -> {
if (message.opponentId != userId) {
localChatDataSource.readMessages(
Expand All @@ -190,7 +191,7 @@ class ChatRepositoryImpl @Inject constructor(
.retryWhen { cause, attempt ->
if (cause is IOException && attempt < MAX_RETRY_ATTEMPTS) {
connectWebSocket()
delay(calculateBackoffTime(attempt.toInt()))
delay(calculateRetryTime(attempt.toInt()))
true
} else {
false
Expand Down
Loading