mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-27 09:01:38 +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() {
|
public int describeContents() {
|
||||||
return 0;
|
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) {
|
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
|
||||||
DeviceCandidate candidate = new DeviceCandidate(device, (short) rssi);
|
DeviceCandidate candidate = new DeviceCandidate(device, (short) rssi);
|
||||||
if (DeviceHelper.getInstance().isSupported(candidate)) {
|
if (DeviceHelper.getInstance().isSupported(candidate)) {
|
||||||
|
int index = deviceCandidates.indexOf(candidate);
|
||||||
|
if (index >= 0) {
|
||||||
|
deviceCandidates.set(index, candidate); // replace
|
||||||
|
} else {
|
||||||
deviceCandidates.add(candidate);
|
deviceCandidates.add(candidate);
|
||||||
|
}
|
||||||
cadidateListAdapter.notifyDataSetChanged();
|
cadidateListAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user