mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 11:26:47 +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:
parent
705361ae3a
commit
904a7807a8
@ -476,27 +476,36 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
break;
|
break;
|
||||||
case ACTION_CONNECT:
|
case ACTION_CONNECT:
|
||||||
start(); // ensure started
|
start(); // ensure started
|
||||||
GBDevice gbDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
List<GBDevice> gbDevs = null;
|
||||||
String btDeviceAddress = null;
|
boolean fromExtra = false;
|
||||||
if (gbDevice == null) {
|
|
||||||
if (prefs != null) { // may be null in test cases
|
GBDevice extraDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||||
btDeviceAddress = prefs.getString("last_device_address", null);
|
if (extraDevice != null) {
|
||||||
if (btDeviceAddress != null) {
|
gbDevs = new ArrayList<>();
|
||||||
gbDevice = DeviceHelper.getInstance().findAvailableDevice(btDeviceAddress, this);
|
gbDevs.add(extraDevice);
|
||||||
}
|
fromExtra = true;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
btDeviceAddress = gbDevice.getAddress();
|
gbDevs = GBApplication.app().getDeviceManager().getDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gbDevice == null){
|
if(gbDevs == null || gbDevs.size() == 0) {
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(GBDevice gbDevice : gbDevs) {
|
||||||
|
String btDeviceAddress = gbDevice.getAddress();
|
||||||
|
|
||||||
boolean autoReconnect = GBPrefs.AUTO_RECONNECT_DEFAULT;
|
boolean autoReconnect = GBPrefs.AUTO_RECONNECT_DEFAULT;
|
||||||
if (prefs != null && prefs.getPreferences() != null) {
|
if (prefs != null && prefs.getPreferences() != null) {
|
||||||
prefs.getPreferences().edit().putString("last_device_address", btDeviceAddress).apply();
|
|
||||||
autoReconnect = getGBPrefs().getAutoReconnect(gbDevice);
|
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);
|
DeviceStruct registeredStruct = getDeviceStructOrNull(gbDevice);
|
||||||
@ -537,6 +546,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
for(DeviceStruct struct2 : deviceStructs){
|
for(DeviceStruct struct2 : deviceStructs){
|
||||||
struct2.getDevice().sendDeviceUpdateIntent(this);
|
struct2.getDevice().sendDeviceUpdateIntent(this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
GBDevice targetedDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
GBDevice targetedDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||||
|
@ -203,7 +203,7 @@
|
|||||||
<string name="pref_header_time">Time</string>
|
<string name="pref_header_time">Time</string>
|
||||||
<string name="pref_header_workout">Workout</string>
|
<string name="pref_header_workout">Workout</string>
|
||||||
<string name="pref_header_equalizer">Equalizer</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_autostartonboot">Start automatically</string>
|
||||||
<string name="pref_title_general_autoreconnect">Reconnect automatically</string>
|
<string name="pref_title_general_autoreconnect">Reconnect automatically</string>
|
||||||
<string name="pref_title_mb_intents">Broadcast Media Button Intents Directly</string>
|
<string name="pref_title_mb_intents">Broadcast Media Button Intents Directly</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user