aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/io/trygvis/android/bt/BtDevice.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/io/trygvis/android/bt/BtDevice.java')
-rw-r--r--app/src/main/java/io/trygvis/android/bt/BtDevice.java40
1 files changed, 26 insertions, 14 deletions
diff --git a/app/src/main/java/io/trygvis/android/bt/BtDevice.java b/app/src/main/java/io/trygvis/android/bt/BtDevice.java
index ba10d2d..e34e9ea 100644
--- a/app/src/main/java/io/trygvis/android/bt/BtDevice.java
+++ b/app/src/main/java/io/trygvis/android/bt/BtDevice.java
@@ -3,6 +3,8 @@ package io.trygvis.android.bt;
import android.bluetooth.BluetoothDevice;
import android.util.Log;
+import io.trygvis.android.Function;
+
public class BtDevice<A> {
private final static String TAG = BtDevice.class.getSimpleName();
@@ -14,31 +16,22 @@ public class BtDevice<A> {
private boolean seenNow;
- private BtDeviceListener l = null;
-
- private BtDeviceListener listener = new BtDeviceListener() {
- };
+ public static interface BtDeviceWrapper<A> {
+ BtDevice<A> getBtDevice();
+ }
- public BtDevice(DefaultBtService btService, BluetoothDevice bluetoothDevice, A tag, Integer rssi, BtScanResult scanResult) {
+ BtDevice(DefaultBtService btService, BluetoothDevice bluetoothDevice, Function<BtDevice<A>, A> tagConstructor, Integer rssi, BtScanResult scanResult) {
this.btService = btService;
this.bluetoothDevice = bluetoothDevice;
- this.tag = tag;
+ this.tag = tagConstructor.apply(this);
this.rssi = rssi;
this.scanResult = scanResult;
}
- public void addListener(BtDeviceListener listener) {
- this.l = listener;
- }
-
public A getTag() {
return tag;
}
- public void setTag(A tag) {
- this.tag = tag;
- }
-
public String getAddress() {
return bluetoothDevice.getAddress();
}
@@ -65,4 +58,23 @@ public class BtDevice<A> {
public String toString() {
return "BtDevice{address=" + bluetoothDevice.getAddress() + '}';
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ BtDevice other = (BtDevice) o;
+
+ return getAddress().equals(other.getAddress());
+ }
+
+ @Override
+ public int hashCode() {
+ return getAddress().hashCode();
+ }
}