1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 03:16:51 +01:00

Automatically connect to all devices

Automatically connect to all devices instead of connecting only to the
last connected device.
This commit is contained in:
Davis Mosenkovs 2023-10-01 23:54:45 +03:00 committed by José Rebelo
parent 705361ae3a
commit 904a7807a8
2 changed files with 61 additions and 51 deletions

View File

@ -476,27 +476,36 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
break;
case ACTION_CONNECT:
start(); // ensure started
GBDevice gbDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
String btDeviceAddress = null;
if (gbDevice == null) {
if (prefs != null) { // may be null in test cases
btDeviceAddress = prefs.getString("last_device_address", null);
if (btDeviceAddress != null) {
gbDevice = DeviceHelper.getInstance().findAvailableDevice(btDeviceAddress, this);
}
}
List<GBDevice> gbDevs = null;
boolean fromExtra = false;
GBDevice extraDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
if (extraDevice != null) {
gbDevs = new ArrayList<>();
gbDevs.add(extraDevice);
fromExtra = true;
} else {
btDeviceAddress = gbDevice.getAddress();
gbDevs = GBApplication.app().getDeviceManager().getDevices();
}
if(gbDevice == null){
if(gbDevs == null || gbDevs.size() == 0) {
return START_NOT_STICKY;
}
for(GBDevice gbDevice : gbDevs) {
String btDeviceAddress = gbDevice.getAddress();
boolean autoReconnect = GBPrefs.AUTO_RECONNECT_DEFAULT;
if (prefs != null && prefs.getPreferences() != null) {
prefs.getPreferences().edit().putString("last_device_address", btDeviceAddress).apply();
autoReconnect = getGBPrefs().getAutoReconnect(gbDevice);
if(!fromExtra && !autoReconnect) {
continue;
}
prefs.getPreferences().edit().putString("last_device_address", btDeviceAddress).apply();
}
if(!fromExtra && !autoReconnect) {
continue;
}
DeviceStruct registeredStruct = getDeviceStructOrNull(gbDevice);
@ -537,6 +546,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
for(DeviceStruct struct2 : deviceStructs){
struct2.getDevice().sendDeviceUpdateIntent(this);
}
}
break;
default:
GBDevice targetedDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);

View File

@ -203,7 +203,7 @@
<string name="pref_header_time">Time</string>
<string name="pref_header_workout">Workout</string>
<string name="pref_header_equalizer">Equalizer</string>
<string name="pref_title_general_autoconnectonbluetooth">Connect to Gadgetbridge device when Bluetooth is turned on</string>
<string name="pref_title_general_autoconnectonbluetooth">Connect to Gadgetbridge device(s) when Bluetooth is turned on</string>
<string name="pref_title_general_autostartonboot">Start automatically</string>
<string name="pref_title_general_autoreconnect">Reconnect automatically</string>
<string name="pref_title_mb_intents">Broadcast Media Button Intents Directly</string>