Remove "Bluetooth is disabled" toast when getting available devices

A simple getter should not be responsible for checking whether bluetooth
is available or not.
This commit is contained in:
José Rebelo
2025-12-07 17:36:00 +00:00
parent 0e54d331e4
commit e923d54cb3
4 changed files with 6 additions and 14 deletions
+1
View File
@@ -76,6 +76,7 @@
* Fix pairing of unsupported devices
* Fix spam from Microsoft Teams and WhatsApp notifications
* Improve gpx parsing and exporting
* Remove toast when bluetooth is off
#### 0.87.1
@@ -403,7 +403,7 @@ public class ControlCenterv2 extends AppCompatActivity
if(ACTION_CONNECT.equals(intent.getAction())) {
String btDeviceAddress = intent.getStringExtra("device");
if(btDeviceAddress!=null){
GBDevice candidate = DeviceHelper.getInstance().findAvailableDevice(btDeviceAddress, this);
GBDevice candidate = DeviceHelper.getInstance().findAvailableDevice(btDeviceAddress);
if (candidate != null && !candidate.isConnected()) {
GBApplication.deviceService(candidate).connect();
}
@@ -153,7 +153,7 @@ public class DeviceManager {
}
private void refreshPairedDevices() {
Set<GBDevice> availableDevices = DeviceHelper.getInstance().getAvailableDevices(context);
Set<GBDevice> availableDevices = DeviceHelper.getInstance().getAvailableDevices();
deviceList.retainAll(availableDevices);
for (GBDevice availableDevice : availableDevices) {
if (!deviceList.contains(availableDevice)) {
@@ -27,7 +27,6 @@
package nodomain.freeyourgadget.gadgetbridge.util;
import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.widget.Toast;
@@ -81,8 +80,8 @@ public class DeviceHelper {
private final HashMap<String, DeviceType> deviceTypeCache = new HashMap<>();
@Nullable
public GBDevice findAvailableDevice(String deviceAddress, Context context) {
Set<GBDevice> availableDevices = getAvailableDevices(context);
public GBDevice findAvailableDevice(String deviceAddress) {
Set<GBDevice> availableDevices = getAvailableDevices();
for (GBDevice availableDevice : availableDevices) {
if (deviceAddress.equals(availableDevice.getAddress())) {
return availableDevice;
@@ -99,15 +98,7 @@ public class DeviceHelper {
* Clients interested in the "live" devices being managed should use the class
* DeviceManager.
*/
public Set<GBDevice> getAvailableDevices(Context context) {
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter == null) {
GB.toast(context, context.getString(R.string.bluetooth_is_not_supported_), Toast.LENGTH_SHORT, GB.WARN);
} else if (!btAdapter.isEnabled()) {
GB.toast(context, context.getString(R.string.bluetooth_is_disabled_), Toast.LENGTH_SHORT, GB.WARN);
}
public Set<GBDevice> getAvailableDevices() {
return new LinkedHashSet<>(getDatabaseDevices());
}