DanaR history loader
This commit is contained in:
parent
978770d70a
commit
61e8ffeebd
|
@ -37,7 +37,7 @@
|
|||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
|
||||
<!-- Receiver from NSClient -->
|
||||
<action android:name="info.nightscout.client.NEW_TREATMENT" />
|
||||
<action android:name="info.nightscout.client.CHANGED_TREATMENT" />
|
||||
|
@ -74,6 +75,8 @@
|
|||
<meta-data
|
||||
android:name="io.fabric.ApiKey"
|
||||
android:value="59d462666c664c57b29e1d79ea123e01f8057cfa" />
|
||||
|
||||
<activity android:name=".plugins.DanaR.History.DanaRHistoryActivity"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -31,12 +31,14 @@ import info.nightscout.androidaps.Constants;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
||||
import info.nightscout.androidaps.plugins.DanaR.History.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.Objectives.ObjectivesFragment;
|
||||
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.Events.EventNewSMS;
|
||||
|
@ -380,6 +382,7 @@ public class DataService extends IntentService {
|
|||
|
||||
private void handleAddedTreatment(String trstring) throws JSONException, SQLException {
|
||||
JSONObject trJson = new JSONObject(trstring);
|
||||
handleDanaRHistoryRecords(trJson); // update record _id in history
|
||||
if (!trJson.has("insulin") && !trJson.has("carbs")) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("ADD: Uninterested treatment: " + trstring);
|
||||
|
@ -429,6 +432,7 @@ public class DataService extends IntentService {
|
|||
|
||||
private void handleChangedTreatment(String trstring) throws JSONException, SQLException {
|
||||
JSONObject trJson = new JSONObject(trstring);
|
||||
handleDanaRHistoryRecords(trJson); // update record _id in history
|
||||
if (!trJson.has("insulin") && !trJson.has("carbs")) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("CHANGE: Uninterested treatment: " + trstring);
|
||||
|
@ -472,6 +476,30 @@ public class DataService extends IntentService {
|
|||
}
|
||||
}
|
||||
|
||||
public void handleDanaRHistoryRecords(JSONObject trJson) throws JSONException, SQLException {
|
||||
if (trJson.has(DanaRNSHistorySync.DANARSIGNATURE)) {
|
||||
Dao<DanaRHistoryRecord, String> daoHistoryRecords = MainApp.getDbHelper().getDaoDanaRHistory();
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = daoHistoryRecords.queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.ge("bytes", trJson.get(DanaRNSHistorySync.DANARSIGNATURE));
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
List<DanaRHistoryRecord> list = daoHistoryRecords.query(preparedQuery);
|
||||
if (list.size() == 0) {
|
||||
// Record does not exists. Ignore
|
||||
} else if (list.size() == 1) {
|
||||
DanaRHistoryRecord record = list.get(0);
|
||||
if (record.get_id() == null || record.get_id() != trJson.getString("_id")) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Updating _id in DanaR history database: " + trJson.getString("_id"));
|
||||
record.set_id(trJson.getString("_id"));
|
||||
daoHistoryRecords.update(record);
|
||||
} else {
|
||||
// already set
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Treatment findById(String _id) {
|
||||
try {
|
||||
|
|
|
@ -43,7 +43,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
public static final String DATABASE_TREATMENTS = "Treatments";
|
||||
public static final String DATABASE_DANARHISTORY = "DanaRHistory";
|
||||
|
||||
private static final int DATABASE_VERSION = 2;
|
||||
private static final int DATABASE_VERSION = 3;
|
||||
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
|
@ -101,9 +101,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
getWritableDatabase().delete("Treatments", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
|
||||
log.debug("After Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TREATMENTS));
|
||||
|
||||
log.debug("Before History size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_DANARHISTORY));
|
||||
log.debug("Before History size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "DanaRHistory"));
|
||||
getWritableDatabase().delete("History", "recordDate" + " < '" + (new Date().getTime() - Constants.daysToKeepHistoryInDatabase * 24 * 60 * 60 * 1000L) + "'", null);
|
||||
log.debug("After History size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_DANARHISTORY));
|
||||
log.debug("After History size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "DanaRHistory"));
|
||||
}
|
||||
|
||||
public void resetDatabases() {
|
||||
|
@ -116,9 +116,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, DanaRHistoryRecord.class);
|
||||
MainApp.bus().post(new EventNewBG());
|
||||
MainApp.bus().post(new EventTreatmentChange());
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
// MainApp.bus().post(new EventNewBG());
|
||||
// MainApp.bus().post(new EventTreatmentChange());
|
||||
// MainApp.bus().post(new EventTempBasalChange());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
return getDao(BgReading.class);
|
||||
}
|
||||
|
||||
public Dao<DanaRHistoryRecord, String> getDaoHistory() throws SQLException {
|
||||
public Dao<DanaRHistoryRecord, String> getDaoDanaRHistory() throws SQLException {
|
||||
return getDao(DanaRHistoryRecord.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
|||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
||||
import info.nightscout.androidaps.plugins.DanaR.Dialogs.ProfileViewDialog;
|
||||
import info.nightscout.androidaps.plugins.DanaR.History.DanaRHistoryActivity;
|
||||
import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus;
|
||||
|
@ -88,6 +89,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
TextView reservoirView;
|
||||
TextView iobView;
|
||||
Button viewProfileButton;
|
||||
Button historyButton;
|
||||
|
||||
// TODO: password in prefs
|
||||
|
||||
|
@ -161,6 +163,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
reservoirView = (TextView) view.findViewById(R.id.danar_reservoir);
|
||||
iobView = (TextView) view.findViewById(R.id.danar_iob);
|
||||
viewProfileButton = (Button) view.findViewById(R.id.danar_viewprofile);
|
||||
historyButton = (Button) view.findViewById(R.id.danar_history);
|
||||
|
||||
viewProfileButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -171,6 +174,13 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
}
|
||||
});
|
||||
|
||||
historyButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(getContext(), DanaRHistoryActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
btConnectionView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -812,7 +822,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
reservoirView.setText(DecimalFormatter.to0Decimal(getDanaRPump().reservoirRemainingUnits) + " / 300 U");
|
||||
SetWarnColor.setColorInverse(reservoirView, getDanaRPump().reservoirRemainingUnits, 50d, 20d);
|
||||
batteryView.setText("{fa-battery-" + (getDanaRPump().batteryRemaining / 25) + "}");
|
||||
SetWarnColor.setColorInverse(reservoirView, getDanaRPump().batteryRemaining, 51d, 26d);
|
||||
SetWarnColor.setColorInverse(batteryView, getDanaRPump().batteryRemaining, 51d, 26d);
|
||||
iobView.setText(getDanaRPump().iob + " U");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,452 @@
|
|||
package info.nightscout.androidaps.plugins.DanaR.History;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.IBinder;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.stmt.PreparedQuery;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.Where;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
||||
import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
public class DanaRHistoryActivity extends Activity {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRHistoryActivity.class);
|
||||
|
||||
private boolean mBounded;
|
||||
private static ExecutionService mExecutionService;
|
||||
|
||||
private Handler mHandler;
|
||||
private static HandlerThread mHandlerThread;
|
||||
|
||||
static NSProfile profile = null;
|
||||
|
||||
Spinner historyTypeSpinner;
|
||||
TextView statusView;
|
||||
Button reloadButton;
|
||||
Button syncButton;
|
||||
RecyclerView recyclerView;
|
||||
LinearLayoutManager llm;
|
||||
|
||||
static byte showingType = RecordTypes.RECORD_TYPE_ALARM;
|
||||
List<DanaRHistoryRecord> historyList = new ArrayList<DanaRHistoryRecord>();
|
||||
|
||||
public static class TypeList {
|
||||
public byte type;
|
||||
String name;
|
||||
|
||||
public TypeList(byte type, String name) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public DanaRHistoryActivity() {
|
||||
super();
|
||||
mHandlerThread = new HandlerThread(DanaRHistoryActivity.class.getSimpleName());
|
||||
mHandlerThread.start();
|
||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Intent intent = new Intent(this, ExecutionService.class);
|
||||
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
MainApp.bus().unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if (mBounded) {
|
||||
unbindService(mConnection);
|
||||
mBounded = false;
|
||||
}
|
||||
}
|
||||
|
||||
ServiceConnection mConnection = new ServiceConnection() {
|
||||
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
log.debug("Service is disconnected");
|
||||
mBounded = false;
|
||||
mExecutionService = null;
|
||||
}
|
||||
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
log.debug("Service is connected");
|
||||
mBounded = true;
|
||||
ExecutionService.LocalBinder mLocalBinder = (ExecutionService.LocalBinder) service;
|
||||
mExecutionService = mLocalBinder.getServiceInstance();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.danar_historyactivity);
|
||||
|
||||
historyTypeSpinner = (Spinner) findViewById(R.id.danar_historytype);
|
||||
statusView = (TextView) findViewById(R.id.danar_historystatus);
|
||||
reloadButton = (Button) findViewById(R.id.danar_historyreload);
|
||||
syncButton = (Button) findViewById(R.id.danar_historysync);
|
||||
recyclerView = (RecyclerView) findViewById(R.id.danar_history_recyclerview);
|
||||
|
||||
recyclerView.setHasFixedSize(true);
|
||||
llm = new LinearLayoutManager(this);
|
||||
recyclerView.setLayoutManager(llm);
|
||||
|
||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(historyList);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
statusView.setVisibility(View.GONE);
|
||||
|
||||
// Types
|
||||
|
||||
ArrayList<TypeList> typeList = new ArrayList<>();
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_ALARM, "Alarms"));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_BASALHOUR, "Basal Hours"));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_BOLUS, "Bolus"));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_CARBO, "Carbohydrates"));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_DAILY, "Daily insulin"));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_ERROR, "Errors"));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_GLUCOSE, "Glucose"));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_REFILL, "Refill"));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_SUSPEND, "Suspend"));
|
||||
ArrayAdapter<TypeList> spinnerAdapter = new ArrayAdapter<TypeList>(this,
|
||||
android.R.layout.simple_spinner_item, typeList);
|
||||
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
historyTypeSpinner.setAdapter(spinnerAdapter);
|
||||
|
||||
reloadButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TypeList selected = (TypeList) historyTypeSpinner.getSelectedItem();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reloadButton.setVisibility(View.GONE);
|
||||
syncButton.setVisibility(View.GONE);
|
||||
statusView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
clearCardView();
|
||||
mExecutionService.loadHistory(selected.type);
|
||||
loadDataFromDB(selected.type);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reloadButton.setVisibility(View.VISIBLE);
|
||||
syncButton.setVisibility(View.VISIBLE);
|
||||
statusView.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
syncButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TypeList selected = (TypeList) historyTypeSpinner.getSelectedItem();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reloadButton.setVisibility(View.GONE);
|
||||
syncButton.setVisibility(View.GONE);
|
||||
statusView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
DanaRNSHistorySync sync = new DanaRNSHistorySync(historyList);
|
||||
sync.sync(DanaRNSHistorySync.SYNC_ALL);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reloadButton.setVisibility(View.VISIBLE);
|
||||
syncButton.setVisibility(View.VISIBLE);
|
||||
statusView.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
historyTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
TypeList selected = (TypeList) historyTypeSpinner.getSelectedItem();
|
||||
loadDataFromDB(selected.type);
|
||||
showingType = selected.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
clearCardView();
|
||||
}
|
||||
});
|
||||
ConfigBuilderFragment configBuilderFragment = MainApp.getConfigBuilder();
|
||||
profile = configBuilderFragment.getActiveProfile().getProfile();
|
||||
if (profile == null) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.noprofile));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> {
|
||||
|
||||
List<DanaRHistoryRecord> historyList;
|
||||
|
||||
RecyclerViewAdapter(List<DanaRHistoryRecord> historyList) {
|
||||
this.historyList = historyList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HistoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.danar_history_item, viewGroup, false);
|
||||
HistoryViewHolder tempBasalsViewHolder = new HistoryViewHolder(v);
|
||||
return tempBasalsViewHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(HistoryViewHolder holder, int position) {
|
||||
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
DanaRHistoryRecord record = historyList.get(position);
|
||||
holder.time.setText(df.format(new Date(record.getRecordDate())));
|
||||
holder.value.setText(DecimalFormatter.to2Decimal(record.getRecordValue()));
|
||||
holder.stringvalue.setText(record.getStringRecordValue());
|
||||
holder.bolustype.setText(record.getBolusType());
|
||||
holder.duration.setText(DecimalFormatter.to0Decimal(record.getRecordDuration()));
|
||||
holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + "U");
|
||||
holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + "U");
|
||||
holder.alarm.setText(record.getRecordAlarm());
|
||||
switch (showingType) {
|
||||
case RecordTypes.RECORD_TYPE_ALARM:
|
||||
holder.time.setVisibility(View.VISIBLE);
|
||||
holder.value.setVisibility(View.VISIBLE);
|
||||
holder.stringvalue.setVisibility(View.GONE);
|
||||
holder.bolustype.setVisibility(View.GONE);
|
||||
holder.duration.setVisibility(View.GONE);
|
||||
holder.dailybasal.setVisibility(View.GONE);
|
||||
holder.dailybolus.setVisibility(View.GONE);
|
||||
holder.alarm.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_BOLUS:
|
||||
holder.time.setVisibility(View.VISIBLE);
|
||||
holder.value.setVisibility(View.VISIBLE);
|
||||
holder.stringvalue.setVisibility(View.GONE);
|
||||
holder.bolustype.setVisibility(View.VISIBLE);
|
||||
holder.duration.setVisibility(View.VISIBLE);
|
||||
holder.dailybasal.setVisibility(View.GONE);
|
||||
holder.dailybolus.setVisibility(View.GONE);
|
||||
holder.alarm.setVisibility(View.GONE);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_DAILY:
|
||||
holder.time.setVisibility(View.VISIBLE);
|
||||
holder.value.setVisibility(View.GONE);
|
||||
holder.stringvalue.setVisibility(View.GONE);
|
||||
holder.bolustype.setVisibility(View.GONE);
|
||||
holder.duration.setVisibility(View.GONE);
|
||||
holder.dailybasal.setVisibility(View.VISIBLE);
|
||||
holder.dailybolus.setVisibility(View.VISIBLE);
|
||||
holder.alarm.setVisibility(View.GONE);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_GLUCOSE:
|
||||
holder.value.setText(NSProfile.toUnitsString(record.getRecordValue(), record.getRecordValue() * Constants.MGDL_TO_MMOLL, profile.getUnits()));
|
||||
// rest is the same
|
||||
case RecordTypes.RECORD_TYPE_CARBO:
|
||||
case RecordTypes.RECORD_TYPE_BASALHOUR:
|
||||
case RecordTypes.RECORD_TYPE_ERROR:
|
||||
case RecordTypes.RECORD_TYPE_PRIME:
|
||||
case RecordTypes.RECORD_TYPE_REFILL:
|
||||
case RecordTypes.RECORD_TYPE_TB:
|
||||
holder.time.setVisibility(View.VISIBLE);
|
||||
holder.value.setVisibility(View.VISIBLE);
|
||||
holder.stringvalue.setVisibility(View.GONE);
|
||||
holder.bolustype.setVisibility(View.GONE);
|
||||
holder.duration.setVisibility(View.GONE);
|
||||
holder.dailybasal.setVisibility(View.GONE);
|
||||
holder.dailybolus.setVisibility(View.GONE);
|
||||
holder.alarm.setVisibility(View.GONE);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_SUSPEND:
|
||||
holder.time.setVisibility(View.VISIBLE);
|
||||
holder.value.setVisibility(View.GONE);
|
||||
holder.stringvalue.setVisibility(View.VISIBLE);
|
||||
holder.bolustype.setVisibility(View.GONE);
|
||||
holder.duration.setVisibility(View.GONE);
|
||||
holder.dailybasal.setVisibility(View.GONE);
|
||||
holder.dailybolus.setVisibility(View.GONE);
|
||||
holder.alarm.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return historyList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
public static class HistoryViewHolder extends RecyclerView.ViewHolder {
|
||||
CardView cv;
|
||||
TextView time;
|
||||
TextView value;
|
||||
TextView bolustype;
|
||||
TextView stringvalue;
|
||||
TextView duration;
|
||||
TextView dailybasal;
|
||||
TextView dailybolus;
|
||||
TextView alarm;
|
||||
|
||||
HistoryViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
cv = (CardView) itemView.findViewById(R.id.danar_history_cardview);
|
||||
time = (TextView) itemView.findViewById(R.id.danar_history_time);
|
||||
value = (TextView) itemView.findViewById(R.id.danar_history_value);
|
||||
bolustype = (TextView) itemView.findViewById(R.id.danar_history_bolustype);
|
||||
stringvalue = (TextView) itemView.findViewById(R.id.danar_history_stringvalue);
|
||||
duration = (TextView) itemView.findViewById(R.id.danar_history_duration);
|
||||
dailybasal = (TextView) itemView.findViewById(R.id.danar_history_dailybasal);
|
||||
dailybolus = (TextView) itemView.findViewById(R.id.danar_history_dailybolus);
|
||||
alarm = (TextView) itemView.findViewById(R.id.danar_history_alarm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDataFromDB(byte type) {
|
||||
try {
|
||||
Dao<DanaRHistoryRecord, String> dao = MainApp.getDbHelper().getDaoDanaRHistory();
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = dao.queryBuilder();
|
||||
queryBuilder.orderBy("recordDate", false);
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("recordCode", type);
|
||||
queryBuilder.limit(200L);
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
historyList = dao.query(preparedQuery);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
historyList = new ArrayList<DanaRHistoryRecord>();
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
recyclerView.swapAdapter(new RecyclerViewAdapter(historyList), false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void clearCardView() {
|
||||
historyList = new ArrayList<DanaRHistoryRecord>();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
recyclerView.swapAdapter(new RecyclerViewAdapter(historyList), false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDanaRSyncStatus s) {
|
||||
log.debug("EventDanaRSyncStatus: " + s.message);
|
||||
runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
statusView.setText(s.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDanaRConnectionStatus c) {
|
||||
log.debug("EventDanaRConnectionStatus: " + c.sStatus);
|
||||
runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (c.sStatus == c.CONNECTING) {
|
||||
statusView.setText("Connecting for " + c.sSecondsElapsed + "s");
|
||||
log.debug("EventDanaRConnectionStatus: " + "Connecting for " + c.sSecondsElapsed + "s");
|
||||
} else if (c.sStatus == c.CONNECTED) {
|
||||
statusView.setText("Connected");
|
||||
log.debug("EventDanaRConnectionStatus: Connected");
|
||||
} else {
|
||||
statusView.setText("Disconnected");
|
||||
log.debug("EventDanaRConnectionStatus: Disconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,14 +1,12 @@
|
|||
package info.nightscout.androidaps.plugins.DanaR.History;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
@ -24,21 +22,23 @@ import info.nightscout.utils.ToastUtils;
|
|||
* Created by mike on 20.07.2016.
|
||||
*/
|
||||
|
||||
public class NSHistorySync {
|
||||
private static Logger log = LoggerFactory.getLogger(NSHistorySync.class);
|
||||
private Dao<DanaRHistoryRecord, String> daoHistoryRecords;
|
||||
public class DanaRNSHistorySync {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRNSHistorySync.class);
|
||||
private List<DanaRHistoryRecord> historyRecords;
|
||||
|
||||
public final int SYNC_BOLUS = 0b00000001;
|
||||
public final int SYNC_ERROR = 0b00000010;
|
||||
public final int SYNC_REFILL = 0b00000100;
|
||||
public final int SYNC_GLUCOSE = 0b00001000;
|
||||
public final int SYNC_CARBO = 0b00010000;
|
||||
public final int SYNC_ALARM = 0b00100000;
|
||||
public final int SYNC_BASALOURS = 0b01000000;
|
||||
public final int SYNC_ALL = 0b11111111;
|
||||
public final static int SYNC_BOLUS = 0b00000001;
|
||||
public final static int SYNC_ERROR = 0b00000010;
|
||||
public final static int SYNC_REFILL = 0b00000100;
|
||||
public final static int SYNC_GLUCOSE = 0b00001000;
|
||||
public final static int SYNC_CARBO = 0b00010000;
|
||||
public final static int SYNC_ALARM = 0b00100000;
|
||||
public final static int SYNC_BASALHOURS = 0b01000000;
|
||||
public final static int SYNC_ALL = 0b11111111;
|
||||
|
||||
public NSHistorySync(Dao<DanaRHistoryRecord, String> daoHistoryRecords) {
|
||||
this.daoHistoryRecords = daoHistoryRecords;
|
||||
public final static String DANARSIGNATURE = "DANARMESSAGE";
|
||||
|
||||
public DanaRNSHistorySync(List<DanaRHistoryRecord> historyRecords) {
|
||||
this.historyRecords = historyRecords;
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,12 +51,12 @@ public class NSHistorySync {
|
|||
return;
|
||||
}
|
||||
Calendar cal = Calendar.getInstance();
|
||||
long records = daoHistoryRecords.countOf();
|
||||
long records = historyRecords.size();
|
||||
long processing = 0;
|
||||
long uploaded = 0;
|
||||
log.debug("Database contains " + records + " records");
|
||||
EventDanaRSyncStatus ev = new EventDanaRSyncStatus();
|
||||
for (DanaRHistoryRecord record : daoHistoryRecords) {
|
||||
for (DanaRHistoryRecord record : historyRecords) {
|
||||
processing++;
|
||||
if (record.get_id() != null) continue;
|
||||
//log.debug(record.getBytes());
|
||||
|
@ -68,7 +68,7 @@ public class NSHistorySync {
|
|||
switch (record.getBolusType()) {
|
||||
case "S":
|
||||
log.debug("Syncing standard bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
|
||||
nsrec.put("DANARMESSAGE", record.getBytes());
|
||||
nsrec.put(DANARSIGNATURE, record.getBytes());
|
||||
nsrec.put("eventType", "Meal Bolus");
|
||||
nsrec.put("insulin", record.getRecordValue());
|
||||
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
|
||||
|
@ -80,7 +80,7 @@ public class NSHistorySync {
|
|||
case "E":
|
||||
if (record.getRecordDuration() > 0) {
|
||||
log.debug("Syncing extended bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
|
||||
nsrec.put("DANARMESSAGE", record.getBytes());
|
||||
nsrec.put(DANARSIGNATURE, record.getBytes());
|
||||
nsrec.put("eventType", "Combo Bolus");
|
||||
nsrec.put("insulin", 0);
|
||||
nsrec.put("duration", record.getRecordDuration());
|
||||
|
@ -100,7 +100,7 @@ public class NSHistorySync {
|
|||
break;
|
||||
case "DS":
|
||||
log.debug("Syncing dual(S) bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
|
||||
nsrec.put("DANARMESSAGE", record.getBytes());
|
||||
nsrec.put(DANARSIGNATURE, record.getBytes());
|
||||
nsrec.put("eventType", "Combo Bolus");
|
||||
nsrec.put("insulin", record.getRecordValue());
|
||||
nsrec.put("splitNow", 100);
|
||||
|
@ -113,7 +113,7 @@ public class NSHistorySync {
|
|||
break;
|
||||
case "DE":
|
||||
log.debug("Syncing dual(E) bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
|
||||
nsrec.put("DANARMESSAGE", record.getBytes());
|
||||
nsrec.put(DANARSIGNATURE, record.getBytes());
|
||||
nsrec.put("eventType", "Combo Bolus");
|
||||
nsrec.put("duration", record.getRecordDuration());
|
||||
nsrec.put("relative", record.getRecordValue() / record.getRecordDuration() * 60);
|
||||
|
@ -135,7 +135,7 @@ public class NSHistorySync {
|
|||
case RecordTypes.RECORD_TYPE_ERROR:
|
||||
if ((what & SYNC_ERROR) == 0) break;
|
||||
log.debug("Syncing error record " + DateUtil.toISOString(record.getRecordDate()));
|
||||
nsrec.put("DANARMESSAGE", record.getBytes());
|
||||
nsrec.put(DANARSIGNATURE, record.getBytes());
|
||||
nsrec.put("eventType", "Note");
|
||||
nsrec.put("notes", "Error");
|
||||
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
|
||||
|
@ -147,7 +147,7 @@ public class NSHistorySync {
|
|||
case RecordTypes.RECORD_TYPE_REFILL:
|
||||
if ((what & SYNC_REFILL) == 0) break;
|
||||
log.debug("Syncing refill record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate()));
|
||||
nsrec.put("DANARMESSAGE", record.getBytes());
|
||||
nsrec.put(DANARSIGNATURE, record.getBytes());
|
||||
nsrec.put("eventType", "Insulin Change");
|
||||
nsrec.put("notes", "Refill " + record.getRecordValue() + "U");
|
||||
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
|
||||
|
@ -157,9 +157,9 @@ public class NSHistorySync {
|
|||
ev.message += "refill";
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_BASALHOUR:
|
||||
if ((what & SYNC_BASALOURS) == 0) break;
|
||||
if ((what & SYNC_BASALHOURS) == 0) break;
|
||||
log.debug("Syncing basal hour record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate()));
|
||||
nsrec.put("DANARMESSAGE", record.getBytes());
|
||||
nsrec.put(DANARSIGNATURE, record.getBytes());
|
||||
nsrec.put("eventType", "Temp Basal");
|
||||
nsrec.put("absolute", record.getRecordValue());
|
||||
nsrec.put("duration", 60);
|
||||
|
@ -175,7 +175,7 @@ public class NSHistorySync {
|
|||
case RecordTypes.RECORD_TYPE_GLUCOSE:
|
||||
if ((what & SYNC_GLUCOSE) == 0) break;
|
||||
log.debug("Syncing glucose record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate()));
|
||||
nsrec.put("DANARMESSAGE", record.getBytes());
|
||||
nsrec.put(DANARSIGNATURE, record.getBytes());
|
||||
nsrec.put("eventType", "BG Check");
|
||||
nsrec.put("glucose", NSProfile.fromMgdlToUnits(record.getRecordValue(), profile.getUnits()));
|
||||
nsrec.put("glucoseType", "Finger");
|
||||
|
@ -188,7 +188,7 @@ public class NSHistorySync {
|
|||
case RecordTypes.RECORD_TYPE_CARBO:
|
||||
if ((what & SYNC_CARBO) == 0) break;
|
||||
log.debug("Syncing carbo record " + record.getRecordValue() + "g " + DateUtil.toISOString(record.getRecordDate()));
|
||||
nsrec.put("DANARMESSAGE", record.getBytes());
|
||||
nsrec.put(DANARSIGNATURE, record.getBytes());
|
||||
nsrec.put("eventType", "Meal Bolus");
|
||||
nsrec.put("carbs", record.getRecordValue());
|
||||
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
|
||||
|
@ -200,7 +200,7 @@ public class NSHistorySync {
|
|||
case RecordTypes.RECORD_TYPE_ALARM:
|
||||
if ((what & SYNC_ALARM) == 0) break;
|
||||
log.debug("Syncing alarm record " + record.getRecordAlarm() + " " + DateUtil.toISOString(record.getRecordDate()));
|
||||
nsrec.put("DANARMESSAGE", record.getBytes());
|
||||
nsrec.put(DANARSIGNATURE, record.getBytes());
|
||||
nsrec.put("eventType", "Note");
|
||||
nsrec.put("notes", "Alarm: " + record.getRecordAlarm());
|
||||
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
|
||||
|
@ -223,7 +223,7 @@ public class NSHistorySync {
|
|||
ev.message = "Total " + uploaded + " records uploaded";
|
||||
MainApp.bus().post(ev);
|
||||
|
||||
} catch (JSONException | SQLException e) {
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
|
@ -35,10 +35,23 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
|
|||
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
|
||||
import info.nightscout.androidaps.plugins.DanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.DanaR.SerialIOThread;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MessageBase;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgBolusStart;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgBolusStop;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgCheckValue;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgHistoryAlarm;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgHistoryBasalHour;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgHistoryBolus;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgHistoryCarbo;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgHistoryDailyInsulin;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgHistoryDone;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgHistoryError;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgHistoryGlucose;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgHistoryRefill;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgHistorySuspend;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgPCCommStart;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgPCCommStop;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgSetActivateBasalProfile;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgSetBasalProfile;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgSetCarbsEntry;
|
||||
|
@ -58,6 +71,7 @@ import info.nightscout.androidaps.plugins.DanaR.comm.MsgStatus;
|
|||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgStatusBasic;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgStatusBolusExtended;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgStatusTempBasal;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus;
|
||||
|
@ -374,6 +388,51 @@ public class ExecutionService extends Service {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean loadHistory(byte type) {
|
||||
connect("loadHistory");
|
||||
if (!isConnected()) return false;
|
||||
MessageBase msg = null;
|
||||
switch (type) {
|
||||
case RecordTypes.RECORD_TYPE_ALARM:
|
||||
msg = new MsgHistoryAlarm();
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_BASALHOUR:
|
||||
msg = new MsgHistoryBasalHour();
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_BOLUS:
|
||||
msg = new MsgHistoryBolus();
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_CARBO:
|
||||
msg = new MsgHistoryCarbo();
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_DAILY:
|
||||
msg = new MsgHistoryDailyInsulin();
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_ERROR:
|
||||
msg = new MsgHistoryError();
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_GLUCOSE:
|
||||
msg = new MsgHistoryGlucose();
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_REFILL:
|
||||
msg = new MsgHistoryRefill();
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_SUSPEND:
|
||||
msg = new MsgHistorySuspend();
|
||||
break;
|
||||
}
|
||||
MsgHistoryDone done = new MsgHistoryDone();
|
||||
mSerialIOThread.sendMessage(new MsgPCCommStart());
|
||||
waitMsec(400);
|
||||
mSerialIOThread.sendMessage(msg);
|
||||
while (!done.received && mRfcommSocket.isConnected()) {
|
||||
waitMsec(100);
|
||||
}
|
||||
waitMsec(200);
|
||||
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean updateBasalsInPump(final NSProfile profile) {
|
||||
connect("updateBasalsInPump");
|
||||
if (!isConnected()) return false;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class MessageOriginalNames {
|
|||
messageNames.put(0x3109, "CMD_HISTORY_SUSPEND");
|
||||
messageNames.put(0x310a, "CMD_HISTORY_BASAL_HOUR");
|
||||
messageNames.put(0x310b, "CMD_HISTORY_TB");
|
||||
messageNames.put(0x31f1, "CMD_HISTORY_DONT_USED");
|
||||
messageNames.put(0x31f1, "CMD_HISTORY_STOP");
|
||||
messageNames.put(0x31f2, "CMD_HISTORY_LAST_T_R");
|
||||
messageNames.put(0x31f3, "CMD_HISTORY_LAST_T_S");
|
||||
|
||||
|
|
|
@ -6,10 +6,12 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus;
|
||||
|
||||
public class MsgHistoryAll extends MessageBase {
|
||||
private static Logger log = LoggerFactory.getLogger(MsgHistoryAll.class);
|
||||
|
@ -25,32 +27,42 @@ public class MsgHistoryAll extends MessageBase {
|
|||
Date datetime = dateTimeFromBuff(bytes, 1); // 5 bytes
|
||||
Date datetimewihtsec = dateTimeSecFromBuff(bytes, 1); // 6 bytes
|
||||
|
||||
double dailyBasal = intFromBuff(bytes, 4, 2) * 0.01d;
|
||||
double dailyBolus = intFromBuff(bytes, 6, 2) * 0.01d;
|
||||
byte paramByte5 = (byte) intFromBuff(bytes, 4, 1);
|
||||
byte paramByte6 = (byte) intFromBuff(bytes, 5, 1);
|
||||
byte paramByte7 = (byte) intFromBuff(bytes, 6, 1);
|
||||
byte paramByte8 = (byte) intFromBuff(bytes, 7, 1);
|
||||
double value = (double) intFromBuff(bytes, 8, 2);
|
||||
|
||||
EventDanaRSyncStatus ev = new EventDanaRSyncStatus();
|
||||
|
||||
DanaRHistoryRecord danaRHistoryRecord = new DanaRHistoryRecord();
|
||||
|
||||
danaRHistoryRecord.setRecordCode(recordCode);
|
||||
danaRHistoryRecord.setBytes(bytes);
|
||||
|
||||
String messageType = "";
|
||||
|
||||
switch (recordCode) {
|
||||
case RecordTypes.RECORD_TYPE_BOLUS:
|
||||
danaRHistoryRecord.setRecordDate(datetime);
|
||||
switch (0xF0 & paramByte8) {
|
||||
case 0xA0:
|
||||
danaRHistoryRecord.setBolusType("DS");
|
||||
messageType += "DS bolus";
|
||||
break;
|
||||
case 0xC0:
|
||||
danaRHistoryRecord.setBolusType("E");
|
||||
messageType += "E bolus";
|
||||
break;
|
||||
case 0x80:
|
||||
danaRHistoryRecord.setBolusType("S");
|
||||
messageType += "S bolus";
|
||||
break;
|
||||
case 0x90:
|
||||
danaRHistoryRecord.setBolusType("DE");
|
||||
messageType += "DE bolus";
|
||||
break;
|
||||
default:
|
||||
danaRHistoryRecord.setBolusType("None");
|
||||
|
@ -60,24 +72,48 @@ public class MsgHistoryAll extends MessageBase {
|
|||
danaRHistoryRecord.setRecordValue(value * 0.01);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_DAILY:
|
||||
messageType += "dailyinsulin";
|
||||
danaRHistoryRecord.setRecordDate(date);
|
||||
danaRHistoryRecord.setRecordDailyBasal((double) ((int) paramByte5 * 0xFF + (int) paramByte6) * 0.01);
|
||||
danaRHistoryRecord.setRecordDailyBolus((double) ((int) paramByte7 * 0xFF + (int) paramByte8) / 0.01);
|
||||
danaRHistoryRecord.setRecordDailyBasal(dailyBasal);
|
||||
danaRHistoryRecord.setRecordDailyBolus(dailyBolus);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_PRIME:
|
||||
messageType += "prime";
|
||||
danaRHistoryRecord.setRecordDate(datetimewihtsec);
|
||||
danaRHistoryRecord.setRecordValue(value * 0.01);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_ERROR:
|
||||
messageType += "error";
|
||||
danaRHistoryRecord.setRecordDate(datetimewihtsec);
|
||||
danaRHistoryRecord.setRecordValue(value * 0.01);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_REFILL:
|
||||
messageType += "refill";
|
||||
danaRHistoryRecord.setRecordDate(datetimewihtsec);
|
||||
danaRHistoryRecord.setRecordValue(value * 0.01);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_BASALHOUR:
|
||||
messageType += "basal hour";
|
||||
danaRHistoryRecord.setRecordDate(datetimewihtsec);
|
||||
danaRHistoryRecord.setRecordValue(value * 0.01);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_TB:
|
||||
messageType += "tb";
|
||||
danaRHistoryRecord.setRecordDate(datetimewihtsec);
|
||||
danaRHistoryRecord.setRecordValue(value * 0.01);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_GLUCOSE:
|
||||
messageType += "glucose";
|
||||
danaRHistoryRecord.setRecordDate(datetimewihtsec);
|
||||
danaRHistoryRecord.setRecordValue(value);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_CARBO:
|
||||
messageType += "carbo";
|
||||
danaRHistoryRecord.setRecordDate(datetimewihtsec);
|
||||
danaRHistoryRecord.setRecordValue(value);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_ALARM:
|
||||
messageType += "alarm";
|
||||
danaRHistoryRecord.setRecordDate(datetimewihtsec);
|
||||
String strAlarm = "None";
|
||||
switch ((int) paramByte8) {
|
||||
|
@ -98,6 +134,7 @@ public class MsgHistoryAll extends MessageBase {
|
|||
danaRHistoryRecord.setRecordValue(value * 0.01);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_SUSPEND:
|
||||
messageType += "suspend";
|
||||
danaRHistoryRecord.setRecordDate(datetimewihtsec);
|
||||
String strRecordValue = "Off";
|
||||
if ((int) paramByte8 == 79)
|
||||
|
@ -107,11 +144,17 @@ public class MsgHistoryAll extends MessageBase {
|
|||
}
|
||||
|
||||
try {
|
||||
Dao<DanaRHistoryRecord, String> daoHistoryRecords = MainApp.getDbHelper().getDaoHistory();
|
||||
Dao<DanaRHistoryRecord, String> daoHistoryRecords = MainApp.getDbHelper().getDaoDanaRHistory();
|
||||
daoHistoryRecords.createIfNotExists(danaRHistoryRecord);
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
ev.message = df.format(new Date(danaRHistoryRecord.getRecordDate()));
|
||||
ev.message += " " + messageType;
|
||||
MainApp.bus().post(ev);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class MsgHistoryDone extends MessageBase {
|
|||
private static Logger log = LoggerFactory.getLogger(MsgHistoryDone.class);
|
||||
public static boolean received = false;
|
||||
|
||||
MsgHistoryDone() {
|
||||
public MsgHistoryDone() {
|
||||
SetCommand(0x31F1);
|
||||
received = false;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
package info.nightscout.androidaps.plugins.DanaR.comm;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
|
||||
public class MsgPCCommStart extends MessageBase {
|
||||
private static Logger log = LoggerFactory.getLogger(MsgPCCommStart.class);
|
||||
public MsgPCCommStart() {
|
||||
SetCommand(0x3001);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(byte[] bytes) {
|
||||
if (Config.logDanaMessageDetail)
|
||||
log.debug("PC comm start received");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
package info.nightscout.androidaps.plugins.DanaR.comm;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
|
||||
public class MsgPCCommStop extends MessageBase {
|
||||
private static Logger log = LoggerFactory.getLogger(MsgPCCommStop.class);
|
||||
public MsgPCCommStop() {
|
||||
SetCommand(0x3002);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(byte[] bytes) {
|
||||
if (Config.logDanaMessageDetail)
|
||||
log.debug("PC comm stop received");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,16 +252,23 @@
|
|||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/danar_viewprofile"
|
||||
android:id="@+id/danar_viewprofile"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/danar_history"
|
||||
android:id="@+id/danar_history"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
|
83
app/src/main/res/layout/danar_history_item.xml
Normal file
83
app/src/main/res/layout/danar_history_item.xml
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/danar_history_cardview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
card_view:cardBackgroundColor="@color/cardColorBackground"
|
||||
card_view:cardCornerRadius="6dp"
|
||||
card_view:cardUseCompatPadding="true"
|
||||
card_view:contentPadding="6dp">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/tempbasals_datelinearlayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:baselineAligned="true"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_time"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="27.06.2016 18:00" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_value"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="0.25"
|
||||
android:gravity="right" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_bolustype"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="E"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_stringvalue"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="XXXXXXX"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_duration"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="30"
|
||||
android:gravity="right" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_dailybasal"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:gravity="right" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_dailybolus"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:gravity="right" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_alarm"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
82
app/src/main/res/layout/danar_historyactivity.xml
Normal file
82
app/src/main/res/layout/danar_historyactivity.xml
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".plugins.DanaR.History.DanaRHistoryActivity">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/danar_historytop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:text="Type:"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/danar_historytype"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="20dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/loopmodeborder"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="DanaR History" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_historystatus"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/danar_historytop"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:gravity="center_horizontal" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/danar_history_recyclerview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_above="@+id/danar_historybuttons"
|
||||
android:layout_below="@+id/danar_historystatus" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/danar_historybuttons"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/danar_historyreload"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/danar_historyreload" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/danar_historysync"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Sync to NS" />
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
|
@ -247,9 +247,9 @@
|
|||
<string name="waitingforpumpresult">Waiting for result</string>
|
||||
<string name="smscommunicator_allowednumbers">Allowed phone numbers</string>
|
||||
<string name="smscommunicator_allowednumbers_summary">+XXXXXXXXXX;+YYYYYYYYYY</string>
|
||||
<string formatted="false" name="replywithcode">To deliver bolus %.2fU reply with code %s</string>
|
||||
<string name="replywithcode" formatted="false">To deliver bolus %.2fU reply with code %s</string>
|
||||
<string name="bolusfailed">Bolus failed</string>
|
||||
<string formatted="false" name="bolusdelivered">Bolus %.2fU delivered successfully</string>
|
||||
<string name="bolusdelivered" formatted="false">Bolus %.2fU delivered successfully</string>
|
||||
<string name="smscommunicator_remotebolusingallowed">Allow remote bolusing via SMS</string>
|
||||
<string name="remotebolusnotallowed">Remote bolus not allowed</string>
|
||||
<string name="glucosetype_finger">Finger</string>
|
||||
|
@ -261,5 +261,7 @@
|
|||
<string name="danarprofile_dia">DIA [h]</string>
|
||||
<string name="danarprofile_car">Carbs absorption rate</string>
|
||||
<string name="failedupdatebasalprofile">Failed to update basal profile</string>
|
||||
<string name="danar_history">History</string>
|
||||
<string name="danar_historyreload">Reload</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue