From 92f7de1638a6bc5e5d34108d7d90f88028521b36 Mon Sep 17 00:00:00 2001 From: EmilyCh0 Date: Thu, 20 Jul 2023 12:40:50 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=EC=B9=B4=EB=A9=94=EB=9D=BC=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=EC=9A=94=EC=B2=AD=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/src/main/AndroidManifest.xml | 5 +++ .../extension/ActivityExtension.kt | 8 +++++ .../TicketValidationActivity.kt | 34 +++++++++++++++++-- .../app/src/main/res/values/strings.xml | 3 ++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 android/festago-staff/app/src/main/java/com/festago/festagostaff/presentation/extension/ActivityExtension.kt diff --git a/android/festago-staff/app/src/main/AndroidManifest.xml b/android/festago-staff/app/src/main/AndroidManifest.xml index 2ec8f96df..aa8d87037 100644 --- a/android/festago-staff/app/src/main/AndroidManifest.xml +++ b/android/festago-staff/app/src/main/AndroidManifest.xml @@ -2,7 +2,12 @@ + + + if (result.text == null) { - Toast.makeText(this, "No content", Toast.LENGTH_SHORT).show() + showToast(getString(R.string.ticket_validation_no_content)) return@BarcodeCallback } if (!vm.isLatestCode(result.text)) { @@ -40,6 +46,7 @@ class TicketValidationActivity : AppCompatActivity() { super.onCreate(savedInstanceState) initBinding() + checkPermission(Manifest.permission.CAMERA, CAMERA_PERMISSION_CODE) } private fun initBinding() { @@ -69,7 +76,30 @@ class TicketValidationActivity : AppCompatActivity() { return binding.dbvScanner.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event) } + private fun checkPermission(permission: String, requestCode: Int) { + if (ContextCompat.checkSelfPermission(this, permission) == PERMISSION_DENIED) { + ActivityCompat.requestPermissions(this, arrayOf(permission), requestCode) + } + } + + override fun onRequestPermissionsResult( + requestCode: Int, + permissions: Array, + grantResults: IntArray, + ) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + if (requestCode == CAMERA_PERMISSION_CODE) { + if (grantResults.isNotEmpty() && grantResults[0] == PERMISSION_GRANTED) { + showToast(getString(R.string.ticket_validation_camera_permission_granted)) + } else { + showToast(getString(R.string.ticket_validation_camera_permission_denied)) + } + } + } + companion object { + private const val CAMERA_PERMISSION_CODE = 111 + fun getIntent(context: Context): Intent { return Intent(context, TicketValidationActivity::class.java) } diff --git a/android/festago-staff/app/src/main/res/values/strings.xml b/android/festago-staff/app/src/main/res/values/strings.xml index e88c23bac..d32edf137 100644 --- a/android/festago-staff/app/src/main/res/values/strings.xml +++ b/android/festago-staff/app/src/main/res/values/strings.xml @@ -2,4 +2,7 @@ festago-staff 티켓 검사 STAFF + 카메라 권한이 허용되었습니다. + 카메라 권한을 거부했습니다. + No content From 788b0e1ff573e8223d60b2a41ef1b6cf40e5021e Mon Sep 17 00:00:00 2001 From: EmilyCh0 Date: Thu, 20 Jul 2023 12:48:06 +0900 Subject: [PATCH 2/3] =?UTF-8?q?style:=20=EB=AC=B8=EC=9E=90=EC=97=B4=20?= =?UTF-8?q?=EB=A6=AC=EC=86=8C=EC=8A=A4=20name=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/ticketvalidation/TicketValidationActivity.kt | 6 +++--- android/festago-staff/app/src/main/res/values/strings.xml | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/android/festago-staff/app/src/main/java/com/festago/festagostaff/presentation/ui/ticketvalidation/TicketValidationActivity.kt b/android/festago-staff/app/src/main/java/com/festago/festagostaff/presentation/ui/ticketvalidation/TicketValidationActivity.kt index f2fac129a..0d2b5cc68 100644 --- a/android/festago-staff/app/src/main/java/com/festago/festagostaff/presentation/ui/ticketvalidation/TicketValidationActivity.kt +++ b/android/festago-staff/app/src/main/java/com/festago/festagostaff/presentation/ui/ticketvalidation/TicketValidationActivity.kt @@ -34,7 +34,7 @@ class TicketValidationActivity : AppCompatActivity() { private val barcodeCallback = BarcodeCallback { result -> if (result.text == null) { - showToast(getString(R.string.ticket_validation_no_content)) + showToast(getString(R.string.ticket_validation_toast_no_content)) return@BarcodeCallback } if (!vm.isLatestCode(result.text)) { @@ -90,9 +90,9 @@ class TicketValidationActivity : AppCompatActivity() { super.onRequestPermissionsResult(requestCode, permissions, grantResults) if (requestCode == CAMERA_PERMISSION_CODE) { if (grantResults.isNotEmpty() && grantResults[0] == PERMISSION_GRANTED) { - showToast(getString(R.string.ticket_validation_camera_permission_granted)) + showToast(getString(R.string.ticket_validation_toast_camera_permission_granted)) } else { - showToast(getString(R.string.ticket_validation_camera_permission_denied)) + showToast(getString(R.string.ticket_validation_toast_camera_permission_denied)) } } } diff --git a/android/festago-staff/app/src/main/res/values/strings.xml b/android/festago-staff/app/src/main/res/values/strings.xml index d32edf137..b89859c45 100644 --- a/android/festago-staff/app/src/main/res/values/strings.xml +++ b/android/festago-staff/app/src/main/res/values/strings.xml @@ -2,7 +2,9 @@ festago-staff 티켓 검사 STAFF - 카메라 권한이 허용되었습니다. - 카메라 권한을 거부했습니다. - No content + + + 카메라 권한이 허용되었습니다. + 카메라 권한을 거부했습니다. + No content From f4cf7005af7e5e287316b20c764d7bf6314f80a1 Mon Sep 17 00:00:00 2001 From: EmilyCh0 Date: Thu, 20 Jul 2023 12:52:54 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EC=BD=94=ED=8B=80=EB=A6=B0=20?= =?UTF-8?q?=EC=BB=AC=EB=A0=89=EC=85=98=20api=EB=A1=9C=20=EB=A6=AC=ED=8E=99?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/ticketvalidation/TicketValidationActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/festago-staff/app/src/main/java/com/festago/festagostaff/presentation/ui/ticketvalidation/TicketValidationActivity.kt b/android/festago-staff/app/src/main/java/com/festago/festagostaff/presentation/ui/ticketvalidation/TicketValidationActivity.kt index 0d2b5cc68..d0e6dd5d8 100644 --- a/android/festago-staff/app/src/main/java/com/festago/festagostaff/presentation/ui/ticketvalidation/TicketValidationActivity.kt +++ b/android/festago-staff/app/src/main/java/com/festago/festagostaff/presentation/ui/ticketvalidation/TicketValidationActivity.kt @@ -89,7 +89,7 @@ class TicketValidationActivity : AppCompatActivity() { ) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) if (requestCode == CAMERA_PERMISSION_CODE) { - if (grantResults.isNotEmpty() && grantResults[0] == PERMISSION_GRANTED) { + if (grantResults.getOrNull(0) == PERMISSION_GRANTED) { showToast(getString(R.string.ticket_validation_toast_camera_permission_granted)) } else { showToast(getString(R.string.ticket_validation_toast_camera_permission_denied))