Skip to content

Commit

Permalink
Merge pull request #70 from snuhcs-course/fix/onapp-take-photo
Browse files Browse the repository at this point in the history
fix/onapp-take-photo
  • Loading branch information
89645321 authored Nov 29, 2023
2 parents 02530cd + 860e752 commit ab5ba6b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import com.example.speechbuddy.ui.models.DialogState
import com.example.speechbuddy.ui.models.PhotoType
import com.example.speechbuddy.ui.models.SymbolCreationErrorType
import com.example.speechbuddy.ui.models.SymbolCreationUiState
import com.example.speechbuddy.ui.models.ToastState
import com.example.speechbuddy.utils.Constants
import com.example.speechbuddy.viewmodel.SymbolCreationViewModel

Expand Down Expand Up @@ -109,14 +110,19 @@ fun SymbolCreationScreen(
if (isGranted) {
cameraLauncher.launch(null)
} else {
Toast.makeText(
context,
"Camera permission is required to take photos",
Toast.LENGTH_SHORT
).show()
viewModel.updateToastState("show")
}
}

if (viewModel.toastState == ToastState.SHOW) {
Toast.makeText(
context,
stringResource(id = R.string.camera_permission_description),
Toast.LENGTH_LONG
).show()
viewModel.updateToastState("hide")
}

if (creationResultMessage != null) {
LaunchedEffect(key1 = creationResultMessage) {
val toastMessage = context.resources.getString(creationResultMessage!!)
Expand Down Expand Up @@ -264,7 +270,8 @@ private fun DropdownUi(
)
} else {
label?.invoke() ?: Text(
"Select an option", color = MaterialTheme.colorScheme.onSurface
text = stringResource(id = R.string.choose_a_category),
color = MaterialTheme.colorScheme.onSurface
)
}
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ enum class PhotoType {
enum class DialogState {
SHOW,
HIDE
}

enum class ToastState {
SHOW,
HIDE
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.example.speechbuddy.ui.models.PhotoType
import com.example.speechbuddy.ui.models.SymbolCreationError
import com.example.speechbuddy.ui.models.SymbolCreationErrorType
import com.example.speechbuddy.ui.models.SymbolCreationUiState
import com.example.speechbuddy.ui.models.ToastState
import com.example.speechbuddy.utils.Status
import com.example.speechbuddy.utils.isValidSymbolText
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -65,6 +66,8 @@ class SymbolCreationViewModel @Inject internal constructor(

var dialogState by mutableStateOf<DialogState?>(DialogState.HIDE)

var toastState by mutableStateOf<ToastState?>(ToastState.HIDE)

var symbolTextInput by mutableStateOf("")
private set

Expand All @@ -83,6 +86,18 @@ class SymbolCreationViewModel @Inject internal constructor(
}
}

fun updateToastState(updateState: String) {
when (updateState) {
"show" -> {
toastState = ToastState.SHOW
}

"hide" -> {
toastState = ToastState.HIDE
}
}
}

fun expandCategory() {
_uiState.update { currentState ->
currentState.copy(
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
<string name="choose_photo_option">사진을 어떻게 추가하실 건가요?</string>
<string name="choose_from_gallery">사진 보관함에서 사진 선택하기</string>
<string name="take_photo">사진 촬영하기</string>
<string name="camera_permission_description">기기설정에서 카메라 권한을 허용해주세요</string>
<string name="choose_a_category">대분류를 선택하십시오</string>

<!-- Settings -->
<string name="settings">설정</string>
Expand Down

0 comments on commit ab5ba6b

Please sign in to comment.