Skip to content

Commit

Permalink
Add more precise setting for auto print
Browse files Browse the repository at this point in the history
  • Loading branch information
robbi5 committed Nov 11, 2024
1 parent 77b9557 commit 3b4c1d9
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ 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()
}
PREFS_KEY_LEGACY_AUTOPRINTBADGES
}

override fun isDebug(): Boolean {
Expand Down Expand Up @@ -354,9 +365,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 +437,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
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>Nur auf Knopfdruck</item>
<item>Nur, wenn noch nicht gedruckt</item>
<item>Immer</item>
</string-array>
</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>Only when button 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"
<DropDownPreference
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 3b4c1d9

Please sign in to comment.