aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/io/trygvis/soilmoisture
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-01-04 21:04:18 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-01-04 21:04:18 +0100
commit31fc64bec1c5286c27bdc1f683d037ae0e91418d (patch)
treecfc74e502e5499422f0cd11a1716bcb07977887a /app/src/main/java/io/trygvis/soilmoisture
parent1b9a4defe73f3aa8c10aa4af49002f0cebd1c292 (diff)
downloadio.trygvis.soilmoisture-android-31fc64bec1c5286c27bdc1f683d037ae0e91418d.tar.gz
io.trygvis.soilmoisture-android-31fc64bec1c5286c27bdc1f683d037ae0e91418d.tar.bz2
io.trygvis.soilmoisture-android-31fc64bec1c5286c27bdc1f683d037ae0e91418d.tar.xz
io.trygvis.soilmoisture-android-31fc64bec1c5286c27bdc1f683d037ae0e91418d.zip
o Adding a method to run a transaction in the BtService's database.
Diffstat (limited to 'app/src/main/java/io/trygvis/soilmoisture')
-rw-r--r--app/src/main/java/io/trygvis/soilmoisture/DefaultSoilMoistureService.java18
-rw-r--r--app/src/main/java/io/trygvis/soilmoisture/MainActivity.java12
-rw-r--r--app/src/main/java/io/trygvis/soilmoisture/SmDevice.java6
-rw-r--r--app/src/main/java/io/trygvis/soilmoisture/SmSensor.java (renamed from app/src/main/java/io/trygvis/soilmoisture/SoilMonitor.java)4
4 files changed, 28 insertions, 12 deletions
diff --git a/app/src/main/java/io/trygvis/soilmoisture/DefaultSoilMoistureService.java b/app/src/main/java/io/trygvis/soilmoisture/DefaultSoilMoistureService.java
index 8a36476..0f08076 100644
--- a/app/src/main/java/io/trygvis/soilmoisture/DefaultSoilMoistureService.java
+++ b/app/src/main/java/io/trygvis/soilmoisture/DefaultSoilMoistureService.java
@@ -5,6 +5,7 @@ import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.content.ComponentName;
+import android.content.ContentValues;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
@@ -27,6 +28,7 @@ import static io.trygvis.android.bt.BtService.BtServiceListenerBroadcastReceiver
public class DefaultSoilMoistureService extends Service implements SoilMoistureService {
private final static String TAG = DefaultSoilMoistureService.class.getSimpleName();
+ private final static int DEFAULT_WARNING_LEVEL = 750;
private final IBinder binder = new LocalBinder<>(this);
@@ -123,7 +125,21 @@ public class DefaultSoilMoistureService extends Service implements SoilMoistureS
return false;
}).
- onFinally(() -> sendBroadcast(createNewDevice(address)));
+ onFinally(() -> {
+ btService.runTx(db -> {
+ if (!btDevice.isSeenBefore() && smDevice.isUseful()) {
+ for (SmSensor soilMonitor : smDevice.getSensors()) {
+ ContentValues values = new ContentValues();
+ values.put("bt_device", btDevice.getId());
+ values.put("warning_level", DEFAULT_WARNING_LEVEL);
+ db.insert("soil_monitor", null, values);
+ }
+ }
+
+ return null;
+ });
+ sendBroadcast(createNewDevice(address));
+ });
btDevice.connect(executor);
} else {
diff --git a/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java b/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java
index 64e8202..2e6df76 100644
--- a/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java
+++ b/app/src/main/java/io/trygvis/soilmoisture/MainActivity.java
@@ -252,9 +252,9 @@ public class MainActivity extends ListActivity {
for (SmDevice d : devices) {
(d.isUseful() ? usefulDevices : unusefulDevices).add(d);
}
- List<SoilMonitor> monitors = new ArrayList<>();
+ List<SmSensor> monitors = new ArrayList<>();
for (SmDevice d : devices) {
- monitors.addAll(d.getMonitors());
+ monitors.addAll(d.getSensors());
}
if (groupByDevice) {
@@ -333,7 +333,7 @@ public class MainActivity extends ListActivity {
if (o instanceof SmDevice) {
return 0;
- } else if (o instanceof SoilMonitor) {
+ } else if (o instanceof SmSensor) {
return 1;
}
@@ -371,8 +371,8 @@ public class MainActivity extends ListActivity {
if (o instanceof SmDevice) {
return getSmDeviceView((SmDevice) o, view);
- } else if (o instanceof SoilMonitor) {
- return getSoilMonitorView((SoilMonitor) o, view);
+ } else if (o instanceof SmSensor) {
+ return getSoilMonitorView((SmSensor) o, view);
}
throw new RuntimeException("Not implemented");
@@ -408,7 +408,7 @@ public class MainActivity extends ListActivity {
return view;
}
- private View getSoilMonitorView(SoilMonitor soilMonitor, View view) {
+ private View getSoilMonitorView(SmSensor smSensor, View view) {
throw new RuntimeException("Not implemented");
}
}
diff --git a/app/src/main/java/io/trygvis/soilmoisture/SmDevice.java b/app/src/main/java/io/trygvis/soilmoisture/SmDevice.java
index 169f4b3..e24416c 100644
--- a/app/src/main/java/io/trygvis/soilmoisture/SmDevice.java
+++ b/app/src/main/java/io/trygvis/soilmoisture/SmDevice.java
@@ -16,7 +16,7 @@ class SmDevice implements BtDevice.BtDeviceWrapper<SmDevice> {
private Boolean isUseful;
- private List<SoilMonitor> monitors = new ArrayList<>();
+ private List<SmSensor> sensors = new ArrayList<>();
public SmDevice(BtDevice<SmDevice> btDevice) {
this.btDevice = btDevice;
@@ -54,7 +54,7 @@ class SmDevice implements BtDevice.BtDeviceWrapper<SmDevice> {
return name;
}
- public List<SoilMonitor> getMonitors() {
- return monitors;
+ public List<SmSensor> getSensors() {
+ return sensors;
}
}
diff --git a/app/src/main/java/io/trygvis/soilmoisture/SoilMonitor.java b/app/src/main/java/io/trygvis/soilmoisture/SmSensor.java
index 564202d..f27c364 100644
--- a/app/src/main/java/io/trygvis/soilmoisture/SoilMonitor.java
+++ b/app/src/main/java/io/trygvis/soilmoisture/SmSensor.java
@@ -2,14 +2,14 @@ package io.trygvis.soilmoisture;
import java.util.Date;
-class SoilMonitor {
+class SmSensor {
private final SmDevice device;
private Date timestamp;
private int lastValue;
- SoilMonitor(SmDevice device) {
+ SmSensor(SmDevice device) {
this.device = device;
}