From cec624efb7d89eaf56f0050e57f9994a414cf86d Mon Sep 17 00:00:00 2001 From: bellerbrock Date: Mon, 26 Aug 2024 15:05:39 -0400 Subject: [PATCH] ensure permissions check and skip blank device names --- .../tracker/traits/LabelPrintTraitLayout.java | 20 ++++++++++--------- .../tracker/utilities/BluetoothUtil.kt | 13 +++++++----- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/fieldbook/tracker/traits/LabelPrintTraitLayout.java b/app/src/main/java/com/fieldbook/tracker/traits/LabelPrintTraitLayout.java index 3249f52ad..a10b35b09 100644 --- a/app/src/main/java/com/fieldbook/tracker/traits/LabelPrintTraitLayout.java +++ b/app/src/main/java/com/fieldbook/tracker/traits/LabelPrintTraitLayout.java @@ -316,17 +316,19 @@ public void onNothingSelected(AdapterView arg0) { } connectPrinter.setOnClickListener(view -> { - - mBluetoothUtil.choose(getContext(), new BluetoothChooseCallback() { - @Override - public void onDeviceChosen(String newDeviceName) { - saveDeviceNamePreference(newDeviceName); - } - }); - + if (checkPermissions(mActivity)) { + mBluetoothUtil.choose(getContext(), new BluetoothChooseCallback() { + @Override + public void onDeviceChosen(String newDeviceName) { + saveDeviceNamePreference(newDeviceName); + } + }); + } else { + Toast.makeText(getContext(), R.string.permission_ask_bluetooth, Toast.LENGTH_SHORT).show(); + } }); - /* + /*j * This section handles print events. TODO: Create a label prototype based class. Move most of this logic to a function/class. chaneylc 8/26/2020 * More info on prototyping: https://refactoring.guru/design-patterns/prototype */ diff --git a/app/src/main/java/com/fieldbook/tracker/utilities/BluetoothUtil.kt b/app/src/main/java/com/fieldbook/tracker/utilities/BluetoothUtil.kt index 015b986fa..cb3dab4aa 100644 --- a/app/src/main/java/com/fieldbook/tracker/utilities/BluetoothUtil.kt +++ b/app/src/main/java/com/fieldbook/tracker/utilities/BluetoothUtil.kt @@ -34,11 +34,14 @@ class BluetoothUtil { val input = RadioGroup(ctx) - pairedDevices.forEachIndexed { _, t -> - val button = RadioButton(ctx) - button.text = t.name - input.addView(button) - map[button.id] = t + pairedDevices.forEach { device -> + val deviceName = device.name + if (!deviceName.isNullOrBlank()) { + val button = RadioButton(ctx) + button.text = deviceName + input.addView(button) + map[button.id] = device + } } val builder = AlertDialog.Builder(ctx, R.style.AppAlertDialog).apply {