Skip to content

Commit

Permalink
Merge pull request #121 from Nexters/feature/clean-up
Browse files Browse the repository at this point in the history
[FIX] 마이 페이지 화면 AccessToken 만료, 서버 에러 대응
  • Loading branch information
easyhooon authored Mar 27, 2024
2 parents b1f940e + b853704 commit d93e954
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ internal object ApplicationConfig {
const val MinSdk = 26
const val TargetSdk = 34
const val CompileSdk = 34
const val VersionCode = 6
const val VersionName = "1.0.5"
const val VersionCode = 7
const val VersionName = "1.0.6"
val JavaVersion = org.gradle.api.JavaVersion.VERSION_17
const val JavaVersionAsInt = 17
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TokenRepositoryImpl @Inject constructor(
return dataSource.getUUID()
}

override suspend fun clear() {
dataSource.clear()
override suspend fun clearAuthToken() {
dataSource.clearAuthToken()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface TokenDataSource {
suspend fun getAccessToken(): String
suspend fun getRefreshToken(): String
suspend fun getUUID(): Long
suspend fun clear()
suspend fun clearAuthToken()
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TokenDataSourceImpl @Inject constructor(
else throw exception
}.first()[KEY_REFRESH_TOKEN] ?: ""

override suspend fun clear() {
override suspend fun clearAuthToken() {
dataStore.edit { it.clear() }
}
}
1 change: 0 additions & 1 deletion core/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ android {
dependencies {
implementations(
libs.androidx.core,
libs.androidx.splash,
libs.coil.compose,
)
}
1 change: 1 addition & 0 deletions core/designsystem/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<string name="mypage_name_postfix">님</string>
<string name="mypage_dropdown_delete">삭제하기</string>
<string name="mypage_dropdown_share">공유하기</string>
<string name="mypage_logout">로그인 세션이 종료되어 다시 로그인이 필요합니다.</string>

<!-- Setting -->
<string name="setting_title">설정</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface TokenRepository {
suspend fun getAccessToken(): String
suspend fun getRefreshToken(): String
suspend fun getUUID(): Long
suspend fun clear()
suspend fun clearAuthToken()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package com.nexters.ilab.android.feature.intro
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.graphics.Color
import androidx.activity.enableEdgeToEdge
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.nexters.ilab.android.core.designsystem.theme.ILabTheme
import com.nexters.ilab.android.feature.intro.viewmodel.IntroViewModel
import com.nexters.ilab.android.feature.navigator.LoginNavigator
import com.nexters.ilab.android.feature.navigator.MainNavigator
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -18,8 +16,6 @@ import javax.inject.Inject

@AndroidEntryPoint
class IntroActivity : ComponentActivity() {
private val viewModel: IntroViewModel by viewModels()

@Inject
lateinit var loginNavigator: LoginNavigator

Expand Down Expand Up @@ -58,7 +54,6 @@ class IntroActivity : ComponentActivity() {
withFinish = true,
)
},
viewModel = viewModel,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class IntroViewModel @Inject constructor(

fun autoLoginFail() = intent {
viewModelScope.launch {
repository.clear()
repository.clearAuthToken()
postSideEffect(IntroSideEffect.AutoLoginFail)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.graphics.Color
import com.nexters.ilab.android.core.designsystem.theme.ILabTheme
import com.nexters.ilab.android.feature.login.viewmodel.LoginViewModel
import com.nexters.ilab.android.feature.navigator.MainNavigator
import dagger.hilt.android.AndroidEntryPoint
import tech.thdev.compose.exteions.system.ui.controller.rememberExSystemUiController
import javax.inject.Inject

@AndroidEntryPoint
class LoginActivity : ComponentActivity() {
private val viewModel: LoginViewModel by viewModels()

@Inject
lateinit var mainNavigator: MainNavigator

Expand Down Expand Up @@ -46,7 +42,6 @@ class LoginActivity : ComponentActivity() {
withFinish = true,
)
},
viewModel = viewModel,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LoginViewModel @Inject constructor(
}
.onFailure { exception ->
Timber.e(exception)
tokenRepository.clear()
tokenRepository.clearAuthToken()
postSideEffect(LoginSideEffect.LoginFail(exception))
}
reduce {
Expand Down
8 changes: 1 addition & 7 deletions feature/main/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@

<activity
android:name=".MainActivity"
android:exported="true"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@style/Theme.ILab">

<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->

<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->

</activity>

</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ internal fun MainScreen(
padding = padding,
onSettingClick = navigator::navigateToSetting,
onNavigateToMyAlbum = navigator::navigateToMyAlbum,
onNavigateToLogin = onNavigateToLogin,
)

myAlbumNavGraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.nexters.ilab.android.feature.mypage
import android.content.ClipData
import android.content.Intent
import android.net.Uri
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.Image
Expand Down Expand Up @@ -48,6 +49,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
Expand All @@ -72,7 +74,6 @@ import com.nexters.ilab.core.ui.component.ILabTopAppBar
import com.nexters.ilab.core.ui.component.LoadingIndicator
import com.nexters.ilab.core.ui.component.NetworkErrorDialog
import com.nexters.ilab.core.ui.component.NetworkImage
import com.nexters.ilab.core.ui.component.ServerErrorDialog
import com.nexters.ilab.core.ui.component.TopAppBarNavigationType
import kotlinx.collections.immutable.ImmutableList

Expand All @@ -81,9 +82,11 @@ internal fun MyPageRoute(
padding: PaddingValues,
onSettingClick: () -> Unit,
onNavigateToMyAlbum: (String, List<String>) -> Unit,
onNavigateToLogin: () -> Unit,
viewModel: MyPageViewModel = hiltViewModel(),
) {
val uiState by viewModel.container.stateFlow.collectAsStateWithLifecycle()
val context = LocalContext.current

val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { _ ->
viewModel.deleteCacheDir()
Expand All @@ -100,7 +103,7 @@ internal fun MyPageRoute(
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
// https://stackoverflow.com/questions/57689792/permission-denial-while-sharing-file-with-fileprovider
val clipData = ClipData.newRawUri("", uriList.get(0)).apply {
val clipData = ClipData.newRawUri("", uriList[0]).apply {
for (i in 1 until uriList.size) {
addItem(ClipData.Item(uriList[i]))
}
Expand All @@ -119,6 +122,10 @@ internal fun MyPageRoute(
sideEffect.imageUrlList,
)
}

is MyPageSideEffect.ShowToast -> {
Toast.makeText(context, sideEffect.message.asString(context), Toast.LENGTH_SHORT).show()
}
}
}
}
Expand All @@ -131,8 +138,10 @@ internal fun MyPageRoute(
onShareBtnClick = viewModel::shareMyAlbum,
onDeleteBtnClick = viewModel::deleteMyAlbum,
onAlbumClick = viewModel::onAlbumClick,
dismissServerErrorDialog = viewModel::dismissServerErrorDialog,
// dismissServerErrorDialog = viewModel::dismissServerErrorDialog,
dismissNetworkErrorDialog = viewModel::dismissNetworkErrorDialog,
onNavigateToLogin = onNavigateToLogin,
clearAuthToken = viewModel::clearAuthToken,
)
}

Expand All @@ -145,8 +154,10 @@ internal fun MyPageScreen(
onShareBtnClick: () -> Unit,
onDeleteBtnClick: (Int) -> Unit,
onAlbumClick: (Int) -> Unit,
dismissServerErrorDialog: () -> Unit,
// dismissServerErrorDialog: () -> Unit,
dismissNetworkErrorDialog: () -> Unit,
onNavigateToLogin: () -> Unit,
clearAuthToken: () -> Unit,
) {
Column(
modifier = Modifier
Expand All @@ -158,12 +169,14 @@ internal fun MyPageScreen(
LoadingIndicator(modifier = Modifier.fillMaxSize())
}
if (uiState.isServerErrorDialogVisible) {
ServerErrorDialog(
onRetryClick = {
dismissServerErrorDialog()
getUserInfo()
},
)
// ServerErrorDialog(
// onRetryClick = {
// dismissServerErrorDialog()
// getUserInfo()
// },
// )
clearAuthToken()
onNavigateToLogin()
}
if (uiState.isNetworkErrorDialogVisible) {
NetworkErrorDialog(
Expand Down Expand Up @@ -442,14 +455,16 @@ fun MyPageScreenPreview() {
onAlbumClick = {},
getUserInfo = {},
dismissNetworkErrorDialog = {},
dismissServerErrorDialog = {},
// dismissServerErrorDialog = {},
onNavigateToLogin = {},
clearAuthToken = {},
)
}
}

@DevicePreview
@Composable
fun MyPageScreenTestPreview() {
fun MyPageScreenEmptyPreview() {
ILabTheme {
MyPageContentEmpty()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ fun NavGraphBuilder.myPageNavGraph(
padding: PaddingValues,
onSettingClick: () -> Unit,
onNavigateToMyAlbum: (String, List<String>) -> Unit,
onNavigateToLogin: () -> Unit,
) {
composable(route = MY_PAGE_ROUTE) {
MyPageRoute(
padding = padding,
onSettingClick = onSettingClick,
onNavigateToMyAlbum = onNavigateToMyAlbum,
onNavigateToLogin = onNavigateToLogin,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.nexters.ilab.android.feature.mypage.viewmodel

import com.nexters.ilab.android.core.common.UiText

sealed interface MyPageSideEffect {
data class ShareMyAlbum(val imageUriList: List<String>) : MyPageSideEffect
data class NavigateToMyAlbum(
val imageUrlList: List<String>,
val imageStyle: String,
) : MyPageSideEffect

data class ShowToast(val message: UiText) : MyPageSideEffect
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package com.nexters.ilab.android.feature.mypage.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.nexters.ilab.android.core.common.ErrorHandlerActions
import com.nexters.ilab.android.core.common.UiText
import com.nexters.ilab.android.core.common.handleException
import com.nexters.ilab.android.core.designsystem.R
import com.nexters.ilab.android.core.domain.repository.AuthRepository
import com.nexters.ilab.android.core.domain.repository.DeleteMyAlbumRepository
import com.nexters.ilab.android.core.domain.repository.FileRepository
import com.nexters.ilab.android.core.domain.repository.TokenRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.launch
Expand All @@ -23,6 +26,7 @@ class MyPageViewModel @Inject constructor(
private val authRepository: AuthRepository,
private val fileRepository: FileRepository,
private val deleteMyAlbumRepository: DeleteMyAlbumRepository,
private val tokenRepository: TokenRepository,
) : ViewModel(), ContainerHost<MyPageState, MyPageSideEffect>, ErrorHandlerActions {
override val container = container<MyPageState, MyPageSideEffect>(MyPageState())

Expand Down Expand Up @@ -135,8 +139,12 @@ class MyPageViewModel @Inject constructor(
}
}

override fun onCleared() {
super.onCleared()
Timber.d("MyPageViewModel is cleared")
fun clearAuthToken() = intent {
viewModelScope.launch {
tokenRepository.clearAuthToken()
postSideEffect(
MyPageSideEffect.ShowToast(UiText.StringResource(R.string.mypage_logout)),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SettingViewModel @Inject constructor(
reduce { state.copy(isLoading = true) }
authRepository.signOut()
.onSuccess {
tokenRepository.clear()
tokenRepository.clearAuthToken()
postSideEffect(SettingSideEffect.LogoutSuccess)
}.onFailure { exception ->
Timber.d("$exception")
Expand All @@ -41,11 +41,7 @@ class SettingViewModel @Inject constructor(

fun getVersionInfo(context: Context): String {
val packageInfo: PackageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
if (packageInfo != null) {
return packageInfo.versionName
} else {
return "버전 정보가 없습니다."
}
return packageInfo.versionName
}

fun deleteAccount() = intent {
Expand All @@ -54,7 +50,7 @@ class SettingViewModel @Inject constructor(
reduce { state.copy(isLoading = true) }
authRepository.deleteAccount()
.onSuccess {
tokenRepository.clear()
tokenRepository.clearAuthToken()
postSideEffect(SettingSideEffect.LogoutSuccess)
}.onFailure { exception ->
Timber.d("$exception")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ fun NavGraphBuilder.uploadPhotoNavGraph(
) {
composable(route = UPLOAD_ROUTE) { entry ->
val viewModel = entry.sharedViewModel<UploadPhotoViewModel>(navController)

UploadPhotoRoute(
onBackClick = onBackClick,
onNavigateToPrivacyPolicy = onNavigateToPrivacyPolicy,
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.
kotlin-ktlint = { group = "com.pinterest", name = "ktlint", version.ref = "kotlin-ktlint-source" }
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinx-datetime" }
kotlinx-collections-immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "kotlinx-collections-immutable" }

hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
Expand Down

0 comments on commit d93e954

Please sign in to comment.