GLS race condition fixed

This commit is contained in:
Aleksander Nowakowski
2018-11-12 14:08:17 +01:00
parent ce8bcdf495
commit c6dd14c194
2 changed files with 16 additions and 9 deletions

View File

@@ -24,6 +24,7 @@ package no.nordicsemi.android.nrftoolbox.gls;
import android.content.Context;
import android.content.res.Resources;
import android.util.Pair;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -32,30 +33,38 @@ import android.widget.TextView;
import no.nordicsemi.android.nrftoolbox.R;
public class ExpandableRecordAdapter extends BaseExpandableListAdapter {
public class ExpandableRecordAdapter extends BaseExpandableListAdapter {;
private final GlucoseManager mGlucoseManager;
private final LayoutInflater mInflater;
private final Context mContext;
private SparseArray<GlucoseRecord> mRecords;
public ExpandableRecordAdapter(final Context context, final GlucoseManager manager) {
mGlucoseManager = manager;
mContext = context;
mInflater = LayoutInflater.from(context);
mRecords = manager.getRecords().clone();
}
@Override
public void notifyDataSetChanged() {
mRecords = mGlucoseManager.getRecords().clone();
super.notifyDataSetChanged();
}
@Override
public int getGroupCount() {
return mGlucoseManager.getRecords().size();
return mRecords.size();
}
@Override
public Object getGroup(int groupPosition) {
return mGlucoseManager.getRecords().valueAt(groupPosition);
public Object getGroup(final int groupPosition) {
return mRecords.valueAt(groupPosition);
}
@Override
public long getGroupId(final int groupPosition) {
return mGlucoseManager.getRecords().keyAt(groupPosition);
return mRecords.keyAt(groupPosition);
}
@Override

View File

@@ -140,11 +140,9 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
record.sampleLocation = sampleLocation != null ? sampleLocation : 0;
record.status = status != null ? status.value : 0;
// data set modifications must be done in UI thread
mHandler.post(() -> {
// insert the new record to storage
mRecords.put(record.sequenceNumber, record);
mHandler.post(() -> {
// if there is no context information following the measurement data,
// notify callback about the new record
if (!contextInformationFollows)