Singleton & Crashlytics logging part 1

This commit is contained in:
Milos Kozak 2017-10-06 16:39:59 +02:00
parent 4db82fd275
commit 0e763724f6
17 changed files with 519 additions and 442 deletions

View file

@ -29,7 +29,7 @@ import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesFragment;
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingPlugin;
import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingProlongedPlugin;
@ -37,12 +37,13 @@ import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin;
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin;
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefUltraRapidActingPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalFragment;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.receivers.AckAlarmReceiver;
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAFragment;
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment;
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.Persistentnotification.PersistentNotificationPlugin;
import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfileFragment;
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
@ -110,7 +111,7 @@ public class MainApp extends Application {
if (pluginsList == null) {
pluginsList = new ArrayList<>();
// Register all tabs in app here
pluginsList.add(OverviewFragment.getPlugin());
pluginsList.add(OverviewPlugin.getPlugin());
pluginsList.add(IobCobCalculatorPlugin.getPlugin());
if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin());
pluginsList.add(InsulinFastactingPlugin.getPlugin());
@ -127,9 +128,9 @@ public class MainApp extends Application {
pluginsList.add(CareportalFragment.getPlugin());
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin());
if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getInstance());
if (Config.LOOPENABLED) pluginsList.add(LoopFragment.getPlugin());
if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSMAFragment.getPlugin());
if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSAMAFragment.getPlugin());
if (Config.LOOPENABLED) pluginsList.add(LoopPlugin.getPlugin());
if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSMAPlugin.getPlugin());
if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
pluginsList.add(NSProfileFragment.getPlugin());
if (Config.OTHERPROFILES) pluginsList.add(SimpleProfileFragment.getPlugin());
if (Config.OTHERPROFILES) pluginsList.add(LocalProfileFragment.getPlugin());
@ -137,7 +138,7 @@ public class MainApp extends Application {
pluginsList.add(CircadianPercentageProfileFragment.getPlugin());
pluginsList.add(TreatmentsFragment.getPlugin());
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin());
if (Config.APS) pluginsList.add(ObjectivesFragment.getPlugin());
if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin());
if (!Config.NSCLIENT)
pluginsList.add(SourceXdripPlugin.getPlugin());
pluginsList.add(SourceNSClientPlugin.getPlugin());
@ -150,7 +151,7 @@ public class MainApp extends Application {
if (Config.WEAR) pluginsList.add(WearFragment.getPlugin(this));
pluginsList.add(StatuslinePlugin.getPlugin(this));
pluginsList.add(new PersistentNotificationPlugin(this));
pluginsList.add(NSClientInternalFragment.getPlugin());
pluginsList.add(NSClientInternalPlugin.getPlugin());
pluginsList.add(sConfigBuilder = ConfigBuilderFragment.getPlugin());

View file

@ -12,6 +12,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe;
@ -69,6 +70,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.actions_fragment, container, false);
profileSwitch = (Button) view.findViewById(R.id.actions_profileswitch);
@ -89,6 +91,11 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
updateGUI();
return view;
} catch (Exception e) {
Crashlytics.logException(e);
}
return null;
}
@Subscribe

View file

@ -12,6 +12,7 @@ import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.BuildConfig;
@ -71,6 +72,7 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.careportal_fragment, container, false);
view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this);
@ -99,9 +101,9 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
sage = (TextView) view.findViewById(R.id.careportal_sensorage);
pbage = (TextView) view.findViewById(R.id.careportal_pbage);
statsLayout = (View) view.findViewById(R.id.careportal_stats);
statsLayout = view.findViewById(R.id.careportal_stats);
noProfileView = (View) view.findViewById(R.id.profileview_noprofile);
noProfileView = view.findViewById(R.id.profileview_noprofile);
butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons);
ProfileStore profileStore = ConfigBuilderPlugin.getActiveProfileInterface().getProfile();
@ -118,6 +120,11 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
updateGUI();
return view;
} catch (Exception e) {
Crashlytics.logException(e);
}
return null;
}
@Override

