mirror of
https://github.com/oliexdev/openScale.git
synced 2025-09-02 21:02:48 +02:00
merge last measurement to the Bluetooth measurement.
This commit is contained in:
@@ -21,10 +21,12 @@ import android.arch.persistence.room.Entity;
|
|||||||
import android.arch.persistence.room.ForeignKey;
|
import android.arch.persistence.room.ForeignKey;
|
||||||
import android.arch.persistence.room.Index;
|
import android.arch.persistence.room.Index;
|
||||||
import android.arch.persistence.room.PrimaryKey;
|
import android.arch.persistence.room.PrimaryKey;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.health.openscale.core.utils.Converters;
|
import com.health.openscale.core.utils.Converters;
|
||||||
import com.j256.simplecsv.common.CsvColumn;
|
import com.j256.simplecsv.common.CsvColumn;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Entity(tableName = "scaleMeasurements",
|
@Entity(tableName = "scaleMeasurements",
|
||||||
@@ -125,6 +127,25 @@ public class ScaleMeasurement implements Cloneable {
|
|||||||
hip /= divisor;
|
hip /= divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void merge(ScaleMeasurement measurements) {
|
||||||
|
try {
|
||||||
|
Field[] fields = getClass().getDeclaredFields();
|
||||||
|
|
||||||
|
for (Field field : fields) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object value = field.get(measurements);
|
||||||
|
if (Float.class.isAssignableFrom(value.getClass())) {
|
||||||
|
if ((float)field.get(this) == 0.0f) {
|
||||||
|
field.set(this, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
field.setAccessible(false);
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
Log.e("ScaleMeasurement", "Error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@@ -67,6 +67,7 @@ import com.health.openscale.gui.utils.PermissionHelper;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import cat.ereza.customactivityoncrash.config.CaocConfig;
|
import cat.ereza.customactivityoncrash.config.CaocConfig;
|
||||||
|
|
||||||
@@ -486,7 +487,16 @@ public class MainActivity extends AppCompatActivity
|
|||||||
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
|
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
|
||||||
ScaleMeasurement scaleBtData = (ScaleMeasurement) msg.obj;
|
ScaleMeasurement scaleBtData = (ScaleMeasurement) msg.obj;
|
||||||
|
|
||||||
OpenScale.getInstance(getApplicationContext()).addScaleData(scaleBtData);
|
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
|
||||||
|
|
||||||
|
List<ScaleMeasurement> scaleMeasurementList = openScale.getScaleMeasurementList();
|
||||||
|
|
||||||
|
if (!scaleMeasurementList.isEmpty()) {
|
||||||
|
ScaleMeasurement lastMeasurement = scaleMeasurementList.get(0);
|
||||||
|
scaleBtData.merge(lastMeasurement);
|
||||||
|
}
|
||||||
|
|
||||||
|
openScale.addScaleData(scaleBtData);
|
||||||
break;
|
break;
|
||||||
case BT_INIT_PROCESS:
|
case BT_INIT_PROCESS:
|
||||||
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
|
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
|
||||||
|
@@ -0,0 +1,49 @@
|
|||||||
|
/* Copyright (C) 2018 olie.xdev <olie.xdev@googlemail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
package com.health.openscale;
|
||||||
|
|
||||||
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class MeasurementTest {
|
||||||
|
private static final double DELTA = 1e-15;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mergeTest() throws InstantiationException, IllegalAccessException {
|
||||||
|
ScaleMeasurement measurementA = new ScaleMeasurement();
|
||||||
|
ScaleMeasurement measurementB = new ScaleMeasurement();
|
||||||
|
|
||||||
|
measurementA.setWeight(80.0f);
|
||||||
|
measurementA.setBone(3.0f);
|
||||||
|
measurementA.setMuscle(55.0f);
|
||||||
|
|
||||||
|
measurementB.setWeight(90.0f);
|
||||||
|
measurementB.setBone(10.0f);
|
||||||
|
measurementB.setHip(5.0f);
|
||||||
|
measurementB.setWater(12.0f);
|
||||||
|
|
||||||
|
measurementA.merge(measurementB);
|
||||||
|
|
||||||
|
assertEquals(80.0f, measurementA.getWeight(), DELTA);
|
||||||
|
assertEquals(3.0f, measurementA.getBone(), DELTA);
|
||||||
|
assertEquals( 5.0f, measurementA.getHip(), DELTA);
|
||||||
|
assertEquals( 12.0f, measurementA.getWater(), DELTA);
|
||||||
|
assertEquals( 55.0f, measurementA.getMuscle(), DELTA);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user