Skip to content

Commit

Permalink
✨ 마이페이지 수정 - 앨범에서 이미지 가져와서 프로필 편집 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-j0y committed Jul 9, 2024
1 parent 2633f96 commit b794abc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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>(Uri.EMPTY) }
val context = LocalContext.current

LaunchedEffect(viewModel.profileImg) {
Expand All @@ -93,7 +91,6 @@ fun EditProfileScreen(navController: NavController) {
)

val cameraLauncher = rememberLauncherForActivityResult(contract = ActivityResultContracts.TakePicture()) {
capturedUri = uri
viewModel.setProfileUrl(uri.toString())
}

Expand All @@ -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
)
Expand Down Expand Up @@ -148,15 +151,17 @@ fun EditProfileScreen(navController: NavController) {
WalkieBottomSheetButton(
buttonText = "앨범에서 프로필 사진 가져오기",
onClick = {
// 앨범 실행
galleryLauncher.launch("image/*")
}
)

Spacer(modifier = Modifier.height(8.dp))

WalkieBottomSheetButton(
buttonText = "현재 프로필 사진 삭제",
onClick = { }
onClick = {
viewModel.setProfileUrl(null)
}
)
}
}
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EditProfileViewModel(
.onSuccess { _isMyInfoChanged.emit(true) }
}

fun setProfileUrl(url: String) {
fun setProfileUrl(url: String?) {
_currentProfileUrl.update { url }
}
}

0 comments on commit b794abc

Please sign in to comment.