View file

@ -15,6 +15,7 @@ import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
@ -79,6 +80,7 @@ public class ConfigBuilderFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.configbuilder_fragment, container, false);
insulinListView = (ListView) view.findViewById(R.id.configbuilder_insulinlistview);
@ -120,6 +122,11 @@ public class ConfigBuilderFragment extends Fragment {
unlock.setVisibility(View.GONE);
}
return view;
} catch (Exception e) {
Crashlytics.logException(e);
}
return null;
}
void setViews() {

View file

@ -15,6 +15,8 @@ import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -27,15 +29,6 @@ import info.nightscout.androidaps.R;
public class ObjectivesFragment extends Fragment {
private static Logger log = LoggerFactory.getLogger(ObjectivesFragment.class);
private static ObjectivesPlugin objectivesPlugin;
public static ObjectivesPlugin getPlugin() {
if (objectivesPlugin == null) {
objectivesPlugin = new ObjectivesPlugin();
}
return objectivesPlugin;
}
RecyclerView recyclerView;
LinearLayoutManager llm;
CheckBox enableFake;
@ -59,7 +52,7 @@ public class ObjectivesFragment extends Fragment {
@Override
public void onBindViewHolder(ObjectiveViewHolder holder, int position) {
ObjectivesPlugin.Objective o = objectives.get(position);
ObjectivesPlugin.RequirementResult requirementsMet = getPlugin().requirementsMet(position);
ObjectivesPlugin.RequirementResult requirementsMet = ObjectivesPlugin.getPlugin().requirementsMet(position);
Context context = MainApp.instance().getApplicationContext();
holder.position.setText(String.valueOf(position + 1));
holder.objective.setText(o.objective);
@ -83,7 +76,7 @@ public class ObjectivesFragment extends Fragment {
holder.verifyButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ObjectivesPlugin.Objective o = (ObjectivesPlugin.Objective) v.getTag();
if (getPlugin().requirementsMet(o.num).done || enableFake.isChecked()) {
if (ObjectivesPlugin.getPlugin().requirementsMet(o.num).done || enableFake.isChecked()) {
o.accomplished = new Date();
updateGUI();
ObjectivesPlugin.saveProgress();
@ -173,6 +166,7 @@ public class ObjectivesFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.objectives_fragment, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.objectives_recyclerview);
@ -189,29 +183,34 @@ public class ObjectivesFragment extends Fragment {
});
reset.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
getPlugin().initializeData();
getPlugin().saveProgress();
ObjectivesPlugin.getPlugin().initializeData();
ObjectivesPlugin.saveProgress();
updateGUI();
}
});
// Add correct translations to array after app is initialized
getPlugin().objectives.get(0).objective = MainApp.sResources.getString(R.string.objectives_0_objective);
getPlugin().objectives.get(1).objective = MainApp.sResources.getString(R.string.objectives_1_objective);
getPlugin().objectives.get(2).objective = MainApp.sResources.getString(R.string.objectives_2_objective);
getPlugin().objectives.get(3).objective = MainApp.sResources.getString(R.string.objectives_3_objective);
getPlugin().objectives.get(4).objective = MainApp.sResources.getString(R.string.objectives_4_objective);
getPlugin().objectives.get(5).objective = MainApp.sResources.getString(R.string.objectives_5_objective);
getPlugin().objectives.get(6).objective = MainApp.sResources.getString(R.string.objectives_6_objective);
getPlugin().objectives.get(0).gate = MainApp.sResources.getString(R.string.objectives_0_gate);
getPlugin().objectives.get(1).gate = MainApp.sResources.getString(R.string.objectives_1_gate);
getPlugin().objectives.get(2).gate = MainApp.sResources.getString(R.string.objectives_2_gate);
getPlugin().objectives.get(3).gate = MainApp.sResources.getString(R.string.objectives_3_gate);
getPlugin().objectives.get(4).gate = MainApp.sResources.getString(R.string.objectives_4_gate);
getPlugin().objectives.get(5).gate = MainApp.sResources.getString(R.string.objectives_5_gate);
ObjectivesPlugin.objectives.get(0).objective = MainApp.sResources.getString(R.string.objectives_0_objective);
ObjectivesPlugin.objectives.get(1).objective = MainApp.sResources.getString(R.string.objectives_1_objective);
ObjectivesPlugin.objectives.get(2).objective = MainApp.sResources.getString(R.string.objectives_2_objective);
ObjectivesPlugin.objectives.get(3).objective = MainApp.sResources.getString(R.string.objectives_3_objective);
ObjectivesPlugin.objectives.get(4).objective = MainApp.sResources.getString(R.string.objectives_4_objective);
ObjectivesPlugin.objectives.get(5).objective = MainApp.sResources.getString(R.string.objectives_5_objective);
ObjectivesPlugin.objectives.get(6).objective = MainApp.sResources.getString(R.string.objectives_6_objective);
ObjectivesPlugin.objectives.get(0).gate = MainApp.sResources.getString(R.string.objectives_0_gate);
ObjectivesPlugin.objectives.get(1).gate = MainApp.sResources.getString(R.string.objectives_1_gate);
ObjectivesPlugin.objectives.get(2).gate = MainApp.sResources.getString(R.string.objectives_2_gate);
ObjectivesPlugin.objectives.get(3).gate = MainApp.sResources.getString(R.string.objectives_3_gate);
ObjectivesPlugin.objectives.get(4).gate = MainApp.sResources.getString(R.string.objectives_4_gate);
ObjectivesPlugin.objectives.get(5).gate = MainApp.sResources.getString(R.string.objectives_5_gate);
updateGUI();
return view;
} catch (Exception e) {
Crashlytics.logException(e);
}
return null;
}
void updateGUI() {

View file

@ -25,11 +25,20 @@ import info.nightscout.utils.SP;
public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
private static Logger log = LoggerFactory.getLogger(ObjectivesPlugin.class);
private static ObjectivesPlugin objectivesPlugin;
public static ObjectivesPlugin getPlugin() {
if (objectivesPlugin == null) {
objectivesPlugin = new ObjectivesPlugin();
}
return objectivesPlugin;
}
public static List<Objective> objectives;
boolean fragmentVisible = true;
private boolean fragmentVisible = true;
public ObjectivesPlugin() {
private ObjectivesPlugin() {
initializeData();
loadProgress();
MainApp.bus().register(this);
@ -95,7 +104,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
if (type == CONSTRAINTS) this.fragmentVisible = fragmentVisible;
}
public class Objective {
class Objective {
Integer num;
String objective;
String gate;
@ -118,13 +127,13 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
public static boolean pumpStatusIsAvailableInNS = false;
// Objective 1
public static Integer manualEnacts = 0;
public static final Integer manualEnactsNeeded = 20;
private static final Integer manualEnactsNeeded = 20;
public class RequirementResult {
class RequirementResult {
boolean done = false;
String comment = "";
public RequirementResult(boolean done, String comment) {
RequirementResult(boolean done, String comment) {
this.done = done;
this.comment = comment;
}
@ -135,7 +144,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
else return "---";
}
public RequirementResult requirementsMet(Integer objNum) {
RequirementResult requirementsMet(Integer objNum) {
switch (objNum) {
case 0:
return new RequirementResult(bgIsAvailableInNS && pumpStatusIsAvailableInNS,
@ -152,7 +161,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
}
public void initializeData() {
void initializeData() {
bgIsAvailableInNS = false;
pumpStatusIsAvailableInNS = false;
manualEnacts = 0;
@ -220,7 +229,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
}
}
void loadProgress() {
private void loadProgress() {
for (int num = 0; num < objectives.size(); num++) {
Objective o = objectives.get(num);
try {

View file

@ -7,8 +7,11 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
/**
* Created by mike on 17.04.2017.
@ -22,6 +25,7 @@ public class InsulinFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.insulin_fragment, container, false);
insulinName = (TextView) view.findViewById(R.id.insulin_name);
@ -32,6 +36,11 @@ public class InsulinFragment extends Fragment {
updateGUI();
return view;
} catch (Exception e) {
Crashlytics.logException(e);
}
return null;
}
@Override
@ -41,10 +50,10 @@ public class InsulinFragment extends Fragment {
}
private void updateGUI() {
insulinName.setText(MainApp.getConfigBuilder().getActiveInsulin().getFriendlyName());
insulinComment.setText(MainApp.getConfigBuilder().getActiveInsulin().getComment());
insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + Double.toString(MainApp.getConfigBuilder().getActiveInsulin().getDia()) + "h");
insulinGraph.show(MainApp.getConfigBuilder().getActiveInsulin());
insulinName.setText(ConfigBuilderPlugin.getActiveInsulin().getFriendlyName());
insulinComment.setText(ConfigBuilderPlugin.getActiveInsulin().getComment());
insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + Double.toString(ConfigBuilderPlugin.getActiveInsulin().getDia()) + "h");
insulinGraph.show(ConfigBuilderPlugin.getActiveInsulin());
}
}

View file

@ -9,6 +9,7 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe;
@ -25,15 +26,6 @@ import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
public class LoopFragment extends SubscriberFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(LoopFragment.class);
private static LoopPlugin loopPlugin;
public static LoopPlugin getPlugin() {
if (loopPlugin == null){
loopPlugin = new LoopPlugin();
}
return loopPlugin;
}
Button runNowButton;
TextView lastRunView;
TextView lastEnactView;
@ -46,6 +38,7 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.loop_fragment, container, false);
lastRunView = (TextView) view.findViewById(R.id.loop_lastrun);
@ -59,6 +52,11 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
updateGUI();
return view;
} catch (Exception e) {
Crashlytics.logException(e);
}
return null;
}
@Override
@ -69,7 +67,7 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
getPlugin().invoke("Loop button", true);
LoopPlugin.getPlugin().invoke("Loop button", true);
}
});
thread.start();
@ -105,13 +103,13 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (getPlugin().lastRun != null) {
requestView.setText(getPlugin().lastRun.request != null ? getPlugin().lastRun.request.toSpanned() : "");
constraintsProcessedView.setText(getPlugin().lastRun.constraintsProcessed != null ? getPlugin().lastRun.constraintsProcessed.toSpanned() : "");
setByPumpView.setText(getPlugin().lastRun.setByPump != null ? getPlugin().lastRun.setByPump.toSpanned() : "");
sourceView.setText(getPlugin().lastRun.source != null ? getPlugin().lastRun.source : "");
lastRunView.setText(getPlugin().lastRun.lastAPSRun != null && getPlugin().lastRun.lastAPSRun.getTime() != 0 ? getPlugin().lastRun.lastAPSRun.toLocaleString() : "");
lastEnactView.setText(getPlugin().lastRun.lastEnact != null && getPlugin().lastRun.lastEnact.getTime() != 0 ? getPlugin().lastRun.lastEnact.toLocaleString() : "");
if (LoopPlugin.lastRun != null) {
requestView.setText(LoopPlugin.lastRun.request != null ? LoopPlugin.lastRun.request.toSpanned() : "");
constraintsProcessedView.setText(LoopPlugin.lastRun.constraintsProcessed != null ? LoopPlugin.lastRun.constraintsProcessed.toSpanned() : "");
setByPumpView.setText(LoopPlugin.lastRun.setByPump != null ? LoopPlugin.lastRun.setByPump.toSpanned() : "");
sourceView.setText(LoopPlugin.lastRun.source != null ? LoopPlugin.lastRun.source : "");
lastRunView.setText(LoopPlugin.lastRun.lastAPSRun != null && LoopPlugin.lastRun.lastAPSRun.getTime() != 0 ? LoopPlugin.lastRun.lastAPSRun.toLocaleString() : "");
lastEnactView.setText(LoopPlugin.lastRun.lastEnact != null && LoopPlugin.lastRun.lastEnact.getTime() != 0 ? LoopPlugin.lastRun.lastEnact.toLocaleString() : "");
}
}
});

View file

@ -46,6 +46,15 @@ import info.nightscout.utils.SafeParse;
public class LoopPlugin implements PluginBase {
private static Logger log = LoggerFactory.getLogger(LoopPlugin.class);
private static LoopPlugin loopPlugin;
public static LoopPlugin getPlugin() {
if (loopPlugin == null) {
loopPlugin = new LoopPlugin();
}
return loopPlugin;
}
private static Handler sHandler;
private static HandlerThread sHandlerThread;

View file

@ -18,6 +18,7 @@ import android.widget.CompoundButton;
import android.widget.ScrollView;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe;
@ -37,15 +38,6 @@ import info.nightscout.utils.SP;
public class NSClientInternalFragment extends SubscriberFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
private static Logger log = LoggerFactory.getLogger(NSClientInternalFragment.class);
static NSClientInternalPlugin nsClientInternalPlugin;
static public NSClientInternalPlugin getPlugin() {
if (nsClientInternalPlugin == null) {
nsClientInternalPlugin = new NSClientInternalPlugin();
}
return nsClientInternalPlugin;
}
private TextView logTextView;
private TextView queueTextView;
private TextView urlTextView;
@ -62,14 +54,15 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.nsclientinternal_fragment, container, false);
logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll);
autoscrollCheckbox.setChecked(getPlugin().autoscroll);
autoscrollCheckbox.setChecked(NSClientInternalPlugin.getPlugin().autoscroll);
autoscrollCheckbox.setOnCheckedChangeListener(this);
pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused);
pausedCheckbox.setChecked(getPlugin().paused);
pausedCheckbox.setChecked(NSClientInternalPlugin.getPlugin().paused);
pausedCheckbox.setOnCheckedChangeListener(this);
logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log);
queueTextView = (TextView) view.findViewById(R.id.nsclientinternal_queue);
@ -94,6 +87,11 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
updateGUI();
return view;
} catch (Exception e) {
Crashlytics.logException(e);
}
return null;
}
@Override
@ -104,11 +102,11 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
Answers.getInstance().logCustom(new CustomEvent("NSClientRestart"));
break;
case R.id.nsclientinternal_delivernow:
getPlugin().resend("GUI");
NSClientInternalPlugin.getPlugin().resend("GUI");
Answers.getInstance().logCustom(new CustomEvent("NSClientDeliverNow"));
break;
case R.id.nsclientinternal_clearlog:
getPlugin().clearLog();
NSClientInternalPlugin.getPlugin().clearLog();
break;
case R.id.nsclientinternal_clearqueue:
final Context context = getContext();
@ -127,7 +125,7 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
builder.show();
break;
case R.id.nsclientinternal_showqueue:
MainApp.bus().post(new EventNSClientNewLog("QUEUE", getPlugin().queue().textList()));
MainApp.bus().post(new EventNSClientNewLog("QUEUE", NSClientInternalPlugin.getPlugin().queue().textList()));
Answers.getInstance().logCustom(new CustomEvent("NSClientShowQueue"));
break;
}
@ -138,14 +136,14 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
switch (buttonView.getId()) {
case R.id.nsclientinternal_paused:
SP.putBoolean(R.string.key_nsclientinternal_paused, isChecked);
getPlugin().paused = isChecked;
NSClientInternalPlugin.getPlugin().paused = isChecked;
MainApp.bus().post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
updateGUI();
Answers.getInstance().logCustom(new CustomEvent("NSClientPause"));
break;
case R.id.nsclientinternal_autoscroll:
SP.putBoolean(R.string.key_nsclientinternal_autoscroll, isChecked);
getPlugin().autoscroll = isChecked;
NSClientInternalPlugin.getPlugin().autoscroll = isChecked;
updateGUI();
break;
}
@ -165,13 +163,13 @@ public class NSClientInternalFragment extends SubscriberFragment implements View
public void run() {
NSClientInternalPlugin.updateLog();
logTextView.setText(NSClientInternalPlugin.textLog);
if (getPlugin().autoscroll) {
if (NSClientInternalPlugin.getPlugin().autoscroll) {
logScrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
urlTextView.setText(getPlugin().url());
urlTextView.setText(NSClientInternalPlugin.getPlugin().url());
Spanned queuetext = Html.fromHtml(MainApp.sResources.getString(R.string.queue) + " <b>" + UploadQueue.size() + "</b>");
queueTextView.setText(queuetext);
statusTextView.setText(getPlugin().status);
statusTextView.setText(NSClientInternalPlugin.getPlugin().status);
}
});
}

View file

@ -34,6 +34,15 @@ import info.nightscout.utils.ToastUtils;
public class NSClientInternalPlugin implements PluginBase {
private static Logger log = LoggerFactory.getLogger(NSClientInternalPlugin.class);
static NSClientInternalPlugin nsClientInternalPlugin;
static public NSClientInternalPlugin getPlugin() {
if (nsClientInternalPlugin == null) {
nsClientInternalPlugin = new NSClientInternalPlugin();
}
return nsClientInternalPlugin;
}
private boolean fragmentEnabled = true;
private boolean fragmentVisible = true;

View file

@ -9,6 +9,7 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe;
@ -28,15 +29,6 @@ import info.nightscout.utils.JSONFormatter;
public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(OpenAPSAMAFragment.class);
private static OpenAPSAMAPlugin openAPSAMAPlugin;
public static OpenAPSAMAPlugin getPlugin() {
if(openAPSAMAPlugin ==null){
openAPSAMAPlugin = new OpenAPSAMAPlugin();
}
return openAPSAMAPlugin;
}
Button run;
TextView lastRunView;
TextView glucoseStatusView;
@ -52,6 +44,7 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.openapsama_fragment, container, false);
run = (Button) view.findViewById(R.id.openapsma_run);
@ -69,13 +62,18 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
updateGUI();
return view;
} catch (Exception e) {
Crashlytics.logException(e);
}
return null;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.openapsma_run:
getPlugin().invoke("OpenAPSAMA button");
OpenAPSAMAPlugin.getPlugin().invoke("OpenAPSAMA button");
Answers.getInstance().logCustom(new CustomEvent("OpenAPS_AMA_Run"));
break;
}
@ -99,12 +97,12 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
DetermineBasalResultAMA lastAPSResult = getPlugin().lastAPSResult;
DetermineBasalResultAMA lastAPSResult = OpenAPSAMAPlugin.getPlugin().lastAPSResult;
if (lastAPSResult != null) {
resultView.setText(JSONFormatter.format(lastAPSResult.json));
requestView.setText(lastAPSResult.toSpanned());
}
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS = getPlugin().lastDetermineBasalAdapterAMAJS;
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS = OpenAPSAMAPlugin.getPlugin().lastDetermineBasalAdapterAMAJS;
if (determineBasalAdapterAMAJS != null) {
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getGlucoseStatusParam()));
currentTempView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getCurrentTempParam()));
@ -119,11 +117,11 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
mealDataView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getMealDataParam()));
scriptdebugView.setText(determineBasalAdapterAMAJS.getScriptDebug());
}
if (getPlugin().lastAPSRun != null) {
lastRunView.setText(getPlugin().lastAPSRun.toLocaleString());
if (OpenAPSAMAPlugin.getPlugin().lastAPSRun != null) {
lastRunView.setText(OpenAPSAMAPlugin.getPlugin().lastAPSRun.toLocaleString());
}
if (getPlugin().lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(getPlugin().lastAutosensResult.json()));
if (OpenAPSAMAPlugin.getPlugin().lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(OpenAPSAMAPlugin.getPlugin().lastAutosensResult.json()));
}
}
});

View file

@ -39,14 +39,23 @@ import info.nightscout.utils.ToastUtils;
public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
private static Logger log = LoggerFactory.getLogger(OpenAPSAMAPlugin.class);
private static OpenAPSAMAPlugin openAPSAMAPlugin;
public static OpenAPSAMAPlugin getPlugin() {
if (openAPSAMAPlugin == null) {
openAPSAMAPlugin = new OpenAPSAMAPlugin();
}
return openAPSAMAPlugin;
}
// last values
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
Date lastAPSRun = null;
DetermineBasalResultAMA lastAPSResult = null;
AutosensResult lastAutosensResult = null;
boolean fragmentEnabled = false;
boolean fragmentVisible = true;
private boolean fragmentEnabled = false;
private boolean fragmentVisible = true;
@Override
public String getName() {
@ -196,9 +205,9 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
maxBasal = verifyHardLimits(maxBasal, "max_basal", 0.1, 10);
if (!checkOnlyHardLimits(profile.getDia(), "dia", 2, 7)) return;
if (!checkOnlyHardLimits(profile.getIc(profile.secondsFromMidnight()), "carbratio", 2, 100))
if (!checkOnlyHardLimits(profile.getIc(Profile.secondsFromMidnight()), "carbratio", 2, 100))
return;
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf().doubleValue(), units), "sens", 2, 900))
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", 2, 900))
return;
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;

View file

@ -9,6 +9,7 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe;
@ -26,15 +27,6 @@ import info.nightscout.utils.JSONFormatter;
public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(OpenAPSMAFragment.class);
private static OpenAPSMAPlugin openAPSMAPlugin;
public static OpenAPSMAPlugin getPlugin() {
if (openAPSMAPlugin == null) {
openAPSMAPlugin = new OpenAPSMAPlugin();
}
return openAPSMAPlugin;
}
Button run;
TextView lastRunView;
TextView glucoseStatusView;
@ -48,6 +40,7 @@ public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClic
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.openapsma_fragment, container, false);
run = (Button) view.findViewById(R.id.openapsma_run);
@ -63,13 +56,18 @@ public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClic
updateGUI();
return view;
} catch (Exception e) {
Crashlytics.logException(e);
}
return null;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.openapsma_run:
getPlugin().invoke("OpenAPSMA button");
OpenAPSMAPlugin.getPlugin().invoke("OpenAPSMA button");
Answers.getInstance().logCustom(new CustomEvent("OpenAPS_MA_Run"));
break;
}
@ -93,12 +91,12 @@ public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClic
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
DetermineBasalResultMA lastAPSResult = getPlugin().lastAPSResult;
DetermineBasalResultMA lastAPSResult = OpenAPSMAPlugin.getPlugin().lastAPSResult;
if (lastAPSResult != null) {
resultView.setText(JSONFormatter.format(lastAPSResult.json));
requestView.setText(lastAPSResult.toSpanned());
}
DetermineBasalAdapterMAJS determineBasalAdapterMAJS = getPlugin().lastDetermineBasalAdapterMAJS;
DetermineBasalAdapterMAJS determineBasalAdapterMAJS = OpenAPSMAPlugin.getPlugin().lastDetermineBasalAdapterMAJS;
if (determineBasalAdapterMAJS != null) {
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getGlucoseStatusParam()));
currentTempView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getCurrentTempParam()));
@ -106,8 +104,8 @@ public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClic
profileView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getProfileParam()));
mealDataView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getMealDataParam()));
}
if (getPlugin().lastAPSRun != null) {
lastRunView.setText(getPlugin().lastAPSRun.toLocaleString());
if (OpenAPSMAPlugin.getPlugin().lastAPSRun != null) {
lastRunView.setText(OpenAPSMAPlugin.getPlugin().lastAPSRun.toLocaleString());
}
}
});

View file

@ -38,13 +38,22 @@ import static info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin.ver
public class OpenAPSMAPlugin implements PluginBase, APSInterface {
private static Logger log = LoggerFactory.getLogger(OpenAPSMAPlugin.class);
private static OpenAPSMAPlugin openAPSMAPlugin;
public static OpenAPSMAPlugin getPlugin() {
if (openAPSMAPlugin == null) {
openAPSMAPlugin = new OpenAPSMAPlugin();
}
return openAPSMAPlugin;
}
// last values
DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null;
Date lastAPSRun = null;
DetermineBasalResultMA lastAPSResult = null;
boolean fragmentEnabled = false;
boolean fragmentVisible = true;
private boolean fragmentEnabled = false;
private boolean fragmentVisible = true;
@Override
public String getName() {
@ -196,7 +205,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
if (!checkOnlyHardLimits(profile.getDia(), "dia", 2, 7)) return;
if (!checkOnlyHardLimits(profile.getIc(), "carbratio", 2, 100)) return;
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf().doubleValue(), units), "sens", 2, 900))
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", 2, 900))
return;
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;

View file

@ -33,6 +33,7 @@ import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.jjoe64.graphview.GraphView;
@ -133,12 +134,6 @@ import info.nightscout.utils.ToastUtils;
public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
private static Logger log = LoggerFactory.getLogger(OverviewFragment.class);
private static OverviewPlugin overviewPlugin = new OverviewPlugin();
public static OverviewPlugin getPlugin() {
return overviewPlugin;
}
TextView timeView;
TextView bgView;
TextView arrowView;
@ -214,6 +209,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
//check screen width
final DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
@ -344,6 +340,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
return view;
} catch (Exception e) {
Crashlytics.logException(e);
}
return null;
}
@ -638,7 +639,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final Profile profile = MainApp.getConfigBuilder().getProfile();
final TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory();
QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive();
QuickWizard.QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
if (quickWizardEntry != null && actualBg != null) {
quickWizardButton.setVisibility(View.VISIBLE);
BolusWizard wizard = new BolusWizard();
@ -1118,7 +1119,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
tempTargetView.setLongClickable(true);
// QuickWizard button
QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive();
QuickWizard.QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) {
quickWizardButton.setVisibility(View.VISIBLE);
String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
@ -1805,7 +1806,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// Adding current time to snooze if we got staleData
log.debug("Notification text is: " + notification.text);
if (notification.text.equals(MainApp.sResources.getString(R.string.nsalarm_staledata))) {
NotificationStore nstore = getPlugin().notificationStore;
NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore;
long msToSnooze = SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L;
log.debug("snooze nsalarm_staledatavalue in minutes is " + SP.getInt("nsalarm_staledatavalue", 15) + "\n in ms is: " + msToSnooze + " currentTimeMillis is: " + System.currentTimeMillis());
nstore.snoozeTo(System.currentTimeMillis() + (SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L));
@ -1822,7 +1823,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
NotificationStore nstore = getPlugin().notificationStore;
NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore;
nstore.removeExpired();
nstore.unSnooze();
if (nstore.store.size() > 0) {

View file

@ -21,6 +21,15 @@ import info.nightscout.utils.SP;
public class OverviewPlugin implements PluginBase {
private static Logger log = LoggerFactory.getLogger(OverviewPlugin.class);
private static OverviewPlugin overviewPlugin = new OverviewPlugin();
public static OverviewPlugin getPlugin() {
if (overviewPlugin == null)
overviewPlugin = new OverviewPlugin();
return overviewPlugin;
}
public static double bgTargetLow = 80d;
public static double bgTargetHigh = 180d;