Initialise Bluetooth state when view model is created.

This commit is contained in:
akwizgran
2020-08-14 16:13:29 +01:00
parent a1e3c81bda
commit 2cf146a104

View File

@@ -1,6 +1,7 @@
package org.briarproject.briar.android.navdrawer; package org.briarproject.briar.android.navdrawer;
import android.app.Application; import android.app.Application;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -99,6 +100,7 @@ public class PluginViewModel extends AndroidViewModel implements EventListener {
torPluginState.setValue(getTransportState(TorConstants.ID)); torPluginState.setValue(getTransportState(TorConstants.ID));
wifiPluginState.setValue(getTransportState(LanTcpConstants.ID)); wifiPluginState.setValue(getTransportState(LanTcpConstants.ID));
btPluginState.setValue(getTransportState(BluetoothConstants.ID)); btPluginState.setValue(getTransportState(BluetoothConstants.ID));
initialiseBluetoothState();
loadSettings(); loadSettings();
} }
@@ -173,6 +175,12 @@ public class PluginViewModel extends AndroidViewModel implements EventListener {
mergeSettings(s, id.getString()); mergeSettings(s, id.getString());
} }
private void initialiseBluetoothState() {
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
if (bt == null) bluetoothTurnedOn.setValue(false);
else bluetoothTurnedOn.setValue(bt.getState() == STATE_ON);
}
private void loadSettings() { private void loadSettings() {
dbExecutor.execute(() -> { dbExecutor.execute(() -> {
try { try {