Skip to content

Commit

Permalink
[feat/#76] setting 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnseo committed Feb 9, 2024
1 parent e44d101 commit 01e0e15
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class AttendViewModel @Inject constructor(
initialValue = AttendInfoModel(0, "", false, "", "")
)

private val _qrEnabled = MutableStateFlow(true)
val qrEnabled: StateFlow<Boolean> = _qrEnabled.asStateFlow()

private val _attendCheckModel = MutableStateFlow(
AttendCheckModel(curriculumId = upcomingAttend.value.curriculumId, text = "")
)
Expand Down Expand Up @@ -107,6 +110,7 @@ class AttendViewModel @Inject constructor(
.collectLatest {
Log.d("출석 확인", "출석 성공")
_snackbarEvent.emit(AttendSnackBarEvent.Attend_success)
_qrEnabled.value = true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.kusitms.presentation.model.setting

import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.UriHandler
import androidx.compose.ui.text.font.FontVariation
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.NavHostController
import com.kusitms.domain.usecase.signin.MemberLogOutUseCase
import com.kusitms.domain.usecase.signin.MemberSignOutUseCase
import com.kusitms.presentation.R
import com.kusitms.presentation.model.login.LoginStatus
import com.kusitms.presentation.model.signIn.SignInViewModel
import com.kusitms.presentation.navigation.NavRoutes
Expand Down Expand Up @@ -40,7 +43,7 @@ class SettingViewModel @Inject constructor(
viewModelScope.launch {
memberLogOutUseCase()
.onSuccess {
updateSettingStatus(SettingStatus.LOGOUT)
updateSettingStatus(SettingStatus.LOGOUT_SUCCESS)
}
.onFailure {
updateSettingStatus(SettingStatus.ERROR)
Expand All @@ -52,16 +55,34 @@ class SettingViewModel @Inject constructor(
viewModelScope.launch {
memberSignOutUseCase()
.onSuccess {
updateSettingStatus(SettingStatus.SIGNOUT)
updateSettingStatus(SettingStatus.SIGNOUT_SUCCESS)
}
.onFailure {
updateSettingStatus(SettingStatus.ERROR)
}
}
}

companion object {
enum class SettingStatus { LOGOUT, SIGNOUT, DEFAULT, ERROR}

enum class SettingStatus {
LOGOUT, LOGOUT_SUCCESS, SIGNOUT_INIT,SIGNOUT, SIGNOUT_SUCCESS, DEFAULT, ERROR;

@StringRes
fun getTitleResId(): Int {
return when (this) {
LOGOUT -> R.string.logout_dialog_title
SIGNOUT -> R.string.signout_dialog_title
else -> R.string.signout_blank_title
}
}
@StringRes
fun getContentResId(): Int {
return when (this) {
LOGOUT -> R.string.logout_dialog_content
SIGNOUT -> R.string.signout_dialog_content
else -> R.string.signout_blank_title
}
}
}

}
Expand All @@ -84,8 +105,8 @@ fun getMemberSetting(viewModel: SettingViewModel, navController: NavHostControll
SettingUiModel(title = "개인정보 처리 방침", url = "https://sheer-billboard-d63.notion.site/KUSITMS-9e6619383bcd4ce68b6ba4b2b6ef0d40?pvs=4"),
SettingUiModel(title = "서비스 이용약관", url = "https://sheer-billboard-d63.notion.site/24a4639559d4433cb89c8f1abb889726?pvs=4"),
SettingUiModel(title = "비밀번호 변경", onClick = { goToSetPw(navController) }),
SettingUiModel(title = "로그아웃", onClick = { viewModel.logOut() }),
SettingUiModel(title = "회원탈퇴", onClick = { viewModel.signOut() })
SettingUiModel(title = "로그아웃", onClick = { viewModel.updateSettingStatus(SettingViewModel.SettingStatus.LOGOUT) }),
SettingUiModel(title = "회원탈퇴", onClick = { viewModel.updateSettingStatus(SettingViewModel.SettingStatus.SIGNOUT_INIT) })
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ fun CameraScreen(
},
onGranted = {
val onQrCodeScanned: (String) -> Unit = { qrText ->
viewModel.updateScannedQrCode(qrText)
viewModel.postAttendCheck()
if(qrText != "") {
viewModel.updateScannedQrCode(qrText)
viewModel.postAttendCheck()
}
}
Box(
modifier = Modifier.fillMaxSize(),
Expand All @@ -104,7 +106,7 @@ fun CameraScreen(
}
}
}
CameraPreview(onQrCodeScanned = onQrCodeScanned)
CameraPreview(viewModel = viewModel, onQrCodeScanned = onQrCodeScanned)
}
)
}
Expand Down Expand Up @@ -270,11 +272,12 @@ private fun createCornersPath(

@Composable
@androidx.annotation.OptIn(androidx.camera.core.ExperimentalGetImage::class)
fun CameraPreview(onQrCodeScanned: (String) -> Unit) {
fun CameraPreview(viewModel: AttendViewModel, onQrCodeScanned: (String) -> Unit) {
val lifecycleOwner = LocalLifecycleOwner.current
val context = LocalContext.current
val cameraProviderFuture = remember { ProcessCameraProvider.getInstance(context) }
val previewView = remember { PreviewView(context) }
val qrEnabled by viewModel.qrEnabled.collectAsState()
val preview = Preview.Builder().build().also {
it.setSurfaceProvider(previewView.surfaceProvider)
}
Expand All @@ -285,32 +288,36 @@ fun CameraPreview(onQrCodeScanned: (String) -> Unit) {
.build()
.also {
it.setAnalyzer(ContextCompat.getMainExecutor(context)) { imageProxy ->
val image = imageProxy.image
if (image != null) {
val buffer = image.planes[0].buffer
val bytes = ByteArray(buffer.remaining())
buffer.get(bytes)
val source = PlanarYUVLuminanceSource(
bytes, image.width, image.height, 0, 0, image.width, image.height, false
)
val binaryBitmap = BinaryBitmap(HybridBinarizer(source))
try {
val reader = MultiFormatReader().apply {
val hints = mapOf<DecodeHintType, Any>(
DecodeHintType.POSSIBLE_FORMATS to listOf(
BarcodeFormat.QR_CODE
if(qrEnabled) {
val image = imageProxy.image
if (image != null) {
val buffer = image.planes[0].buffer
val bytes = ByteArray(buffer.remaining())
buffer.get(bytes)
val source = PlanarYUVLuminanceSource(
bytes, image.width, image.height, 0, 0, image.width, image.height, false
)
val binaryBitmap = BinaryBitmap(HybridBinarizer(source))
try {
val reader = MultiFormatReader().apply {
val hints = mapOf<DecodeHintType, Any>(
DecodeHintType.POSSIBLE_FORMATS to listOf(
BarcodeFormat.QR_CODE
)
)
)
setHints(hints)
setHints(hints)
}
val result = reader.decode(binaryBitmap)
val qrText = result.text
onQrCodeScanned(qrText)
} catch (e: NotFoundException) {
// QR 코드를 찾지 못함
} finally {
imageProxy.close()
}
val result = reader.decode(binaryBitmap)
val qrText = result.text
onQrCodeScanned(qrText)
} catch (e: NotFoundException) {
// QR 코드를 찾지 못함
} finally {
imageProxy.close()
}
} else {
imageProxy.close()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ fun SettingMember(

LaunchedEffect(settingStatus) {
when(settingStatus) {
SettingViewModel.Companion.SettingStatus.LOGOUT, SettingViewModel.Companion.SettingStatus.SIGNOUT -> {
SettingViewModel.SettingStatus.LOGOUT_SUCCESS, SettingViewModel.SettingStatus.SIGNOUT_SUCCESS-> {
navController.navigate(NavRoutes.LogInScreen.route) {
popUpTo(NavRoutes.SettingMember.route) { inclusive = true }
}

}
}
SettingViewModel.SettingStatus.LOGOUT -> {
openDialogState = true
}
SettingViewModel.SettingStatus.SIGNOUT -> {
openDialogState = true
}
//처리.. 필요..
SettingViewModel.Companion.SettingStatus.ERROR, SettingViewModel.Companion.SettingStatus.DEFAULT -> {}
SettingViewModel.SettingStatus.ERROR, SettingViewModel.SettingStatus.DEFAULT -> {}
else -> {}
}
}

Expand Down
5 changes: 5 additions & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@
<string name="logout_dialog_title">로그아웃</string>
<string name="logout_dialog_content">로그아웃을 진행할까요?</string>

<string name="signout_dialog_title">회원탈퇴</string>

<string name="signout_blank_title"></string>
<string name="signout_dialog_content">회원탈퇴를 진행할까요?\n 탈퇴하게 되면 정보가 삭제되며 되돌릴 수 없습니다.</string>

<string name="attend_topbar">출석</string>
<string name="attend_box1_title">다가오는 커리큘럼</string>
<string name="attend_box1_subTitle">%s</string>
Expand Down

0 comments on commit 01e0e15

Please sign in to comment.