1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 10:05:49 +01:00

Ensure that discovery doesn't display duplicates (#33)

This commit is contained in:
cpfeiffer 2015-05-05 01:08:30 +02:00
parent 9df661bd96
commit cf12c78a64
2 changed files with 24 additions and 1 deletions

View File

@ -64,4 +64,22 @@ public class DeviceCandidate implements Parcelable {
public int describeContents() {
return 0;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DeviceCandidate that = (DeviceCandidate) o;
return device.getAddress().equals(that.device.getAddress());
}
@Override
public int hashCode() {
return device.getAddress().hashCode() ^ 37;
}
}

View File

@ -82,7 +82,12 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
DeviceCandidate candidate = new DeviceCandidate(device, (short) rssi);
if (DeviceHelper.getInstance().isSupported(candidate)) {
deviceCandidates.add(candidate);
int index = deviceCandidates.indexOf(candidate);
if (index >= 0) {
deviceCandidates.set(index, candidate); // replace
} else {
deviceCandidates.add(candidate);
}
cadidateListAdapter.notifyDataSetChanged();
}
}