feat: added code scanning
This commit is contained in:
@@ -13,12 +13,15 @@
|
||||
android:theme="@style/Base.Theme.OmniCards">
|
||||
<activity
|
||||
android:name=".ShowCardActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".AddCardActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
@@ -10,10 +10,25 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import com.google.zxing.BarcodeFormat
|
||||
import com.journeyapps.barcodescanner.ScanContract
|
||||
import com.journeyapps.barcodescanner.ScanOptions
|
||||
|
||||
class AddCardActivity : AppCompatActivity() {
|
||||
private lateinit var db: DbHelper
|
||||
|
||||
private val barcodeLauncher = registerForActivityResult(ScanContract()) { result ->
|
||||
if (result.contents != null) {
|
||||
val codeTypes = BarcodeFormat.entries.map { it.name }
|
||||
val codeTypeIndex = codeTypes.indexOf(result.formatName)
|
||||
|
||||
if (codeTypeIndex >= 0) {
|
||||
findViewById<Spinner>(R.id.cardCodeTypeSelector).setSelection(codeTypeIndex)
|
||||
}
|
||||
|
||||
findViewById<EditText>(R.id.cardValueInput).setText(result.contents)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
@@ -28,6 +43,7 @@ class AddCardActivity : AppCompatActivity() {
|
||||
|
||||
val cardNameInput: EditText = findViewById(R.id.cardNameInput)
|
||||
val cardValueInput: EditText = findViewById(R.id.cardValueInput)
|
||||
val scanCodeButton: Button = findViewById(R.id.scanCodeButton)
|
||||
val cardCodeTypeSelector: Spinner = findViewById(R.id.cardCodeTypeSelector)
|
||||
val saveCardButton: Button = findViewById(R.id.saveCardButton)
|
||||
|
||||
@@ -36,6 +52,14 @@ class AddCardActivity : AppCompatActivity() {
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
cardCodeTypeSelector.adapter = adapter
|
||||
|
||||
scanCodeButton.setOnClickListener {
|
||||
val options = ScanOptions()
|
||||
options.setPrompt("Scan code")
|
||||
options.setBeepEnabled(false)
|
||||
options.setOrientationLocked(false)
|
||||
barcodeLauncher.launch(options)
|
||||
}
|
||||
|
||||
saveCardButton.setOnClickListener {
|
||||
val cardName = cardNameInput.text.toString()
|
||||
val cardValue = cardValueInput.text.toString()
|
||||
|
||||
@@ -50,14 +50,27 @@
|
||||
android:hint="Card name"
|
||||
android:inputType="text" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/cardValueInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="259dp"
|
||||
android:layout_height="46dp"
|
||||
android:ems="10"
|
||||
android:hint="Card value"
|
||||
android:inputType="text" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/scanCodeButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="38dp"
|
||||
android:text="Scan" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/cardCodeTypeSelector"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user