Skip to content

Commit

Permalink
[FEAT]: Intent Provider #416
Browse files Browse the repository at this point in the history
core network need Intent(auth activity)
  • Loading branch information
lsakee committed Nov 1, 2023
1 parent c5e8d91 commit c4d0ed3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/org/sopt/official/di/AuthModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import org.sopt.official.data.source.api.auth.RemoteAuthDataSource
import org.sopt.official.data.source.impl.DefaultLocalAuthDataSource
import org.sopt.official.data.source.impl.DefaultRemoteAuthDataSource
import org.sopt.official.domain.repository.AuthRepository
import org.sopt.official.feature.auth.ProvidesIntent
import org.sopt.official.network.authenticator.ProvidesIntents
import retrofit2.Retrofit
import javax.inject.Singleton

Expand Down Expand Up @@ -68,5 +70,9 @@ object AuthModule {
@Binds
@Singleton
fun bindLocalAuthDataSource(dataSource: DefaultLocalAuthDataSource): LocalAuthDataSource

@Binds
@Singleton
fun bindIntent(providesIntents: ProvidesIntent): ProvidesIntents
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/org/sopt/official/feature/auth/ProvidesIntent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.sopt.official.feature.auth

import android.content.Context
import android.content.Intent
import dagger.hilt.android.qualifiers.ApplicationContext
import org.sopt.official.network.authenticator.ProvidesIntents
import javax.inject.Inject

class ProvidesIntent @Inject constructor(
@ApplicationContext private val context: Context
) : ProvidesIntents {
override fun getAuthActivityIntent(): Intent =
AuthActivity.newInstance(context)

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
package org.sopt.official.network.authenticator

import android.content.Context
import android.content.Intent
import com.jakewharton.processphoenix.ProcessPhoenix
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.runBlocking
import okhttp3.Authenticator
Expand All @@ -43,7 +45,8 @@ import javax.inject.Singleton
class SoptAuthenticator @Inject constructor(
private val dataStore: SoptDataStore,
@Auth(false) private val service: AuthService,
@ApplicationContext private val context: Context
@ApplicationContext private val context: Context,
private val providesIntent: ProvidesIntents
) : Authenticator {
override fun authenticate(route: Route?, response: Response): Request? {
if (response.code == 401) {
Expand All @@ -59,7 +62,7 @@ class SoptAuthenticator @Inject constructor(
}.onFailure {
dataStore.clear()
Timber.e(it)
// ProcessPhoenix.triggerRebirth(context, AuthActivity.newInstance(context))
ProcessPhoenix.triggerRebirth(context, providesIntent.getAuthActivityIntent())
}.getOrThrow()

return response.request.newBuilder()
Expand All @@ -69,3 +72,7 @@ class SoptAuthenticator @Inject constructor(
return null
}
}

interface ProvidesIntents {
fun getAuthActivityIntent(): Intent
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class SoptDataStore @Inject constructor(

var userStatus: String
set(value) = store.edit { putString(USER_STATUS, value) }
get() = store.getString(USER_STATUS, UserStatus.UNAUTHENTICATED.value) ?: UserStatus.UNAUTHENTICATED.value
get() = store.getString(USER_STATUS, UNAUTHENTICATED) ?: UNAUTHENTICATED

var pushToken: String
set(value) = store.edit { putString(PUSH_TOKEN, value) }
Expand All @@ -124,18 +124,7 @@ class SoptDataStore @Inject constructor(
private const val KEY_ALIAS_AUTH = "alias.preferences.auth_token"
private const val ANDROID_KEY_STORE = "AndroidKeyStore"
private const val PUSH_TOKEN = "push_token"
private const val UNAUTHENTICATED="UNAUTHENTICATED"

enum class UserStatus(
val value: String
) {
ACTIVE("ACTIVE"),
INACTIVE("INACTIVE"),
UNAUTHENTICATED("UNAUTHENTICATED");

companion object {
fun of(value: String) = entries.find { it.value == value }
?: throw IllegalArgumentException("Invalid user status: $value")
}
}
}
}

0 comments on commit c4d0ed3

Please sign in to comment.