Skip to content

Commit

Permalink
Add more precise setting for auto print (#115)
Browse files Browse the repository at this point in the history
* Add more precise setting for auto print

* Fix restriction support for pref_auto_print_badges_option

* Cleanup translations

* Cleanup, use ListPreference instead

* Update pretixscan/app/src/main/res/values/strings.xml

---------

Co-authored-by: Raphael Michel <[email protected]>
  • Loading branch information
robbi5 and raphaelm authored Nov 11, 2024
1 parent 77b9557 commit 117b671
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ class AppConfig(ctx: Context) : ConfigStore {
init {
prefs = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
default_prefs = PreferenceManager.getDefaultSharedPreferences(ctx)
migrate()
}

private fun migrate() {
if (prefs.contains(PREFS_KEY_LEGACY_AUTOPRINTBADGES)) {
prefs.edit()
.putString(PREFS_KEY_AUTOPRINTBADGES, if (prefs.getBoolean(PREFS_KEY_LEGACY_AUTOPRINTBADGES, false)) "true" else "false")
.remove(PREFS_KEY_LEGACY_AUTOPRINTBADGES)
.commit()
}
}

override fun isDebug(): Boolean {
Expand Down Expand Up @@ -354,9 +364,9 @@ class AppConfig(ctx: Context) : ConfigStore {
get() = default_prefs.getBoolean(PREFS_KEY_PRINTBADGES, false)
set(value) = default_prefs.edit().putBoolean(PREFS_KEY_PRINTBADGES, value).apply()

var autoPrintBadges: Boolean
get() = default_prefs.getBoolean(PREFS_KEY_AUTOPRINTBADGES, false)
set(value) = default_prefs.edit().putBoolean(PREFS_KEY_AUTOPRINTBADGES, value).apply()
var autoPrintBadges: String
get() = default_prefs.getString(PREFS_KEY_AUTOPRINTBADGES, "false") ?: "false"
set(value) = default_prefs.edit().putString(PREFS_KEY_AUTOPRINTBADGES, value).apply()

var printBadgesTwice: Boolean
get() = default_prefs.getBoolean(PREFS_KEY_PRINTBADGESTWICE, false)
Expand Down Expand Up @@ -426,7 +436,8 @@ class AppConfig(ctx: Context) : ConfigStore {
val PREFS_KEY_SCAN_PROXY = "pref_scan_proxy"
val PREFS_KEY_PRINTBADGES = "pref_print_badges"
val PREFS_KEY_PRINTBADGESTWICE = "pref_print_badges_twice"
val PREFS_KEY_AUTOPRINTBADGES = "pref_auto_print_badges"
val PREFS_KEY_AUTOPRINTBADGES = "pref_auto_print_badges_option"
val PREFS_KEY_LEGACY_AUTOPRINTBADGES = "pref_auto_print_badges"
val PREFS_KEY_UNPAID_ASK = "pref_unpaid_ask"
val PREFS_KEY_IGNORE_QUESTIONS = "pref_ignore_questions"
val PREFS_KEY_SCAN_TYPE = "pref_scan_type"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ class MainActivity : AppCompatActivity(), ReloadableActivity, ScannerView.Result
}
view_data.scanType.set(conf.scanType)
view_data.hardwareScan.set(!conf.useCamera)
view_data.badgePrintEnabled.set(conf.printBadges && conf.autoPrintBadges)
view_data.badgePrintEnabled.set(conf.printBadges && conf.autoPrintBadges != "false")

setKioskAnimation()

Expand Down Expand Up @@ -1236,9 +1236,17 @@ class MainActivity : AppCompatActivity(), ReloadableActivity, ScannerView.Result
}
}

val shouldAutoPrint = (conf.autoPrintBadges &&
val shouldAutoPrint = when(conf.autoPrintBadges) {
"false" -> false
"true" -> {
result.type == TicketCheckProvider.CheckResult.Type.VALID
}
"once" -> {
result.type == TicketCheckProvider.CheckResult.Type.VALID &&
!isPreviouslyPrinted((application as PretixScan).data, result.position!!))
!isPreviouslyPrinted((application as PretixScan).data, result.position!!)
}
else -> false
}

if (shouldAutoPrint) {
printBadge(
Expand Down Expand Up @@ -1441,7 +1449,11 @@ class MainActivity : AppCompatActivity(), ReloadableActivity, ScannerView.Result
val prefs = PreferenceManager.getDefaultSharedPreferences(ctx)

for (key in restrictions.keySet()) {
prefs.edit().putBoolean(key, restrictions.getBoolean(key)).apply()
if (key == "pref_auto_print_badges_option") {
prefs.edit().putString(key, restrictions.getString(key)).apply()
} else {
prefs.edit().putBoolean(key, restrictions.getBoolean(key)).apply()
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion pretixscan/app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
<string name="dialog_unpaid_retry">Trotzdem einchecken</string>
<string name="preference_badgeprint_enable">Badge-Druck aktivieren</string>
<string name="preference_autobadgeprint_enable">Badges automatisch drucken</string>
<string name="preference_autobadgeprint_enable_help">Badges werden nicht automatisch gedruckt, wenn das System weiß, dass sie bereits zuvor gedruckt wurden.</string>
<string name="preference_badgeprint_install_pretixprint">Badge-Druck benötigt die pretixPRINT-App. Wollen Sie diese installieren\?</string>
<string name="settings_label_badges">Badges</string>
<string name="preference_badges_twice">Jedes Badge doppelt drucken</string>
Expand Down Expand Up @@ -179,4 +178,9 @@
<string name="event_select_calendar">Kalender anzeigen</string>
<string name="action_label_ok">OK</string>
<string name="setup_grant_camera_permission">Bitte erteilen Sie die Kamera-Berechtigung für den QR-Code-Scanner</string>
<string-array name="settings_valuelabels_auto_print_badges">
<item>Nein, nur auf Knopfdruck</item>
<item>Nur, wenn noch nicht gedruckt</item>
<item>Immer</item>
</string-array>
</resources>
1 change: 0 additions & 1 deletion pretixscan/app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@
<string name="currently_inside">asiste actualmente</string>
<string name="event_select_calendar">Ver calendario</string>
<string name="settings_label_kioskmode">Modo kiosco</string>
<string name="preference_autobadgeprint_enable_help">Las tarjetas no se imprimen automáticamente, si ya se imprimieron anteriormente.</string>
<string name="settings_label_search_disable">Deshabilitar búsqueda</string>
<string name="setup_grant_camera_permission">Debe conceder permisos para utilizar la cámara y escáner QR</string>
<string name="error_no_available_events">No se ha encontrado ningún evento presente o futuro. Compruebe las fechas y los derechos de acceso de los eventos.</string>
Expand Down
1 change: 0 additions & 1 deletion pretixscan/app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,4 @@
<string name="scan_result_unapproved">Commande non approuvée</string>
<string name="pin_protection_enter">Saisir le code PIN</string>
<string name="pref_ignore_questions">Ne pas poser de questions lors de l\'enregistrement</string>
<string name="preference_autobadgeprint_enable_help">Les badges ne sont pas imprimés automatiquement si ils ont déjà été imprimés.</string>
</resources>
1 change: 0 additions & 1 deletion pretixscan/app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,4 @@
<string name="status_empty">La ricerca non ha portato a nessun risultato. ASsicurarsi di aver inserito almeno quattro caratteri.</string>
<string name="settings_summary_kioskmode">La modalità kiosk nasconde i menu che non sono necessari per essere usati in una installazione sel-service. la modalità kiosk non previene di uscire dall\' applicazione. Per accedere alle impostazioni, è necessario scannerizzare un QR code con il vostro PIN.</string>
<string name="force_full_resync_help">Questa azione non cancellerà alcun dato locale, ma forzerà una sincornizzazione di ogli evento come sincronizzazione completa, ad esempio scaricherà tutti i dati al posto che solamente i dati modificati.</string>
<string name="preference_autobadgeprint_enable_help">I badge non vengono stampati automaticamente se il sistema sa che sono già stati stampati in precedenza.</string>
</resources>
1 change: 0 additions & 1 deletion pretixscan/app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,4 @@
<string name="label_shop_inactive">Sklep dezaktywowany</string>
<string name="label_shop_active">Aktywny</string>
<string name="setup_grant_camera_permission">Zezwól na używanie kamery aby korzystać ze skanera QR</string>
<string name="preference_autobadgeprint_enable_help">Identyfikatory nie są drukowane automatycznie, jeśli system wie, że zostały już wcześniej wydrukowane.</string>
</resources>
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 @@ -11,4 +11,9 @@
<item>20s</item>
<item>errors</item>
</string-array>
<string-array name="settings_values_auto_print_badges">
<item>false</item>
<item>once</item>
<item>true</item>
</string-array>
</resources>
8 changes: 6 additions & 2 deletions pretixscan/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@
<string name="dialog_unpaid_text">This ticket belongs to an order that has not yet been paid. Do you still want to check it in? This will not mark the order as paid.</string>
<string name="dialog_unpaid_retry">Check in anyways</string>
<string name="preference_badgeprint_enable">Enable badge printing</string>
<string name="preference_autobadgeprint_enable">Print badges automatically after successful scan</string>
<string name="preference_autobadgeprint_enable_help">Badges are not automatically printed if the system knows they have been printed before.</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="already_scanned">already scanned</string>
<string name="total_tickets_sold">total tickets sold</string>
Expand Down Expand Up @@ -178,4 +177,9 @@
<string name="error_no_available_events">No current or future event could be found. Please check the dates and access rights of your events.</string>
<string name="event_select_calendar">Show calendar</string>
<string name="setup_grant_camera_permission">Please grant camera permission to use the QR Scanner</string>
<string-array name="settings_valuelabels_auto_print_badges">
<item>No, only when button is pressed</item>
<item>Once, if not yet printed</item>
<item>Always</item>
</string-array>
</resources>
6 changes: 4 additions & 2 deletions pretixscan/app/src/main/res/xml/app_restrictions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
android:title="@string/preference_badgeprint_enable" />
<restriction
android:defaultValue="false"
android:key="pref_auto_print_badges"
android:key="pref_auto_print_badges_option"
android:dependency="pref_print_badges"
android:restrictionType="bool"
android:restrictionType="choice"
android:entries="@array/settings_valuelabels_auto_print_badges"
android:entryValues="@array/settings_values_auto_print_badges"
android:title="@string/preference_autobadgeprint_enable" />
</restrictions>
12 changes: 7 additions & 5 deletions pretixscan/app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@
android:defaultValue="false"
android:key="pref_print_badges"
android:title="@string/preference_badgeprint_enable" />
<CheckBoxPreference
android:defaultValue="false"
<ListPreference
android:dependency="pref_print_badges"
android:key="pref_auto_print_badges"
android:summary="@string/preference_autobadgeprint_enable_help"
android:title="@string/preference_autobadgeprint_enable" />
android:key="pref_auto_print_badges_option"
android:defaultValue="off"
android:entries="@array/settings_valuelabels_auto_print_badges"
android:entryValues="@array/settings_values_auto_print_badges"
android:title="@string/preference_autobadgeprint_enable"
android:summary="%s" />
<CheckBoxPreference
android:defaultValue="false"
android:dependency="pref_print_badges"
Expand Down

0 comments on commit 117b671

Please sign in to comment.