From b794abcacd9c65a9a904fe320a8d22346bf415f1 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 9 Jul 2024 22:49:56 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=88=98=EC=A0=95=20-=20=EC=95=A8?= =?UTF-8?q?=EB=B2=94=EC=97=90=EC=84=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=99=80=EC=84=9C=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=20=ED=8E=B8=EC=A7=91=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mypage/editprofile/EditProfileScreen.kt | 24 ++++++++++--------- .../editprofile/EditProfileViewModel.kt | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/editprofile/EditProfileScreen.kt b/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/editprofile/EditProfileScreen.kt index 117d3e8..792a4b1 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/editprofile/EditProfileScreen.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/editprofile/EditProfileScreen.kt @@ -1,7 +1,6 @@ package com.whyranoid.presentation.screens.mypage.editprofile import android.Manifest -import android.net.Uri import android.widget.Toast import androidx.activity.compose.BackHandler import androidx.activity.compose.rememberLauncherForActivityResult @@ -77,7 +76,6 @@ fun EditProfileScreen(navController: NavController) { val walkieId = viewModel.walkieId.collectAsStateWithLifecycle(initialValue = 0L) val name = viewModel.name.collectAsStateWithLifecycle(initialValue = String.EMPTY) val nick = viewModel.nick.collectAsStateWithLifecycle(initialValue = String.EMPTY) - var capturedUri by remember { mutableStateOf(Uri.EMPTY) } val context = LocalContext.current LaunchedEffect(viewModel.profileImg) { @@ -93,7 +91,6 @@ fun EditProfileScreen(navController: NavController) { ) val cameraLauncher = rememberLauncherForActivityResult(contract = ActivityResultContracts.TakePicture()) { - capturedUri = uri viewModel.setProfileUrl(uri.toString()) } @@ -107,6 +104,12 @@ fun EditProfileScreen(navController: NavController) { } } + val galleryLauncher = rememberLauncherForActivityResult( + ActivityResultContracts.GetContent() + ) { + it?.let { uri -> viewModel.setProfileUrl(uri.toString()) } + } + val bottomSheetState = rememberModalBottomSheetState( initialValue = ModalBottomSheetValue.Hidden ) @@ -148,7 +151,7 @@ fun EditProfileScreen(navController: NavController) { WalkieBottomSheetButton( buttonText = "앨범에서 프로필 사진 가져오기", onClick = { - // 앨범 실행 + galleryLauncher.launch("image/*") } ) @@ -156,7 +159,9 @@ fun EditProfileScreen(navController: NavController) { WalkieBottomSheetButton( buttonText = "현재 프로필 사진 삭제", - onClick = { } + onClick = { + viewModel.setProfileUrl(null) + } ) } } @@ -202,15 +207,12 @@ fun EditProfileContent( } } - if (currentProfileImg != null) { - LaunchedEffect(currentProfileImg) { - if (currentProfileImg != initialProfileImg) { - isChangeEnabled = true - } + LaunchedEffect(currentProfileImg) { + if (currentProfileImg != initialProfileImg) { + isChangeEnabled = true } } - LaunchedEffect(viewModel.isMyInfoChanged) { viewModel.isMyInfoChanged.collectLatest { Toast.makeText(context, "정보가 수정되었습니다.", Toast.LENGTH_SHORT).show() diff --git a/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/editprofile/EditProfileViewModel.kt b/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/editprofile/EditProfileViewModel.kt index 7872537..32d0f42 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/editprofile/EditProfileViewModel.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/editprofile/EditProfileViewModel.kt @@ -42,7 +42,7 @@ class EditProfileViewModel( .onSuccess { _isMyInfoChanged.emit(true) } } - fun setProfileUrl(url: String) { + fun setProfileUrl(url: String?) { _currentProfileUrl.update { url } } }