From d38b6ed19ac290f02e9652dc1af6ae437b5fe3d9 Mon Sep 17 00:00:00 2001 From: kimhyemin Date: Sat, 4 Jan 2025 14:25:26 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20runBlocking=20->=20launch=EB=A1=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ody/data/local/service/EtaDashboard.kt | 45 ++++++++++++------- .../thirdparty/fcm/service/FCMService.kt | 6 ++- 2 files changed, 33 insertions(+), 18 deletions(-) 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) } }