Skip to content

Commit

Permalink
Replace me.dm7.barcodescanner with camerax
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Nov 28, 2023
1 parent 5b4232e commit 1517d41
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 49 deletions.
1 change: 0 additions & 1 deletion pretixscan/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ dependencies {

implementation 'com.louiscad.splitties:splitties-toast:3.0.0'
implementation 'com.github.traex.rippleeffect:library:1.3'
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
implementation 'com.github.kizitonwose:CalendarView:1.0.4'

implementation 'com.squareup.okhttp3:okhttp:4.9.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.module.SimpleModule
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.google.zxing.Result
import eu.pretix.libpretixsync.api.PretixApi
import eu.pretix.libpretixsync.check.CheckException
import eu.pretix.libpretixsync.check.OnlineCheckProvider
Expand All @@ -71,6 +70,7 @@ import eu.pretix.libpretixui.android.covid.SAMPLE_SETTINGS
import eu.pretix.libpretixui.android.questions.QuestionsDialogInterface
import eu.pretix.libpretixui.android.scanning.HardwareScanner
import eu.pretix.libpretixui.android.scanning.ScanReceiver
import eu.pretix.libpretixui.android.scanning.ScannerView
import eu.pretix.pretixscan.droid.*
import eu.pretix.pretixscan.droid.connectivity.ConnectivityChangedListener
import eu.pretix.pretixscan.droid.databinding.ActivityMainBinding
Expand All @@ -80,7 +80,6 @@ import io.sentry.Sentry
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import me.dm7.barcodescanner.zxing.ZXingScannerView
import org.json.JSONArray
import org.json.JSONObject
import splitties.toast.toast
Expand All @@ -91,7 +90,6 @@ import java.security.MessageDigest
import java.text.SimpleDateFormat
import java.time.ZoneId
import java.util.*
import splitties.toast.toast


interface ReloadableActivity {
Expand Down Expand Up @@ -146,7 +144,7 @@ class ViewDataHolder(private val ctx: Context) {
}
}

class MainActivity : AppCompatActivity(), ReloadableActivity, ZXingScannerView.ResultHandler, MediaPlayer.OnCompletionListener, ConnectivityChangedListener {
class MainActivity : AppCompatActivity(), ReloadableActivity, ScannerView.ResultHandler, MediaPlayer.OnCompletionListener, ConnectivityChangedListener {

private val REQ_EVENT = 1

Expand Down Expand Up @@ -857,13 +855,13 @@ class MainActivity : AppCompatActivity(), ReloadableActivity, ZXingScannerView.R

fun reloadCameraState() {
try {
binding.scannerView.flash = conf.scanFlash
binding.scannerView.torch = conf.scanFlash
if (conf.scanFlash) {
binding.fabFlash.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.pretix_brand_green))
} else {
binding.fabFlash.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.fab_disable))
}
binding.scannerView.setAutoFocus(conf.scanFocus)
binding.scannerView.autofocus = conf.scanFocus
if (conf.scanFocus) {
binding.fabFocus.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.pretix_brand_green))
} else {
Expand Down Expand Up @@ -1270,9 +1268,7 @@ class MainActivity : AppCompatActivity(), ReloadableActivity, ZXingScannerView.R

}

override fun handleResult(rawResult: Result) {
binding.scannerView.resumeCameraPreview(this@MainActivity)

override fun handleResult(rawResult: ScannerView.Result) {
if ((dialog != null && dialog!!.isShowing()) || view_data.resultState.get() == LOADING) {
return
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.zxing.Result
import eu.pretix.libpretixsync.setup.*
import eu.pretix.libpretixui.android.scanning.HardwareScanner
import eu.pretix.libpretixui.android.scanning.ScanReceiver
import eu.pretix.libpretixui.android.scanning.ScannerView
import eu.pretix.pretixscan.droid.*
import eu.pretix.pretixscan.droid.databinding.ActivitySetupBinding
import io.sentry.Sentry
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import me.dm7.barcodescanner.zxing.ZXingScannerView
import org.json.JSONException
import org.json.JSONObject
import java.io.IOException
import java.lang.Exception
import javax.net.ssl.SSLException

class SetupActivity : AppCompatActivity(), ZXingScannerView.ResultHandler {
class SetupActivity : AppCompatActivity(), ScannerView.ResultHandler {
lateinit var binding: ActivitySetupBinding
val bgScope = CoroutineScope(Dispatchers.IO)
var lastScanTime = 0L
Expand Down Expand Up @@ -137,8 +136,7 @@ class SetupActivity : AppCompatActivity(), ZXingScannerView.ResultHandler {
}
}

override fun handleResult(rawResult: Result) {
binding.scannerView.resumeCameraPreview(this)
override fun handleResult(rawResult: ScannerView.Result) {
if (lastScanValue == rawResult.text && lastScanTime > System.currentTimeMillis() - 3000) {
return
}
Expand Down Expand Up @@ -190,7 +188,6 @@ class SetupActivity : AppCompatActivity(), ZXingScannerView.ResultHandler {

fun resume() {
pdialog.dismiss()
binding.scannerView.resumeCameraPreview(this)
ongoing_setup = false
}

Expand Down
2 changes: 1 addition & 1 deletion pretixscan/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
android:layout_width="match_parent"
android:layout_height="fill_parent">

<eu.pretix.pretixscan.droid.ui.ScannerView
<eu.pretix.libpretixui.android.scanning.ScannerView
android:id="@+id/scanner_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion pretixscan/app/src/main/res/layout/activity_setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cardView2">

<eu.pretix.pretixscan.droid.ui.ScannerView
<eu.pretix.libpretixui.android.scanning.ScannerView
android:id="@+id/scanner_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Expand Down

0 comments on commit 1517d41

Please sign in to comment.