simplify danar activities, fix profiles
This commit is contained in:
parent
6fca923275
commit
1de64f06c2
|
@ -42,14 +42,11 @@
|
|||
android:name=".plugins.Overview.Dialogs.BolusProgressHelperActivity"
|
||||
android:theme="@style/Theme.AppCompat.Translucent" />
|
||||
<activity android:name=".AgreementActivity" />
|
||||
<activity android:name=".plugins.PumpDanaR.History.DanaRHistoryActivity" />
|
||||
<activity android:name=".plugins.PumpDanaRKorean.History.DanaRHistoryActivity" />
|
||||
<activity android:name=".plugins.PumpDanaR.History.DanaRStatsActivity" />
|
||||
<activity android:name=".plugins.PumpDanaRKorean.History.DanaRStatsActivity" />
|
||||
<activity android:name=".plugins.PumpDanaR.activities.DanaRHistoryActivity" />
|
||||
<activity android:name=".plugins.PumpDanaR.activities.DanaRStatsActivity" />
|
||||
<activity android:name=".plugins.Overview.activities.QuickWizardListActivity">
|
||||
<intent-filter>
|
||||
<action android:name="info.nightscout.androidaps.plugins.Overview.activities.QuickWizardListActivity" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.slf4j.LoggerFactory;
|
|||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
|
@ -32,7 +31,7 @@ import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
|||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.History.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
||||
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin;
|
||||
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
|
||||
|
|
|
@ -44,7 +44,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange;
|
|||
import info.nightscout.androidaps.events.EventTempTargetChange;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.History.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||
|
||||
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package info.nightscout.androidaps.interfaces;
|
||||
|
||||
/**
|
||||
* Created by mike on 12.06.2017.
|
||||
*/
|
||||
|
||||
public interface DanaRInterface {
|
||||
boolean loadHistory(byte type);
|
||||
}
|
|
@ -208,6 +208,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
return activeLoop;
|
||||
}
|
||||
|
||||
public static PumpInterface getActivePump() {
|
||||
return activePump;
|
||||
}
|
||||
|
||||
void logPluginStatus() {
|
||||
for (PluginBase p : pluginList) {
|
||||
log.debug(p.getName() + ":" +
|
||||
|
|
|
@ -9,6 +9,8 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
|
@ -179,26 +181,23 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
|||
int offset = -(timeshift % 24) + 24;
|
||||
|
||||
JSONArray icArray = new JSONArray();
|
||||
for (int i = 0; i < 24; i++) {
|
||||
icArray.put(new JSONObject().put("timeAsSeconds", i * 60 * 60).put("value", baseic[(offset + i) % 24] * 100d / percentage));
|
||||
}
|
||||
profile.put("carbratio", icArray);
|
||||
|
||||
JSONArray isfArray = new JSONArray();
|
||||
for (int i = 0; i < 24; i++) {
|
||||
isfArray.put(new JSONObject().put("timeAsSeconds", i * 60 * 60).put("value", baseisf[(offset + i) % 24] * 100d / percentage));
|
||||
}
|
||||
profile.put("sens", isfArray);
|
||||
|
||||
JSONArray basalArray = new JSONArray();
|
||||
for (int i = 0; i < 24; i++) {
|
||||
basalArray.put(new JSONObject().put("timeAsSeconds", i * 60 * 60).put("value", basebasal[(offset + i) % 24] * percentage / 100d));
|
||||
String time;
|
||||
DecimalFormat df = new DecimalFormat("00");
|
||||
time = df.format(i) + ":00";
|
||||
icArray.put(new JSONObject().put("time", time).put("timeAsSeconds", i * 60 * 60).put("value", baseic[(offset + i) % 24] * 100d / percentage));
|
||||
isfArray.put(new JSONObject().put("time", time).put("timeAsSeconds", i * 60 * 60).put("value", baseisf[(offset + i) % 24] * 100d / percentage));
|
||||
basalArray.put(new JSONObject().put("time", time).put("timeAsSeconds", i * 60 * 60).put("value", basebasal[(offset + i) % 24] * percentage / 100d));
|
||||
}
|
||||
profile.put("carbratio", icArray);
|
||||
profile.put("sens", isfArray);
|
||||
profile.put("basal", basalArray);
|
||||
|
||||
|
||||
profile.put("target_low", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", targetLow)));
|
||||
profile.put("target_high", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", targetHigh)));
|
||||
profile.put("target_low", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", targetLow)));
|
||||
profile.put("target_high", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", targetHigh)));
|
||||
profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL);
|
||||
store.put(profileName, profile);
|
||||
} catch (JSONException e) {
|
||||
|
|
|
@ -30,7 +30,7 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
|
|||
private static ProfileStore convertedProfile = null;
|
||||
private static String convertedProfileName = null;
|
||||
|
||||
final private String DEFAULTARRAY = "[{\"timeAsSeconds\":0,\"value\":0}]";
|
||||
final private String DEFAULTARRAY = "[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":0}]";
|
||||
|
||||
boolean mgdl;
|
||||
boolean mmol;
|
||||
|
|
|
@ -183,11 +183,11 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface {
|
|||
json.put("defaultProfile", "SimpleProfile");
|
||||
json.put("store", store);
|
||||
profile.put("dia", dia);
|
||||
profile.put("carbratio", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", ic)));
|
||||
profile.put("sens", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", isf)));
|
||||
profile.put("basal", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", basal)));
|
||||
profile.put("target_low", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", targetLow)));
|
||||
profile.put("target_high", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", targetHigh)));
|
||||
profile.put("carbratio", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", ic)));
|
||||
profile.put("sens", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", isf)));
|
||||
profile.put("basal", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", basal)));
|
||||
profile.put("target_low", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", targetLow)));
|
||||
profile.put("target_high", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", targetHigh)));
|
||||
profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL);
|
||||
store.put("SimpleProfile", profile);
|
||||
} catch (JSONException e) {
|
||||
|
|
|
@ -28,8 +28,8 @@ import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
|||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.History.DanaRHistoryActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.History.DanaRStatsActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
|
|
@ -30,6 +30,7 @@ import info.nightscout.androidaps.db.Treatment;
|
|||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
|
@ -50,7 +51,7 @@ import info.nightscout.utils.SP;
|
|||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterface, ProfileInterface {
|
||||
public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, ConstraintsInterface, ProfileInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRPlugin.class);
|
||||
|
||||
@Override
|
||||
|
@ -706,6 +707,15 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
return pumpDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* DanaR interface
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean loadHistory(byte type) {
|
||||
return sExecutionService.loadHistory(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constraint interface
|
||||
*/
|
||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||
|
@ -103,10 +104,10 @@ public class ProfileViewDialog extends DialogFragment {
|
|||
// } else {
|
||||
// noProfile.setVisibility(View.GONE);
|
||||
// }
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
Profile profile = ((ProfileInterface)MainApp.getConfigBuilder().getActivePump()).getProfile().getDefaultProfile();
|
||||
units.setText(profile.getUnits());
|
||||
dia.setText(DecimalFormatter.to2Decimal(profile.getDia()) + " h");
|
||||
activeProfile.setText(MainApp.getConfigBuilder().getProfileName());
|
||||
activeProfile.setText(((ProfileInterface)MainApp.getConfigBuilder().getActivePump()).getProfileName());
|
||||
ic.setText(profile.getIcList());
|
||||
isf.setText(profile.getIsfList());
|
||||
basal.setText(profile.getBasalList());
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.plugins.PumpDanaR.History;
|
||||
package info.nightscout.androidaps.plugins.PumpDanaR.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
|
@ -35,9 +35,13 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
@ -46,7 +50,6 @@ public class DanaRHistoryActivity extends Activity {
|
|||
private static Logger log = LoggerFactory.getLogger(DanaRHistoryActivity.class);
|
||||
|
||||
private boolean mBounded;
|
||||
private static DanaRExecutionService mExecutionService;
|
||||
|
||||
private Handler mHandler;
|
||||
private static HandlerThread mHandlerThread;
|
||||
|
@ -86,13 +89,6 @@ public class DanaRHistoryActivity extends Activity {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Intent intent = new Intent(this, DanaRExecutionService.class);
|
||||
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
@ -105,31 +101,6 @@ public class DanaRHistoryActivity extends Activity {
|
|||
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;
|
||||
DanaRExecutionService.LocalBinder mLocalBinder = (DanaRExecutionService.LocalBinder) service;
|
||||
mExecutionService = mLocalBinder.getServiceInstance();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -150,6 +121,8 @@ public class DanaRHistoryActivity extends Activity {
|
|||
|
||||
statusView.setVisibility(View.GONE);
|
||||
|
||||
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PUMP);
|
||||
|
||||
// Types
|
||||
|
||||
ArrayList<TypeList> typeList = new ArrayList<>();
|
||||
|
@ -158,10 +131,12 @@ public class DanaRHistoryActivity extends Activity {
|
|||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_BOLUS, getString(R.string.danar_history_bolus)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_CARBO, getString(R.string.danar_history_carbohydrates)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_DAILY, getString(R.string.danar_history_dailyinsulin)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_ERROR, getString(R.string.danar_history_errors)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_GLUCOSE, getString(R.string.danar_history_glucose)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_REFILL, getString(R.string.danar_history_refill)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_SUSPEND, getString(R.string.danar_history_syspend)));
|
||||
if (!isKorean) {
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_ERROR, getString(R.string.danar_history_errors)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_REFILL, getString(R.string.danar_history_refill)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_SUSPEND, getString(R.string.danar_history_syspend)));
|
||||
}
|
||||
ArrayAdapter<TypeList> spinnerAdapter = new ArrayAdapter<>(this,
|
||||
R.layout.spinner_centered, typeList);
|
||||
historyTypeSpinner.setAdapter(spinnerAdapter);
|
||||
|
@ -169,7 +144,8 @@ public class DanaRHistoryActivity extends Activity {
|
|||
reloadButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mExecutionService.isConnected() || mExecutionService.isConnecting()) {
|
||||
final PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
if (pump.isBusy()) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.pumpbusy));
|
||||
return;
|
||||
}
|
||||
|
@ -186,7 +162,7 @@ public class DanaRHistoryActivity extends Activity {
|
|||
}
|
||||
});
|
||||
clearCardView();
|
||||
mExecutionService.loadHistory(selected.type);
|
||||
((DanaRInterface)pump).loadHistory(RecordTypes.RECORD_TYPE_DAILY);
|
||||
loadDataFromDB(selected.type);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.plugins.PumpDanaR.History;
|
||||
package info.nightscout.androidaps.plugins.PumpDanaR.activities;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.plugins.PumpDanaR.History;
|
||||
package info.nightscout.androidaps.plugins.PumpDanaR.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
|
@ -42,7 +42,9 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||
|
@ -57,7 +59,6 @@ public class DanaRStatsActivity extends Activity {
|
|||
private static Logger log = LoggerFactory.getLogger(DanaRStatsActivity.class);
|
||||
|
||||
private boolean mBounded;
|
||||
private static DanaRExecutionService mExecutionService;
|
||||
|
||||
private Handler mHandler;
|
||||
private static HandlerThread mHandlerThread;
|
||||
|
@ -80,13 +81,6 @@ public class DanaRStatsActivity extends Activity {
|
|||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Intent intent = new Intent(this, DanaRExecutionService.class);
|
||||
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
@ -99,15 +93,6 @@ public class DanaRStatsActivity extends Activity {
|
|||
MainApp.bus().unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if (mBounded) {
|
||||
unbindService(mConnection);
|
||||
mBounded = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
|
@ -123,22 +108,6 @@ public class DanaRStatsActivity extends Activity {
|
|||
return super.dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
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;
|
||||
DanaRExecutionService.LocalBinder mLocalBinder = (DanaRExecutionService.LocalBinder) service;
|
||||
mExecutionService = mLocalBinder.getServiceInstance();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -269,7 +238,8 @@ public class DanaRStatsActivity extends Activity {
|
|||
reloadButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mExecutionService.isConnected() || mExecutionService.isConnecting()) {
|
||||
final PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
if (pump.isBusy()) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.pumpbusy));
|
||||
return;
|
||||
}
|
||||
|
@ -285,7 +255,7 @@ public class DanaRStatsActivity extends Activity {
|
|||
statsMessage.setText(getString(R.string.danar_stats_warning_Message));
|
||||
}
|
||||
});
|
||||
mExecutionService.loadHistory(RecordTypes.RECORD_TYPE_DAILY);
|
||||
((DanaRInterface)pump).loadHistory(RecordTypes.RECORD_TYPE_DAILY);
|
||||
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
|
@ -29,9 +29,9 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
|||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.History.DanaRHistoryActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.History.DanaRStatsActivity;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.SetWarnColor;
|
||||
|
|
|
@ -30,6 +30,7 @@ import info.nightscout.androidaps.db.Treatment;
|
|||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
|
@ -51,7 +52,7 @@ import info.nightscout.utils.SP;
|
|||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class DanaRKoreanPlugin implements PluginBase, PumpInterface, ConstraintsInterface, ProfileInterface {
|
||||
public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterface, ConstraintsInterface, ProfileInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRKoreanPlugin.class);
|
||||
|
||||
@Override
|
||||
|
@ -710,6 +711,15 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
|||
return pumpDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* DanaR interface
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean loadHistory(byte type) {
|
||||
return sExecutionService.loadHistory(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constraint interface
|
||||
*/
|
||||
|
|
|
@ -1,430 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpDanaRKorean.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.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.History.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
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 DanaRKoreanExecutionService mExecutionService;
|
||||
|
||||
private Handler mHandler;
|
||||
private static HandlerThread mHandlerThread;
|
||||
|
||||
static Profile 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<>();
|
||||
|
||||
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, DanaRKoreanExecutionService.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;
|
||||
DanaRKoreanExecutionService.LocalBinder mLocalBinder = (DanaRKoreanExecutionService.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, getString(R.string.danar_history_alarm)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_BASALHOUR, getString(R.string.danar_history_basalhours)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_BOLUS, getString(R.string.danar_history_bolus)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_CARBO, getString(R.string.danar_history_carbohydrates)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_DAILY, getString(R.string.danar_history_dailyinsulin)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_GLUCOSE, getString(R.string.danar_history_glucose)));
|
||||
|
||||
ArrayAdapter<TypeList> spinnerAdapter = new ArrayAdapter<>(this,
|
||||
R.layout.spinner_centered, typeList);
|
||||
historyTypeSpinner.setAdapter(spinnerAdapter);
|
||||
|
||||
reloadButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mExecutionService.isConnected() || mExecutionService.isConnecting()) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.pumpbusy));
|
||||
return;
|
||||
}
|
||||
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() {
|
||||
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();
|
||||
}
|
||||
});
|
||||
profile = MainApp.getConfigBuilder().getProfile();
|
||||
if (profile == null) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.noprofile));
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
return new HistoryViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(HistoryViewHolder holder, int position) {
|
||||
DanaRHistoryRecord record = historyList.get(position);
|
||||
holder.time.setText(DateUtil.dateAndTimeString(record.recordDate));
|
||||
holder.value.setText(DecimalFormatter.to2Decimal(record.recordValue));
|
||||
holder.stringvalue.setText(record.stringRecordValue);
|
||||
holder.bolustype.setText(record.bolusType);
|
||||
holder.duration.setText(DecimalFormatter.to0Decimal(record.recordDuration));
|
||||
holder.alarm.setText(record.recordAlarm);
|
||||
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.dailytotal.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.dailytotal.setVisibility(View.GONE);
|
||||
holder.alarm.setVisibility(View.GONE);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_DAILY:
|
||||
holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.recordDailyBasal) + "U");
|
||||
holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus) + "U");
|
||||
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus + record.recordDailyBasal) + "U");
|
||||
holder.time.setText(DateUtil.dateString(record.recordDate));
|
||||
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.dailytotal.setVisibility(View.VISIBLE);
|
||||
holder.alarm.setVisibility(View.GONE);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_GLUCOSE:
|
||||
holder.value.setText(Profile.toUnitsString(record.recordValue, record.recordValue * 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.dailytotal.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.dailytotal.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 dailytotal;
|
||||
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);
|
||||
dailytotal = (TextView) itemView.findViewById(R.id.danar_history_dailytotal);
|
||||
alarm = (TextView) itemView.findViewById(R.id.danar_history_alarm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDataFromDB(byte type) {
|
||||
historyList = MainApp.getDbHelper().getDanaRHistoryRecordsByType(type);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
recyclerView.swapAdapter(new RecyclerViewAdapter(historyList), false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void clearCardView() {
|
||||
historyList = new ArrayList<>();
|
||||
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 EventPumpStatusChanged c) {
|
||||
runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
statusView.setText(c.textStatus());
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,539 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpDanaRKorean.History;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.IBinder;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.SP;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
public class DanaRStatsActivity extends Activity {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRStatsActivity.class);
|
||||
|
||||
private boolean mBounded;
|
||||
private static DanaRKoreanExecutionService mExecutionService;
|
||||
|
||||
private Handler mHandler;
|
||||
private static HandlerThread mHandlerThread;
|
||||
|
||||
TextView statusView, statsMessage, totalBaseBasal2;
|
||||
EditText totalBaseBasal;
|
||||
Button reloadButton;
|
||||
LinearLayoutManager llm;
|
||||
TableLayout tl, ctl, etl;
|
||||
String TBB;
|
||||
double magicNumber;
|
||||
DecimalFormat decimalFormat;
|
||||
|
||||
List<DanaRHistoryRecord> historyList = new ArrayList<>();
|
||||
|
||||
public DanaRStatsActivity() {
|
||||
super();
|
||||
mHandlerThread = new HandlerThread(DanaRStatsActivity.class.getSimpleName());
|
||||
mHandlerThread.start();
|
||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Intent intent = new Intent(this, DanaRKoreanExecutionService.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;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
View myView = getCurrentFocus();
|
||||
if (myView instanceof EditText) {
|
||||
Rect rect = new Rect();
|
||||
myView.getGlobalVisibleRect(rect);
|
||||
if (!rect.contains((int) event.getRawX(), (int) event.getRawY())) {
|
||||
myView.clearFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
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;
|
||||
DanaRKoreanExecutionService.LocalBinder mLocalBinder = (DanaRKoreanExecutionService.LocalBinder) service;
|
||||
mExecutionService = mLocalBinder.getServiceInstance();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.danar_statsactivity);
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
||||
statusView = (TextView) findViewById(R.id.danar_stats_connection_status);
|
||||
reloadButton = (Button) findViewById(R.id.danar_statsreload);
|
||||
totalBaseBasal = (EditText) findViewById(R.id.danar_stats_editTotalBaseBasal);
|
||||
totalBaseBasal2 = (TextView) findViewById(R.id.danar_stats_editTotalBaseBasal2);
|
||||
statsMessage = (TextView) findViewById(R.id.danar_stats_Message);
|
||||
|
||||
statusView.setVisibility(View.GONE);
|
||||
statsMessage.setVisibility(View.GONE);
|
||||
|
||||
totalBaseBasal2.setEnabled(false);
|
||||
totalBaseBasal2.setClickable(false);
|
||||
totalBaseBasal2.setFocusable(false);
|
||||
totalBaseBasal2.setInputType(0);
|
||||
|
||||
decimalFormat = new DecimalFormat("0.000");
|
||||
llm = new LinearLayoutManager(this);
|
||||
|
||||
TBB = SP.getString("TBB", "10.00");
|
||||
totalBaseBasal.setText(TBB);
|
||||
|
||||
ProfileInterface pi = ConfigBuilderPlugin.getActiveProfileInterface();
|
||||
if (pi != null && pi instanceof CircadianPercentageProfilePlugin) {
|
||||
double cppTBB = ((CircadianPercentageProfilePlugin) pi).baseBasalSum();
|
||||
totalBaseBasal.setText(decimalFormat.format(cppTBB));
|
||||
SP.putString("TBB", totalBaseBasal.getText().toString());
|
||||
TBB = SP.getString("TBB", "");
|
||||
}
|
||||
|
||||
// stats table
|
||||
tl = (TableLayout) findViewById(R.id.main_table);
|
||||
TableRow tr_head = new TableRow(this);
|
||||
tr_head.setBackgroundColor(Color.DKGRAY);
|
||||
tr_head.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
TextView label_date = new TextView(this);
|
||||
label_date.setText(getString(R.string.danar_stats_date));
|
||||
label_date.setTextColor(Color.WHITE);
|
||||
tr_head.addView(label_date);
|
||||
|
||||
TextView label_basalrate = new TextView(this);
|
||||
label_basalrate.setText(getString(R.string.danar_stats_basalrate));
|
||||
label_basalrate.setTextColor(Color.WHITE);
|
||||
tr_head.addView(label_basalrate);
|
||||
|
||||
TextView label_bolus = new TextView(this);
|
||||
label_bolus.setText(getString(R.string.danar_stats_bolus));
|
||||
label_bolus.setTextColor(Color.WHITE);
|
||||
tr_head.addView(label_bolus);
|
||||
|
||||
TextView label_tdd = new TextView(this);
|
||||
label_tdd.setText(getString(R.string.danar_stats_tdd));
|
||||
label_tdd.setTextColor(Color.WHITE);
|
||||
tr_head.addView(label_tdd);
|
||||
|
||||
TextView label_ratio = new TextView(this);
|
||||
label_ratio.setText(getString(R.string.danar_stats_ratio));
|
||||
label_ratio.setTextColor(Color.WHITE);
|
||||
tr_head.addView(label_ratio);
|
||||
|
||||
// add stats headers to tables
|
||||
tl.addView(tr_head, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
// cumulative table
|
||||
ctl = (TableLayout) findViewById(R.id.cumulative_table);
|
||||
TableRow ctr_head = new TableRow(this);
|
||||
ctr_head.setBackgroundColor(Color.DKGRAY);
|
||||
ctr_head.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
TextView label_cum_amount_days = new TextView(this);
|
||||
label_cum_amount_days.setText(getString(R.string.danar_stats_amount_days));
|
||||
label_cum_amount_days.setTextColor(Color.WHITE);
|
||||
ctr_head.addView(label_cum_amount_days);
|
||||
|
||||
TextView label_cum_tdd = new TextView(this);
|
||||
label_cum_tdd.setText(getString(R.string.danar_stats_tdd));
|
||||
label_cum_tdd.setTextColor(Color.WHITE);
|
||||
ctr_head.addView(label_cum_tdd);
|
||||
|
||||
TextView label_cum_ratio = new TextView(this);
|
||||
label_cum_ratio.setText(getString(R.string.danar_stats_ratio));
|
||||
label_cum_ratio.setTextColor(Color.WHITE);
|
||||
ctr_head.addView(label_cum_ratio);
|
||||
|
||||
// add cummulative headers to tables
|
||||
ctl.addView(ctr_head, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
// expontial table
|
||||
etl = (TableLayout) findViewById(R.id.expweight_table);
|
||||
TableRow etr_head = new TableRow(this);
|
||||
etr_head.setBackgroundColor(Color.DKGRAY);
|
||||
etr_head.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
TextView label_exp_weight = new TextView(this);
|
||||
label_exp_weight.setText(getString(R.string.danar_stats_weight));
|
||||
label_exp_weight.setTextColor(Color.WHITE);
|
||||
etr_head.addView(label_exp_weight);
|
||||
|
||||
TextView label_exp_tdd = new TextView(this);
|
||||
label_exp_tdd.setText(getString(R.string.danar_stats_tdd));
|
||||
label_exp_tdd.setTextColor(Color.WHITE);
|
||||
etr_head.addView(label_exp_tdd);
|
||||
|
||||
TextView label_exp_ratio = new TextView(this);
|
||||
label_exp_ratio.setText(getString(R.string.danar_stats_ratio));
|
||||
label_exp_ratio.setTextColor(Color.WHITE);
|
||||
etr_head.addView(label_exp_ratio);
|
||||
|
||||
// add expontial headers to tables
|
||||
etl.addView(etr_head, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
reloadButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mExecutionService.isConnected() || mExecutionService.isConnecting()) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.pumpbusy));
|
||||
return;
|
||||
}
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reloadButton.setVisibility(View.GONE);
|
||||
statusView.setVisibility(View.VISIBLE);
|
||||
statsMessage.setVisibility(View.VISIBLE);
|
||||
statsMessage.setText(getString(R.string.danar_stats_warning_Message));
|
||||
}
|
||||
});
|
||||
mExecutionService.loadHistory(RecordTypes.RECORD_TYPE_DAILY);
|
||||
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reloadButton.setVisibility(View.VISIBLE);
|
||||
statusView.setVisibility(View.GONE);
|
||||
statsMessage.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
totalBaseBasal.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
totalBaseBasal.clearFocus();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
totalBaseBasal.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (hasFocus) {
|
||||
totalBaseBasal.getText().clear();
|
||||
} else {
|
||||
SP.putString("TBB", totalBaseBasal.getText().toString());
|
||||
TBB = SP.getString("TBB", "");
|
||||
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(totalBaseBasal.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
|
||||
}
|
||||
|
||||
private void loadDataFromDB(byte type) {
|
||||
historyList = MainApp.getDbHelper().getDanaRHistoryRecordsByType(type);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cleanTable(tl);
|
||||
cleanTable(ctl);
|
||||
cleanTable(etl);
|
||||
DateFormat df = new SimpleDateFormat("dd.MM.");
|
||||
|
||||
if (TextUtils.isEmpty(TBB)) {
|
||||
totalBaseBasal.setError("Please Enter Total Base Basal");
|
||||
return;
|
||||
} else {
|
||||
magicNumber = SafeParse.stringToDouble(TBB);
|
||||
}
|
||||
|
||||
magicNumber *= 2;
|
||||
totalBaseBasal2.setText(decimalFormat.format(magicNumber));
|
||||
|
||||
int i = 0;
|
||||
double sum = 0d;
|
||||
double weighted03 = 0d;
|
||||
double weighted05 = 0d;
|
||||
double weighted07 = 0d;
|
||||
|
||||
for (DanaRHistoryRecord record : historyList) {
|
||||
double tdd = record.recordDailyBolus + record.recordDailyBasal;
|
||||
|
||||
// Create the table row
|
||||
TableRow tr = new TableRow(DanaRStatsActivity.this);
|
||||
if (i % 2 != 0) tr.setBackgroundColor(Color.DKGRAY);
|
||||
tr.setId(100 + i);
|
||||
tr.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
// Here create the TextView dynamically
|
||||
TextView labelDATE = new TextView(DanaRStatsActivity.this);
|
||||
labelDATE.setId(200 + i);
|
||||
labelDATE.setText(df.format(new Date(record.recordDate)));
|
||||
labelDATE.setTextColor(Color.WHITE);
|
||||
tr.addView(labelDATE);
|
||||
|
||||
TextView labelBASAL = new TextView(DanaRStatsActivity.this);
|
||||
labelBASAL.setId(300 + i);
|
||||
labelBASAL.setText(DecimalFormatter.to2Decimal(record.recordDailyBasal) + " U");
|
||||
labelBASAL.setTextColor(Color.WHITE);
|
||||
tr.addView(labelBASAL);
|
||||
|
||||
TextView labelBOLUS = new TextView(DanaRStatsActivity.this);
|
||||
labelBOLUS.setId(400 + i);
|
||||
labelBOLUS.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus) + " U");
|
||||
labelBOLUS.setTextColor(Color.WHITE);
|
||||
tr.addView(labelBOLUS);
|
||||
|
||||
TextView labelTDD = new TextView(DanaRStatsActivity.this);
|
||||
labelTDD.setId(500 + i);
|
||||
labelTDD.setText(DecimalFormatter.to2Decimal(tdd) + " U");
|
||||
labelTDD.setTextColor(Color.WHITE);
|
||||
tr.addView(labelTDD);
|
||||
|
||||
TextView labelRATIO = new TextView(DanaRStatsActivity.this);
|
||||
labelRATIO.setId(600 + i);
|
||||
labelRATIO.setText(Math.round(100 * tdd / magicNumber) + " %");
|
||||
labelRATIO.setTextColor(Color.WHITE);
|
||||
tr.addView(labelRATIO);
|
||||
|
||||
// add stats rows to tables
|
||||
tl.addView(tr, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
sum = sum + tdd;
|
||||
i++;
|
||||
|
||||
// Create the cumtable row
|
||||
TableRow ctr = new TableRow(DanaRStatsActivity.this);
|
||||
if (i % 2 == 0) ctr.setBackgroundColor(Color.DKGRAY);
|
||||
ctr.setId(700 + i);
|
||||
ctr.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
// Here create the TextView dynamically
|
||||
TextView labelDAYS = new TextView(DanaRStatsActivity.this);
|
||||
labelDAYS.setId(800 + i);
|
||||
labelDAYS.setText("" + i);
|
||||
labelDAYS.setTextColor(Color.WHITE);
|
||||
ctr.addView(labelDAYS);
|
||||
|
||||
TextView labelCUMTDD = new TextView(DanaRStatsActivity.this);
|
||||
labelCUMTDD.setId(900 + i);
|
||||
labelCUMTDD.setText(DecimalFormatter.to2Decimal(sum / i) + " U");
|
||||
labelCUMTDD.setTextColor(Color.WHITE);
|
||||
ctr.addView(labelCUMTDD);
|
||||
|
||||
TextView labelCUMRATIO = new TextView(DanaRStatsActivity.this);
|
||||
labelCUMRATIO.setId(1000 + i);
|
||||
labelCUMRATIO.setText(Math.round(100 * sum / i / magicNumber) + " %");
|
||||
labelCUMRATIO.setTextColor(Color.WHITE);
|
||||
ctr.addView(labelCUMRATIO);
|
||||
|
||||
// add cummulative rows to tables
|
||||
ctl.addView(ctr, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
|
||||
if (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).recordDate)).equals(df.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24))))) {
|
||||
statsMessage.setVisibility(View.VISIBLE);
|
||||
statsMessage.setText(getString(R.string.danar_stats_olddata_Message));
|
||||
|
||||
} else {
|
||||
tl.setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
Collections.reverse(historyList);
|
||||
|
||||
i = 0;
|
||||
|
||||
for (DanaRHistoryRecord record : historyList) {
|
||||
double tdd = record.recordDailyBolus + record.recordDailyBasal;
|
||||
if (i == 0) {
|
||||
weighted03 = tdd;
|
||||
weighted05 = tdd;
|
||||
weighted07 = tdd;
|
||||
|
||||
} else {
|
||||
weighted07 = (weighted07 * 0.3 + tdd * 0.7);
|
||||
weighted05 = (weighted05 * 0.5 + tdd * 0.5);
|
||||
weighted03 = (weighted03 * 0.7 + tdd * 0.3);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
// Create the exptable row
|
||||
TableRow etr = new TableRow(DanaRStatsActivity.this);
|
||||
if (i % 2 != 0) etr.setBackgroundColor(Color.DKGRAY);
|
||||
etr.setId(1100 + i);
|
||||
etr.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
// Here create the TextView dynamically
|
||||
TextView labelWEIGHT = new TextView(DanaRStatsActivity.this);
|
||||
labelWEIGHT.setId(1200 + i);
|
||||
labelWEIGHT.setText("0.3\n" + "0.5\n" + "0.7");
|
||||
labelWEIGHT.setTextColor(Color.WHITE);
|
||||
etr.addView(labelWEIGHT);
|
||||
|
||||
TextView labelEXPTDD = new TextView(DanaRStatsActivity.this);
|
||||
labelEXPTDD.setId(1300 + i);
|
||||
labelEXPTDD.setText(DecimalFormatter.to2Decimal(weighted03)
|
||||
+ " U\n" + DecimalFormatter.to2Decimal(weighted05)
|
||||
+ " U\n" + DecimalFormatter.to2Decimal(weighted07) + " U");
|
||||
labelEXPTDD.setTextColor(Color.WHITE);
|
||||
etr.addView(labelEXPTDD);
|
||||
|
||||
TextView labelEXPRATIO = new TextView(DanaRStatsActivity.this);
|
||||
labelEXPRATIO.setId(1400 + i);
|
||||
labelEXPRATIO.setText(Math.round(100 * weighted03 / magicNumber) + " %\n"
|
||||
+ Math.round(100 * weighted05 / magicNumber) + " %\n"
|
||||
+ Math.round(100 * weighted07 / magicNumber) + " %");
|
||||
labelEXPRATIO.setTextColor(Color.WHITE);
|
||||
etr.addView(labelEXPRATIO);
|
||||
|
||||
// add exponentail rows to tables
|
||||
etl.addView(etr, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void cleanTable(TableLayout table) {
|
||||
int childCount = table.getChildCount();
|
||||
// Remove all rows except the first one
|
||||
if (childCount > 1) {
|
||||
table.removeViews(1, childCount - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@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 EventPumpStatusChanged c) {
|
||||
runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
statusView.setText(c.textStatus());
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -29,9 +29,9 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
|||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.History.DanaRHistoryActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.History.DanaRStatsActivity;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.SetWarnColor;
|
||||
|
|
|
@ -31,6 +31,7 @@ import info.nightscout.androidaps.db.TemporaryBasal;
|
|||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
|
@ -51,7 +52,7 @@ import info.nightscout.utils.Round;
|
|||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInterface, ProfileInterface {
|
||||
public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, ConstraintsInterface, ProfileInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRv2Plugin.class);
|
||||
|
||||
@Override
|
||||
|
@ -623,6 +624,15 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
|
|||
return pumpDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* DanaR interface
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean loadHistory(byte type) {
|
||||
return sExecutionService.loadHistory(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constraint interface
|
||||
*/
|
||||
|
@ -735,6 +745,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
|
|||
ret += "Batt: " + pump.batteryRemaining + "\n";
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO: daily total constraint
|
||||
|
||||
}
|
||||
|
|
|
@ -1,431 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpDanaRv2.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.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.History.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
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 DanaRv2ExecutionService mExecutionService;
|
||||
|
||||
private Handler mHandler;
|
||||
private static HandlerThread mHandlerThread;
|
||||
|
||||
static Profile 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<>();
|
||||
|
||||
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, DanaRv2ExecutionService.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;
|
||||
DanaRv2ExecutionService.LocalBinder mLocalBinder = (DanaRv2ExecutionService.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, getString(R.string.danar_history_alarm)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_BASALHOUR, getString(R.string.danar_history_basalhours)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_BOLUS, getString(R.string.danar_history_bolus)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_CARBO, getString(R.string.danar_history_carbohydrates)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_DAILY, getString(R.string.danar_history_dailyinsulin)));
|
||||
typeList.add(new TypeList(RecordTypes.RECORD_TYPE_GLUCOSE, getString(R.string.danar_history_glucose)));
|
||||
|
||||
ArrayAdapter<TypeList> spinnerAdapter = new ArrayAdapter<>(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) {
|
||||
if (mExecutionService.isConnected() || mExecutionService.isConnecting()) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.pumpbusy));
|
||||
return;
|
||||
}
|
||||
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() {
|
||||
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();
|
||||
}
|
||||
});
|
||||
profile = MainApp.getConfigBuilder().getProfile();
|
||||
if (profile == null) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.noprofile));
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
return new HistoryViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(HistoryViewHolder holder, int position) {
|
||||
DanaRHistoryRecord record = historyList.get(position);
|
||||
holder.time.setText(DateUtil.dateAndTimeString(record.recordDate));
|
||||
holder.value.setText(DecimalFormatter.to2Decimal(record.recordValue));
|
||||
holder.stringvalue.setText(record.stringRecordValue);
|
||||
holder.bolustype.setText(record.bolusType);
|
||||
holder.duration.setText(DecimalFormatter.to0Decimal(record.recordDuration));
|
||||
holder.alarm.setText(record.recordAlarm);
|
||||
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.dailytotal.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.dailytotal.setVisibility(View.GONE);
|
||||
holder.alarm.setVisibility(View.GONE);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_DAILY:
|
||||
holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.recordDailyBasal) + "U");
|
||||
holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus) + "U");
|
||||
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus + record.recordDailyBasal) + "U");
|
||||
holder.time.setText(DateUtil.dateString(record.recordDate));
|
||||
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.dailytotal.setVisibility(View.VISIBLE);
|
||||
holder.alarm.setVisibility(View.GONE);
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_GLUCOSE:
|
||||
holder.value.setText(Profile.toUnitsString(record.recordValue, record.recordValue * 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.dailytotal.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.dailytotal.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 dailytotal;
|
||||
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);
|
||||
dailytotal = (TextView) itemView.findViewById(R.id.danar_history_dailytotal);
|
||||
alarm = (TextView) itemView.findViewById(R.id.danar_history_alarm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDataFromDB(byte type) {
|
||||
historyList = MainApp.getDbHelper().getDanaRHistoryRecordsByType(type);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
recyclerView.swapAdapter(new RecyclerViewAdapter(historyList), false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void clearCardView() {
|
||||
historyList = new ArrayList<>();
|
||||
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 EventPumpStatusChanged c) {
|
||||
runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
statusView.setText(c.textStatus());
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,546 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpDanaRv2.History;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
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.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.SP;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
public class DanaRStatsActivity extends Activity {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRStatsActivity.class);
|
||||
|
||||
private boolean mBounded;
|
||||
private static DanaRv2ExecutionService mExecutionService;
|
||||
|
||||
private Handler mHandler;
|
||||
private static HandlerThread mHandlerThread;
|
||||
|
||||
TextView statusView, statsMessage, totalBaseBasal2;
|
||||
EditText totalBaseBasal;
|
||||
Button reloadButton;
|
||||
LinearLayoutManager llm;
|
||||
TableLayout tl, ctl, etl;
|
||||
String TBB;
|
||||
double magicNumber;
|
||||
DecimalFormat decimalFormat;
|
||||
|
||||
List<DanaRHistoryRecord> historyList = new ArrayList<>();
|
||||
|
||||
public DanaRStatsActivity() {
|
||||
super();
|
||||
mHandlerThread = new HandlerThread(DanaRStatsActivity.class.getSimpleName());
|
||||
mHandlerThread.start();
|
||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Intent intent = new Intent(this, DanaRv2ExecutionService.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;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
View myView = getCurrentFocus();
|
||||
if (myView instanceof EditText) {
|
||||
Rect rect = new Rect();
|
||||
myView.getGlobalVisibleRect(rect);
|
||||
if (!rect.contains((int) event.getRawX(), (int) event.getRawY())) {
|
||||
myView.clearFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
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;
|
||||
DanaRv2ExecutionService.LocalBinder mLocalBinder = (DanaRv2ExecutionService.LocalBinder) service;
|
||||
mExecutionService = mLocalBinder.getServiceInstance();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.danar_statsactivity);
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
||||
statusView = (TextView) findViewById(R.id.danar_stats_connection_status);
|
||||
reloadButton = (Button) findViewById(R.id.danar_statsreload);
|
||||
totalBaseBasal = (EditText) findViewById(R.id.danar_stats_editTotalBaseBasal);
|
||||
totalBaseBasal2 = (TextView) findViewById(R.id.danar_stats_editTotalBaseBasal2);
|
||||
statsMessage = (TextView) findViewById(R.id.danar_stats_Message);
|
||||
|
||||
statusView.setVisibility(View.GONE);
|
||||
statsMessage.setVisibility(View.GONE);
|
||||
|
||||
totalBaseBasal2.setEnabled(false);
|
||||
totalBaseBasal2.setClickable(false);
|
||||
totalBaseBasal2.setFocusable(false);
|
||||
totalBaseBasal2.setInputType(0);
|
||||
|
||||
decimalFormat = new DecimalFormat("0.000");
|
||||
llm = new LinearLayoutManager(this);
|
||||
|
||||
TBB = SP.getString("TBB", "10.00");
|
||||
totalBaseBasal.setText(TBB);
|
||||
|
||||
ProfileInterface pi = ConfigBuilderPlugin.getActiveProfileInterface();
|
||||
if (pi != null && pi instanceof CircadianPercentageProfilePlugin) {
|
||||
double cppTBB = ((CircadianPercentageProfilePlugin) pi).baseBasalSum();
|
||||
totalBaseBasal.setText(decimalFormat.format(cppTBB));
|
||||
SP.putString("TBB", totalBaseBasal.getText().toString());
|
||||
TBB = SP.getString("TBB", "");
|
||||
}
|
||||
|
||||
// stats table
|
||||
tl = (TableLayout) findViewById(R.id.main_table);
|
||||
TableRow tr_head = new TableRow(this);
|
||||
tr_head.setBackgroundColor(Color.DKGRAY);
|
||||
tr_head.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
TextView label_date = new TextView(this);
|
||||
label_date.setText(getString(R.string.danar_stats_date));
|
||||
label_date.setTextColor(Color.WHITE);
|
||||
tr_head.addView(label_date);
|
||||
|
||||
TextView label_basalrate = new TextView(this);
|
||||
label_basalrate.setText(getString(R.string.danar_stats_basalrate));
|
||||
label_basalrate.setTextColor(Color.WHITE);
|
||||
tr_head.addView(label_basalrate);
|
||||
|
||||
TextView label_bolus = new TextView(this);
|
||||
label_bolus.setText(getString(R.string.danar_stats_bolus));
|
||||
label_bolus.setTextColor(Color.WHITE);
|
||||
tr_head.addView(label_bolus);
|
||||
|
||||
TextView label_tdd = new TextView(this);
|
||||
label_tdd.setText(getString(R.string.danar_stats_tdd));
|
||||
label_tdd.setTextColor(Color.WHITE);
|
||||
tr_head.addView(label_tdd);
|
||||
|
||||
TextView label_ratio = new TextView(this);
|
||||
label_ratio.setText(getString(R.string.danar_stats_ratio));
|
||||
label_ratio.setTextColor(Color.WHITE);
|
||||
tr_head.addView(label_ratio);
|
||||
|
||||
// add stats headers to tables
|
||||
tl.addView(tr_head, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
// cumulative table
|
||||
ctl = (TableLayout) findViewById(R.id.cumulative_table);
|
||||
TableRow ctr_head = new TableRow(this);
|
||||
ctr_head.setBackgroundColor(Color.DKGRAY);
|
||||
ctr_head.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
TextView label_cum_amount_days = new TextView(this);
|
||||
label_cum_amount_days.setText(getString(R.string.danar_stats_amount_days));
|
||||
label_cum_amount_days.setTextColor(Color.WHITE);
|
||||
ctr_head.addView(label_cum_amount_days);
|
||||
|
||||
TextView label_cum_tdd = new TextView(this);
|
||||
label_cum_tdd.setText(getString(R.string.danar_stats_tdd));
|
||||
label_cum_tdd.setTextColor(Color.WHITE);
|
||||
ctr_head.addView(label_cum_tdd);
|
||||
|
||||
TextView label_cum_ratio = new TextView(this);
|
||||
label_cum_ratio.setText(getString(R.string.danar_stats_ratio));
|
||||
label_cum_ratio.setTextColor(Color.WHITE);
|
||||
ctr_head.addView(label_cum_ratio);
|
||||
|
||||
// add cummulative headers to tables
|
||||
ctl.addView(ctr_head, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
// expontial table
|
||||
etl = (TableLayout) findViewById(R.id.expweight_table);
|
||||
TableRow etr_head = new TableRow(this);
|
||||
etr_head.setBackgroundColor(Color.DKGRAY);
|
||||
etr_head.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
TextView label_exp_weight = new TextView(this);
|
||||
label_exp_weight.setText(getString(R.string.danar_stats_weight));
|
||||
label_exp_weight.setTextColor(Color.WHITE);
|
||||
etr_head.addView(label_exp_weight);
|
||||
|
||||
TextView label_exp_tdd = new TextView(this);
|
||||
label_exp_tdd.setText(getString(R.string.danar_stats_tdd));
|
||||
label_exp_tdd.setTextColor(Color.WHITE);
|
||||
etr_head.addView(label_exp_tdd);
|
||||
|
||||
TextView label_exp_ratio = new TextView(this);
|
||||
label_exp_ratio.setText(getString(R.string.danar_stats_ratio));
|
||||
label_exp_ratio.setTextColor(Color.WHITE);
|
||||
etr_head.addView(label_exp_ratio);
|
||||
|
||||
// add expontial headers to tables
|
||||
etl.addView(etr_head, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
reloadButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mExecutionService.isConnected() || mExecutionService.isConnecting()) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.pumpbusy));
|
||||
return;
|
||||
}
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reloadButton.setVisibility(View.GONE);
|
||||
statusView.setVisibility(View.VISIBLE);
|
||||
statsMessage.setVisibility(View.VISIBLE);
|
||||
statsMessage.setText(getString(R.string.danar_stats_warning_Message));
|
||||
}
|
||||
});
|
||||
mExecutionService.loadHistory(RecordTypes.RECORD_TYPE_DAILY);
|
||||
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reloadButton.setVisibility(View.VISIBLE);
|
||||
statusView.setVisibility(View.GONE);
|
||||
statsMessage.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
totalBaseBasal.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
totalBaseBasal.clearFocus();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
totalBaseBasal.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (hasFocus) {
|
||||
totalBaseBasal.getText().clear();
|
||||
} else {
|
||||
SP.putString("TBB", totalBaseBasal.getText().toString());
|
||||
TBB = SP.getString("TBB", "");
|
||||
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(totalBaseBasal.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
|
||||
}
|
||||
|
||||
private void loadDataFromDB(byte type) {
|
||||
historyList = MainApp.getDbHelper().getDanaRHistoryRecordsByType(type);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cleanTable(tl);
|
||||
cleanTable(ctl);
|
||||
cleanTable(etl);
|
||||
DateFormat df = new SimpleDateFormat("dd.MM.");
|
||||
|
||||
if (TextUtils.isEmpty(TBB)) {
|
||||
totalBaseBasal.setError("Please Enter Total Base Basal");
|
||||
return;
|
||||
} else {
|
||||
magicNumber = SafeParse.stringToDouble(TBB);
|
||||
}
|
||||
|
||||
magicNumber *= 2;
|
||||
totalBaseBasal2.setText(decimalFormat.format(magicNumber));
|
||||
|
||||
int i = 0;
|
||||
double sum = 0d;
|
||||
double weighted03 = 0d;
|
||||
double weighted05 = 0d;
|
||||
double weighted07 = 0d;
|
||||
|
||||
for (DanaRHistoryRecord record : historyList) {
|
||||
double tdd = record.recordDailyBolus + record.recordDailyBasal;
|
||||
|
||||
// Create the table row
|
||||
TableRow tr = new TableRow(DanaRStatsActivity.this);
|
||||
if (i % 2 != 0) tr.setBackgroundColor(Color.DKGRAY);
|
||||
tr.setId(100 + i);
|
||||
tr.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
// Here create the TextView dynamically
|
||||
TextView labelDATE = new TextView(DanaRStatsActivity.this);
|
||||
labelDATE.setId(200 + i);
|
||||
labelDATE.setText(df.format(new Date(record.recordDate)));
|
||||
labelDATE.setTextColor(Color.WHITE);
|
||||
tr.addView(labelDATE);
|
||||
|
||||
TextView labelBASAL = new TextView(DanaRStatsActivity.this);
|
||||
labelBASAL.setId(300 + i);
|
||||
labelBASAL.setText(DecimalFormatter.to2Decimal(record.recordDailyBasal) + " U");
|
||||
labelBASAL.setTextColor(Color.WHITE);
|
||||
tr.addView(labelBASAL);
|
||||
|
||||
TextView labelBOLUS = new TextView(DanaRStatsActivity.this);
|
||||
labelBOLUS.setId(400 + i);
|
||||
labelBOLUS.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus) + " U");
|
||||
labelBOLUS.setTextColor(Color.WHITE);
|
||||
tr.addView(labelBOLUS);
|
||||
|
||||
TextView labelTDD = new TextView(DanaRStatsActivity.this);
|
||||
labelTDD.setId(500 + i);
|
||||
labelTDD.setText(DecimalFormatter.to2Decimal(tdd) + " U");
|
||||
labelTDD.setTextColor(Color.WHITE);
|
||||
tr.addView(labelTDD);
|
||||
|
||||
TextView labelRATIO = new TextView(DanaRStatsActivity.this);
|
||||
labelRATIO.setId(600 + i);
|
||||
labelRATIO.setText(Math.round(100 * tdd / magicNumber) + " %");
|
||||
labelRATIO.setTextColor(Color.WHITE);
|
||||
tr.addView(labelRATIO);
|
||||
|
||||
// add stats rows to tables
|
||||
tl.addView(tr, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
sum = sum + tdd;
|
||||
i++;
|
||||
|
||||
// Create the cumtable row
|
||||
TableRow ctr = new TableRow(DanaRStatsActivity.this);
|
||||
if (i % 2 == 0) ctr.setBackgroundColor(Color.DKGRAY);
|
||||
ctr.setId(700 + i);
|
||||
ctr.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
// Here create the TextView dynamically
|
||||
TextView labelDAYS = new TextView(DanaRStatsActivity.this);
|
||||
labelDAYS.setId(800 + i);
|
||||
labelDAYS.setText("" + i);
|
||||
labelDAYS.setTextColor(Color.WHITE);
|
||||
ctr.addView(labelDAYS);
|
||||
|
||||
TextView labelCUMTDD = new TextView(DanaRStatsActivity.this);
|
||||
labelCUMTDD.setId(900 + i);
|
||||
labelCUMTDD.setText(DecimalFormatter.to2Decimal(sum / i) + " U");
|
||||
labelCUMTDD.setTextColor(Color.WHITE);
|
||||
ctr.addView(labelCUMTDD);
|
||||
|
||||
TextView labelCUMRATIO = new TextView(DanaRStatsActivity.this);
|
||||
labelCUMRATIO.setId(1000 + i);
|
||||
labelCUMRATIO.setText(Math.round(100 * sum / i / magicNumber) + " %");
|
||||
labelCUMRATIO.setTextColor(Color.WHITE);
|
||||
ctr.addView(labelCUMRATIO);
|
||||
|
||||
// add cummulative rows to tables
|
||||
ctl.addView(ctr, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
|
||||
if (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).recordDate)).equals(df.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24))))) {
|
||||
statsMessage.setVisibility(View.VISIBLE);
|
||||
statsMessage.setText(getString(R.string.danar_stats_olddata_Message));
|
||||
|
||||
} else {
|
||||
tl.setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
Collections.reverse(historyList);
|
||||
|
||||
i = 0;
|
||||
|
||||
for (DanaRHistoryRecord record : historyList) {
|
||||
double tdd = record.recordDailyBolus + record.recordDailyBasal;
|
||||
if (i == 0) {
|
||||
weighted03 = tdd;
|
||||
weighted05 = tdd;
|
||||
weighted07 = tdd;
|
||||
|
||||
} else {
|
||||
weighted07 = (weighted07 * 0.3 + tdd * 0.7);
|
||||
weighted05 = (weighted05 * 0.5 + tdd * 0.5);
|
||||
weighted03 = (weighted03 * 0.7 + tdd * 0.3);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
// Create the exptable row
|
||||
TableRow etr = new TableRow(DanaRStatsActivity.this);
|
||||
if (i % 2 != 0) etr.setBackgroundColor(Color.DKGRAY);
|
||||
etr.setId(1100 + i);
|
||||
etr.setLayoutParams(new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
// Here create the TextView dynamically
|
||||
TextView labelWEIGHT = new TextView(DanaRStatsActivity.this);
|
||||
labelWEIGHT.setId(1200 + i);
|
||||
labelWEIGHT.setText("0.3\n" + "0.5\n" + "0.7");
|
||||
labelWEIGHT.setTextColor(Color.WHITE);
|
||||
etr.addView(labelWEIGHT);
|
||||
|
||||
TextView labelEXPTDD = new TextView(DanaRStatsActivity.this);
|
||||
labelEXPTDD.setId(1300 + i);
|
||||
labelEXPTDD.setText(DecimalFormatter.to2Decimal(weighted03)
|
||||
+ " U\n" + DecimalFormatter.to2Decimal(weighted05)
|
||||
+ " U\n" + DecimalFormatter.to2Decimal(weighted07) + " U");
|
||||
labelEXPTDD.setTextColor(Color.WHITE);
|
||||
etr.addView(labelEXPTDD);
|
||||
|
||||
TextView labelEXPRATIO = new TextView(DanaRStatsActivity.this);
|
||||
labelEXPRATIO.setId(1400 + i);
|
||||
labelEXPRATIO.setText(Math.round(100 * weighted03 / magicNumber) + " %\n"
|
||||
+ Math.round(100 * weighted05 / magicNumber) + " %\n"
|
||||
+ Math.round(100 * weighted07 / magicNumber) + " %");
|
||||
labelEXPRATIO.setTextColor(Color.WHITE);
|
||||
etr.addView(labelEXPRATIO);
|
||||
|
||||
// add exponentail rows to tables
|
||||
etl.addView(etr, new TableLayout.LayoutParams(
|
||||
TableLayout.LayoutParams.MATCH_PARENT,
|
||||
TableLayout.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void cleanTable(TableLayout table) {
|
||||
int childCount = table.getChildCount();
|
||||
// Remove all rows except the first one
|
||||
if (childCount > 1) {
|
||||
table.removeViews(1, childCount - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@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 EventPumpStatusChanged c) {
|
||||
runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
statusView.setText(c.textStatus());
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -285,12 +286,19 @@ public class TimeListEdit {
|
|||
|
||||
public void editItem(int index, int timeAsSeconds, double value1, double value2) {
|
||||
try {
|
||||
String time;
|
||||
int hour = timeAsSeconds / 60 / 60;
|
||||
DecimalFormat df = new DecimalFormat("00");
|
||||
time = df.format(hour) + ":00";
|
||||
|
||||
JSONObject newObject1 = new JSONObject();
|
||||
newObject1.put("time", time);
|
||||
newObject1.put("timeAsSeconds", timeAsSeconds);
|
||||
newObject1.put("value", value1);
|
||||
data1.put(index, newObject1);
|
||||
if (data2 != null) {
|
||||
JSONObject newObject2 = new JSONObject();
|
||||
newObject1.put("time", time);
|
||||
newObject2.put("timeAsSeconds", timeAsSeconds);
|
||||
newObject2.put("value", value2);
|
||||
data2.put(index, newObject2);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
android:layout_height="fill_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".plugins.PumpDanaR.History.DanaRHistoryActivity">
|
||||
tools:context=".plugins.PumpDanaR.activities.DanaRHistoryActivity">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
android:layout_height="fill_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".plugins.PumpDanaR.History.DanaRHistoryActivity">
|
||||
tools:context=".plugins.PumpDanaR.activities.DanaRHistoryActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/danar_statstop"
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="2"
|
||||
android:gravity="end"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/nsprofileview_activeprofile_label"
|
||||
|
@ -77,7 +77,7 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="2"
|
||||
android:gravity="end"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/nsprofileview_units_label"
|
||||
|
@ -122,7 +122,7 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="2"
|
||||
android:gravity="end"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/nsprofileview_dia_label"
|
||||
|
@ -167,7 +167,7 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="2"
|
||||
android:gravity="end"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/nsprofileview_ic_label"
|
||||
|
@ -212,7 +212,7 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="2"
|
||||
android:gravity="end"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/nsprofileview_isf_label"
|
||||
|
@ -257,7 +257,7 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="2"
|
||||
android:gravity="end"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/nsprofileview_basal_label"
|
||||
|
@ -302,7 +302,7 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="2"
|
||||
android:gravity="end"
|
||||
android:paddingRight="5dp"
|
||||
android:text="@string/nsprofileview_target_label"
|
||||
|
|
Loading…
Reference in a new issue