Skip to content

Commit

Permalink
FGL: Allow to set cut policy (Z#23162512) (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm authored Aug 19, 2024
1 parent 940cd06 commit 54a2aba
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class FGL : StreamByteProtocol<Bitmap> {
return (type !is SunmiInternalConnection) && (type !is IMinInternalConnection)
}

enum class CutMode(val id: String, val stringId: Int) {
AfterJob("job", R.string.field_label_cutmode_job),
EveryTicket("ticket", R.string.field_label_cutmode_ticket),
Never("never", R.string.field_label_cutmode_never),
}

enum class Ticketpath(val id: Int) {
Path1(1),
Path2(2)
Expand All @@ -53,6 +59,7 @@ class FGL : StreamByteProtocol<Bitmap> {
}

val path = conf.get("hardware_${type}printer_path") ?: "1"
val cutmode = CutMode.entries.find { it.id == (conf.get("hardware_${type}printer_cutmode") ?: CutMode.AfterJob.id) }
ostream.write("<P$path>".toByteArray())

for (yoffset in 0 until h step 8) {
Expand Down Expand Up @@ -84,12 +91,20 @@ class FGL : StreamByteProtocol<Bitmap> {
}
}
}
if (isLastPage) {
ostream.write("<z>\n".toByteArray())
if (isLastPage && (cutmode == CutMode.AfterJob || cutmode == CutMode.EveryTicket)) {
ostream.write("<z>\n".toByteArray()) // PRINT TICKET AND EJECT
} else if (diffRendering) {
ostream.write("<r>\n".toByteArray())
if (cutmode == CutMode.EveryTicket) {
ostream.write("<h>\n".toByteArray()) // PRINT / CUT (HOLD TICKET IMAGE)
} else if (cutmode == CutMode.AfterJob) {
ostream.write("<r>\n".toByteArray()) // PRINT / NO CUT (HOLD TICKET IMAGE)
}
} else {
ostream.write("<q>\n".toByteArray())
if (cutmode == CutMode.EveryTicket) {
ostream.write("<z>\n".toByteArray()) // PRINT TICKET AND EJECT
} else {
ostream.write("<q>\n".toByteArray()) // PRINT / NO CUT TICKET
}
}
return ostream.toByteArray()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ class FGLSettingsFragment : SetupFragment() {
(view.findViewById<TextInputLayout>(R.id.tilPath).editText as? AutoCompleteTextView)?.setText(chosenPath, false)
}

val cutModeAdapter = ArrayAdapter(requireContext(), R.layout.list_item, FGL.CutMode.values().map {
getString(it.stringId)
})
(view.findViewById<TextInputLayout>(R.id.tilCutMode).editText as? AutoCompleteTextView)?.setAdapter(cutModeAdapter)
val chosenCutModeId = ((activity as PrinterSetupActivity).settingsStagingArea.get(
"hardware_${useCase}printer_cutmode"
)) ?: prefs.getString("hardware_${useCase}printer_cutmode", "job")
if (chosenCutModeId?.isNotEmpty() == true) {
val chosenCutMode = getString(FGL.CutMode.values().find { it.id == chosenCutModeId }!!.stringId)
(view.findViewById<TextInputLayout>(R.id.tilCutMode).editText as? AutoCompleteTextView)?.setText(chosenCutMode, false)
}

val rotationAdapter = ArrayAdapter(requireContext(), R.layout.list_item, Rotation.values().map {
it.toString()
})
Expand All @@ -61,6 +73,7 @@ class FGLSettingsFragment : SetupFragment() {
}
view.findViewById<Button>(R.id.btnNext).setOnClickListener {
val path = view.findViewById<TextInputLayout>(R.id.tilPath).editText?.text.toString()
val cutmode = view.findViewById<TextInputLayout>(R.id.tilCutMode).editText?.text.toString()
val dpi = view.findViewById<TextInputEditText>(R.id.teDPI).text.toString()
val rotation = view.findViewById<TextInputLayout>(R.id.tilRotation).editText?.text.toString()
if (TextUtils.isEmpty(dpi)) {
Expand All @@ -71,6 +84,8 @@ class FGLSettingsFragment : SetupFragment() {
view.findViewById<TextInputEditText>(R.id.tilPath).error = getString(R.string.err_field_required)
} else if (!TextUtils.isDigitsOnly(path)) {
view.findViewById<TextInputEditText>(R.id.tilPath).error = getString(R.string.err_field_invalid)
} else if (!FGL.CutMode.values().any { getString(it.stringId) == cutmode }) {
view.findViewById<TextInputEditText>(R.id.tilPath).error = getString(R.string.err_field_invalid)
} else {
view.findViewById<TextInputEditText>(R.id.teDPI).error = null
val mappedRotation = Rotation.values().find { it.toString() == rotation }!!.degrees
Expand All @@ -80,6 +95,8 @@ class FGLSettingsFragment : SetupFragment() {
dpi)
(activity as PrinterSetupActivity).settingsStagingArea.put("hardware_${useCase}printer_path",
path)
(activity as PrinterSetupActivity).settingsStagingArea.put("hardware_${useCase}printer_cutmode",
FGL.CutMode.values().find { getString(it.stringId) == cutmode }!!.id)
(activity as PrinterSetupActivity).startFinalPage()
}
}
Expand Down
22 changes: 21 additions & 1 deletion pretixprint/app/src/main/res/layout/fragment_fgl_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilPath"
android:id="@+id/tilCutMode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
Expand All @@ -85,6 +85,26 @@
app:layout_constraintTop_toBottomOf="@+id/tilRotation"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">

<AutoCompleteTextView
android:id="@+id/teCutMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/field_label_cutmode"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilPath"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tilCutMode"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">

<AutoCompleteTextView
android:id="@+id/tePath"
android:layout_width="match_parent"
Expand Down
4 changes: 4 additions & 0 deletions pretixprint/app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
<string name="field_label_card_destination">Kartenausgabe</string>
<string name="field_label_label">Papiergröße</string>
<string name="field_label_ticketpath_fgl">Ticketpfad (nur Lemur-2)</string>
<string name="field_label_cutmode">Abschnitt</string>
<string name="field_label_cutmode_job">Abschnitt nach jedem Druckauftrag</string>
<string name="field_label_cutmode_ticket">Abschnitt nach jedem Ticket</string>
<string name="field_label_cutmode_never">Kein Abschnitt</string>
<string name="field_label_quality">Druckqualität erhöhen (etwas langsamer)</string>
<string name="field_label_rotation">Drehung</string>
<string name="label_two_color">rot/schwarz</string>
Expand Down
4 changes: 4 additions & 0 deletions pretixprint/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
<string name="field_label_card_destination">Card Destination</string>
<string name="field_label_label">Label size</string>
<string name="field_label_ticketpath_fgl">Ticket path (Lemur-2 only)</string>
<string name="field_label_cutmode">Cutting</string>
<string name="field_label_cutmode_job">Cut after every print job</string>
<string name="field_label_cutmode_ticket">Cut after every ticket</string>
<string name="field_label_cutmode_never">Cut never</string>
<string name="field_label_dialect">Dialect</string>
<string name="field_label_quality">Priority given to print quality (a bit slower)</string>
<string name="field_label_rotation">Rotation</string>
Expand Down

0 comments on commit 54a2aba

Please sign in to comment.