aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/io/trygvis/soilmoisture/MainActivity.java')
-rw-r--r--app/src/main/java/io/trygvis/soilmoisture/MainActivity.java88
1 files changed, 65 insertions, 23 deletions
diff --git a/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java b/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java
index 385a566..e9ecae2 100644
--- a/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java
+++ b/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java
@@ -342,6 +342,13 @@ public class MainActivity extends ListActivity {
} else {
current.addAll(sensors);
}
+
+ Log.i(TAG, "sort result:");
+ for (int i = 0; i < current.size(); i++) {
+ Object o = current.get(i);
+ Log.i(TAG, i + " = " + o);
+ }
+
dataSetObservable.notifyChanged();
}
@@ -401,27 +408,32 @@ public class MainActivity extends ListActivity {
@Override
public boolean hasStableIds() {
- return true;
+ return false;
+// return true;
}
@Override
public int getItemViewType(int position) {
- Object o = current.get(position);
-
- if (o instanceof BtDevice) {
- return 0;
- } else if (o instanceof SmDevice) {
- return 1;
- } else if (o instanceof SmSensor) {
- return 2;
- }
+// Object o = current.get(position);
+//
+// if (o instanceof BtDevice) {
+// return 0;
+// } else if (o instanceof SmDevice) {
+// return 1;
+// } else if (o instanceof SmSensor) {
+// return 2;
+// }
+//
+// throw new RuntimeException("Unknown kind: " + o.getClass());
- throw new RuntimeException("Unknown kind: " + o.getClass());
+ return IGNORE_ITEM_VIEW_TYPE;
+// throw new RuntimeException("Not supported");
}
@Override
public int getViewTypeCount() {
- return 3;
+ return 1;
+// return IGNORE_ITEM_VIEW_TYPE;
}
@Override
@@ -441,20 +453,35 @@ public class MainActivity extends ListActivity {
@Override
public long getItemId(int position) {
- return position;
+ Log.i(TAG, "getItemId, position=" + position);
+
+ Object o = current.get(position);
+ if (o instanceof BtDevice) {
+ BtDevice btDevice = (BtDevice) o;
+ return 1000 + btDevice.getId();
+ } else if (o instanceof SmDevice) {
+ SmDevice smDevice = (SmDevice) o;
+ return 2000 + smDevice.getId();
+ } else if (o instanceof SmSensor) {
+ SmSensor smSensor = (SmSensor) o;
+ return 3000 + smSensor.getId();
+ }
+
+ throw new RuntimeException("Not implemented");
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
+ Log.i(TAG, "getView, position=" + position + ", view=" + view);
Object o = current.get(position);
if (o instanceof BtDevice) {
//noinspection unchecked
return getBtDeviceView((BtDevice<SmDevice>) o, view);
} else if (o instanceof SmDevice) {
- return getSmDeviceView((SmDevice) o, view);
+ return getSmDeviceView(position, (SmDevice) o, view);
} else if (o instanceof SmSensor) {
- return getSoilSensorView((SmSensor) o, view);
+ return getSoilSensorView(position, (SmSensor) o, view);
}
throw new RuntimeException("Not implemented");
@@ -486,12 +513,17 @@ public class MainActivity extends ListActivity {
return view;
}
- private View getSmDeviceView(SmDevice smDevice, View view) {
+ private View getSmDeviceView(int position, SmDevice smDevice, View view) {
if (view == null) {
view = inflater.inflate(R.layout.fragment_device, null);
view.setTag(new DeviceItem(view));
- view.setClickable(true);
- view.setOnClickListener(v -> onSmDeviceClick(smDevice));
+ view.setOnClickListener(v -> {
+ Log.i(TAG, "onClick: SmDevice, " +
+// "position=" + position + ", " +
+ "device=" + smDevice /*+ ", " +
+ "tag=" + v.getTag()*/);
+ onSmDeviceClick(smDevice);
+ });
}
DeviceItem item = (DeviceItem) view.getTag();
@@ -511,10 +543,14 @@ public class MainActivity extends ListActivity {
address += " not useful";
}
+ address += ", connected=" + smDevice.getBtDevice().connected();
+
item.deviceAddress.setText(address);
- item.rssi.setText(getText(R.string.rssi) + ": " +
- (smDevice.getBtDevice().getRssi() != null ? valueOf(smDevice.getBtDevice().getRssi()) : getText(R.string.unknown)));
+ String rssi = getText(R.string.rssi) + ": " +
+ (smDevice.getBtDevice().getRssi() != null ? valueOf(smDevice.getBtDevice().getRssi()) : getText(R.string.unknown));
+ rssi += ", device: " + smDevice.toString();
+ item.rssi.setText(rssi);
boolean useful = smDevice.isUseful();
@@ -527,18 +563,24 @@ public class MainActivity extends ListActivity {
return view;
}
- private View getSoilSensorView(SmSensor smSensor, View view) {
+ private View getSoilSensorView(int position, SmSensor smSensor, View view) {
if (view == null) {
view = inflater.inflate(R.layout.fragment_sensor, null);
view.setTag(new SensorItem(smSensor, view));
view.setClickable(true);
- view.setOnClickListener(v -> onSensorClick(smSensor));
+ view.setOnClickListener(v -> {
+ Log.i(TAG, "onClick, SmSensor: " +
+// "position=" + position + ", " +
+ "sensor=" + smSensor /*+ ", " +
+ "tag=" + v.getTag()*/);
+ onSensorClick(smSensor);
+ });
}
SensorItem item = (SensorItem) view.getTag();
Integer value = smSensor.getLastValue();
- String text = "Connected: " + smSensor.getDevice().getBtDevice().connected();
+ String text = "Sensor " + smSensor;
text += ", value: " + (value == null ? "Unknown" : value);
item.description.setText(text);