Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add progress indicator while bluetooth is pairing #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.core.content.IntentCompat
import androidx.preference.PreferenceManager
import com.github.razir.progressbutton.attachTextChangeAnimator
import com.github.razir.progressbutton.bindProgressButton
import com.github.razir.progressbutton.hideProgress
import com.github.razir.progressbutton.showProgress
import com.google.android.material.textfield.TextInputEditText
import eu.pretix.pretixprint.R
import eu.pretix.pretixprint.ui.BluetoothDeviceManager.BluetoothDevicePickResultHandler
Expand Down Expand Up @@ -165,6 +169,8 @@ class BluetoothSettingsFragment : SetupFragment() {
ContextCompat.registerReceiver(requireContext(), btStateReceiver, filter, ContextCompat.RECEIVER_EXPORTED)

val next = view.findViewById<Button>(R.id.btnNext)
this.bindProgressButton(next)
next.attachTextChangeAnimator()
next.setOnClickListener {
val mac = teMAC.text.toString()
if (TextUtils.isEmpty(mac)) {
Expand Down Expand Up @@ -200,6 +206,7 @@ class BluetoothSettingsFragment : SetupFragment() {
BluetoothDevice.ERROR,
BluetoothDevice.BOND_NONE,
BluetoothDevice.BOND_BONDED -> {
next.hideProgress(R.string.btn_next)
(activity as PrinterSetupActivity).startProtocolChoice()
}
BluetoothDevice.BOND_BONDING -> {
Expand All @@ -212,6 +219,10 @@ class BluetoothSettingsFragment : SetupFragment() {
val launched = device.createBond()
if (launched) {
instantGoToNextStep = false
next.showProgress {
buttonTextRes = R.string.pairing
progressColorRes = R.color.white
}
}
}
if (instantGoToNextStep) {
Expand Down Expand Up @@ -245,7 +256,7 @@ class BluetoothDeviceManager(context: Context) : BluetoothDevicePicker {
private class BluetoothDeviceManagerReceiver(private val handler: BluetoothDevicePickResultHandler) : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
context.unregisterReceiver(this)
val device = intent.getParcelableExtra<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
val device = IntentCompat.getParcelableExtra(intent, BluetoothDevice.EXTRA_DEVICE, BluetoothDevice::class.java)
handler.onDevicePicked(device)
}

Expand Down
1 change: 1 addition & 0 deletions pretixprint/app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,5 @@
<string name="warning_bluetooth_disabled_title">Bluetooth ist auf diesem Gerät ausgeschaltet</string>
<string name="warning_bluetooth_disabled_summary">Bluetooth muss aktiv sein, um mit Druckern kommunizieren zu können</string>
<string name="warning_bluetooth_disabled_turn_on">Einschalten</string>
<string name="pairing">Koppeln…</string>
</resources>
1 change: 1 addition & 0 deletions pretixprint/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,5 @@
<string name="warning_bluetooth_disabled_title">Bluetooth is turned off on this device</string>
<string name="warning_bluetooth_disabled_summary">Bluetooth must be active in order to communicate with printers</string>
<string name="warning_bluetooth_disabled_turn_on">Turn on</string>
<string name="pairing">Pairing…</string>
</resources>
Loading