fix online service

This commit is contained in:
2024-07-16 08:00:25 +03:00
parent 6980d830f9
commit 9e09cbb640
@@ -7,13 +7,16 @@ import android.util.Log
import dev.meloda.fast.common.UserConfig import dev.meloda.fast.common.UserConfig
import dev.meloda.fast.common.extensions.createTimerFlow import dev.meloda.fast.common.extensions.createTimerFlow
import dev.meloda.fast.data.api.account.AccountUseCase import dev.meloda.fast.data.api.account.AccountUseCase
import dev.meloda.fast.data.processState
import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject import org.koin.android.ext.android.inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@@ -48,14 +51,7 @@ class OnlineService : Service() {
Log.d(STATE_TAG, "onStartCommand: flags: $flags; startId: $startId\ninstance: $this") Log.d(STATE_TAG, "onStartCommand: flags: $flags; startId: $startId\ninstance: $this")
// TODO: 05/05/2024, Danil Nikolaev: implement createTimer()
// if (AppGlobal.preferences.getBoolean(
// SettingsKeys.KEY_VISIBILITY_SEND_ONLINE_STATUS,
// SettingsKeys.DEFAULT_VALUE_KEY_VISIBILITY_SEND_ONLINE_STATUS
// )
// ) {
// createTimer()
// }
return START_STICKY return START_STICKY
} }
@@ -72,14 +68,6 @@ class OnlineService : Service() {
private fun setOnline() { private fun setOnline() {
if (onlineJob != null) return if (onlineJob != null) return
// TODO: 05/05/2024, Danil Nikolaev: implement
// if (!AppGlobal.preferences.getBoolean(
// SettingsKeys.KEY_VISIBILITY_SEND_ONLINE_STATUS,
// SettingsKeys.DEFAULT_VALUE_KEY_VISIBILITY_SEND_ONLINE_STATUS
// )
// ) return
Log.d(TAG, "setOnline()") Log.d(TAG, "setOnline()")
onlineJob = coroutineScope.launch { onlineJob = coroutineScope.launch {
@@ -90,24 +78,23 @@ class OnlineService : Service() {
return@launch return@launch
} }
val response = useCase.setOnline( useCase.setOnline(
voip = false, voip = false,
accessToken = token accessToken = token
) ).onEach { state ->
Log.d(TAG, "setOnline: response: $response") state.processState(
error = { error ->
Log.w(TAG, "setOnline(): error: $error")
},
success = { response ->
Log.d(TAG, "setOnline(): success: $response")
}
)
}.collect()
}.also { coroutine -> coroutine.invokeOnCompletion { onlineJob = null } } }.also { coroutine -> coroutine.invokeOnCompletion { onlineJob = null } }
} }
private suspend fun setOffline() {
Log.d(TAG, "setOffline()")
val response = useCase.setOffline(
accessToken = UserConfig.accessToken
)
Log.d(TAG, "setOffline: response: $response")
}
override fun onLowMemory() { override fun onLowMemory() {
Log.d(STATE_TAG, "onLowMemory") Log.d(STATE_TAG, "onLowMemory")
super.onLowMemory() super.onLowMemory()