From d0d0008c0b69d5edf1beb8a2f164e162e0471846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A4=EC=B0=AC?= Date: Thu, 25 Apr 2024 20:15:14 +0900 Subject: [PATCH] Fix:[snsproject] ktlintFormat --- .../main/setting/SettingScreen.kt | 44 ++++---- .../main/setting/SettingViewModel.kt | 104 +++++++++--------- .../main/setting/UsernameDialog.kt | 29 ++--- 3 files changed, 85 insertions(+), 92 deletions(-) diff --git a/presentation/src/main/java/com/example/presentation/main/setting/SettingScreen.kt b/presentation/src/main/java/com/example/presentation/main/setting/SettingScreen.kt index 4e91d78..eda5a0d 100644 --- a/presentation/src/main/java/com/example/presentation/main/setting/SettingScreen.kt +++ b/presentation/src/main/java/com/example/presentation/main/setting/SettingScreen.kt @@ -5,7 +5,6 @@ import android.util.Log import android.widget.Toast import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.PickVisualMediaRequest -import androidx.activity.result.contract.ActivityResultContract import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.background import androidx.compose.foundation.border @@ -47,7 +46,7 @@ import org.orbitmvi.orbit.compose.collectSideEffect fun SettingScreen(viewModel: SettingViewModel = hiltViewModel()) { val state = viewModel.collectAsState().value val context = LocalContext.current - + var usernameDialogVisible by remember { mutableStateOf(false) } @@ -57,7 +56,7 @@ fun SettingScreen(viewModel: SettingViewModel = hiltViewModel()) { Log.e("SettingScreen", sideEffect.message) Toast.makeText(context, sideEffect.message, Toast.LENGTH_SHORT).show() } - + is SettingSideEffect.NavigateToLoginActivity -> { context.startActivity( Intent(context, LoginActivity::class.java).apply { @@ -67,11 +66,12 @@ fun SettingScreen(viewModel: SettingViewModel = hiltViewModel()) { } } } - - val visualMediaPickerLauncher = rememberLauncherForActivityResult(contract = ActivityResultContracts.PickVisualMedia()) { - viewModel.onImageChange(it) - } - + + val visualMediaPickerLauncher = + rememberLauncherForActivityResult(contract = ActivityResultContracts.PickVisualMedia()) { + viewModel.onImageChange(it) + } + SettingScreen( username = state.username, profileImageUrl = state.profileImageUrl, @@ -79,16 +79,16 @@ fun SettingScreen(viewModel: SettingViewModel = hiltViewModel()) { onLogoutClick = viewModel::onLogoutClick, onImageChangeClick = { visualMediaPickerLauncher.launch( - PickVisualMediaRequest(mediaType = ActivityResultContracts.PickVisualMedia.ImageOnly) + PickVisualMediaRequest(mediaType = ActivityResultContracts.PickVisualMedia.ImageOnly), ) }, ) - + UsernameDialog( visible = usernameDialogVisible, initialUsername = state.username, onDismissRequest = { usernameDialogVisible = false }, - onUserNameChange = viewModel::onUsernameChange + onUserNameChange = viewModel::onUsernameChange, ) } @@ -110,23 +110,23 @@ fun SettingScreen( modifier = Modifier.size(150.dp), profileImageUrl = profileImageUrl, ) - + IconButton( modifier = Modifier.align(Alignment.BottomEnd), onClick = onImageChangeClick, ) { Box( modifier = - Modifier - .size(30.dp) - .border(width = 1.dp, color = Color.Gray, shape = CircleShape) - .background(color = Color.White, shape = CircleShape), + Modifier + .size(30.dp) + .border(width = 1.dp, color = Color.Gray, shape = CircleShape) + .background(color = Color.White, shape = CircleShape), ) { Icon( modifier = - Modifier - .align(Alignment.Center) - .size(20.dp), + Modifier + .align(Alignment.Center) + .size(20.dp), imageVector = Icons.Default.Settings, contentDescription = null, tint = MaterialTheme.colorScheme.primary, @@ -136,9 +136,9 @@ fun SettingScreen( } Text( modifier = - Modifier - .padding(top = 8.dp) - .clickable { onNameChangeClick() }, + Modifier + .padding(top = 8.dp) + .clickable { onNameChangeClick() }, text = username, style = MaterialTheme.typography.headlineMedium, fontWeight = FontWeight.Bold, diff --git a/presentation/src/main/java/com/example/presentation/main/setting/SettingViewModel.kt b/presentation/src/main/java/com/example/presentation/main/setting/SettingViewModel.kt index a82e236..71f586e 100644 --- a/presentation/src/main/java/com/example/presentation/main/setting/SettingViewModel.kt +++ b/presentation/src/main/java/com/example/presentation/main/setting/SettingViewModel.kt @@ -20,58 +20,60 @@ import org.orbitmvi.orbit.viewmodel.container @HiltViewModel class SettingViewModel -@Inject -constructor( - private val clearTokenUseCase: ClearTokenUseCase, - private val getMyUserUseCase: GetMyUserUseCase, - private val setMyUserUseCase: SetMyUserUseCase, - private val setProfileImageUseCase: SetProfileImageUseCase -) : ViewModel(), ContainerHost { - override val container: Container = - container( - initialState = SettingState(), - buildSettings = { - this.exceptionHandler = - CoroutineExceptionHandler { _, throwable -> - intent { postSideEffect(SettingSideEffect.Toast(throwable.message ?: "")) } - } - }, - ) - - init { - load() - } - - private fun load() = - intent { - val user = getMyUserUseCase().getOrThrow() - Log.e("SettingViewModel", "user : $user") - reduce { - state.copy( - profileImageUrl = user.profileImageUrl, - username = user.username, - ) - } - } - - fun onLogoutClick() = - intent { - clearTokenUseCase().getOrThrow() - postSideEffect(SettingSideEffect.NavigateToLoginActivity) + @Inject + constructor( + private val clearTokenUseCase: ClearTokenUseCase, + private val getMyUserUseCase: GetMyUserUseCase, + private val setMyUserUseCase: SetMyUserUseCase, + private val setProfileImageUseCase: SetProfileImageUseCase, + ) : ViewModel(), ContainerHost { + override val container: Container = + container( + initialState = SettingState(), + buildSettings = { + this.exceptionHandler = + CoroutineExceptionHandler { _, throwable -> + intent { postSideEffect(SettingSideEffect.Toast(throwable.message ?: "")) } + } + }, + ) + + init { + load() } - - fun onUsernameChange(username: String) = intent { - setMyUserUseCase(username).getOrThrow() - load() - } - - fun onImageChange(uri : Uri?) = intent { - setProfileImageUseCase( - contentUri = uri.toString() - ).getOrThrow() - load() + + private fun load() = + intent { + val user = getMyUserUseCase().getOrThrow() + Log.e("SettingViewModel", "user : $user") + reduce { + state.copy( + profileImageUrl = user.profileImageUrl, + username = user.username, + ) + } + } + + fun onLogoutClick() = + intent { + clearTokenUseCase().getOrThrow() + postSideEffect(SettingSideEffect.NavigateToLoginActivity) + } + + fun onUsernameChange(username: String) = + intent { + setMyUserUseCase(username).getOrThrow() + load() + } + + fun onImageChange(uri: Uri?) = + intent { + setProfileImageUseCase( + contentUri = uri.toString(), + ).getOrThrow() + load() + } } -} @Immutable data class SettingState( @@ -81,6 +83,6 @@ data class SettingState( sealed interface SettingSideEffect { class Toast(val message: String) : SettingSideEffect - + data object NavigateToLoginActivity : SettingSideEffect } diff --git a/presentation/src/main/java/com/example/presentation/main/setting/UsernameDialog.kt b/presentation/src/main/java/com/example/presentation/main/setting/UsernameDialog.kt index 45d9f8b..13a52cf 100644 --- a/presentation/src/main/java/com/example/presentation/main/setting/UsernameDialog.kt +++ b/presentation/src/main/java/com/example/presentation/main/setting/UsernameDialog.kt @@ -1,11 +1,7 @@ package com.example.presentation.main.setting -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.Surface @@ -17,14 +13,10 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.window.Dialog -import androidx.compose.ui.window.DialogProperties -import androidx.compose.ui.window.SecureFlagPolicy import com.example.presentation.ui.theme.SnsProjectTheme @Composable @@ -34,7 +26,6 @@ fun UsernameDialog( onUserNameChange: (String) -> Unit, onDismissRequest: () -> Unit, ) { - if (visible) { var username by remember { mutableStateOf(initialUsername) @@ -45,33 +36,33 @@ fun UsernameDialog( Surface { Column(modifier = Modifier.fillMaxWidth(0.8f)) { TextField( - modifier = Modifier - .fillMaxWidth(), + modifier = + Modifier + .fillMaxWidth(), value = username, onValueChange = { username = it }, textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center), - - ) - + ) + Row { TextButton( modifier = Modifier.weight(1f), onClick = { onUserNameChange(username) onDismissRequest() - }) { + }, + ) { Text(text = "변경") } - + TextButton( modifier = Modifier.weight(1f), - onClick = onDismissRequest) { + onClick = onDismissRequest, + ) { Text(text = "취소") } } } - - } } }