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:
parent
9df661bd96
commit
cf12c78a64
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user