forked from omni/OmniCards
feat: setted QR by default code type
This commit is contained in:
@@ -18,12 +18,7 @@ class AddCardActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private val barcodeLauncher = registerForActivityResult(ScanContract()) { result ->
|
private val barcodeLauncher = registerForActivityResult(ScanContract()) { result ->
|
||||||
if (result.contents != null) {
|
if (result.contents != null) {
|
||||||
val codeTypes = BarcodeFormat.entries.map { it.name }
|
setCodeType(result.formatName)
|
||||||
val codeTypeIndex = codeTypes.indexOf(result.formatName)
|
|
||||||
|
|
||||||
if (codeTypeIndex >= 0) {
|
|
||||||
findViewById<Spinner>(R.id.cardCodeTypeSelector).setSelection(codeTypeIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
findViewById<EditText>(R.id.cardValueInput).setText(result.contents)
|
findViewById<EditText>(R.id.cardValueInput).setText(result.contents)
|
||||||
}
|
}
|
||||||
@@ -51,6 +46,7 @@ class AddCardActivity : AppCompatActivity() {
|
|||||||
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, options)
|
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, options)
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||||
cardCodeTypeSelector.adapter = adapter
|
cardCodeTypeSelector.adapter = adapter
|
||||||
|
setCodeType("QR_CODE")
|
||||||
|
|
||||||
scanCodeButton.setOnClickListener {
|
scanCodeButton.setOnClickListener {
|
||||||
val options = ScanOptions()
|
val options = ScanOptions()
|
||||||
@@ -70,4 +66,13 @@ class AddCardActivity : AppCompatActivity() {
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setCodeType(codeTypeString: String) {
|
||||||
|
val codeTypes = BarcodeFormat.entries.map { it.name }
|
||||||
|
val codeTypeIndex = codeTypes.indexOf(codeTypeString)
|
||||||
|
|
||||||
|
if (codeTypeIndex >= 0) {
|
||||||
|
findViewById<Spinner>(R.id.cardCodeTypeSelector).setSelection(codeTypeIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user