Skip to content

Commit

Permalink
using extra method for Bluetooth connection
Browse files Browse the repository at this point in the history
  • Loading branch information
oliexdev committed Nov 16, 2021
1 parent 7a0dcff commit 7d77614
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,19 @@ private void invokeConnectToBluetoothDevice() {
return;
}

connectToBluetooth();
}

private void connectToBluetooth() {
String deviceName = prefs.getString(
BluetoothSettingsFragment.PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME, "");
String hwAddress = prefs.getString(
BluetoothSettingsFragment.PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, "");

Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_try_connection) + " " + deviceName, Toast.LENGTH_SHORT).show();
setBluetoothStatusIcon(R.drawable.ic_bluetooth_searching);

if (!openScale.connectToBluetoothDevice(deviceName, hwAddress, callbackBtHandler)) {
if (!OpenScale.getInstance().connectToBluetoothDevice(deviceName, hwAddress, callbackBtHandler)) {
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_lost);
Toast.makeText(getApplicationContext(), deviceName + " " + getResources().getString(R.string.label_bt_device_no_support), Toast.LENGTH_SHORT).show();
}
Expand Down Expand Up @@ -902,7 +911,7 @@ public void onRequestPermissionsResult(int requestCode, String permissions[], in

if (allGranted) {
Timber.d("All Bluetooth permissions granted");
invokeConnectToBluetoothDevice();
connectToBluetooth();
} else {
Timber.d("At least one Bluetooth permission was not granted");
Toast.makeText(this, R.string.permission_not_granted, Toast.LENGTH_SHORT).show();
Expand Down

0 comments on commit 7d77614

Please sign in to comment.