From 5a1afc54bb2f8bb1849c84ee6f4eb19e0c42c40e Mon Sep 17 00:00:00 2001 From: chanu Date: Fri, 11 Oct 2024 23:02:00 +0900 Subject: [PATCH] =?UTF-8?q?#93=20[mod]=20:=20refresh=20=EC=8B=9C=20toast?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/teamwable/network/TokenInterceptor.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/network/src/main/java/com/teamwable/network/TokenInterceptor.kt b/core/network/src/main/java/com/teamwable/network/TokenInterceptor.kt index 457f4cba..0386bbd1 100644 --- a/core/network/src/main/java/com/teamwable/network/TokenInterceptor.kt +++ b/core/network/src/main/java/com/teamwable/network/TokenInterceptor.kt @@ -2,6 +2,7 @@ package com.teamwable.network import android.app.Application import android.content.Intent +import android.widget.Toast import com.teamwable.datastore.datasource.DefaultWablePreferenceDatasource import com.teamwable.network.datasource.AuthService import kotlinx.coroutines.CoroutineScope @@ -25,6 +26,7 @@ class TokenInterceptor @Inject constructor( private val authService: AuthService, ) : Interceptor { private val mutex = Mutex() + private var currentToast: Toast? = null override fun intercept(chain: Interceptor.Chain): Response { val originalRequest = chain.request() @@ -71,12 +73,19 @@ class TokenInterceptor @Inject constructor( } private fun handleFailedTokenReissue() = CoroutineScope(Dispatchers.Main).launch { + showToast() withContext(Dispatchers.IO) { defaultWablePreferenceDatasource.clear() } restartActivity() } + private fun showToast() { + currentToast?.cancel() + currentToast = Toast.makeText(context, "재 로그인이 필요해요", Toast.LENGTH_SHORT) + currentToast?.show() + } + private suspend fun restartActivity() = with(context) { mutex.withLock { startActivity(