From 683ec9b2bd5457d964ac0469992edb8e13f4395b Mon Sep 17 00:00:00 2001 From: Park Hyejin Date: Mon, 5 Sep 2022 23:02:31 +0900 Subject: [PATCH 1/3] [UPDATE] reduece StoreActivity : listen feature --- .../com/euphonyio/orderwith/StoreActivity.kt | 124 +++++------------- 1 file changed, 30 insertions(+), 94 deletions(-) diff --git a/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt b/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt index 604dc48..96da10e 100644 --- a/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt +++ b/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt @@ -56,111 +56,43 @@ class StoreActivity : ComponentActivity() { private val TAG = "[StoreActivity]" private lateinit var dbUtil: DBUtil private lateinit var mTxManager: EuTxManager - private lateinit var mRxManager: EuRxManager - private lateinit var mEuPIRxManager: EuRxManager - - private var flag = MutableLiveData("") + private lateinit var mEuPIRxManagerMenu: EuRxManager + private lateinit var mEuPIRxManagerOrder: EuRxManager override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) dbUtil = DBUtil(this) mTxManager = EuTxManager(this) - mRxManager = EuRxManager() - - mEuPIRxManager = EuRxManager(EuOption.ModeType.EUPI) + mEuPIRxManagerMenu = EuRxManager(EuOption.ModeType.EUPI) + mEuPIRxManagerMenu.setOnWaveKeyDown(RequestCodeEnum.MENU_REQUEST.code.toInt()) { + Toast.makeText(this, "Menu request detected", Toast.LENGTH_SHORT).show() + Log.d(TAG, "mEuPIRxManagerMenu - Receive menu request.") + } + mEuPIRxManagerOrder = EuRxManager(EuOption.ModeType.EUPI) + mEuPIRxManagerOrder.setOnWaveKeyDown(RequestCodeEnum.ORDER_REQUEST.code.toInt()) { + Toast.makeText(this, "Order request detected", Toast.LENGTH_SHORT).show() + Log.d(TAG, "mEuPIRxManagerOrder - Receive order request.") + } var allMenu: List runBlocking { allMenu = dbUtil.getAllMenu() } - Log.e(TAG, "Finish menu check") + Log.i(TAG, "Finish menu check.") setContent { InitView(dbUtil) } if (!allMenu.isNullOrEmpty()) { - mRxManager.listen() - - var orderContent = "" - mRxManager.acousticSensor = AcousticSensor { letters -> - if (letters == MENU_REQUEST) { - flag.value = MENU_REQUEST - } else { - flag.value = letters.substring(0..1) - orderContent = letters.substring(2) - } + if (mEuPIRxManagerOrder.listen()) { + Log.d(TAG, "mEuPIRxManagerOrder - listen success") } - - flag.observe(this) { flag -> - var speakOn = false - - when (flag) { - // setCode()방식. - // EuPI 방식으로 대체 -// MENU_REQUEST -> { -// Log.i(TAG, "Receive Menu Request.") -// if (speakOn) { -// mTxManager.stop() -// } -// mRxManager.finish() -// Toast.makeText( -// this@StoreActivity, -// "Menu requested", -// Toast.LENGTH_SHORT -// ).show() -// /* TODO: send menu content -// speakOn = true */ -// } - ORDER_REQUEST -> { - Log.i(TAG, "Receive Order Request.") - - mRxManager.finish() - Toast.makeText( - this@StoreActivity, - "Order requested", - Toast.LENGTH_SHORT - ).show() - //TODO: save order data - // receiveOrder(orderContent, dbUtil) - - } - else -> { - Log.i(TAG, "Receive Wrong Data.") - //nothing received - } - } + if (mEuPIRxManagerMenu.listen()) { + Log.d(TAG, "mEuPIRxManagerMenu - listen success") } - } else { - showErrorToast("Store has no menu. Add menu and Try again") - } - - // EuPI 방식. RequestCodeEnum.MENU_REQUEST 주파수를 들었을때 작업 수행 -// /** -// * 해당 주파수의 음파가 인식될 때 계속 호출되는 API -// * */ -// mEuPIRxManager.setOnWaveKeyPressed(RequestCodeEnum.MENU_REQUEST.code.toInt()) { -// Toast.makeText(this, "menu request detected", Toast.LENGTH_SHORT).show() -// } -// /** -// * 해당 주파수의 음파가 발생하고 꺼졌을 때 최초 1회 인식하는 API -// * */ -// mEuPIRxManager.setOnWaveKeyUp(RequestCodeEnum.MENU_REQUEST.code.toInt()) { -// Toast.makeText(this, "menu request detected", Toast.LENGTH_SHORT).show() -// } - /** - * 해당 주파수의 음파가 발생했을 때 최초 1회 인식하는 API - * */ - mEuPIRxManager.setOnWaveKeyDown(RequestCodeEnum.MENU_REQUEST.code.toInt()) { - Toast.makeText(this, "menu request detected", Toast.LENGTH_SHORT).show() - } - - if (mEuPIRxManager.listen()) { - Log.d(TAG, "StoreActivity - mEuPIRxManager listen return : true") - } else { - Log.d(TAG, "StoreActivity - mEuPIRxManager listen return : false") - } + }else{Log.d(TAG, "Menu is empty")} } override fun onPause() { @@ -175,8 +107,8 @@ class StoreActivity : ComponentActivity() { private fun stopEuphony() { mTxManager.stop() - mRxManager.finish() - mEuPIRxManager.finish() + mEuPIRxManagerOrder.finish() + mEuPIRxManagerMenu.finish() } private fun receiveOrder(letters: String, dbUtil: DBUtil) { @@ -234,7 +166,7 @@ class StoreActivity : ComponentActivity() { // } fun showErrorToast(logMsg: String) { - Log.i(TAG, logMsg) + Log.d(TAG, logMsg) Toast.makeText( this@StoreActivity, this@StoreActivity.resources.getString(R.string.common_error_message), @@ -284,7 +216,7 @@ fun TopBar() { "go to add" ) if (openDialog.value) { - AddMenuDialog(onDismissRequest = {openDialog.value=false}) + AddMenuDialog(onDismissRequest = { openDialog.value = false }) } } @@ -472,9 +404,10 @@ fun AddMenuDialog( Button( modifier = Modifier .size(100.dp, 50.dp), - onClick = {onDismissRequest - Log.i("[StoreActivity]", "Cancel Add menu") - }, + onClick = { + onDismissRequest + Log.i("[StoreActivity]", "Cancel Add menu") + }, colors = ButtonDefaults.buttonColors(backgroundColor = Color.LightGray) ) { Text("CANCEL") @@ -490,7 +423,10 @@ fun AddMenuDialog( description = descriptionText, cost = costText.toInt() ) - Log.i("[StoreActivity]", "Menu:: Id: " +menuId.toString()+", name: "+nameText+", cost: "+costText+", description: "+descriptionText) + Log.i( + "[StoreActivity]", + "Menu:: Id: " + menuId.toString() + ", name: " + nameText + ", cost: " + costText + ", description: " + descriptionText + ) Log.i("[StoreActivity]", "Finish Add menu") onDismissRequest() } From 853b3f9bd21d2d8a30da4d7e7a23a116e85cf3c9 Mon Sep 17 00:00:00 2001 From: Hyejin Park <89901283+phj0407@users.noreply.github.com> Date: Tue, 6 Sep 2022 06:57:59 +0900 Subject: [PATCH 2/3] [Refactor] Revise EuPI code --- .../java/com/euphonyio/orderwith/StoreActivity.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt b/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt index 96da10e..d7cce8b 100644 --- a/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt +++ b/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt @@ -56,21 +56,20 @@ class StoreActivity : ComponentActivity() { private val TAG = "[StoreActivity]" private lateinit var dbUtil: DBUtil private lateinit var mTxManager: EuTxManager - private lateinit var mEuPIRxManagerMenu: EuRxManager - private lateinit var mEuPIRxManagerOrder: EuRxManager + private lateinit var EuPIRxManager: EuRxManager + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) dbUtil = DBUtil(this) mTxManager = EuTxManager(this) - mEuPIRxManagerMenu = EuRxManager(EuOption.ModeType.EUPI) - mEuPIRxManagerMenu.setOnWaveKeyDown(RequestCodeEnum.MENU_REQUEST.code.toInt()) { + EuPIRxManager = EuRxManager(EuOption.ModeType.EUPI) + EuPIRxManager.setOnWaveKeyDown(RequestCodeEnum.MENU_REQUEST.code.toInt()) { Toast.makeText(this, "Menu request detected", Toast.LENGTH_SHORT).show() Log.d(TAG, "mEuPIRxManagerMenu - Receive menu request.") } - mEuPIRxManagerOrder = EuRxManager(EuOption.ModeType.EUPI) - mEuPIRxManagerOrder.setOnWaveKeyDown(RequestCodeEnum.ORDER_REQUEST.code.toInt()) { + EuPIRxManager.setOnWaveKeyDown(RequestCodeEnum.ORDER_REQUEST.code.toInt()) { Toast.makeText(this, "Order request detected", Toast.LENGTH_SHORT).show() Log.d(TAG, "mEuPIRxManagerOrder - Receive order request.") } From 900a9049010c421ca6298d550847428cff65fa09 Mon Sep 17 00:00:00 2001 From: Hyejin Park <89901283+phj0407@users.noreply.github.com> Date: Tue, 6 Sep 2022 07:01:21 +0900 Subject: [PATCH 3/3] [Refactor] Revise EuPI code --- .../com/euphonyio/orderwith/StoreActivity.kt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt b/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt index d7cce8b..7f735a0 100644 --- a/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt +++ b/app/src/main/java/com/euphonyio/orderwith/StoreActivity.kt @@ -67,11 +67,11 @@ class StoreActivity : ComponentActivity() { EuPIRxManager = EuRxManager(EuOption.ModeType.EUPI) EuPIRxManager.setOnWaveKeyDown(RequestCodeEnum.MENU_REQUEST.code.toInt()) { Toast.makeText(this, "Menu request detected", Toast.LENGTH_SHORT).show() - Log.d(TAG, "mEuPIRxManagerMenu - Receive menu request.") + Log.d(TAG, "EuPIRxManager - Receive menu request.") } EuPIRxManager.setOnWaveKeyDown(RequestCodeEnum.ORDER_REQUEST.code.toInt()) { Toast.makeText(this, "Order request detected", Toast.LENGTH_SHORT).show() - Log.d(TAG, "mEuPIRxManagerOrder - Receive order request.") + Log.d(TAG, "EuPIRxManager - Receive order request.") } var allMenu: List @@ -85,12 +85,9 @@ class StoreActivity : ComponentActivity() { } if (!allMenu.isNullOrEmpty()) { - if (mEuPIRxManagerOrder.listen()) { - Log.d(TAG, "mEuPIRxManagerOrder - listen success") - } - if (mEuPIRxManagerMenu.listen()) { - Log.d(TAG, "mEuPIRxManagerMenu - listen success") - } + if (EuPIRxManager.listen()) { + Log.d(TAG, "EuPIRxManager - listen success") + }else{Log.d(TAG, "EuPIRxManager - listen fail") }else{Log.d(TAG, "Menu is empty")} } @@ -106,8 +103,7 @@ class StoreActivity : ComponentActivity() { private fun stopEuphony() { mTxManager.stop() - mEuPIRxManagerOrder.finish() - mEuPIRxManagerMenu.finish() + EuPIRxManager.finish() } private fun receiveOrder(letters: String, dbUtil: DBUtil) {