Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pretixscan/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ dependencies {
}
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.github.apg-mobile:android-round-textview:v1.0.0'

implementation "com.google.android.gms:play-services-base:18.7.2"
implementation "com.google.android.gms:play-services-mlkit-barcode-scanning:18.3.1"
}

sqldelight {
Expand Down
4 changes: 4 additions & 0 deletions pretixscan/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
android:resource="@xml/filepaths" />
</provider>

<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="barcode" />

<meta-data android:name="io.sentry.dsn" android:value="${SENTRY_DSN}" />
<meta-data android:name="io.sentry.attach-screenshot" android:value="false" />
<meta-data android:name="io.sentry.attach-view-hierarchy" android:value="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ class AppConfig(ctx: Context) : ConfigStore {
.putString(PREFS_KEY_AUTOPRINTBADGES, "once")
.commit()
}
if (prefs.contains(LEGACY_PREFS_KEY_USE_CAMERA)) {
prefs.edit()
.putString(PREFS_KEY_SCAN_ENGINE, if (prefs.getBoolean(LEGACY_PREFS_KEY_USE_CAMERA, true)) "zxing" else "hardware")
.remove(LEGACY_PREFS_KEY_USE_CAMERA)
.commit()
}
}

override fun isDebug(): Boolean {
Expand Down Expand Up @@ -339,9 +345,9 @@ class AppConfig(ctx: Context) : ConfigStore {
}
}

var useCamera: Boolean
get() = default_prefs.getBoolean(PREFS_KEY_USE_CAMERA, true)
set(value) = default_prefs.edit().putBoolean(PREFS_KEY_USE_CAMERA, value).apply()
@Deprecated("use scanEngine instead")
val useCamera: Boolean
get() = default_prefs.getString(PREFS_KEY_SCAN_ENGINE, "zxing") != "hardware"

val hideNames: Boolean
get() = default_prefs.getBoolean(PREFS_KEY_HIDE_NAMES, false)
Expand Down Expand Up @@ -397,6 +403,10 @@ class AppConfig(ctx: Context) : ConfigStore {
get() = default_prefs.getBoolean(PREFS_KEY_SYNC_ORDERS, true)
set(value) = default_prefs.edit().putBoolean(PREFS_KEY_SYNC_ORDERS, value).apply()

var scanEngine: String
get() = default_prefs.getString(PREFS_KEY_SCAN_ENGINE, "zxing") ?: "zxing"
set(value) = default_prefs.edit().putString(PREFS_KEY_SCAN_ENGINE, value).apply()

override fun getKnownLiveEventSlugs(): Set<String> {
return default_prefs.getStringSet(PREFS_KEY_KNOWN_LIVE_EVENT_SLUGS, emptySet()) as Set<String>
}
Expand Down Expand Up @@ -435,7 +445,7 @@ class AppConfig(ctx: Context) : ConfigStore {
val PREFS_KEY_SCAN_FLASH = "scan_flash"
val PREFS_KEY_SYNC_ORDERS = "pref_sync_orders"
val PREFS_KEY_AUTO_SWITCH = "pref_auto_switch"
val PREFS_KEY_USE_CAMERA = "pref_use_camera"
val LEGACY_PREFS_KEY_USE_CAMERA = "pref_use_camera"
val PREFS_KEY_SCAN_OFFLINE = "pref_scan_offline"
val PREFS_KEY_SCAN_OFFLINE_AUTO = "pref_auto_offline"
val PREFS_KEY_SCAN_PROXY = "pref_scan_proxy"
Expand All @@ -451,6 +461,7 @@ class AppConfig(ctx: Context) : ConfigStore {
val PREFS_KEY_SEARCH_DISABLE = "pref_search_disable"
val PREFS_KEY_KIOSK_MODE = "pref_kiosk_mode"
val PREFS_KEY_MULTI_EVENT_MODE = "multi_event_mode"
val PREFS_KEY_SCAN_ENGINE = "pref_scan_engine"
private const val PREFS_KEY_KNOWN_LIVE_EVENT_SLUGS = "cache_known_live_event_slugs"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.module.SimpleModule
import com.google.android.gms.common.moduleinstall.InstallStatusListener
import com.google.android.gms.common.moduleinstall.ModuleInstall
import com.google.android.gms.common.moduleinstall.ModuleInstallRequest
import com.google.android.gms.common.moduleinstall.ModuleInstallStatusUpdate
import com.google.android.gms.common.moduleinstall.ModuleInstallStatusUpdate.InstallState.STATE_CANCELED
import com.google.android.gms.common.moduleinstall.ModuleInstallStatusUpdate.InstallState.STATE_COMPLETED
import com.google.android.gms.common.moduleinstall.ModuleInstallStatusUpdate.InstallState.STATE_FAILED
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.google.mlkit.vision.barcode.BarcodeScanning
import eu.pretix.libpretixsync.api.PretixApi
import eu.pretix.libpretixsync.check.CheckException
import eu.pretix.libpretixsync.check.OnlineCheckProvider
Expand Down Expand Up @@ -528,6 +536,66 @@ class MainActivity : AppCompatActivity(), ReloadableActivity, ScannerView.Result
pendingPinAction?.let { it(pin) }
}
}

if (conf.scanEngine == "mlkit") {
val moduleInstallClient = ModuleInstall.getClient(this)
val barcodeModule = BarcodeScanning.getClient()
moduleInstallClient.areModulesAvailable(
barcodeModule
)
class ModuleInstallProgressListener : InstallStatusListener {
override fun onInstallStatusUpdated(update: ModuleInstallStatusUpdate) {
// Progress info is only set when modules are in the progress of downloading.
update.progressInfo?.let {
val progress = (it.bytesDownloaded * 100 / it.totalBytesToDownload).toInt()
// Set the progress for the progress bar.
//progressBar.setProgress(progress)
}

if (isTerminateState(update.installState)) {
moduleInstallClient.unregisterListener(this)
}
if (update.installState == STATE_COMPLETED) {
// -> switch engine
switchScanEngine()
}
}

fun isTerminateState(@ModuleInstallStatusUpdate.InstallState state: Int): Boolean {
return state == STATE_CANCELED || state == STATE_COMPLETED || state == STATE_FAILED
}
}

val listener = ModuleInstallProgressListener()
val moduleInstallRequest = ModuleInstallRequest.newBuilder()
.addApi(barcodeModule)
.setListener(listener)
.build()

moduleInstallClient
.installModules(moduleInstallRequest)
.addOnSuccessListener {
if (it.areModulesAlreadyInstalled()) {
// Modules are already installed when the request is sent.
// -> switch engine
switchScanEngine()
}
// The install request has been sent successfully. This does not mean
// the installation is completed. To monitor the install status, set an
// InstallStatusListener to the ModuleInstallRequest.
}
.addOnFailureListener {
// Handle failure…
}
}
}

