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
robbi5 authored and raphaelm committed Jul 18, 2024
1 parent 4a03d37 commit c3a4e04
Show file tree
Hide file tree
Showing 8 changed files with 12 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 @@ -131,7 +131,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:$okhttp_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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 @@ -70,6 +69,7 @@ import eu.pretix.libpretixsync.sync.SyncManager
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 @@ -79,7 +79,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 Down Expand Up @@ -146,7 +145,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 @@ -902,13 +901,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 @@ -1261,9 +1260,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 c3a4e04

Please sign in to comment.