From f039405901896d97a7355ed681a024f4a7a6cb8e Mon Sep 17 00:00:00 2001 From: Seungmin Joo Date: Sun, 26 Nov 2023 20:47:50 +0900 Subject: [PATCH 1/4] :recycle: Refactor strings --- .../symbolcreation/SymbolCreationScreen.kt | 22 ++++++++++++++----- frontend/app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt b/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt index 53df6cbd..509e36c0 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt @@ -49,6 +49,8 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ImageBitmap @@ -81,6 +83,8 @@ fun SymbolCreationScreen( viewModel: SymbolCreationViewModel = hiltViewModel() ) { val context = LocalContext.current + // Define a state for showing the toast + val showToast = remember { mutableStateOf(false) } val uiState by viewModel.uiState.collectAsState() val categories by viewModel.categories.observeAsState(emptyList()) @@ -111,14 +115,19 @@ fun SymbolCreationScreen( if (isGranted) { cameraLauncher.launch(null) } else { - Toast.makeText( - context, - "Camera permission is required to take photos", - Toast.LENGTH_SHORT - ).show() + showToast.value = true } } + if (showToast.value) { + Toast.makeText( + context, + stringResource(id = R.string.camera_permisson_request), + Toast.LENGTH_SHORT + ).show() + showToast.value = false + } + if (creationResultMessage != null) { LaunchedEffect(key1 = creationResultMessage) { val toastMessage = context.resources.getString(creationResultMessage!!) @@ -262,7 +271,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( diff --git a/frontend/app/src/main/res/values/strings.xml b/frontend/app/src/main/res/values/strings.xml index 787531ca..d1c71a3f 100644 --- a/frontend/app/src/main/res/values/strings.xml +++ b/frontend/app/src/main/res/values/strings.xml @@ -91,6 +91,8 @@ 사진을 어떻게 추가하실 건가요? 사진 보관함에서 사진 선택하기 사진 촬영하기 + 사진을 촬영하려면 앱이 카메라를 사용할 수 있도록 허용하십시오 + 대분류를 선택하십시오 설정 From 43d6ff981ba095dca26f506a0108e90228adea28 Mon Sep 17 00:00:00 2001 From: Seungmin Joo Date: Sun, 26 Nov 2023 21:54:21 +0900 Subject: [PATCH 2/4] :recycle: Refactor camera permission related toast and string --- .../compose/symbolcreation/SymbolCreationScreen.kt | 6 +++--- frontend/app/src/main/res/values/strings.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt b/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt index 509e36c0..ca4d36e5 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt @@ -83,7 +83,7 @@ fun SymbolCreationScreen( viewModel: SymbolCreationViewModel = hiltViewModel() ) { val context = LocalContext.current - // Define a state for showing the toast + val showToast = remember { mutableStateOf(false) } val uiState by viewModel.uiState.collectAsState() @@ -122,8 +122,8 @@ fun SymbolCreationScreen( if (showToast.value) { Toast.makeText( context, - stringResource(id = R.string.camera_permisson_request), - Toast.LENGTH_SHORT + stringResource(id = R.string.camera_permission_description), + Toast.LENGTH_LONG ).show() showToast.value = false } diff --git a/frontend/app/src/main/res/values/strings.xml b/frontend/app/src/main/res/values/strings.xml index d1c71a3f..02ce0a0e 100644 --- a/frontend/app/src/main/res/values/strings.xml +++ b/frontend/app/src/main/res/values/strings.xml @@ -91,7 +91,7 @@ 사진을 어떻게 추가하실 건가요? 사진 보관함에서 사진 선택하기 사진 촬영하기 - 사진을 촬영하려면 앱이 카메라를 사용할 수 있도록 허용하십시오 + 카메라 접근이 허용되지 않았습니다\n기기설정에서 카메라 권한을 허용해주세요 대분류를 선택하십시오 From 92510fc104409f7c1f86d7cc266d19a946ad9087 Mon Sep 17 00:00:00 2001 From: Seungmin Joo Date: Wed, 29 Nov 2023 22:30:08 +0900 Subject: [PATCH 3/4] :recycle: Hide variables into viewModel --- .../symbolcreation/SymbolCreationScreen.kt | 11 ++++------- .../ui/models/SymbolCreationUiState.kt | 5 +++++ .../viewmodel/SymbolCreationViewModel.kt | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt b/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt index ca4d36e5..2654d6db 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/compose/symbolcreation/SymbolCreationScreen.kt @@ -49,8 +49,6 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ImageBitmap @@ -72,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 @@ -84,8 +83,6 @@ fun SymbolCreationScreen( ) { val context = LocalContext.current - val showToast = remember { mutableStateOf(false) } - val uiState by viewModel.uiState.collectAsState() val categories by viewModel.categories.observeAsState(emptyList()) @@ -115,17 +112,17 @@ fun SymbolCreationScreen( if (isGranted) { cameraLauncher.launch(null) } else { - showToast.value = true + viewModel.updateToastState("show") } } - if (showToast.value) { + if (viewModel.toastState == ToastState.SHOW) { Toast.makeText( context, stringResource(id = R.string.camera_permission_description), Toast.LENGTH_LONG ).show() - showToast.value = false + viewModel.updateToastState("hide") } if (creationResultMessage != null) { diff --git a/frontend/app/src/main/java/com/example/speechbuddy/ui/models/SymbolCreationUiState.kt b/frontend/app/src/main/java/com/example/speechbuddy/ui/models/SymbolCreationUiState.kt index 1bf4301b..ce92e4d9 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/ui/models/SymbolCreationUiState.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/ui/models/SymbolCreationUiState.kt @@ -28,4 +28,9 @@ enum class PhotoType { enum class DialogState { SHOW, HIDE +} + +enum class ToastState { + SHOW, + HIDE } \ No newline at end of file diff --git a/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/SymbolCreationViewModel.kt b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/SymbolCreationViewModel.kt index 82d98fa9..f6fe66ca 100644 --- a/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/SymbolCreationViewModel.kt +++ b/frontend/app/src/main/java/com/example/speechbuddy/viewmodel/SymbolCreationViewModel.kt @@ -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 @@ -65,6 +66,8 @@ class SymbolCreationViewModel @Inject internal constructor( var dialogState by mutableStateOf(DialogState.HIDE) + var toastState by mutableStateOf(ToastState.HIDE) + var symbolTextInput by mutableStateOf("") private set @@ -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( From 860e7525e56ca3dd7bd3a9f6a266ce3fefeb536a Mon Sep 17 00:00:00 2001 From: Seungmin Joo Date: Wed, 29 Nov 2023 23:00:47 +0900 Subject: [PATCH 4/4] :recycle: Modify camera toast text --- frontend/app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/src/main/res/values/strings.xml b/frontend/app/src/main/res/values/strings.xml index 02ce0a0e..61624bd1 100644 --- a/frontend/app/src/main/res/values/strings.xml +++ b/frontend/app/src/main/res/values/strings.xml @@ -91,7 +91,7 @@ 사진을 어떻게 추가하실 건가요? 사진 보관함에서 사진 선택하기 사진 촬영하기 - 카메라 접근이 허용되지 않았습니다\n기기설정에서 카메라 권한을 허용해주세요 + 기기설정에서 카메라 권한을 허용해주세요 대분류를 선택하십시오