private fun switchScanEngine() {
when(conf.scanEngine) {
"zxing" -> binding.scannerView.setAnalyzer(ScannerView.Companion.ANALYZER.ZXING)
"mlkit" -> binding.scannerView.setAnalyzer(ScannerView.Companion.ANALYZER.MLKIT)
else -> {}
}
}

private fun eventButtonText(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
true
}
}

// FIXME: pref_scan_engine. if BuildConfig.FLAVOR_edition == "foss", don't offer mlkit (disable?)
// FIXME: pref_scan_engine. check installation status of mlkit and warn for potential large download
// FIXME: pref_scan_engine. if changed to mlkit, check installation status
}

private fun asset_dialog(@RawRes htmlRes: Int, @StringRes title: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SetupActivity : AppCompatActivity(), SetupCallable {

override fun config(useCamera: Boolean) {
val conf = AppConfig(this)
conf.useCamera = useCamera
conf.scanEngine = if (useCamera) "zxing" else "hardware"
}

override fun setup(url: String, token: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class WelcomeActivity : AppCompatActivity() {

if (defaultToScanner()) {
val conf = AppConfig(this)
conf.useCamera = false
conf.scanEngine = "hardware"
}
}

Expand Down
5 changes: 5 additions & 0 deletions pretixscan/app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
<item>once</item>
<item>true</item>
</string-array>
<string-array name="settings_values_scan_engine">
<item>zxing</item>
<item>mlkit</item>
<item>hardware</item>
</string-array>
</resources>
6 changes: 6 additions & 0 deletions pretixscan/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<string name="preference_badgeprint_enable">Enable badge printing</string>
<string name="preference_autobadgeprint_enable">Print badges automatically</string>
<string name="preference_badgeprint_install_pretixprint">Printing badges requires the separate pretixPRINT app. Do you want to install it?</string>
<string name="preference_scan_engine">Barcode scanner to use</string>
<string name="already_scanned">already scanned</string>
<string name="total_tickets_sold">total tickets sold</string>
<string name="ticket_attention">Attention, special ticket!</string>
Expand Down Expand Up @@ -169,6 +170,11 @@
<item>Once, if not yet printed</item>
<item>Always</item>
</string-array>
<string-array name="settings_valuelabels_scan_engine">
<item>Zebra Crossing (ZXing)</item>
<item>Google ML Kit</item>
<item>Hardware scanner of this device</item>
</string-array>
<string name="headline_please_reinstall">Please reinstall pretixSCAN</string>
<string name="reinstall_text">Your previous pretixSCAN version was too old and your local data cannot be used for the current version.\n\nPlease clear the storage for the pretixSCAN app or delete and reinstall the app.</string>
<string name="reinstall_open_app_settings">Open Android App Settings</string>
Expand Down
1 change: 1 addition & 0 deletions pretixscan/app/src/main/res/xml/app_restrictions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:key="pref_sync_auto"
android:restrictionType="bool"
android:title="@string/settings_label_auto_sync" />
<!-- FIXME, remove/migrate? -->
<restriction
android:defaultValue="true"
android:key="pref_use_camera"
Expand Down
11 changes: 7 additions & 4 deletions pretixscan/app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
android:title="@string/settings_label_auto_switch" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/settings_label_ui">
<CheckBoxPreference
android:defaultValue="true"
android:key="pref_use_camera"
android:title="@string/settings_label_device_camera" />
<ListPreference
android:key="pref_scan_engine"
android:defaultValue="zxing"
android:entries="@array/settings_valuelabels_scan_engine"
android:entryValues="@array/settings_values_scan_engine"
android:title="@string/preference_scan_engine"
android:summary="%s" />
<CheckBoxPreference
android:defaultValue="true"
android:key="pref_sounds"
Expand Down
Loading