Skip to content

Commit

Permalink
[Fix/#871] 마이페이지 오류 수정 (#907)
Browse files Browse the repository at this point in the history
* [fix/#871] remove logout responses

* [fix/#871] delete LogOutResponse.kt

* [feature/#871] get Profile Message

* [feature/#871] modify button enable condition

* [feature/#871] modify button enable condition

* [feature/#871] make adjust sentence toast

* [feature/#871] delete mypage nickname view

* [feature/#871] make resetSoptamp success

* [feature/#871] add refreshToken empty function

* [feature/#871] modify login and logout logic

* [feature/#871] change mypage state

* [feature/#871] delete delay function

* [feature/#871] code refactoring

* [feature/#871] code refactoring

* [feature/#871] MIT License

* [feature/#871] change ui state

* [feature/#871] rename onDismiss function

* [feature/#871] update 함수 사용

* [feature/#871] myPageState 변수명 수정

* [feature/#871] sealed class -> sealed interface

* [feature/#871] 초기 한마디 변수명 수정

* [feature/#871] logout -> deleteUserInfo

* [feature/#871] 타입 명시

* [feature/#871] License
  • Loading branch information
leeeyubin authored Oct 17, 2024
1 parent 1f20800 commit 8abbfad
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 3,936 deletions.
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@
android:name=".feature.mypage.signOut.SignOutActivity"
android:exported="false"
android:theme="@style/Theme.SOPT" />
<activity
android:name=".feature.mypage.soptamp.nickName.ChangeNickNameActivity"
android:exported="false"
android:theme="@style/Theme.SOPT" />
<activity
android:name=".feature.mypage.soptamp.sentence.AdjustSentenceActivity"
android:exported="false"
Expand Down
1,799 changes: 21 additions & 1,778 deletions app/src/release/generated/baselineProfiles/baseline-prof.txt

Large diffs are not rendered by default.

1,799 changes: 21 additions & 1,778 deletions app/src/release/generated/baselineProfiles/startup-prof.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ package org.sopt.official.auth.impl.api

import org.sopt.official.auth.impl.model.request.AuthRequest
import org.sopt.official.auth.impl.model.response.LogOutRequest
import org.sopt.official.auth.impl.model.response.LogOutResponse
import org.sopt.official.network.model.response.AuthResponse
import retrofit2.http.Body
import retrofit2.http.DELETE
Expand All @@ -41,5 +40,5 @@ interface AuthService {
suspend fun withdraw()

@HTTP(method = "DELETE", path = "user/logout", hasBody = true)
suspend fun logOut(@Body body: LogOutRequest): LogOutResponse
suspend fun deleteUserInfo(@Body body: LogOutRequest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package org.sopt.official.auth.impl.remote
import javax.inject.Inject
import org.sopt.official.auth.impl.api.AuthService
import org.sopt.official.auth.impl.model.response.LogOutRequest
import org.sopt.official.auth.impl.model.response.LogOutResponse
import org.sopt.official.auth.impl.source.RemoteAuthDataSource
import org.sopt.official.common.di.Auth
import org.sopt.official.network.model.request.RefreshRequest
Expand All @@ -46,7 +45,7 @@ class DefaultRemoteAuthDataSource @Inject constructor(
authService.withdraw()
}

override suspend fun logout(request: LogOutRequest): LogOutResponse {
return authService.logOut(request)
override suspend fun deleteUserInfo(request: LogOutRequest) {
authService.deleteUserInfo(request)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class AuthRepositoryImpl @Inject constructor(
remoteAuthDataSource.withdraw()
}

override suspend fun logout(pushToken: String): Result<Unit> = runCatching {
remoteAuthDataSource.logout(
override suspend fun logout(pushToken: String) = runCatching {
remoteAuthDataSource.deleteUserInfo(
LogOutRequest(
platform = "Android",
pushToken = pushToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
package org.sopt.official.auth.impl.source

import org.sopt.official.auth.impl.model.response.LogOutRequest
import org.sopt.official.auth.impl.model.response.LogOutResponse
import org.sopt.official.network.model.request.RefreshRequest
import org.sopt.official.network.model.response.AuthResponse

interface RemoteAuthDataSource {
suspend fun refresh(token: RefreshRequest): AuthResponse
suspend fun withdraw()
suspend fun logout(request: LogOutRequest): LogOutResponse
suspend fun deleteUserInfo(request: LogOutRequest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ package org.sopt.official.network.authenticator
import android.content.Context
import com.jakewharton.processphoenix.ProcessPhoenix
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.runBlocking
import okhttp3.Authenticator
import okhttp3.Request
Expand All @@ -39,6 +37,8 @@ import org.sopt.official.network.model.request.RefreshRequest
import org.sopt.official.network.persistence.SoptDataStore
import org.sopt.official.network.service.RefreshService
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SoptAuthenticator @Inject constructor(
Expand All @@ -50,6 +50,7 @@ class SoptAuthenticator @Inject constructor(
override fun authenticate(route: Route?, response: Response): Request? {
if (response.code == 401) {
val refreshToken = dataStore.refreshToken
if (refreshToken.isEmpty()) return null
val newTokens = runCatching {
runBlocking {
refreshService.refresh(RefreshRequest(refreshToken))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* MIT License
* Copyright 2024 SOPT - Shout Our Passion Together
* Copyright 2023-2024 SOPT - Shout Our Passion Together
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
package org.sopt.official.feature.mypage.model

import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable

@Stable
sealed interface MyPageUiModel {
@Immutable
data class Header(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@
*/
package org.sopt.official.feature.mypage.model

import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import org.sopt.official.auth.model.UserActiveState
import org.sopt.official.feature.mypage.mypage.MyPageAction

@Stable
sealed interface MyPageUiState {

@Immutable
data object UnInitialized : MyPageUiState
data class User(val activeState: UserActiveState) : MyPageUiState
data class Dialog(val action: MyPageAction) : MyPageUiState

@Immutable
data class Authenticated(
val activeState: UserActiveState,
) : MyPageUiState

@Immutable
data object UnAuthenticated : MyPageUiState
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.flowWithLifecycle
import com.jakewharton.processphoenix.ProcessPhoenix
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.collections.immutable.persistentListOf
import org.sopt.official.auth.model.UserActiveState
Expand Down Expand Up @@ -84,8 +83,8 @@ class MyPageActivity : AppCompatActivity() {
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current

val isAuthenticated by viewModel.userActiveState.collectAsStateWithLifecycle(initialValue = false)
val dialogState by viewModel.dialogState.collectAsStateWithLifecycle()
val myPageState by viewModel.state.collectAsStateWithLifecycle()
val myPageAction by viewModel.action.collectAsStateWithLifecycle()
val scrollState = rememberScrollState()

val serviceSectionItems = remember {
Expand Down Expand Up @@ -156,34 +155,25 @@ class MyPageActivity : AppCompatActivity() {
MyPageUiModel.MyPageItem(
title = "로그인",
onItemClick = {
onBackPressedDispatcher.onBackPressed()
startActivity(navigatorProvider.getAuthActivityIntent())
}
)
)
}

LaunchedEffect(Unit) {
args?.userActiveState?.let {
viewModel.setUserActiveState(MyPageUiState.User(it))
viewModel.setUserActiveState(it)
}
}

LaunchedEffect(viewModel.finish, lifecycleOwner) {
viewModel.finish.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle)
.collect {
ProcessPhoenix.triggerRebirth(context, navigatorProvider.getAuthActivityIntent())
startActivity(navigatorProvider.getAuthActivityIntent())
}
}

if (dialogState is MyPageUiState.Dialog) {
ShowMyPageDialog(
action = (dialogState as MyPageUiState.Dialog).action,
onDismissRequest = viewModel::onDismiss,
onClearSoptampClick = viewModel::resetSoptamp,
onLogoutClick = viewModel::logOut
)
}

Scaffold(modifier = Modifier
.background(SoptTheme.colors.background)
.fillMaxSize(),
Expand All @@ -204,17 +194,31 @@ class MyPageActivity : AppCompatActivity() {
Spacer(modifier = Modifier.height(20.dp))
MyPageSection(items = serviceSectionItems)
Spacer(modifier = Modifier.height(16.dp))
if (isAuthenticated) {
MyPageSection(items = notificationSectionItems)
Spacer(modifier = Modifier.height(16.dp))
MyPageSection(items = soptampSectionItems)
Spacer(modifier = Modifier.height(16.dp))
MyPageSection(items = etcSectionItems)
} else {
MyPageSection(items = etcLoginSectionItems)
when (myPageState) {
is MyPageUiState.Authenticated -> {
MyPageSection(items = notificationSectionItems)
Spacer(modifier = Modifier.height(16.dp))
MyPageSection(items = soptampSectionItems)
Spacer(modifier = Modifier.height(16.dp))
MyPageSection(items = etcSectionItems)
}

is MyPageUiState.UnAuthenticated -> {
MyPageSection(items = etcLoginSectionItems)
}

is MyPageUiState.UnInitialized -> {}
}
Spacer(modifier = Modifier.height(32.dp))
}
if (myPageAction != null) {
ShowMyPageDialog(
action = myPageAction ?: return@Scaffold,
onDismissRequest = viewModel::closeDialog,
onClearSoptampClick = viewModel::resetSoptamp,
onLogoutClick = viewModel::logOut
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await
import org.sopt.official.auth.model.UserActiveState
Expand All @@ -54,18 +53,20 @@ class MyPageViewModel @Inject constructor(
private val stampRepository: StampRepository,
) : ViewModel() {

private val _userActiveState = MutableStateFlow<MyPageUiState>(MyPageUiState.UnInitialized)
val userActiveState = _userActiveState.filterIsInstance<MyPageUiState.User>()
.map { it.activeState != UserActiveState.UNAUTHENTICATED }
private val _state: MutableStateFlow<MyPageUiState> = MutableStateFlow(MyPageUiState.UnInitialized)
val state: StateFlow<MyPageUiState> = _state.asStateFlow()

private val _dialogState: MutableStateFlow<MyPageUiState> = MutableStateFlow(MyPageUiState.UnInitialized)
val dialogState: StateFlow<MyPageUiState> = _dialogState.asStateFlow()
private val _action = MutableStateFlow<MyPageAction?>(null)
val action: StateFlow<MyPageAction?> = _action.asStateFlow()

private val _finish = Channel<Unit>()
val finish = _finish.receiveAsFlow()

fun setUserActiveState(new: MyPageUiState) {
_userActiveState.value = new
fun setUserActiveState(activeState: UserActiveState) {
_state.update {
if (activeState == UserActiveState.UNAUTHENTICATED) MyPageUiState.UnAuthenticated
else MyPageUiState.Authenticated(activeState)
}
}

fun logOut() {
Expand All @@ -87,16 +88,16 @@ class MyPageViewModel @Inject constructor(
fun resetSoptamp() {
viewModelScope.launch {
stampRepository.deleteAllStamps()
.onSuccess { closeDialog() }
.onFailure { Timber.e(it) }
}
}

fun showDialogState(action: MyPageAction) {
_dialogState.tryEmit(MyPageUiState.Dialog(action))
_action.update { action }
}

fun onDismiss() {
_dialogState.tryEmit(MyPageUiState.UnInitialized)
fun closeDialog() {
_action.update { null }
}

}

This file was deleted.

Loading

0 comments on commit 8abbfad

Please sign in to comment.