Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AN/STAFF] fix: 카메라 권한 요청(#77) #80

Merged
merged 3 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions android/festago-staff/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-feature
android:name="android.hardware.camera"
android:required="false" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.festago.festagostaff.presentation.extension

import android.app.Activity
import android.widget.Toast

fun Activity.showToast(message: String, duration: Int = Toast.LENGTH_SHORT) {
Toast.makeText(this, message, duration).show()
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.festago.festagostaff.presentation.ui.ticketvalidation

import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager.PERMISSION_DENIED
import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.os.Bundle
import android.view.KeyEvent
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.festago.festagostaff.R
import com.festago.festagostaff.data.RetrofitClient
import com.festago.festagostaff.data.repository.TicketDefaultRepository
import com.festago.festagostaff.databinding.ActivityTicketValidationBinding
import com.festago.festagostaff.presentation.extension.showToast
import com.google.zxing.BarcodeFormat
import com.journeyapps.barcodescanner.BarcodeCallback
import com.journeyapps.barcodescanner.DefaultDecoderFactory
Expand All @@ -28,7 +34,7 @@ class TicketValidationActivity : AppCompatActivity() {

private val barcodeCallback = BarcodeCallback { result ->
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)) {
Expand All @@ -40,6 +46,7 @@ class TicketValidationActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)

initBinding()
checkPermission(Manifest.permission.CAMERA, CAMERA_PERMISSION_CODE)
}

private fun initBinding() {
Expand Down Expand Up @@ -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<out String>,
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)
}
Expand Down
5 changes: 5 additions & 0 deletions android/festago-staff/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
<string name="app_name">festago-staff</string>
<string name="main_btn_check_ticket">티켓 검사</string>
<string name="main_label_staff">STAFF</string>

<!-- Strings related to ticket validation -->
<string name="ticket_validation_toast_camera_permission_granted">카메라 권한이 허용되었습니다.</string>
<string name="ticket_validation_toast_camera_permission_denied">카메라 권한을 거부했습니다.</string>
<string name="ticket_validation_toast_no_content">No content</string>
</resources>