From a1e387813c494a0a0287c01e9afa0fdc8d4b803e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=B4=EC=8B=9C?= <67777523+EmilyCh0@users.noreply.github.com> Date: Thu, 20 Jul 2023 15:14:08 +0900 Subject: [PATCH] =?UTF-8?q?[AN/STAFF]=20fix:=20=EC=B9=B4=EB=A9=94=EB=9D=BC?= =?UTF-8?q?=20=EA=B6=8C=ED=95=9C=20=EC=9A=94=EC=B2=AD(#77)=20(#80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 카메라 권한 요청 구현 * style: 문자열 리소스 name 수정 * refactor: 코틀린 컬렉션 api로 리펙토링 --- .../app/src/main/AndroidManifest.xml | 5 +++ .../extension/ActivityExtension.kt | 8 +++++ .../TicketValidationActivity.kt | 34 +++++++++++++++++-- .../app/src/main/res/values/strings.xml | 5 +++ 4 files changed, 50 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_toast_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.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)) + } + } + } + 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..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,4 +2,9 @@ festago-staff 티켓 검사 STAFF + + + 카메라 권한이 허용되었습니다. + 카메라 권한을 거부했습니다. + No content