add more checks for possible NPE and simplify the UI

This commit is contained in:
n8fr8 2015-07-13 15:04:38 -04:00
parent cc6b2736ce
commit c399a17369
2 changed files with 25 additions and 16 deletions

View File

@ -17,7 +17,7 @@ public class BluetoothClient {
}
public BluetoothConnection openConnection() throws IOException {
BluetoothSocket socket = device.createRfcommSocketToServiceRecord(BluetoothConstants.fdroidUuid());
BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(BluetoothConstants.fdroidUuid());
BluetoothConnection connection = new BluetoothConnection(socket);
connection.open();
return connection;

View File

@ -31,6 +31,7 @@ import org.fdroid.fdroid.localrepo.SwapManager;
import org.fdroid.fdroid.net.BluetoothDownloader;
import org.fdroid.fdroid.net.bluetooth.BluetoothClient;
import org.fdroid.fdroid.net.bluetooth.BluetoothConnection;
import org.fdroid.fdroid.net.bluetooth.BluetoothServer;
import org.fdroid.fdroid.views.fragments.ThemeableListFragment;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -140,7 +141,9 @@ public class BluetoothDeviceListView extends ListView implements
final TextView address = (TextView) headerView.findViewById(R.id.device_address);
address.setText(bluetooth.getAddress());
populateBondedDevices();
initiateBluetoothScan();
// populateBondedDevices();
}
@ -166,8 +169,10 @@ public class BluetoothDeviceListView extends ListView implements
{
Log.d(TAG, "Starting bluetooth scan...");
if (cancelMenuItem != null) {
cancelMenuItem.setVisible(true);
scanMenuItem.setVisible(false);
}
final ContentLoadingProgressBar loadingBar = getLoadingIndicator();
@ -181,6 +186,9 @@ public class BluetoothDeviceListView extends ListView implements
if (BluetoothDevice.ACTION_FOUND.equals(intent.getAction())) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.d(TAG, "Found bluetooth device: " + device.toString());
if (device != null && device.getName() != null)
if (device.getName().contains(BluetoothServer.BLUETOOTH_NAME_TAG)) {
boolean exists = false;
for (int i = 0; i < adapter.getCount(); i++) {
if (adapter.getItem(i).getAddress().equals(device.getAddress())) {
@ -194,6 +202,7 @@ public class BluetoothDeviceListView extends ListView implements
}
}
}
}
};
final BroadcastReceiver scanCompleteReceiver = new BroadcastReceiver() {