Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/onapp-take-photo #70

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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 @@ -111,14 +112,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 @@ -262,7 +268,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 @@ -28,4 +28,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