Skip to content

Commit

Permalink
[MERGE] pull request #58 from Keyneez/feature/#46-ocr-feat-text-recog…
Browse files Browse the repository at this point in the history
…nition

[FEAT/#46] ocr, main / ocr 및 바텀 네비게이션 이슈 해결
  • Loading branch information
Chaeyeon authored Jan 13, 2023
2 parents a8f488e + 54c2dbc commit 0df1e9e
Show file tree
Hide file tree
Showing 16 changed files with 307 additions and 156 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ dependencies {
// shared preference
implementation 'androidx.security:security-crypto-ktx:1.1.0-alpha04'

// firebase
implementation platform('com.google.firebase:firebase-bom:31.1.1')
implementation 'com.google.firebase:firebase-analytics-ktx'

// firebase storage
implementation 'com.google.firebase:firebase-core:21.1.1'
implementation 'com.google.firebase:firebase-storage:20.1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.keyneez.data.model.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestPostStudentUserCheckDto(
@SerialName("user_school")
val school: String,
@SerialName("user_name")
val name: String,
@SerialName("user_ocr")
val ocrImg: String,
@SerialName("ocr_dir")
val ocrDir: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.keyneez.data.model.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestPostYouthUserCheckDto(
@SerialName("user_name")
val name: String,
@SerialName("user_birth")
val birth: String,
@SerialName("user_ocr")
val ocrImg: String,
@SerialName("ocr_dir")
val ocrDir: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.keyneez.data.model.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponsePostUserCheckDto(
@SerialName("user_key")
val key: Int,
@SerialName("user_name")
val name: String,
@SerialName("user_age")
val age: String?,
@SerialName("user_gender")
val gender: String?,
@SerialName("user_birth")
val birthDate: String?,
@SerialName("user_school")
val school: String?,
@SerialName("user_character")
val character: Int?,
@SerialName("user_password")
val password: String?,
@SerialName("user_ocr")
val ocrImg: String?,
@SerialName("ocr_dir")
val ocrDir: Boolean?,
@SerialName("user_benefit")
val benefit: Boolean?,
val Characters: Character?
) {
@Serializable
data class Character(
@SerialName("character_key")
val key: Int,
val inter: String?,
val dispo: String?,
val character: String?,
@SerialName("character_img")
val img: String?,
@SerialName("character_desc")
val description: String?,
@SerialName("test_img")
val testImg: String?
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ interface UserRepository {
suspend fun postPwdCheck(
requestPostPwdCheckDto: RequestPostPwdCheckDto
): Result<Unit>

suspend fun postStudentUserCheck(
requestPostStudentUserCheckDto: RequestPostStudentUserCheckDto
): Result<BaseResponse<ResponsePostUserCheckDto>>

suspend fun postYouthUserCheck(
requestPostYouthUserCheckDto: RequestPostYouthUserCheckDto
): Result<BaseResponse<ResponsePostUserCheckDto>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,14 @@ class UserRepositoryImpl @Inject constructor(
requestPostPwdCheckDto: RequestPostPwdCheckDto
): Result<Unit> =
kotlin.runCatching { userDataSource.postPwdCheck(requestPostPwdCheckDto) }

override suspend fun postStudentUserCheck(
requestPostStudentUserCheckDto: RequestPostStudentUserCheckDto
): Result<BaseResponse<ResponsePostUserCheckDto>> =
kotlin.runCatching { userDataSource.postStudentUserCheck(requestPostStudentUserCheckDto) }

override suspend fun postYouthUserCheck(
requestPostYouthUserCheckDto: RequestPostYouthUserCheckDto
): Result<BaseResponse<ResponsePostUserCheckDto>> =
kotlin.runCatching { userDataSource.postYouthUserCheck(requestPostYouthUserCheckDto) }
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/keyneez/data/service/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ interface UserService {
suspend fun postUserLogIn(
@Body request: RequestPostUserLogInDto
): BaseResponse<ResponsePostUserLogInDto>

// 학생증 유저 대조 (다날*학생)
@POST("user/check")
suspend fun postCheckStudentUser(
@Body request: RequestPostStudentUserCheckDto
): BaseResponse<ResponsePostUserCheckDto>

// 청소년증 유저 대조 (다날*학생)
@POST("user/check")
suspend fun postCheckYouthUser(
@Body request: RequestPostYouthUserCheckDto
): BaseResponse<ResponsePostUserCheckDto>
}
10 changes: 10 additions & 0 deletions app/src/main/java/com/keyneez/data/source/UserDataSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ class UserDataSource @Inject constructor(
suspend fun postPwdCheck(
requestPostPwdCheckDto: RequestPostPwdCheckDto
): Unit = userService.postPwdCheck(requestPostPwdCheckDto)

suspend fun postStudentUserCheck(
requestPostStudentUserCheckDto: RequestPostStudentUserCheckDto
): BaseResponse<ResponsePostUserCheckDto> =
userService.postCheckStudentUser(requestPostStudentUserCheckDto)

suspend fun postYouthUserCheck(
requestPostYouthUserCheckDto: RequestPostYouthUserCheckDto
): BaseResponse<ResponsePostUserCheckDto> =
userService.postCheckYouthUser(requestPostYouthUserCheckDto)
}
50 changes: 4 additions & 46 deletions app/src/main/java/com/keyneez/presentation/main/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.keyneez.presentation.main

import android.os.Bundle
import android.widget.ImageView
import androidx.activity.viewModels
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
Expand All @@ -11,24 +10,24 @@ import com.keyneez.presentation.main.home.HomeFragment
import com.keyneez.presentation.main.id.IdFragment
import com.keyneez.presentation.main.like.LikeFragment
import com.keyneez.presentation.main.setting.SettingFragment
import com.keyneez.util.UiState
import com.keyneez.util.binding.BindingActivity
import com.keyneez.util.extension.setOnSingleClickListener
import com.keyneez.util.extension.showSnackbar
import com.lab.keyneez.R
import com.lab.keyneez.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main) {
private val viewModel by viewModels<MainViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.vm = viewModel

initBottomNavigationBar()
observeIdStateMessage()
initCardBackGround()
}

private fun initBottomNavigationBar() {
// 초기 프래그먼트 설정
val currentFragment = supportFragmentManager.findFragmentById(R.id.container_main)
Expand All @@ -42,51 +41,13 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
R.id.menu_character -> navigateTo<CharacterFragment>()
R.id.menu_setting -> navigateTo<SettingFragment>()
}
false
}
}

private fun observeIdStateMessage() {
viewModel.stateMessage.observe(this) {
when (it) {
is UiState.Success -> return@observe
is UiState.Failure -> showSnackbar(
binding.root,
getString(R.string.msg_id_null)
)
is UiState.Error -> showSnackbar(
binding.root,
getString(R.string.msg_server_error)
)
}
true
}
}

private fun initCardBackGround() {
binding.btnMainCard.setOnSingleClickListener {
navigateTo<IdFragment>()
when (viewModel.userData.value?.userCharacter?.rem(5)) {
// 문화인-파란색
1 -> {
binding.btnMainCard.setImageDrawable(R.drawable.img_id_navi_blue)
}
// 진로탐색러-초록색
2 -> {
binding.btnMainCard.setImageDrawable(R.drawable.img_id_navi_green)
}
// 탐험가-핑크색
3 -> {
binding.btnMainCard.setImageDrawable(R.drawable.img_id_navi_pink)
}
// 경제인-빨간색
4 -> {
binding.btnMainCard.setImageDrawable(R.drawable.img_id_navi_red)
}
// 봉사자-보라색
else -> {
binding.btnMainCard.setImageDrawable(R.drawable.img_id_navi_purple)
}
}
}
}

Expand All @@ -95,7 +56,4 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
replace<T>(R.id.container_main, T::class.java.canonicalName)
}
}

private fun ImageView.setImageDrawable(imgLikeBackground: Int) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MainViewModel @Inject constructor(
private val _userData = MutableLiveData<ResponseIdDto>()
val userData: LiveData<ResponseIdDto>
get() = _userData

private val _stateMessage = MutableLiveData<UiState>()
val stateMessage: LiveData<UiState>
get() = _stateMessage
Expand Down
23 changes: 19 additions & 4 deletions app/src/main/java/com/keyneez/presentation/ocr/OcrActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import com.keyneez.util.extension.setOnSingleClickListener
import com.keyneez.util.extension.showSnackbar
import com.lab.keyneez.R
import com.lab.keyneez.databinding.ActivityOcrBinding
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber
import java.nio.ByteBuffer
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors

@AndroidEntryPoint
class OcrActivity : BindingActivity<ActivityOcrBinding>(R.layout.activity_ocr) {
val viewModel by viewModels<OcrViewModel>()

Expand Down Expand Up @@ -162,10 +164,23 @@ class OcrActivity : BindingActivity<ActivityOcrBinding>(R.layout.activity_ocr) {
isSuccess = true
}
else -> {
if (isSuccess && viewModel.idName.value == "" && word.length == 3) viewModel.setIdName(word)
if (isSuccess && viewModel.idName.value == "" && word.startsWith("명:")) viewModel.setIdName(word.substring(2, 5))
if (isSuccess && viewModel.isStudentId.value == true && viewModel.idSubEntry.value == "" && word.endsWith("학교")) viewModel.setIdSchool(word)
if (isSuccess && viewModel.isStudentId.value == false && viewModel.idSubEntry.value == "" && word.length == 14 && word.contains('-')) viewModel.setBirthDate(word)
if (isSuccess && viewModel.idName.value == "" && word.length == 3) viewModel.setIdName(
word
)
if (isSuccess && viewModel.idName.value == "" && word.startsWith("명:") && word.length == 5) viewModel.setIdName(
word.substring(2, 5)
)
if (isSuccess && viewModel.idName.value == "" && word.startsWith(":") && word.length == 4) viewModel.setIdName(
word.substring(1, 4)
)
if (isSuccess && viewModel.isStudentId.value == true && viewModel.idSubEntry.value == "" && word.endsWith(
"학교"
)
) viewModel.setIdSchool(word)
if (isSuccess && viewModel.isStudentId.value == false && viewModel.idSubEntry.value == "" && word.length == 14 && word.contains(
'-'
)
) viewModel.setBirthDate(word)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class OcrViewModel @Inject constructor() : ViewModel() {
val isStudentId: LiveData<Boolean>
get() = _isStudentId

private val _imgUrl = MutableLiveData<String>()
val imgUrl: LiveData<String>
get() = _imgUrl

init {
_isVertical.value = false
_isPassive.value = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
package com.keyneez.presentation.ocr.dialog

import android.app.Activity.RESULT_OK
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import com.keyneez.presentation.ocr.OcrActivity
import com.keyneez.presentation.ocr.guide.OcrGuideActivity
import com.keyneez.util.UiState
import com.keyneez.util.binding.BindingBottomSheetDialog
import com.keyneez.util.extension.hideKeyboard
import com.keyneez.util.extension.setOnSingleClickListener
import com.keyneez.util.extension.showSnackbar
import com.lab.keyneez.R
import com.lab.keyneez.databinding.BotSheetOcrResultBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class OcrResultFragment :
BindingBottomSheetDialog<BotSheetOcrResultBinding>(R.layout.bot_sheet_ocr_result) {
private val viewModel by viewModels<OcrResultViewModel>()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = (activity as OcrActivity).viewModel

initHideKeyboard()
initReshootBtnClickListener()
initConfirmBtnClickListener()
setupCheckUserState()
}

private fun initHideKeyboard() {
Expand All @@ -37,10 +45,35 @@ class OcrResultFragment :

private fun initConfirmBtnClickListener() {
binding.btnOcrResultConfirm.setOnSingleClickListener {
val intent = Intent(activity, OcrGuideActivity::class.java).apply {
requireActivity().setResult(RESULT_OK, this)
val avm = (activity as OcrActivity).viewModel
val isStudent = avm.isStudentId.value ?: true
val name = avm.idName.value.toString()
val subEntry = avm.idSubEntry.value.toString()
val img = avm.imgUrl.value.toString()
val isVertical = avm.isVertical.value ?: false

viewModel.postUserCheck(isStudent, name, subEntry, img, isVertical)
}
}

private fun setupCheckUserState() {
viewModel.stateMessage.observe(viewLifecycleOwner) {
when (it) {
is UiState.Success -> {
val intent = Intent(activity, OcrGuideActivity::class.java).apply {
requireActivity().setResult(Activity.RESULT_OK, this)
}
requireActivity().finish()
}
is UiState.Failure -> requireContext().showSnackbar(
binding.root,
getString(R.string.msg_error)
)
is UiState.Error -> requireContext().showSnackbar(
binding.root,
getString(R.string.msg_error)
)
}
requireActivity().finish()
}
}

Expand Down
Loading

0 comments on commit 0df1e9e

Please sign in to comment.