diff --git a/android/app/src/main/java/com/mulberry/ody/data/local/service/EtaDashboard.kt b/android/app/src/main/java/com/mulberry/ody/data/local/service/EtaDashboard.kt index f30e96777..06dd5213b 100644 --- a/android/app/src/main/java/com/mulberry/ody/data/local/service/EtaDashboard.kt +++ b/android/app/src/main/java/com/mulberry/ody/data/local/service/EtaDashboard.kt @@ -3,30 +3,43 @@ package com.mulberry.ody.data.local.service import android.content.Context import com.mulberry.ody.data.local.db.OdyDatastore import com.mulberry.ody.domain.common.toMilliSeconds +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.first -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.launch import java.time.LocalDateTime import javax.inject.Inject class EtaDashboard - @Inject - constructor( - val context: Context, - val odyDatastore: OdyDatastore, +@Inject +constructor( + val context: Context, + val odyDatastore: OdyDatastore, +) { + fun open( + meetingId: Long, + meetingTime: LocalDateTime, ) { - fun open( - meetingId: Long, - meetingTime: LocalDateTime, - ) { + CoroutineScope(Dispatchers.Default).launch { if (!isLoggedIn()) { - return + return@launch } - val meetingTimeMills = meetingTime.toMilliSeconds() - val serviceIntent = EtaDashboardService.getIntent(context, meetingId, meetingTimeMills, isOpen = true) - context.startForegroundService(serviceIntent) - } - private fun isLoggedIn(): Boolean { - return runBlocking { odyDatastore.getAuthToken().first().isSuccess } + startEtaDashboardService(meetingId, meetingTime) } } + + private suspend fun isLoggedIn(): Boolean { + return coroutineScope { odyDatastore.getAuthToken().first().isSuccess } + } + + private fun startEtaDashboardService( + meetingId: Long, + meetingTime: LocalDateTime, + ) { + val meetingTimeMills = meetingTime.toMilliSeconds() + val serviceIntent = EtaDashboardService.getIntent(context, meetingId, meetingTimeMills, isOpen = true) + context.startForegroundService(serviceIntent) + } +} diff --git a/android/app/src/main/java/com/mulberry/ody/data/remote/thirdparty/fcm/service/FCMService.kt b/android/app/src/main/java/com/mulberry/ody/data/remote/thirdparty/fcm/service/FCMService.kt index 54d09f4ca..603e81bf7 100644 --- a/android/app/src/main/java/com/mulberry/ody/data/remote/thirdparty/fcm/service/FCMService.kt +++ b/android/app/src/main/java/com/mulberry/ody/data/remote/thirdparty/fcm/service/FCMService.kt @@ -8,7 +8,9 @@ import com.mulberry.ody.domain.model.FCMNotificationType import com.mulberry.ody.domain.model.FCMType import com.mulberry.ody.presentation.notification.FCMNotification import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import java.time.LocalDateTime import java.time.format.DateTimeFormatter import javax.inject.Inject @@ -42,7 +44,7 @@ class FCMService : FirebaseMessagingService() { } override fun onNewToken(token: String) { - runBlocking { + CoroutineScope(Dispatchers.Default).launch { odyDatastore.setFCMToken(token) } }