diff --git a/app/src/main/java/jp/atled/agileworks/model/NotificationRepository.kt b/app/src/main/java/jp/atled/agileworks/model/NotificationRepository.kt index c8890acaea74161236208121a95042679402c4ad..7bca3c86a5d7241c777f5ec84bbec520bc22554b 100644 --- a/app/src/main/java/jp/atled/agileworks/model/NotificationRepository.kt +++ b/app/src/main/java/jp/atled/agileworks/model/NotificationRepository.kt @@ -6,6 +6,12 @@ import android.content.SharedPreferences import android.util.Log import jp.atled.agileworks.AwApp import jp.atled.agileworks.model.api.ApiClient +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.suspendCancellableCoroutine +import kotlinx.coroutines.withTimeoutOrNull +import kotlin.coroutines.resume /** * 通知全般を扱うリポジトリ @@ -39,21 +45,40 @@ class NotificationRepository(_serverNumber: Int? = null) { fun clearToken(onResult: (Boolean) -> Unit) { Log.d("AgileWorks", "firebase token clean") ApiClient.reCreateLogout(serverNumber) - LogoutRepository.getInstance().getLogout { - /* - FcmRepository().removeFcmToken { - Log.d("AgileWorks", "firebase token clean -> ${successOrFailured(it)}") - onResult(it) + // 30秒でタイムアウト + GlobalScope.launch(Dispatchers.Main) { + val timeoutMillis = 30000L + val result = withTimeoutOrNull(timeoutMillis) { + suspendCancellableCoroutine { continuation -> + LogoutRepository.getInstance().getLogout { success -> + if (continuation.isActive) { + continuation.resume(success) + } + } + } } - */ - // 全サーバログアウト状態で FcmToken の削除 - val serverList = ServerRepository().loadServerList() - if (serverList.isEmpty()) { - FcmRepository().removeFcmToken { - Log.d("AgileWorks", "firebase token clean -> ${successOrFailured(it)}") + + if (result == null) { + // タイムアウトした場合 + // 全サーバログアウト状態で FcmToken の削除 + val serverList = ServerRepository().loadServerList() + if (serverList.isEmpty()) { + FcmRepository().removeFcmToken { + Log.d("AgileWorks", "firebase token clean (timeout path)") + } + } + onResult(true) // 成功として扱う + } else { + // タイムアウトしなかった場合 + // 全サーバログアウト状態で FcmToken の削除 + val serverList = ServerRepository().loadServerList() + if (serverList.isEmpty()) { + FcmRepository().removeFcmToken { + Log.d("AgileWorks", "firebase token clean -> ${successOrFailured(result)}") + } } + onResult(result) } - onResult(it) } } diff --git a/app/src/main/java/jp/atled/agileworks/view/ui/DirectOpenDocumentActivity.kt b/app/src/main/java/jp/atled/agileworks/view/ui/DirectOpenDocumentActivity.kt index 036635ee4710b71eb48af3fe1dd720d5c78ac800..0c0df76456699086a9ae181ed76bcd7e66f538d1 100644 --- a/app/src/main/java/jp/atled/agileworks/view/ui/DirectOpenDocumentActivity.kt +++ b/app/src/main/java/jp/atled/agileworks/view/ui/DirectOpenDocumentActivity.kt @@ -52,7 +52,6 @@ class DirectOpenDocumentActivity : BaseActivity(), View.OnClickListener { setContentView(binding.root) binding.toolbar.title = title() setSupportActionBar(binding.toolbar) - setupDrawerMenu() findViewById