From 0e763724f6104d3e33be66cf9180d3c86d00ce28 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 6 Oct 2017 16:39:59 +0200 Subject: [PATCH] Singleton & Crashlytics logging part 1 --- .../info/nightscout/androidaps/MainApp.java | 23 +- .../plugins/Actions/ActionsFragment.java | 41 +-- .../Careportal/CareportalFragment.java | 87 +++--- .../ConfigBuilder/ConfigBuilderFragment.java | 79 +++--- .../ObjectivesFragment.java | 93 +++---- .../ObjectivesPlugin.java | 27 +- .../plugins/Insulin/InsulinFragment.java | 31 ++- .../androidaps/plugins/Loop/LoopFragment.java | 54 ++-- .../androidaps/plugins/Loop/LoopPlugin.java | 9 + .../NSClientInternalFragment.java | 90 +++--- .../NSClientInternalPlugin.java | 9 + .../OpenAPSAMA/OpenAPSAMAFragment.java | 60 ++-- .../plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 17 +- .../plugins/OpenAPSMA/OpenAPSMAFragment.java | 52 ++-- .../plugins/OpenAPSMA/OpenAPSMAPlugin.java | 15 +- .../plugins/Overview/OverviewFragment.java | 263 +++++++++--------- .../plugins/Overview/OverviewPlugin.java | 11 +- 17 files changed, 519 insertions(+), 442 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index fcd92331b0..150aaa1ae6 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -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()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index 849f875567..ade5e074ba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -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,26 +70,32 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.actions_fragment, container, false); + try { + View view = inflater.inflate(R.layout.actions_fragment, container, false); - profileSwitch = (Button) view.findViewById(R.id.actions_profileswitch); - tempTarget = (Button) view.findViewById(R.id.actions_temptarget); - extendedBolus = (Button) view.findViewById(R.id.actions_extendedbolus); - extendedBolusCancel = (Button) view.findViewById(R.id.actions_extendedbolus_cancel); - tempBasal = (Button) view.findViewById(R.id.actions_settempbasal); - tempBasalCancel = (Button) view.findViewById(R.id.actions_canceltempbasal); - fill = (Button) view.findViewById(R.id.actions_fill); + profileSwitch = (Button) view.findViewById(R.id.actions_profileswitch); + tempTarget = (Button) view.findViewById(R.id.actions_temptarget); + extendedBolus = (Button) view.findViewById(R.id.actions_extendedbolus); + extendedBolusCancel = (Button) view.findViewById(R.id.actions_extendedbolus_cancel); + tempBasal = (Button) view.findViewById(R.id.actions_settempbasal); + tempBasalCancel = (Button) view.findViewById(R.id.actions_canceltempbasal); + fill = (Button) view.findViewById(R.id.actions_fill); - profileSwitch.setOnClickListener(this); - tempTarget.setOnClickListener(this); - extendedBolus.setOnClickListener(this); - extendedBolusCancel.setOnClickListener(this); - tempBasal.setOnClickListener(this); - tempBasalCancel.setOnClickListener(this); - fill.setOnClickListener(this); + profileSwitch.setOnClickListener(this); + tempTarget.setOnClickListener(this); + extendedBolus.setOnClickListener(this); + extendedBolusCancel.setOnClickListener(this); + tempBasal.setOnClickListener(this); + tempBasalCancel.setOnClickListener(this); + fill.setOnClickListener(this); - updateGUI(); - return view; + updateGUI(); + return view; + } catch (Exception e) { + Crashlytics.logException(e); + } + + return null; } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java index 2353fa6645..6550959867 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java @@ -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,53 +72,59 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.careportal_fragment, container, false); + try { + View view = inflater.inflate(R.layout.careportal_fragment, container, false); - view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this); - view.findViewById(R.id.careportal_announcement).setOnClickListener(this); - view.findViewById(R.id.careportal_cgmsensorinsert).setOnClickListener(this); - view.findViewById(R.id.careportal_cgmsensorstart).setOnClickListener(this); - view.findViewById(R.id.careportal_combobolus).setOnClickListener(this); - view.findViewById(R.id.careportal_correctionbolus).setOnClickListener(this); - view.findViewById(R.id.careportal_carbscorrection).setOnClickListener(this); - view.findViewById(R.id.careportal_exercise).setOnClickListener(this); - view.findViewById(R.id.careportal_insulincartridgechange).setOnClickListener(this); - view.findViewById(R.id.careportal_pumpbatterychange).setOnClickListener(this); - view.findViewById(R.id.careportal_mealbolus).setOnClickListener(this); - view.findViewById(R.id.careportal_note).setOnClickListener(this); - view.findViewById(R.id.careportal_profileswitch).setOnClickListener(this); - view.findViewById(R.id.careportal_pumpsitechange).setOnClickListener(this); - view.findViewById(R.id.careportal_question).setOnClickListener(this); - view.findViewById(R.id.careportal_snackbolus).setOnClickListener(this); - view.findViewById(R.id.careportal_tempbasalend).setOnClickListener(this); - view.findViewById(R.id.careportal_tempbasalstart).setOnClickListener(this); - view.findViewById(R.id.careportal_openapsoffline).setOnClickListener(this); - view.findViewById(R.id.careportal_temporarytarget).setOnClickListener(this); + view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this); + view.findViewById(R.id.careportal_announcement).setOnClickListener(this); + view.findViewById(R.id.careportal_cgmsensorinsert).setOnClickListener(this); + view.findViewById(R.id.careportal_cgmsensorstart).setOnClickListener(this); + view.findViewById(R.id.careportal_combobolus).setOnClickListener(this); + view.findViewById(R.id.careportal_correctionbolus).setOnClickListener(this); + view.findViewById(R.id.careportal_carbscorrection).setOnClickListener(this); + view.findViewById(R.id.careportal_exercise).setOnClickListener(this); + view.findViewById(R.id.careportal_insulincartridgechange).setOnClickListener(this); + view.findViewById(R.id.careportal_pumpbatterychange).setOnClickListener(this); + view.findViewById(R.id.careportal_mealbolus).setOnClickListener(this); + view.findViewById(R.id.careportal_note).setOnClickListener(this); + view.findViewById(R.id.careportal_profileswitch).setOnClickListener(this); + view.findViewById(R.id.careportal_pumpsitechange).setOnClickListener(this); + view.findViewById(R.id.careportal_question).setOnClickListener(this); + view.findViewById(R.id.careportal_snackbolus).setOnClickListener(this); + view.findViewById(R.id.careportal_tempbasalend).setOnClickListener(this); + view.findViewById(R.id.careportal_tempbasalstart).setOnClickListener(this); + view.findViewById(R.id.careportal_openapsoffline).setOnClickListener(this); + view.findViewById(R.id.careportal_temporarytarget).setOnClickListener(this); - iage = (TextView) view.findViewById(R.id.careportal_insulinage); - cage = (TextView) view.findViewById(R.id.careportal_canulaage); - sage = (TextView) view.findViewById(R.id.careportal_sensorage); - pbage = (TextView) view.findViewById(R.id.careportal_pbage); + iage = (TextView) view.findViewById(R.id.careportal_insulinage); + cage = (TextView) view.findViewById(R.id.careportal_canulaage); + 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); - butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons); + noProfileView = view.findViewById(R.id.profileview_noprofile); + butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons); - ProfileStore profileStore = ConfigBuilderPlugin.getActiveProfileInterface().getProfile(); - if (profileStore == null) { - noProfileView.setVisibility(View.VISIBLE); - butonsLayout.setVisibility(View.GONE); - } else { - noProfileView.setVisibility(View.GONE); - butonsLayout.setVisibility(View.VISIBLE); + ProfileStore profileStore = ConfigBuilderPlugin.getActiveProfileInterface().getProfile(); + if (profileStore == null) { + noProfileView.setVisibility(View.VISIBLE); + butonsLayout.setVisibility(View.GONE); + } else { + noProfileView.setVisibility(View.GONE); + butonsLayout.setVisibility(View.VISIBLE); + } + + if (BuildConfig.NSCLIENTOLNY) + statsLayout.setVisibility(View.GONE); // visible on overview + + updateGUI(); + return view; + } catch (Exception e) { + Crashlytics.logException(e); } - if (BuildConfig.NSCLIENTOLNY) - statsLayout.setVisibility(View.GONE); // visible on overview - - updateGUI(); - return view; + return null; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java index e79c1b06ba..cb4a1ee265 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java @@ -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,47 +80,53 @@ public class ConfigBuilderFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.configbuilder_fragment, container, false); + try { + View view = inflater.inflate(R.layout.configbuilder_fragment, container, false); - insulinListView = (ListView) view.findViewById(R.id.configbuilder_insulinlistview); - sensitivityListView = (ListView) view.findViewById(R.id.configbuilder_sensitivitylistview); - bgsourceListView = (ListView) view.findViewById(R.id.configbuilder_bgsourcelistview); - bgsourceLabel = (TextView) view.findViewById(R.id.configbuilder_bgsourcelabel); - pumpListView = (ListView) view.findViewById(R.id.configbuilder_pumplistview); - pumpLabel = (TextView) view.findViewById(R.id.configbuilder_pumplabel); - loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview); - loopLabel = (TextView) view.findViewById(R.id.configbuilder_looplabel); - profileListView = (ListView) view.findViewById(R.id.configbuilder_profilelistview); - profileLabel = (TextView) view.findViewById(R.id.configbuilder_profilelabel); - apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview); - apsLabel = (TextView) view.findViewById(R.id.configbuilder_apslabel); - constraintsListView = (ListView) view.findViewById(R.id.configbuilder_constraintslistview); - constraintsLabel = (TextView) view.findViewById(R.id.configbuilder_constraintslabel); - generalListView = (ListView) view.findViewById(R.id.configbuilder_generallistview); + insulinListView = (ListView) view.findViewById(R.id.configbuilder_insulinlistview); + sensitivityListView = (ListView) view.findViewById(R.id.configbuilder_sensitivitylistview); + bgsourceListView = (ListView) view.findViewById(R.id.configbuilder_bgsourcelistview); + bgsourceLabel = (TextView) view.findViewById(R.id.configbuilder_bgsourcelabel); + pumpListView = (ListView) view.findViewById(R.id.configbuilder_pumplistview); + pumpLabel = (TextView) view.findViewById(R.id.configbuilder_pumplabel); + loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview); + loopLabel = (TextView) view.findViewById(R.id.configbuilder_looplabel); + profileListView = (ListView) view.findViewById(R.id.configbuilder_profilelistview); + profileLabel = (TextView) view.findViewById(R.id.configbuilder_profilelabel); + apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview); + apsLabel = (TextView) view.findViewById(R.id.configbuilder_apslabel); + constraintsListView = (ListView) view.findViewById(R.id.configbuilder_constraintslistview); + constraintsLabel = (TextView) view.findViewById(R.id.configbuilder_constraintslabel); + generalListView = (ListView) view.findViewById(R.id.configbuilder_generallistview); - mainLayout = (LinearLayout) view.findViewById(R.id.configbuilder_mainlayout); - unlock = (Button) view.findViewById(R.id.configbuilder_unlock); + mainLayout = (LinearLayout) view.findViewById(R.id.configbuilder_mainlayout); + unlock = (Button) view.findViewById(R.id.configbuilder_unlock); - setViews(); + setViews(); - if (PasswordProtection.isLocked("settings_password")) { - mainLayout.setVisibility(View.GONE); - unlock.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() { - @Override - public void run() { - mainLayout.setVisibility(View.VISIBLE); - unlock.setVisibility(View.GONE); - } - }, null); - } - }); - } else { - unlock.setVisibility(View.GONE); + if (PasswordProtection.isLocked("settings_password")) { + mainLayout.setVisibility(View.GONE); + unlock.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() { + @Override + public void run() { + mainLayout.setVisibility(View.VISIBLE); + unlock.setVisibility(View.GONE); + } + }, null); + } + }); + } else { + unlock.setVisibility(View.GONE); + } + return view; + } catch (Exception e) { + Crashlytics.logException(e); } - return view; + + return null; } void setViews() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java index 906bf243ff..f633c1b5ac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java @@ -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,45 +166,51 @@ public class ObjectivesFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.objectives_fragment, container, false); + try { + View view = inflater.inflate(R.layout.objectives_fragment, container, false); - recyclerView = (RecyclerView) view.findViewById(R.id.objectives_recyclerview); - recyclerView.setHasFixedSize(true); - llm = new LinearLayoutManager(view.getContext()); - recyclerView.setLayoutManager(llm); - enableFake = (CheckBox) view.findViewById(R.id.objectives_fake); - fake_layout = (LinearLayout) view.findViewById(R.id.objectives_fake_layout); - reset = (TextView) view.findViewById(R.id.objectives_reset); - enableFake.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - updateGUI(); - } - }); - reset.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - getPlugin().initializeData(); - getPlugin().saveProgress(); - updateGUI(); - } - }); + recyclerView = (RecyclerView) view.findViewById(R.id.objectives_recyclerview); + recyclerView.setHasFixedSize(true); + llm = new LinearLayoutManager(view.getContext()); + recyclerView.setLayoutManager(llm); + enableFake = (CheckBox) view.findViewById(R.id.objectives_fake); + fake_layout = (LinearLayout) view.findViewById(R.id.objectives_fake_layout); + reset = (TextView) view.findViewById(R.id.objectives_reset); + enableFake.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + updateGUI(); + } + }); + reset.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + 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); - updateGUI(); + // Add correct translations to array after app is initialized + 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; + return view; + } catch (Exception e) { + Crashlytics.logException(e); + } + + return null; } void updateGUI() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index 81e0493746..7c353e48e2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -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 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 { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java index 7cd14f346c..f9a9ce38fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFragment.java @@ -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,16 +25,22 @@ public class InsulinFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.insulin_fragment, container, false); + try { + View view = inflater.inflate(R.layout.insulin_fragment, container, false); - insulinName = (TextView) view.findViewById(R.id.insulin_name); - insulinComment = (TextView) view.findViewById(R.id.insulin_comment); - insulinDia = (TextView) view.findViewById(R.id.insulin_dia); - insulinGraph = (ActivityGraph) view.findViewById(R.id.insuling_graph); + insulinName = (TextView) view.findViewById(R.id.insulin_name); + insulinComment = (TextView) view.findViewById(R.id.insulin_comment); + insulinDia = (TextView) view.findViewById(R.id.insulin_dia); + insulinGraph = (ActivityGraph) view.findViewById(R.id.insuling_graph); - updateGUI(); + updateGUI(); - return view; + 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()); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java index 2fb143517b..1b696988b2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java @@ -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,19 +38,25 @@ public class LoopFragment extends SubscriberFragment implements View.OnClickList @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.loop_fragment, container, false); + try { + View view = inflater.inflate(R.layout.loop_fragment, container, false); - lastRunView = (TextView) view.findViewById(R.id.loop_lastrun); - lastEnactView = (TextView) view.findViewById(R.id.loop_lastenact); - sourceView = (TextView) view.findViewById(R.id.loop_source); - requestView = (TextView) view.findViewById(R.id.loop_request); - constraintsProcessedView = (TextView) view.findViewById(R.id.loop_constraintsprocessed); - setByPumpView = (TextView) view.findViewById(R.id.loop_setbypump); - runNowButton = (Button) view.findViewById(R.id.loop_run); - runNowButton.setOnClickListener(this); + lastRunView = (TextView) view.findViewById(R.id.loop_lastrun); + lastEnactView = (TextView) view.findViewById(R.id.loop_lastenact); + sourceView = (TextView) view.findViewById(R.id.loop_source); + requestView = (TextView) view.findViewById(R.id.loop_request); + constraintsProcessedView = (TextView) view.findViewById(R.id.loop_constraintsprocessed); + setByPumpView = (TextView) view.findViewById(R.id.loop_setbypump); + runNowButton = (Button) view.findViewById(R.id.loop_run); + runNowButton.setOnClickListener(this); - updateGUI(); - return view; + 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() : ""); } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index 6e459a03b2..f1fc88625e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -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; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalFragment.java index 164e9902df..8cd9432f81 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalFragment.java @@ -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,38 +54,44 @@ public class NSClientInternalFragment extends SubscriberFragment implements View @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.nsclientinternal_fragment, container, false); + 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.setOnCheckedChangeListener(this); - pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused); - pausedCheckbox.setChecked(getPlugin().paused); - pausedCheckbox.setOnCheckedChangeListener(this); - logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log); - queueTextView = (TextView) view.findViewById(R.id.nsclientinternal_queue); - urlTextView = (TextView) view.findViewById(R.id.nsclientinternal_url); - statusTextView = (TextView) view.findViewById(R.id.nsclientinternal_status); + logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview); + autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll); + autoscrollCheckbox.setChecked(NSClientInternalPlugin.getPlugin().autoscroll); + autoscrollCheckbox.setOnCheckedChangeListener(this); + pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_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); + urlTextView = (TextView) view.findViewById(R.id.nsclientinternal_url); + statusTextView = (TextView) view.findViewById(R.id.nsclientinternal_status); - clearlog = (TextView) view.findViewById(R.id.nsclientinternal_clearlog); - clearlog.setOnClickListener(this); - clearlog.setPaintFlags(clearlog.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - restart = (TextView) view.findViewById(R.id.nsclientinternal_restart); - restart.setOnClickListener(this); - restart.setPaintFlags(restart.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - delivernow = (TextView) view.findViewById(R.id.nsclientinternal_delivernow); - delivernow.setOnClickListener(this); - delivernow.setPaintFlags(delivernow.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - clearqueue = (TextView) view.findViewById(R.id.nsclientinternal_clearqueue); - clearqueue.setOnClickListener(this); - clearqueue.setPaintFlags(clearqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - showqueue = (TextView) view.findViewById(R.id.nsclientinternal_showqueue); - showqueue.setOnClickListener(this); - showqueue.setPaintFlags(showqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + clearlog = (TextView) view.findViewById(R.id.nsclientinternal_clearlog); + clearlog.setOnClickListener(this); + clearlog.setPaintFlags(clearlog.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + restart = (TextView) view.findViewById(R.id.nsclientinternal_restart); + restart.setOnClickListener(this); + restart.setPaintFlags(restart.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + delivernow = (TextView) view.findViewById(R.id.nsclientinternal_delivernow); + delivernow.setOnClickListener(this); + delivernow.setPaintFlags(delivernow.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + clearqueue = (TextView) view.findViewById(R.id.nsclientinternal_clearqueue); + clearqueue.setOnClickListener(this); + clearqueue.setPaintFlags(clearqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + showqueue = (TextView) view.findViewById(R.id.nsclientinternal_showqueue); + showqueue.setOnClickListener(this); + showqueue.setPaintFlags(showqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - updateGUI(); - return 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) + " " + UploadQueue.size() + ""); queueTextView.setText(queuetext); - statusTextView.setText(getPlugin().status); + statusTextView.setText(NSClientInternalPlugin.getPlugin().status); } }); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java index b33d1cb2c3..7e8a76ce1b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientInternalPlugin.java @@ -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; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java index c0d0662747..b35ebe25a6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java @@ -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,30 +44,36 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.openapsama_fragment, container, false); + try { + View view = inflater.inflate(R.layout.openapsama_fragment, container, false); - run = (Button) view.findViewById(R.id.openapsma_run); - run.setOnClickListener(this); - lastRunView = (TextView) view.findViewById(R.id.openapsma_lastrun); - glucoseStatusView = (TextView) view.findViewById(R.id.openapsma_glucosestatus); - currentTempView = (TextView) view.findViewById(R.id.openapsma_currenttemp); - iobDataView = (TextView) view.findViewById(R.id.openapsma_iobdata); - profileView = (TextView) view.findViewById(R.id.openapsma_profile); - mealDataView = (TextView) view.findViewById(R.id.openapsma_mealdata); - autosensDataView = (TextView) view.findViewById(R.id.openapsma_autosensdata); - scriptdebugView = (TextView) view.findViewById(R.id.openapsma_scriptdebugdata); - resultView = (TextView) view.findViewById(R.id.openapsma_result); - requestView = (TextView) view.findViewById(R.id.openapsma_request); + run = (Button) view.findViewById(R.id.openapsma_run); + run.setOnClickListener(this); + lastRunView = (TextView) view.findViewById(R.id.openapsma_lastrun); + glucoseStatusView = (TextView) view.findViewById(R.id.openapsma_glucosestatus); + currentTempView = (TextView) view.findViewById(R.id.openapsma_currenttemp); + iobDataView = (TextView) view.findViewById(R.id.openapsma_iobdata); + profileView = (TextView) view.findViewById(R.id.openapsma_profile); + mealDataView = (TextView) view.findViewById(R.id.openapsma_mealdata); + autosensDataView = (TextView) view.findViewById(R.id.openapsma_autosensdata); + scriptdebugView = (TextView) view.findViewById(R.id.openapsma_scriptdebugdata); + resultView = (TextView) view.findViewById(R.id.openapsma_result); + requestView = (TextView) view.findViewById(R.id.openapsma_request); - updateGUI(); - return view; + 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())); } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index 28bc0f9e4e..dfad17de2e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -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; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java index 90bfc301b1..1183a99e67 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java @@ -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,28 +40,34 @@ public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClic @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.openapsma_fragment, container, false); + try { + View view = inflater.inflate(R.layout.openapsma_fragment, container, false); - run = (Button) view.findViewById(R.id.openapsma_run); - run.setOnClickListener(this); - lastRunView = (TextView) view.findViewById(R.id.openapsma_lastrun); - glucoseStatusView = (TextView) view.findViewById(R.id.openapsma_glucosestatus); - currentTempView = (TextView) view.findViewById(R.id.openapsma_currenttemp); - iobDataView = (TextView) view.findViewById(R.id.openapsma_iobdata); - profileView = (TextView) view.findViewById(R.id.openapsma_profile); - mealDataView = (TextView) view.findViewById(R.id.openapsma_mealdata); - resultView = (TextView) view.findViewById(R.id.openapsma_result); - requestView = (TextView) view.findViewById(R.id.openapsma_request); + run = (Button) view.findViewById(R.id.openapsma_run); + run.setOnClickListener(this); + lastRunView = (TextView) view.findViewById(R.id.openapsma_lastrun); + glucoseStatusView = (TextView) view.findViewById(R.id.openapsma_glucosestatus); + currentTempView = (TextView) view.findViewById(R.id.openapsma_currenttemp); + iobDataView = (TextView) view.findViewById(R.id.openapsma_iobdata); + profileView = (TextView) view.findViewById(R.id.openapsma_profile); + mealDataView = (TextView) view.findViewById(R.id.openapsma_mealdata); + resultView = (TextView) view.findViewById(R.id.openapsma_result); + requestView = (TextView) view.findViewById(R.id.openapsma_request); - updateGUI(); - return view; + 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()); } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index a5c2276a2e..42741340b5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -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; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 5d1c3e5ca7..c331cd0445 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -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,136 +209,142 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - //check screen width - final DisplayMetrics dm = new DisplayMetrics(); - getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); - int screen_width = dm.widthPixels; - int screen_height = dm.heightPixels; - smallWidth = screen_width < Constants.SMALL_WIDTH; - smallHeight = screen_height < Constants.SMALL_HEIGHT; - boolean landscape = screen_height < screen_width; + try { + //check screen width + final DisplayMetrics dm = new DisplayMetrics(); + getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); + int screen_width = dm.widthPixels; + int screen_height = dm.heightPixels; + smallWidth = screen_width < Constants.SMALL_WIDTH; + smallHeight = screen_height < Constants.SMALL_HEIGHT; + boolean landscape = screen_height < screen_width; - View view; + View view; - if (MainApp.sResources.getBoolean(R.bool.isTablet) && BuildConfig.NSCLIENTOLNY) { - view = inflater.inflate(R.layout.overview_fragment_nsclient_tablet, container, false); - } else if (BuildConfig.NSCLIENTOLNY) { - view = inflater.inflate(R.layout.overview_fragment_nsclient, container, false); - shorttextmode = true; - } else if (smallHeight || landscape) { - view = inflater.inflate(R.layout.overview_fragment_smallheight, container, false); - } else { - view = inflater.inflate(R.layout.overview_fragment, container, false); - } - - timeView = (TextView) view.findViewById(R.id.overview_time); - bgView = (TextView) view.findViewById(R.id.overview_bg); - arrowView = (TextView) view.findViewById(R.id.overview_arrow); - if (smallWidth) { - arrowView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 35); - } - timeAgoView = (TextView) view.findViewById(R.id.overview_timeago); - deltaView = (TextView) view.findViewById(R.id.overview_delta); - avgdeltaView = (TextView) view.findViewById(R.id.overview_avgdelta); - baseBasalView = (TextView) view.findViewById(R.id.overview_basebasal); - extendedBolusView = (TextView) view.findViewById(R.id.overview_extendedbolus); - activeProfileView = (TextView) view.findViewById(R.id.overview_activeprofile); - pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus); - pumpDeviceStatusView = (TextView) view.findViewById(R.id.overview_pump); - openapsDeviceStatusView = (TextView) view.findViewById(R.id.overview_openaps); - uploaderDeviceStatusView = (TextView) view.findViewById(R.id.overview_uploader); - loopStatusLayout = (LinearLayout) view.findViewById(R.id.overview_looplayout); - pumpStatusLayout = (LinearLayout) view.findViewById(R.id.overview_pumpstatuslayout); - - pumpStatusView.setBackgroundColor(MainApp.sResources.getColor(R.color.colorInitializingBorder)); - - iobView = (TextView) view.findViewById(R.id.overview_iob); - cobView = (TextView) view.findViewById(R.id.overview_cob); - apsModeView = (TextView) view.findViewById(R.id.overview_apsmode); - tempTargetView = (TextView) view.findViewById(R.id.overview_temptarget); - - iage = (TextView) view.findViewById(R.id.careportal_insulinage); - cage = (TextView) view.findViewById(R.id.careportal_canulaage); - sage = (TextView) view.findViewById(R.id.careportal_sensorage); - pbage = (TextView) view.findViewById(R.id.careportal_pbage); - - bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); - iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph); - - treatmentButton = (Button) view.findViewById(R.id.overview_treatmentbutton); - treatmentButton.setOnClickListener(this); - wizardButton = (Button) view.findViewById(R.id.overview_wizardbutton); - wizardButton.setOnClickListener(this); - acceptTempButton = (Button) view.findViewById(R.id.overview_accepttempbutton); - if (acceptTempButton != null) - acceptTempButton.setOnClickListener(this); - quickWizardButton = (Button) view.findViewById(R.id.overview_quickwizardbutton); - quickWizardButton.setOnClickListener(this); - calibrationButton = (Button) view.findViewById(R.id.overview_calibrationbutton); - if (calibrationButton != null) - calibrationButton.setOnClickListener(this); - - acceptTempLayout = (LinearLayout) view.findViewById(R.id.overview_accepttemplayout); - - showPredictionView = (CheckBox) view.findViewById(R.id.overview_showprediction); - showBasalsView = (CheckBox) view.findViewById(R.id.overview_showbasals); - showIobView = (CheckBox) view.findViewById(R.id.overview_showiob); - showCobView = (CheckBox) view.findViewById(R.id.overview_showcob); - showDeviationsView = (CheckBox) view.findViewById(R.id.overview_showdeviations); - showRatiosView = (CheckBox) view.findViewById(R.id.overview_showratios); - showPredictionView.setChecked(SP.getBoolean("showprediction", false)); - showBasalsView.setChecked(SP.getBoolean("showbasals", true)); - showIobView.setChecked(SP.getBoolean("showiob", false)); - showCobView.setChecked(SP.getBoolean("showcob", false)); - showDeviationsView.setChecked(SP.getBoolean("showdeviations", false)); - showRatiosView.setChecked(SP.getBoolean("showratios", false)); - showPredictionView.setOnCheckedChangeListener(this); - showBasalsView.setOnCheckedChangeListener(this); - showIobView.setOnCheckedChangeListener(this); - showCobView.setOnCheckedChangeListener(this); - showDeviationsView.setOnCheckedChangeListener(this); - showRatiosView.setOnCheckedChangeListener(this); - - notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications); - notificationsView.setHasFixedSize(true); - llm = new LinearLayoutManager(view.getContext()); - notificationsView.setLayoutManager(llm); - - bgGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid)); - bgGraph.getGridLabelRenderer().reloadStyles(); - iobGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid)); - iobGraph.getGridLabelRenderer().reloadStyles(); - iobGraph.getGridLabelRenderer().setHorizontalLabelsVisible(false); - bgGraph.getGridLabelRenderer().setLabelVerticalWidth(50); - iobGraph.getGridLabelRenderer().setLabelVerticalWidth(50); - iobGraph.getGridLabelRenderer().setNumVerticalLabels(5); - - rangeToDisplay = SP.getInt(R.string.key_rangetodisplay, 6); - - bgGraph.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - rangeToDisplay += 6; - rangeToDisplay = rangeToDisplay > 24 ? 6 : rangeToDisplay; - SP.putInt(R.string.key_rangetodisplay, rangeToDisplay); - updateGUI("rangeChange"); - return false; + if (MainApp.sResources.getBoolean(R.bool.isTablet) && BuildConfig.NSCLIENTOLNY) { + view = inflater.inflate(R.layout.overview_fragment_nsclient_tablet, container, false); + } else if (BuildConfig.NSCLIENTOLNY) { + view = inflater.inflate(R.layout.overview_fragment_nsclient, container, false); + shorttextmode = true; + } else if (smallHeight || landscape) { + view = inflater.inflate(R.layout.overview_fragment_smallheight, container, false); + } else { + view = inflater.inflate(R.layout.overview_fragment, container, false); } - }); - lockScreen = (CheckBox) view.findViewById(R.id.overview_lockscreen); - if (lockScreen != null) { - lockScreen.setChecked(SP.getBoolean("lockscreen", false)); - lockScreen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + timeView = (TextView) view.findViewById(R.id.overview_time); + bgView = (TextView) view.findViewById(R.id.overview_bg); + arrowView = (TextView) view.findViewById(R.id.overview_arrow); + if (smallWidth) { + arrowView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 35); + } + timeAgoView = (TextView) view.findViewById(R.id.overview_timeago); + deltaView = (TextView) view.findViewById(R.id.overview_delta); + avgdeltaView = (TextView) view.findViewById(R.id.overview_avgdelta); + baseBasalView = (TextView) view.findViewById(R.id.overview_basebasal); + extendedBolusView = (TextView) view.findViewById(R.id.overview_extendedbolus); + activeProfileView = (TextView) view.findViewById(R.id.overview_activeprofile); + pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus); + pumpDeviceStatusView = (TextView) view.findViewById(R.id.overview_pump); + openapsDeviceStatusView = (TextView) view.findViewById(R.id.overview_openaps); + uploaderDeviceStatusView = (TextView) view.findViewById(R.id.overview_uploader); + loopStatusLayout = (LinearLayout) view.findViewById(R.id.overview_looplayout); + pumpStatusLayout = (LinearLayout) view.findViewById(R.id.overview_pumpstatuslayout); + + pumpStatusView.setBackgroundColor(MainApp.sResources.getColor(R.color.colorInitializingBorder)); + + iobView = (TextView) view.findViewById(R.id.overview_iob); + cobView = (TextView) view.findViewById(R.id.overview_cob); + apsModeView = (TextView) view.findViewById(R.id.overview_apsmode); + tempTargetView = (TextView) view.findViewById(R.id.overview_temptarget); + + iage = (TextView) view.findViewById(R.id.careportal_insulinage); + cage = (TextView) view.findViewById(R.id.careportal_canulaage); + sage = (TextView) view.findViewById(R.id.careportal_sensorage); + pbage = (TextView) view.findViewById(R.id.careportal_pbage); + + bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); + iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph); + + treatmentButton = (Button) view.findViewById(R.id.overview_treatmentbutton); + treatmentButton.setOnClickListener(this); + wizardButton = (Button) view.findViewById(R.id.overview_wizardbutton); + wizardButton.setOnClickListener(this); + acceptTempButton = (Button) view.findViewById(R.id.overview_accepttempbutton); + if (acceptTempButton != null) + acceptTempButton.setOnClickListener(this); + quickWizardButton = (Button) view.findViewById(R.id.overview_quickwizardbutton); + quickWizardButton.setOnClickListener(this); + calibrationButton = (Button) view.findViewById(R.id.overview_calibrationbutton); + if (calibrationButton != null) + calibrationButton.setOnClickListener(this); + + acceptTempLayout = (LinearLayout) view.findViewById(R.id.overview_accepttemplayout); + + showPredictionView = (CheckBox) view.findViewById(R.id.overview_showprediction); + showBasalsView = (CheckBox) view.findViewById(R.id.overview_showbasals); + showIobView = (CheckBox) view.findViewById(R.id.overview_showiob); + showCobView = (CheckBox) view.findViewById(R.id.overview_showcob); + showDeviationsView = (CheckBox) view.findViewById(R.id.overview_showdeviations); + showRatiosView = (CheckBox) view.findViewById(R.id.overview_showratios); + showPredictionView.setChecked(SP.getBoolean("showprediction", false)); + showBasalsView.setChecked(SP.getBoolean("showbasals", true)); + showIobView.setChecked(SP.getBoolean("showiob", false)); + showCobView.setChecked(SP.getBoolean("showcob", false)); + showDeviationsView.setChecked(SP.getBoolean("showdeviations", false)); + showRatiosView.setChecked(SP.getBoolean("showratios", false)); + showPredictionView.setOnCheckedChangeListener(this); + showBasalsView.setOnCheckedChangeListener(this); + showIobView.setOnCheckedChangeListener(this); + showCobView.setOnCheckedChangeListener(this); + showDeviationsView.setOnCheckedChangeListener(this); + showRatiosView.setOnCheckedChangeListener(this); + + notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications); + notificationsView.setHasFixedSize(true); + llm = new LinearLayoutManager(view.getContext()); + notificationsView.setLayoutManager(llm); + + bgGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid)); + bgGraph.getGridLabelRenderer().reloadStyles(); + iobGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid)); + iobGraph.getGridLabelRenderer().reloadStyles(); + iobGraph.getGridLabelRenderer().setHorizontalLabelsVisible(false); + bgGraph.getGridLabelRenderer().setLabelVerticalWidth(50); + iobGraph.getGridLabelRenderer().setLabelVerticalWidth(50); + iobGraph.getGridLabelRenderer().setNumVerticalLabels(5); + + rangeToDisplay = SP.getInt(R.string.key_rangetodisplay, 6); + + bgGraph.setOnLongClickListener(new View.OnLongClickListener() { @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SP.putBoolean("lockscreen", isChecked); - MainApp.bus().post(new EventSetWakeLock(isChecked)); + public boolean onLongClick(View v) { + rangeToDisplay += 6; + rangeToDisplay = rangeToDisplay > 24 ? 6 : rangeToDisplay; + SP.putInt(R.string.key_rangetodisplay, rangeToDisplay); + updateGUI("rangeChange"); + return false; } }); + + lockScreen = (CheckBox) view.findViewById(R.id.overview_lockscreen); + if (lockScreen != null) { + lockScreen.setChecked(SP.getBoolean("lockscreen", false)); + lockScreen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + SP.putBoolean("lockscreen", isChecked); + MainApp.bus().post(new EventSetWakeLock(isChecked)); + } + }); + } + + return view; + } catch (Exception e) { + Crashlytics.logException(e); } - return view; + 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) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java index bb89a70fdf..d779b82ae9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java @@ -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; @@ -51,7 +60,7 @@ public class OverviewPlugin implements PluginBase { @Override public String getNameShort() { String name = MainApp.sResources.getString(R.string.overview_shortname); - if (!name.trim().isEmpty()){ + if (!name.trim().isEmpty()) { //only if translation exists return name; }