Skip to content

Commit faecfeb

Browse files
authored
Merge pull request #105 from Team-HealthC/feature/#102
Feature/#102
2 parents bb041b3 + faadaa4 commit faecfeb

File tree

12 files changed

+180
-55
lines changed

12 files changed

+180
-55
lines changed

client/app/src/main/java/com/healthc/app/presentation/detection/text_detection/TextDetectionFragment.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class TextDetectionFragment : Fragment() {
3939
): View {
4040
_binding = DataBindingUtil.inflate(inflater, R.layout.fragment_text_detection, container, false)
4141
binding.viewModel = viewModel // xml viewModel init
42+
binding.lifecycleOwner = viewLifecycleOwner
4243
return binding.root
4344
}
4445

@@ -91,7 +92,7 @@ class TextDetectionFragment : Fragment() {
9192
private fun showNegativeDialog(detectedList: List<Allergy>){
9293
NegativeSignDialog(
9394
context = requireContext(),
94-
allergyList = detectedList
95+
detectedAllergies = detectedList
9596
).show()
9697
}
9798

client/app/src/main/java/com/healthc/app/presentation/detection/text_detection/TextDetectionViewModel.kt

+12-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
1010
import kotlinx.coroutines.flow.MutableStateFlow
1111
import kotlinx.coroutines.flow.SharedFlow
1212
import kotlinx.coroutines.flow.StateFlow
13+
import kotlinx.coroutines.flow.asStateFlow
1314
import kotlinx.coroutines.launch
1415
import javax.inject.Inject
1516

@@ -24,16 +25,20 @@ class TextDetectionViewModel @Inject constructor(
2425
private val _imageUrl: MutableStateFlow<String> = MutableStateFlow("")
2526
val imageUrl: StateFlow<String> get() = _imageUrl
2627

28+
private val _recognizedText: MutableStateFlow<String> = MutableStateFlow("")
29+
val recognizedText: StateFlow<String> = _recognizedText.asStateFlow()
30+
2731
fun setImageUrl(imageUrl : String){
2832
_imageUrl.value = imageUrl
2933
}
3034

3135
fun checkAllergiesInKoreanText() {
3236
viewModelScope.launch {
3337
checkAllergiesInKoreanTextUseCase(_imageUrl.value)
34-
.onSuccess { list ->
35-
if(list.isNotEmpty())
36-
_textDetectionUiEvent.emit(TextDetectionEvent.Detected(list))
38+
.onSuccess { result ->
39+
_recognizedText.value = result.recognizedText
40+
if(result.allergies.isNotEmpty())
41+
_textDetectionUiEvent.emit(TextDetectionEvent.Detected(result.allergies))
3742
else
3843
_textDetectionUiEvent.emit(TextDetectionEvent.NotDetected)
3944
}
@@ -46,9 +51,10 @@ class TextDetectionViewModel @Inject constructor(
4651
fun checkAllergiesInEnglishText() {
4752
viewModelScope.launch {
4853
checkAllergiesInEnglishTextUseCase(_imageUrl.value)
49-
.onSuccess { list ->
50-
if(list.isNotEmpty())
51-
_textDetectionUiEvent.emit(TextDetectionEvent.Detected(list))
54+
.onSuccess { result ->
55+
_recognizedText.value = result.recognizedText
56+
if(result.allergies.isNotEmpty())
57+
_textDetectionUiEvent.emit(TextDetectionEvent.Detected(result.allergies))
5258
else
5359
_textDetectionUiEvent.emit(TextDetectionEvent.NotDetected)
5460
}
302 Bytes
Loading

client/app/src/main/res/layout/fragment_camera.xml

+16-15
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949

5050
<ImageButton
5151
android:id="@+id/flash_button"
52-
android:layout_width="wrap_content"
53-
android:layout_height="wrap_content"
52+
android:layout_width="24dp"
53+
android:layout_height="24dp"
5454
android:src="@drawable/baseline_flash_on_24"
5555
android:background="@color/black"
5656
app:tint="@color/white"
@@ -121,25 +121,27 @@
121121

122122
</com.google.android.material.chip.ChipGroup>
123123

124-
<androidx.appcompat.widget.AppCompatImageButton
124+
<com.google.android.material.floatingactionbutton.FloatingActionButton
125125
android:id="@+id/goToGalleryButton"
126-
android:layout_width="40dp"
127-
android:layout_height="40dp"
128-
android:layout_margin="32dp"
129-
android:scaleType="fitXY"
126+
android:layout_width="wrap_content"
127+
android:layout_height="wrap_content"
128+
android:clickable="true"
130129
android:src="@drawable/gallery"
131-
android:background="@color/black"
130+
app:backgroundTint="@color/light_black"
131+
app:fabCustomSize="48dp"
132+
app:maxImageSize="24dp"
133+
app:tint="@color/white"
132134
app:layout_constraintBottom_toBottomOf="@+id/capture_image_button"
133135
app:layout_constraintEnd_toStartOf="@+id/capture_image_button"
134136
app:layout_constraintStart_toStartOf="parent"
135-
app:layout_constraintTop_toTopOf="@id/capture_image_button"
136-
app:tint="@color/white" />
137+
app:layout_constraintTop_toTopOf="@id/capture_image_button" />
137138

138139
<com.google.android.material.floatingactionbutton.FloatingActionButton
139140
android:id="@+id/capture_image_button"
140141
android:layout_width="wrap_content"
141142
android:layout_height="wrap_content"
142-
android:layout_margin="16dp"
143+
android:layout_marginTop="16dp"
144+
android:layout_marginBottom="32dp"
143145
app:fabCustomSize="64dp"
144146
app:backgroundTint="@color/light_gray"
145147
app:layout_constraintBottom_toBottomOf="parent"
@@ -151,17 +153,16 @@
151153
android:id="@+id/switch_camera_button"
152154
android:layout_width="wrap_content"
153155
android:layout_height="wrap_content"
154-
android:layout_margin="32dp"
155156
android:clickable="true"
156157
android:src="@drawable/switch_camera"
157158
app:backgroundTint="@color/light_black"
158159
app:fabCustomSize="48dp"
160+
app:maxImageSize="32dp"
161+
app:tint="@color/white"
159162
app:layout_constraintBottom_toBottomOf="@+id/capture_image_button"
160163
app:layout_constraintEnd_toEndOf="parent"
161164
app:layout_constraintStart_toEndOf="@+id/capture_image_button"
162-
app:layout_constraintTop_toTopOf="@+id/capture_image_button"
163-
app:maxImageSize="28dp"
164-
app:tint="@color/white" />
165+
app:layout_constraintTop_toTopOf="@+id/capture_image_button" />
165166

166167
</androidx.constraintlayout.widget.ConstraintLayout>
167168
</androidx.cardview.widget.CardView>

client/app/src/main/res/layout/fragment_text_detection.xml

+124-15
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,136 @@
1212
</data>
1313
<androidx.constraintlayout.widget.ConstraintLayout
1414
android:layout_width="match_parent"
15-
android:layout_height="match_parent">
15+
android:layout_height="match_parent"
16+
android:background="@color/light_gray">
1617

17-
<androidx.appcompat.widget.AppCompatImageView
18-
android:id="@+id/Capture_image_view"
19-
android:layout_width="wrap_content"
20-
android:layout_height="wrap_content"
21-
app:imageUrl="@{viewModel.imageUrl}"
18+
<androidx.cardview.widget.CardView
19+
android:id="@+id/cd_t_d_result"
20+
android:layout_width="match_parent"
21+
android:layout_height="200dp"
2222
app:layout_constraintBottom_toBottomOf="parent"
2323
app:layout_constraintEnd_toEndOf="parent"
24+
app:layout_constraintStart_toStartOf="parent">
25+
26+
<androidx.constraintlayout.widget.ConstraintLayout
27+
android:layout_width="match_parent"
28+
android:layout_height="match_parent"
29+
android:padding="16dp">
30+
31+
<TextView
32+
android:id="@+id/tv_t_d_result_title"
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:fontFamily="@font/sc_dream_nor"
36+
android:text="@string/recongnized_text"
37+
android:textColor="@color/black"
38+
android:textSize="18sp"
39+
app:layout_constraintStart_toStartOf="parent"
40+
app:layout_constraintTop_toTopOf="parent" />
41+
42+
<androidx.cardview.widget.CardView
43+
android:layout_width="match_parent"
44+
android:layout_height="0dp"
45+
android:layout_marginTop="16dp"
46+
android:layout_marginBottom="16dp"
47+
app:layout_constraintBottom_toBottomOf="parent"
48+
app:layout_constraintEnd_toEndOf="parent"
49+
app:layout_constraintStart_toStartOf="parent"
50+
app:layout_constraintTop_toBottomOf="@+id/tv_t_d_result_title" >
51+
52+
<ScrollView
53+
android:layout_width="match_parent"
54+
android:layout_height="wrap_content">
55+
<androidx.constraintlayout.widget.ConstraintLayout
56+
android:layout_width="match_parent"
57+
android:layout_height="wrap_content"
58+
android:background="@color/light_gray">
59+
60+
<TextView
61+
android:id="@+id/tv_t_d_recognized_content"
62+
android:layout_width="match_parent"
63+
android:layout_height="wrap_content"
64+
android:text="@{viewModel.recognizedText}"
65+
android:textSize="14sp"
66+
android:textColor="@color/black"
67+
android:fontFamily="@font/sc_dream_nor"
68+
app:layout_constraintBottom_toBottomOf="parent"
69+
app:layout_constraintEnd_toEndOf="parent"
70+
app:layout_constraintStart_toStartOf="parent"
71+
app:layout_constraintTop_toTopOf="parent" />
72+
</androidx.constraintlayout.widget.ConstraintLayout>
73+
</ScrollView>
74+
75+
</androidx.cardview.widget.CardView>
76+
77+
</androidx.constraintlayout.widget.ConstraintLayout>
78+
</androidx.cardview.widget.CardView>
79+
80+
<androidx.cardview.widget.CardView
81+
android:id="@+id/cd_t_d_top"
82+
android:layout_width="match_parent"
83+
android:layout_height="wrap_content"
84+
app:layout_constraintEnd_toEndOf="parent"
2485
app:layout_constraintStart_toStartOf="parent"
25-
app:layout_constraintTop_toTopOf="parent"
26-
app:placeholder="@{@drawable/health_c}" />
86+
app:layout_constraintTop_toTopOf="parent">
87+
88+
<androidx.constraintlayout.widget.ConstraintLayout
89+
android:layout_width="match_parent"
90+
android:layout_height="match_parent"
91+
android:padding="8dp">
92+
93+
<ImageButton
94+
android:id="@+id/back_to_camera_button"
95+
android:layout_width="wrap_content"
96+
android:layout_height="wrap_content"
97+
android:src="@drawable/ic_baseline_arrow_back_ios_new_24"
98+
app:backgroundTint="@color/white"
99+
app:layout_constraintBottom_toBottomOf="parent"
100+
app:layout_constraintStart_toStartOf="parent"
101+
app:layout_constraintTop_toTopOf="parent" />
102+
103+
<TextView
104+
android:id="@+id/tv_t_d_top_title"
105+
android:layout_width="wrap_content"
106+
android:layout_height="wrap_content"
107+
android:layout_marginStart="4dp"
108+
android:fontFamily="@font/sc_dream_nor"
109+
android:text="@string/korea_ocr_camera"
110+
android:textColor="@color/black"
111+
android:textSize="16sp"
112+
app:layout_constraintBottom_toBottomOf="parent"
113+
app:layout_constraintStart_toEndOf="@+id/back_to_camera_button"
114+
app:layout_constraintTop_toTopOf="parent" />
115+
</androidx.constraintlayout.widget.ConstraintLayout>
116+
</androidx.cardview.widget.CardView>
27117

28-
<ImageButton
29-
android:id="@+id/back_to_camera_button"
30-
android:layout_width="wrap_content"
118+
<androidx.cardview.widget.CardView
119+
android:id="@+id/cd_t_d_image"
120+
android:layout_width="match_parent"
31121
android:layout_height="wrap_content"
32-
android:layout_marginTop="8dp"
33-
android:src="@drawable/ic_baseline_arrow_back_ios_new_24"
34-
app:backgroundTint="@color/white"
122+
android:layout_marginTop="16dp"
123+
app:layout_constraintBottom_toTopOf="@+id/cd_t_d_result"
124+
app:layout_constraintEnd_toEndOf="parent"
35125
app:layout_constraintStart_toStartOf="parent"
36-
app:layout_constraintTop_toTopOf="parent" />
126+
app:layout_constraintTop_toBottomOf="@+id/cd_t_d_top">
127+
128+
<androidx.constraintlayout.widget.ConstraintLayout
129+
android:layout_width="match_parent"
130+
android:layout_height="match_parent">
131+
132+
<androidx.appcompat.widget.AppCompatImageView
133+
android:id="@+id/iv_t_d_image"
134+
android:layout_width="0dp"
135+
android:layout_height="wrap_content"
136+
app:imageUrl="@{viewModel.imageUrl}"
137+
app:layout_constraintBottom_toBottomOf="parent"
138+
app:layout_constraintEnd_toEndOf="parent"
139+
app:layout_constraintStart_toStartOf="parent"
140+
app:layout_constraintTop_toTopOf="parent"
141+
app:placeholder="@{@drawable/health_c}"
142+
tools:layout_height="300dp" />
143+
</androidx.constraintlayout.widget.ConstraintLayout>
144+
</androidx.cardview.widget.CardView>
145+
37146
</androidx.constraintlayout.widget.ConstraintLayout>
38147
</layout>

client/app/src/main/res/values/colors.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<color name="teal_200">#FF03DAC5</color>
77
<color name="teal_700">#FF018786</color>
88
<color name="black">#FF000000</color>
9-
<color name="light_black">#FF474747</color>
9+
<color name="light_black">#FF242425</color>
1010
<color name="white">#FFFFFFFF</color>
1111
<color name="green">#FF2BAE66</color>
1212
<color name="white_yellow">#FFFCF6F5</color>

client/app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@
8888
<string name="failed_object_detection_title">음식을 인식할 수 없습니다.\n더 멀리서 찍거나, 다른 사진을 사용해주세요 !</string>
8989
<string name="object_detection_result">인식된 음식</string>
9090
<string name="food_detection">음식 인식</string>
91+
<string name="recongnized_text">인식된 텍스트</string>
9192
</resources>

client/domain/src/main/java/com/healthc/domain/model/auth/Allergy.kt

-11
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,16 @@ data class Allergy(
77
fun toEnglish(): Allergy {
88
return when (this) {
99
Allergy("돼지고기") -> { Allergy("pork") }
10-
1110
Allergy("대두") -> { Allergy("soybean") }
12-
1311
Allergy("땅콩") -> { Allergy("peanut") }
14-
1512
Allergy("계란") -> { Allergy("egg") }
16-
1713
Allergy("우유") -> { Allergy("milk") }
18-
1914
Allergy("") -> { Allergy("flour") }
20-
2115
Allergy("복숭아") -> { Allergy("peach") }
22-
2316
Allergy("견과류") -> { Allergy("nuts") }
24-
2517
Allergy("갑각류") -> { Allergy("crab") }
26-
2718
Allergy("조개류") -> { Allergy("clam") }
28-
2919
Allergy("생선") -> { Allergy("fish") }
30-
3120
else -> { this }
3221
}
3322
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.healthc.domain.model.detection
2+
3+
import com.healthc.domain.model.auth.Allergy
4+
5+
data class AllergyTextDetection (
6+
val allergies: List<Allergy>,
7+
val recognizedText: String,
8+
)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.healthc.domain.model.detection
22

3+
// 오직 OCR, 문자 인식만을 위한 도메인 모델
34
data class TextDetection(
45
val recognizedText: String
56
)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.healthc.domain.usecase.detection
22

33
import com.healthc.domain.model.auth.Allergy
4+
import com.healthc.domain.model.detection.AllergyTextDetection
45
import com.healthc.domain.repository.DetectionRepository
56
import com.healthc.domain.repository.UserRepository
67
import javax.inject.Inject
@@ -9,23 +10,27 @@ class CheckAllergiesInEnglishTextUseCase @Inject constructor(
910
private val userRepository: UserRepository,
1011
private val detectionRepository: DetectionRepository
1112
){
12-
suspend operator fun invoke(imageUri: String) : Result<List<Allergy>> {
13+
suspend operator fun invoke(imageUri: String) : Result<AllergyTextDetection> {
1314
return runCatching {
1415
val response = userRepository.getUser().getOrThrow()
1516
val userAllergies = response.allergies.map { allergy ->
1617
allergy.toEnglish()
1718
}
1819

1920
val recognizedText =
20-
detectionRepository.getDetectedEnglishText(imageUri).getOrThrow().toString()
21+
detectionRepository.getDetectedEnglishText(imageUri).getOrThrow().recognizedText
2122

2223
val detectedAllergies = mutableListOf<Allergy>()
2324
userAllergies.forEach { allergy ->
2425
if (recognizedText.contains(allergy.allergy)) {
2526
detectedAllergies.add(allergy)
2627
}
2728
}
28-
detectedAllergies
29+
30+
AllergyTextDetection(
31+
allergies = detectedAllergies,
32+
recognizedText = recognizedText,
33+
)
2934
}
3035
}
3136
}

0 commit comments

Comments
 (0)