1. Added demo camera scanner page.
2. Added new checkboxes for patient data collection
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package com.example.hpos.presentation.testRight
|
||||
|
||||
import android.Manifest
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.example.hpos.R
|
||||
import com.example.hpos.databinding.FragmentTestRightExpSampleBinding
|
||||
import com.example.hpos.databinding.FragmentTestRightExpScannerBinding
|
||||
import com.journeyapps.barcodescanner.ScanContract
|
||||
import com.journeyapps.barcodescanner.ScanIntentResult
|
||||
import com.journeyapps.barcodescanner.ScanOptions
|
||||
|
||||
class TestRightExpScanner : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentTestRightExpScannerBinding
|
||||
private val viewModel: TestRightViewModel by activityViewModels()
|
||||
|
||||
val MY_CAMERA_REQUEST_CODE = 100
|
||||
private val TAG = "TestRightExpScanner"
|
||||
|
||||
val requestCameraPermission = registerForActivityResult( ActivityResultContracts.RequestPermission()) { isGranted ->
|
||||
if (isGranted){
|
||||
startCamera()
|
||||
} else {
|
||||
Toast.makeText(requireContext(), "Camera Permission is Required to Scan", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private val barcodeLauncher = registerForActivityResult(ScanContract()) { result: ScanIntentResult ->
|
||||
if (result.contents == null) {
|
||||
Toast.makeText(requireContext(), "Unsuccessful, Please Scan Again!! ", Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
viewModel.processEncodedScannedData(result.contents)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
// Inflate the layout for this fragment
|
||||
binding = FragmentTestRightExpScannerBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
||||
setupListeners()
|
||||
|
||||
}
|
||||
|
||||
private fun setupListeners() {
|
||||
binding.btnScanAadhaar.setOnClickListener {
|
||||
scanAadhaarCard()
|
||||
}
|
||||
binding.btnScanAbha.setOnClickListener {
|
||||
scanAbhaCard()
|
||||
}
|
||||
}
|
||||
|
||||
private fun scanAadhaarCard() {
|
||||
// Toast.makeText(requireContext(), "Scan Aadhaar Clicked", Toast.LENGTH_SHORT).show();
|
||||
requestCameraPermission.launch(Manifest.permission.CAMERA)
|
||||
}
|
||||
|
||||
private fun scanAbhaCard() {
|
||||
Toast.makeText(requireContext(), "Scan Abha Clicked", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
private fun startCamera() {
|
||||
Toast.makeText(requireContext(), "SUCESS CAMERA START", Toast.LENGTH_SHORT).show();
|
||||
|
||||
val options = ScanOptions()
|
||||
options.setDesiredBarcodeFormats(ScanOptions.QR_CODE)
|
||||
options.setPrompt("Scan a barcode")
|
||||
options.setCameraId(0) // Use a specific camera of the device
|
||||
|
||||
options.setBeepEnabled(true)
|
||||
options.setBarcodeImageEnabled(true)
|
||||
|
||||
options.setPrompt("Start Scanning")
|
||||
options.setOrientationLocked(false)
|
||||
// options.setTimeout(1000) // in ms
|
||||
|
||||
barcodeLauncher.launch(options)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -292,6 +292,7 @@ class TestRightViewModel : ViewModel() {
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save CSV, Please try again")
|
||||
}
|
||||
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
@@ -389,4 +390,11 @@ class TestRightViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
// Scanner Fragment Related Members
|
||||
|
||||
fun processEncodedScannedData(contents: String) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user