mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-21 16:34:23 +01:00
GLS race condition fixed
This commit is contained in:
@@ -24,6 +24,7 @@ package no.nordicsemi.android.nrftoolbox.gls;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
import android.util.SparseArray;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -32,30 +33,38 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import no.nordicsemi.android.nrftoolbox.R;
|
import no.nordicsemi.android.nrftoolbox.R;
|
||||||
|
|
||||||
public class ExpandableRecordAdapter extends BaseExpandableListAdapter {
|
public class ExpandableRecordAdapter extends BaseExpandableListAdapter {;
|
||||||
private final GlucoseManager mGlucoseManager;
|
private final GlucoseManager mGlucoseManager;
|
||||||
private final LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
private SparseArray<GlucoseRecord> mRecords;
|
||||||
|
|
||||||
public ExpandableRecordAdapter(final Context context, final GlucoseManager manager) {
|
public ExpandableRecordAdapter(final Context context, final GlucoseManager manager) {
|
||||||
mGlucoseManager = manager;
|
mGlucoseManager = manager;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mInflater = LayoutInflater.from(context);
|
mInflater = LayoutInflater.from(context);
|
||||||
|
mRecords = manager.getRecords().clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyDataSetChanged() {
|
||||||
|
mRecords = mGlucoseManager.getRecords().clone();
|
||||||
|
super.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getGroupCount() {
|
public int getGroupCount() {
|
||||||
return mGlucoseManager.getRecords().size();
|
return mRecords.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getGroup(int groupPosition) {
|
public Object getGroup(final int groupPosition) {
|
||||||
return mGlucoseManager.getRecords().valueAt(groupPosition);
|
return mRecords.valueAt(groupPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getGroupId(final int groupPosition) {
|
public long getGroupId(final int groupPosition) {
|
||||||
return mGlucoseManager.getRecords().keyAt(groupPosition);
|
return mRecords.keyAt(groupPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -140,11 +140,9 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
|||||||
record.sampleLocation = sampleLocation != null ? sampleLocation : 0;
|
record.sampleLocation = sampleLocation != null ? sampleLocation : 0;
|
||||||
record.status = status != null ? status.value : 0;
|
record.status = status != null ? status.value : 0;
|
||||||
|
|
||||||
// data set modifications must be done in UI thread
|
// insert the new record to storage
|
||||||
|
mRecords.put(record.sequenceNumber, record);
|
||||||
mHandler.post(() -> {
|
mHandler.post(() -> {
|
||||||
// insert the new record to storage
|
|
||||||
mRecords.put(record.sequenceNumber, record);
|
|
||||||
|
|
||||||
// if there is no context information following the measurement data,
|
// if there is no context information following the measurement data,
|
||||||
// notify callback about the new record
|
// notify callback about the new record
|
||||||
if (!contextInformationFollows)
|
if (!contextInformationFollows)
|
||||||
|
|||||||
Reference in New Issue
Block a user