mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-20 15:32:04 +02:00
increase performance while switching between data entries
This commit is contained in:
@@ -161,9 +161,9 @@ public class OpenScale {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ScaleData getScaleData(long id)
|
public ScaleData[] getTupleScaleData(long id)
|
||||||
{
|
{
|
||||||
return scaleDB.getDataEntry(id);
|
return scaleDB.getTupleDataEntry(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int addScaleData(ScaleData scaleData) {
|
public int addScaleData(ScaleData scaleData) {
|
||||||
|
@@ -172,25 +172,72 @@ public class ScaleDatabase extends SQLiteOpenHelper {
|
|||||||
dbWrite.update(TABLE_NAME, values, COLUMN_NAME_ID + "=" + id, null);
|
dbWrite.update(TABLE_NAME, values, COLUMN_NAME_ID + "=" + id, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScaleData getDataEntry(long id)
|
public ScaleData[] getTupleDataEntry(long id)
|
||||||
{
|
{
|
||||||
Cursor cursorScaleDB = dbRead.query(
|
Cursor cursorScaleDB;
|
||||||
|
|
||||||
|
ScaleData[] tupleScaleData = new ScaleData[3];
|
||||||
|
|
||||||
|
// selected scale data entry
|
||||||
|
cursorScaleDB = dbRead.query(
|
||||||
TABLE_NAME, // The table to query
|
TABLE_NAME, // The table to query
|
||||||
projection, // The columns to return
|
projection, // The columns to return
|
||||||
COLUMN_NAME_ID + "=?", // The columns for the WHERE clause
|
COLUMN_NAME_ID + "=?", // The columns for the WHERE clause
|
||||||
new String[] {Long.toString(id)}, // The values for the WHERE clause
|
new String[] {Long.toString(id)}, // The values for the WHERE clause
|
||||||
null, // don't group the rows
|
null, // don't group the rows
|
||||||
null, // don't filter by row groups
|
null, // don't filter by row groups
|
||||||
null // The sort order
|
null, // The sort order
|
||||||
|
"1" // Limit
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (cursorScaleDB.getCount() == 1) {
|
||||||
cursorScaleDB.moveToFirst();
|
cursorScaleDB.moveToFirst();
|
||||||
|
tupleScaleData[1] = readAtCursor(cursorScaleDB);
|
||||||
|
} else {
|
||||||
|
tupleScaleData[1] = null;
|
||||||
|
}
|
||||||
|
|
||||||
ScaleData scaleData = readAtCursor(cursorScaleDB);
|
// previous scale entry
|
||||||
|
cursorScaleDB = dbRead.query(
|
||||||
|
TABLE_NAME, // The table to query
|
||||||
|
projection, // The columns to return
|
||||||
|
COLUMN_NAME_DATE_TIME + "<? AND " + COLUMN_NAME_ENABLE + "=1", // The columns for the WHERE clause
|
||||||
|
new String[] {formatDateTime.format(tupleScaleData[1].getDateTime())}, // The values for the WHERE clause
|
||||||
|
null, // don't group the rows
|
||||||
|
null, // don't filter by row groups
|
||||||
|
COLUMN_NAME_DATE_TIME + " DESC", // The sort order
|
||||||
|
"1" // Limit
|
||||||
|
);
|
||||||
|
|
||||||
|
if (cursorScaleDB.getCount() == 1) {
|
||||||
|
cursorScaleDB.moveToFirst();
|
||||||
|
tupleScaleData[0] = readAtCursor(cursorScaleDB);
|
||||||
|
} else {
|
||||||
|
tupleScaleData[0] = null;
|
||||||
|
}
|
||||||
|
|
||||||
cursorScaleDB.close();
|
cursorScaleDB.close();
|
||||||
|
|
||||||
return scaleData;
|
// next scale data entry
|
||||||
|
cursorScaleDB = dbRead.query(
|
||||||
|
TABLE_NAME, // The table to query
|
||||||
|
projection, // The columns to return
|
||||||
|
COLUMN_NAME_DATE_TIME + ">? AND " + COLUMN_NAME_ENABLE + "=1", // The columns for the WHERE clause
|
||||||
|
new String[] {formatDateTime.format(tupleScaleData[1].getDateTime())}, // The values for the WHERE clause
|
||||||
|
null, // don't group the rows
|
||||||
|
null, // don't filter by row groups
|
||||||
|
COLUMN_NAME_DATE_TIME, // The sort order
|
||||||
|
"1" // Limit
|
||||||
|
);
|
||||||
|
|
||||||
|
if (cursorScaleDB.getCount() == 1) {
|
||||||
|
cursorScaleDB.moveToFirst();
|
||||||
|
tupleScaleData[2] = readAtCursor(cursorScaleDB);
|
||||||
|
} else {
|
||||||
|
tupleScaleData[2] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tupleScaleData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteEntry(long id) {
|
public void deleteEntry(long id) {
|
||||||
|
@@ -52,7 +52,6 @@ import java.text.DateFormat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.ListIterator;
|
|
||||||
|
|
||||||
import lecho.lib.hellocharts.util.ChartUtils;
|
import lecho.lib.hellocharts.util.ChartUtils;
|
||||||
|
|
||||||
@@ -184,30 +183,21 @@ public class DataEntryActivity extends Activity {
|
|||||||
|
|
||||||
OpenScale openScale = OpenScale.getInstance(context);
|
OpenScale openScale = OpenScale.getInstance(context);
|
||||||
|
|
||||||
ScaleData selectedScaleData = openScale.getScaleData(id);
|
ScaleData[] tupleScaleData = openScale.getTupleScaleData(id);
|
||||||
|
ScaleData prevScaleData = tupleScaleData[0];
|
||||||
|
ScaleData selectedScaleData = tupleScaleData[1];
|
||||||
|
|
||||||
|
if (prevScaleData == null) {
|
||||||
|
prevScaleData = new ScaleData();
|
||||||
|
}
|
||||||
|
|
||||||
txtDataNr.setText(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(selectedScaleData.getDateTime()));
|
txtDataNr.setText(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(selectedScaleData.getDateTime()));
|
||||||
|
|
||||||
ArrayList<ScaleData> scaleDataList = OpenScale.getInstance(context).getScaleDataList();
|
|
||||||
ListIterator<ScaleData> scaleDataIterator = scaleDataList.listIterator();
|
|
||||||
|
|
||||||
ScaleData lastData = new ScaleData();
|
|
||||||
|
|
||||||
while(scaleDataIterator.hasNext()) {
|
|
||||||
ScaleData scaleData = scaleDataIterator.next();
|
|
||||||
|
|
||||||
if (scaleData.getId() == id) {
|
|
||||||
if (scaleDataIterator.hasNext()) {
|
|
||||||
lastData = scaleDataIterator.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// show selected scale data
|
// show selected scale data
|
||||||
for (MeasurementView measuremt : dataEntryMeasurements) {
|
for (MeasurementView measuremt : dataEntryMeasurements) {
|
||||||
measuremt.setExpand(prefs.getBoolean(String.valueOf(expandButton.getId()), false));
|
measuremt.setExpand(prefs.getBoolean(String.valueOf(expandButton.getId()), false));
|
||||||
measuremt.updateValue(selectedScaleData);
|
measuremt.updateValue(selectedScaleData);
|
||||||
measuremt.updateDiff(selectedScaleData, lastData);
|
measuremt.updateDiff(selectedScaleData, prevScaleData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -298,26 +288,14 @@ public class DataEntryActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean moveLeft() {
|
private boolean moveLeft() {
|
||||||
ArrayList<ScaleData> scaleDataList = OpenScale.getInstance(getApplicationContext()).getScaleDataList();
|
ScaleData[] tupleScaleData = OpenScale.getInstance(getApplicationContext()).getTupleScaleData(id);
|
||||||
|
ScaleData prevScaleData = tupleScaleData[0];
|
||||||
|
|
||||||
ListIterator<ScaleData> scaleDataIterator = scaleDataList.listIterator();
|
if (prevScaleData != null) {
|
||||||
|
|
||||||
while(scaleDataIterator.hasNext())
|
|
||||||
{
|
|
||||||
ScaleData scaleData = scaleDataIterator.next();
|
|
||||||
|
|
||||||
if (scaleData.getId() == id)
|
|
||||||
{
|
|
||||||
if (scaleDataIterator.hasNext()) {
|
|
||||||
saveScaleData();
|
saveScaleData();
|
||||||
getIntent().putExtra("id",scaleDataIterator.next().getId() );
|
getIntent().putExtra("id", prevScaleData.getId());
|
||||||
updateOnView();
|
updateOnView();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -325,25 +303,14 @@ public class DataEntryActivity extends Activity {
|
|||||||
|
|
||||||
private boolean moveRight()
|
private boolean moveRight()
|
||||||
{
|
{
|
||||||
ArrayList<ScaleData> scaleDataList = OpenScale.getInstance(getApplicationContext()).getScaleDataList();
|
ScaleData[] tupleScaleData = OpenScale.getInstance(getApplicationContext()).getTupleScaleData(id);
|
||||||
|
ScaleData nextScaleData = tupleScaleData[2];
|
||||||
|
|
||||||
ListIterator<ScaleData> scaleDataIterator = scaleDataList.listIterator(scaleDataList.size());
|
if (nextScaleData != null) {
|
||||||
|
|
||||||
while(scaleDataIterator.hasPrevious())
|
|
||||||
{
|
|
||||||
ScaleData scaleData = scaleDataIterator.previous();
|
|
||||||
|
|
||||||
if (scaleData.getId() == id)
|
|
||||||
{
|
|
||||||
if (scaleDataIterator.hasPrevious()) {
|
|
||||||
saveScaleData();
|
saveScaleData();
|
||||||
getIntent().putExtra("id", scaleDataIterator.previous().getId());
|
getIntent().putExtra("id", nextScaleData.getId());
|
||||||
updateOnView();
|
updateOnView();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user