Skip to content

Commit

Permalink
#93 [mod] : refresh 시 toast 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
chanubc committed Oct 11, 2024
1 parent 42a9aa9 commit 5a1afc5
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 5a1afc5

Please sign in to comment.