diff --git a/app/src/main/java/io/pslab/activity/LuxMeterActivity.java b/app/src/main/java/io/pslab/activity/LuxMeterActivity.java
index 6d7d63200..14732ae75 100644
--- a/app/src/main/java/io/pslab/activity/LuxMeterActivity.java
+++ b/app/src/main/java/io/pslab/activity/LuxMeterActivity.java
@@ -201,11 +201,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
((LuxMeterFragmentData) selectedFragment).stopSensorFetching();
invalidateOptionsMenu();
Long uniqueRef = realmPreferences.getLong("uniqueCount", 0);
- selectedFragment.saveDataInRealm(uniqueRef, locationPref, gpsLogger);
- CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.exp_data_saved), null, null);
- SharedPreferences.Editor editor = realmPreferences.edit();
- editor.putLong("uniqueCount", uniqueRef + 1);
- editor.commit();
+ if (selectedFragment.saveDataInRealm(uniqueRef, locationPref, gpsLogger)) {
+ CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.exp_data_saved), null, null);
+ SharedPreferences.Editor editor = realmPreferences.edit();
+ editor.putLong("uniqueCount", uniqueRef + 1);
+ editor.commit();
+ } else {
+ CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.no_data_fetched), null, null);
+ }
recordData = false;
} else {
if (locationPref) {
diff --git a/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java b/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java
index 027060581..bcb1d2470 100644
--- a/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java
+++ b/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java
@@ -400,40 +400,46 @@ public void stopSensorFetching() {
}
}
- public void saveDataInRealm(Long uniqueRef, boolean includeLocation, GPSLogger gpsLogger) {
- realm.beginTransaction();
-
- SensorLogged sensorLogged = realm.createObject(SensorLogged.class, uniqueRef);
- sensorLogged.setSensor("Lux Meter");
- sensorLogged.setDateTimeStart(startTime);
- sensorLogged.setDateTimeEnd(endTime);
- sensorLogged.setTimeZone(TimeZone.getDefault().getDisplayName());
-
- if (includeLocation && gpsLogger != null) {
- Location location = gpsLogger.getBestLocation();
- if (location != null) {
- sensorLogged.setLatitude(location.getLatitude());
- sensorLogged.setLongitude(location.getLongitude());
+ public boolean saveDataInRealm(Long uniqueRef, boolean includeLocation, GPSLogger gpsLogger) {
+ boolean flag = luxRealmData.isEmpty();
+ if (!flag) {
+ realm.beginTransaction();
+
+ SensorLogged sensorLogged = realm.createObject(SensorLogged.class, uniqueRef);
+ sensorLogged.setSensor(getResources().getString(R.string.lux_meter));
+ sensorLogged.setDateTimeStart(startTime);
+ sensorLogged.setDateTimeEnd(endTime);
+ sensorLogged.setTimeZone(TimeZone.getDefault().getDisplayName());
+
+ if (includeLocation && gpsLogger != null) {
+ Location location = gpsLogger.getBestLocation();
+ if (location != null) {
+ sensorLogged.setLatitude(location.getLatitude());
+ sensorLogged.setLongitude(location.getLongitude());
+ } else {
+ sensorLogged.setLatitude(0.0);
+ sensorLogged.setLongitude(0.0);
+ }
+ gpsLogger.removeUpdate();
} else {
sensorLogged.setLatitude(0.0);
sensorLogged.setLongitude(0.0);
}
- gpsLogger.removeUpdate();
- } else {
- sensorLogged.setLatitude(0.0);
- sensorLogged.setLongitude(0.0);
- }
- for (int i = 0; i < luxRealmData.size(); i++) {
- LuxData tempObject = luxRealmData.get(i);
- tempObject.setId(i);
- tempObject.setForeignKey(uniqueRef);
- realm.copyToRealm(tempObject);
- Log.i("dataResult", String.valueOf(tempObject.getLux()));
+ for (int i = 0; i < luxRealmData.size(); i++) {
+ LuxData tempObject = luxRealmData.get(i);
+ tempObject.setId(i);
+ tempObject.setForeignKey(uniqueRef);
+ realm.copyToRealm(tempObject);
+ Log.i("dataResult", String.valueOf(tempObject.getLux()));
+ }
+ realm.copyToRealm(sensorLogged);
+ realm.commitTransaction();
+ luxRealmData.clear();
+ return true;
+ } else {
+ return false;
}
- realm.copyToRealm(sensorLogged);
- realm.commitTransaction();
- luxRealmData.clear();
}
@Override
diff --git a/app/src/main/java/io/pslab/others/GPSLogger.java b/app/src/main/java/io/pslab/others/GPSLogger.java
index 4280b3119..040c7b1dd 100644
--- a/app/src/main/java/io/pslab/others/GPSLogger.java
+++ b/app/src/main/java/io/pslab/others/GPSLogger.java
@@ -26,7 +26,7 @@
public class GPSLogger {
public static final int MY_PERMISSIONS_REQUEST_LOCATION = 99;
- private static final int UPDATE_INTERVAL_IN_MILLISECONDS = 1000;
+ private static final int UPDATE_INTERVAL_IN_MILLISECONDS = 400;
private static final int MIN_DISTANCE_CHANGE_FOR_UPDATES = 1;
private LocationManager locationManager;
private Context context;
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8567cb33b..47e559c07 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1036,5 +1036,6 @@
GND. GND is meant for Ground and any of the PSLab device GND pins can be used since they are common.\n\n
\u2022 Select sensor by going to the Configure tab from the bottom navigation bar and choose BHT-1750 in the drop down menu under Select Sensor.\n
Lux Meter Settings
+ No Data Fetched