From 188a9b6313e63aa0414ffab71865eaadcce9cf7e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 29 Jul 2018 15:37:28 +0200 Subject: [PATCH] PROFILE logging --- .../info/nightscout/androidaps/Config.java | 2 - .../nightscout/androidaps/MainActivity.java | 10 +- .../info/nightscout/androidaps/MainApp.java | 14 +- .../info/nightscout/androidaps/logging/L.java | 103 +++++++++++ .../ConfigBuilder/ConfigBuilderPlugin.java | 6 +- .../ProfileLocal/LocalProfileFragment.java | 130 +++++++------- .../ProfileLocal/LocalProfilePlugin.java | 8 +- .../plugins/ProfileNS/NSProfileFragment.java | 21 +-- .../plugins/ProfileNS/NSProfilePlugin.java | 30 ++-- .../ProfileSimple/SimpleProfileFragment.java | 163 +++++++++--------- .../ProfileSimple/SimpleProfilePlugin.java | 10 +- 11 files changed, 292 insertions(+), 205 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/logging/L.java diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index 4d183476e9..edfaf94bfc 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -23,8 +23,6 @@ public class Config { public static final boolean SMSCOMMUNICATORENABLED = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER; - public static boolean logFunctionCalls = true; - public static boolean logPrefsChange = true; public static boolean logConfigBuilder = true; public static boolean logCongigBuilderActions = true; diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index a4370ff683..edb1bd7854 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -48,6 +48,7 @@ import info.nightscout.androidaps.events.EventFeatureRunning; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.Food.FoodPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; @@ -62,7 +63,7 @@ import info.nightscout.utils.PasswordProtection; import info.nightscout.utils.SP; public class MainActivity extends AppCompatActivity { - private static Logger log = LoggerFactory.getLogger(MainActivity.class); + private static Logger log = LoggerFactory.getLogger(L.CORE); protected PowerManager.WakeLock mWakeLock; @@ -74,7 +75,7 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (Config.logFunctionCalls) + if (L.isEnabled(L.CORE)) log.debug("onCreate"); Iconify.with(new FontAwesomeModule()); @@ -134,6 +135,9 @@ public class MainActivity extends AppCompatActivity { protected void onResume() { super.onResume(); + if (L.isEnabled(L.CORE)) + log.debug("onResume"); + if (!SP.getBoolean(R.string.key_setupwizard_processed, false)) { Intent intent = new Intent(this, SetupWizardActivity.class); startActivity(intent); @@ -153,6 +157,8 @@ public class MainActivity extends AppCompatActivity { @Override public void onDestroy() { + if (L.isEnabled(L.CORE)) + log.debug("onDestroy"); if (mWakeLock != null) if (mWakeLock.isHeld()) mWakeLock.release(); diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index d4845a51dd..791f4f07df 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -24,13 +24,12 @@ import java.io.File; import java.util.ArrayList; import ch.qos.logback.classic.LoggerContext; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.data.ConstraintChecker; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.Actions.ActionsFragment; import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; @@ -43,6 +42,7 @@ import info.nightscout.androidaps.plugins.Insulin.InsulinOrefUltraRapidActingPlu import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; +import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.androidaps.plugins.NSClientInternal.receivers.AckAlarmReceiver; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin; @@ -77,13 +77,13 @@ import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.KeepAliveReceiver; import info.nightscout.androidaps.receivers.NSAlarmReceiver; +import info.nightscout.androidaps.services.Intents; import info.nightscout.utils.FabricPrivacy; -import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import io.fabric.sdk.android.Fabric; public class MainApp extends Application { - private static Logger log = LoggerFactory.getLogger(MainApp.class); + private static Logger log = LoggerFactory.getLogger(L.CORE); private static KeepAliveReceiver keepAliveReceiver; private static Bus sBus; @@ -107,6 +107,8 @@ public class MainApp extends Application { @Override public void onCreate() { super.onCreate(); + if (L.isEnabled(L.CORE)) + log.debug("onCreate"); sInstance = this; sResources = getResources(); sConstraintsChecker = new ConstraintChecker(this); @@ -119,7 +121,7 @@ public class MainApp extends Application { Crashlytics.setString("BUILDVERSION", BuildConfig.BUILDVERSION); } } catch (Exception e) { - android.util.Log.e("ANDROIDAPS", "Error with Fabric init! " + e); + log.error("Error with Fabric init! " + e); } JodaTimeAndroid.init(this); @@ -395,6 +397,8 @@ public class MainApp extends Application { @Override public void onTerminate() { + if (L.isEnabled(L.CORE)) + log.debug("onTerminate"); super.onTerminate(); if (sDatabaseHelper != null) { sDatabaseHelper.close(); diff --git a/app/src/main/java/info/nightscout/androidaps/logging/L.java b/app/src/main/java/info/nightscout/androidaps/logging/L.java new file mode 100644 index 0000000000..c14fa46361 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/logging/L.java @@ -0,0 +1,103 @@ +package info.nightscout.androidaps.logging; + +import java.util.ArrayList; +import java.util.List; + +import info.nightscout.utils.SP; + +public class L { + + public static class LogElement { + String name; + boolean defaultValue; + boolean enabled; + boolean requiresRestart = false; + + LogElement(String name, boolean defaultValue) { + this.name = name; + this.defaultValue = defaultValue; + enabled = SP.getBoolean(getSPName(), defaultValue); + } + + LogElement(String name, boolean defaultValue, boolean requiresRestart) { + this.name = name; + this.defaultValue = defaultValue; + this.requiresRestart = requiresRestart; + enabled = SP.getBoolean(getSPName(), defaultValue); + } + + LogElement(boolean defaultValue) { + this.name = "NONEXISTING"; + this.defaultValue = defaultValue; + enabled = defaultValue; + } + + private String getSPName() { + return "log_" + name; + } + + } + + private static List logElements; + + static { + initialize(); + } + + private static LogElement findByName(String name) { + for (LogElement element: logElements + ) { + if (element.name.equals(name)) + return element; + } + return new LogElement(false); + } + + public static boolean isEnabled(String name) { + return findByName(name).enabled; + } + + public static final String CORE = "CORE"; + public static final String AUTOSENS = "AUTOSENS"; + public static final String EVENTS = "EVENTS"; + public static final String BGSOURCE = "BGSOURCE"; + public static final String OVERVIEW = "OVERVIEW"; + public static final String NOTIFICATION = "NOTIFICATION"; + public static final String ALARM = "ALARM"; + public static final String DATASERVICE = "DATASERVICE"; + public static final String DATABASE = "DATABASE"; + public static final String DATAFOOD = "DATAFOOD"; + public static final String DATATREATMENTS = "DATATREATMENTS"; + public static final String NSCLIENT = "NSCLIENT"; + public static final String OBJECTIVES = "OBJECTIVES"; + public static final String PUMP = "PUMP"; + public static final String PUMPQUEUE = "PUMPQUEUE"; + public static final String PUMPCOMM = "PUMPCOMM"; + public static final String PUMPBTCOMM = "PUMPBTCOMM"; + public static final String APS = "APS"; + public static final String PROFILE = "PROFILE"; + + private static void initialize() { + logElements = new ArrayList<>(); + logElements.add(new LogElement(CORE, true)); + logElements.add(new LogElement(AUTOSENS, false)); + logElements.add(new LogElement(EVENTS, false, true)); + logElements.add(new LogElement(BGSOURCE, true)); + logElements.add(new LogElement(OVERVIEW, true)); + logElements.add(new LogElement(NOTIFICATION, true)); + logElements.add(new LogElement(ALARM, false)); + logElements.add(new LogElement(DATASERVICE, true)); + logElements.add(new LogElement(DATABASE, true)); + logElements.add(new LogElement(DATAFOOD, true)); + logElements.add(new LogElement(DATATREATMENTS, true)); + logElements.add(new LogElement(NSCLIENT, true)); + logElements.add(new LogElement(OBJECTIVES, false)); + logElements.add(new LogElement(PUMP, true)); + logElements.add(new LogElement(PUMPQUEUE, true)); + logElements.add(new LogElement(PUMPCOMM, true)); + logElements.add(new LogElement(PUMPBTCOMM, false)); + logElements.add(new LogElement(APS, true)); + logElements.add(new LogElement(PROFILE, true)); + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 8a1b4a9764..3c582c0709 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -120,7 +120,7 @@ public class ConfigBuilderPlugin extends PluginBase { public void storeSettings(String from) { if (pluginList != null) { - if (Config.logPrefsChange) + if (Config.logConfigBuilder) log.debug("Storing settings from: " + from); for (PluginBase p : pluginList) { @@ -152,7 +152,7 @@ public class ConfigBuilderPlugin extends PluginBase { } private void loadSettings() { - if (Config.logPrefsChange) + if (Config.logConfigBuilder) log.debug("Loading stored settings"); for (PluginBase p : pluginList) { PluginType type = p.getType(); @@ -189,7 +189,7 @@ public class ConfigBuilderPlugin extends PluginBase { private void upgradeSettings() { if (!SP.contains("ConfigBuilder_1_NSProfilePlugin_Enabled")) return; - if (Config.logPrefsChange) + if (Config.logConfigBuilder) log.debug("Upgrading stored settings"); for (PluginBase p : pluginList) { log.debug("Processing " + p.getName()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java index 18060ba1ec..3fab80855a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java @@ -25,20 +25,18 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.interfaces.PumpDescription; +import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.NumberPicker; import info.nightscout.utils.SafeParse; import info.nightscout.utils.TimeListEdit; public class LocalProfileFragment extends SubscriberFragment { - private static Logger log = LoggerFactory.getLogger(LocalProfileFragment.class); - NumberPicker diaView; RadioButton mgdlView; RadioButton mmolView; @@ -81,80 +79,72 @@ public class LocalProfileFragment extends SubscriberFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - try { + PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription(); + View layout = inflater.inflate(R.layout.localprofile_fragment, container, false); + diaView = (NumberPicker) layout.findViewById(R.id.localprofile_dia); + diaView.setParams(LocalProfilePlugin.getPlugin().dia, 2d, 48d, 0.1d, new DecimalFormat("0.0"), false, textWatch); + mgdlView = (RadioButton) layout.findViewById(R.id.localprofile_mgdl); + mmolView = (RadioButton) layout.findViewById(R.id.localprofile_mmol); + icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save); + isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save); + basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.gs(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save); + targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save); + profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch); + resetButton = (Button) layout.findViewById(R.id.localprofile_reset); + saveButton = (Button) layout.findViewById(R.id.localprofile_save); - PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription(); - View layout = inflater.inflate(R.layout.localprofile_fragment, container, false); - diaView = (NumberPicker) layout.findViewById(R.id.localprofile_dia); - diaView.setParams(LocalProfilePlugin.getPlugin().dia, 2d, 48d, 0.1d, new DecimalFormat("0.0"), false, textWatch); - mgdlView = (RadioButton) layout.findViewById(R.id.localprofile_mgdl); - mmolView = (RadioButton) layout.findViewById(R.id.localprofile_mmol); + + invalidProfile = (TextView) layout.findViewById(R.id.invalidprofile); + + if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) { + layout.findViewById(R.id.localprofile_basal).setVisibility(View.GONE); + } + + mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl); + mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol); + + mgdlView.setOnClickListener(v -> { + LocalProfilePlugin.getPlugin().mgdl = mgdlView.isChecked(); + LocalProfilePlugin.getPlugin().mmol = !LocalProfilePlugin.getPlugin().mgdl; + mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol); + doEdit(); + }); + mmolView.setOnClickListener(v -> { + LocalProfilePlugin.getPlugin().mmol = mmolView.isChecked(); + LocalProfilePlugin.getPlugin().mgdl = !LocalProfilePlugin.getPlugin().mmol; + mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl); + doEdit(); + }); + + profileswitchButton.setOnClickListener(view -> { + NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); + final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCHDIRECT; + profileswitch.executeProfileSwitch = true; + newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); + newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); + }); + + resetButton.setOnClickListener(view -> { + LocalProfilePlugin.getPlugin().loadSettings(); + mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl); + mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol); + diaView.setParams(LocalProfilePlugin.getPlugin().dia, 5d, 12d, 0.1d, new DecimalFormat("0.0"), false, textWatch); icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save); isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save); basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.gs(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save); targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save); - profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch); - resetButton = (Button) layout.findViewById(R.id.localprofile_reset); - saveButton = (Button) layout.findViewById(R.id.localprofile_save); + updateGUI(); + }); - - invalidProfile = (TextView) layout.findViewById(R.id.invalidprofile); - - if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) { - layout.findViewById(R.id.localprofile_basal).setVisibility(View.GONE); + saveButton.setOnClickListener(view -> { + if (!LocalProfilePlugin.getPlugin().isValidEditState()) { + return; //Should not happen as saveButton should not be visible if not valid } + LocalProfilePlugin.getPlugin().storeSettings(); + updateGUI(); + }); - mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl); - mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol); - - mgdlView.setOnClickListener(v -> { - LocalProfilePlugin.getPlugin().mgdl = mgdlView.isChecked(); - LocalProfilePlugin.getPlugin().mmol = !LocalProfilePlugin.getPlugin().mgdl; - mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol); - doEdit(); - }); - mmolView.setOnClickListener(v -> { - LocalProfilePlugin.getPlugin().mmol = mmolView.isChecked(); - LocalProfilePlugin.getPlugin().mgdl = !LocalProfilePlugin.getPlugin().mmol; - mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl); - doEdit(); - }); - - profileswitchButton.setOnClickListener(view -> { - NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); - final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCHDIRECT; - profileswitch.executeProfileSwitch = true; - newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); - newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); - }); - - resetButton.setOnClickListener(view -> { - LocalProfilePlugin.getPlugin().loadSettings(); - mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl); - mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol); - diaView.setParams(LocalProfilePlugin.getPlugin().dia, 5d, 12d, 0.1d, new DecimalFormat("0.0"), false, textWatch); - icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save); - isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save); - basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.gs(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save); - targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save); - updateGUI(); - }); - - saveButton.setOnClickListener(view -> { - if(!LocalProfilePlugin.getPlugin().isValidEditState()){ - return; //Should not happen as saveButton should not be visible if not valid - } - LocalProfilePlugin.getPlugin().storeSettings(); - updateGUI(); - }); - - return layout; - } catch (Exception e) { - log.error("Unhandled exception: ", e); - FabricPrivacy.logException(e); - } - - return null; + return layout; } public void doEdit() { @@ -203,7 +193,7 @@ public class LocalProfileFragment extends SubscriberFragment { } //Show reset button iff data was edited - if(isEdited) { + if (isEdited) { resetButton.setVisibility(View.VISIBLE); } else { resetButton.setVisibility(View.GONE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java index 8d4e2d6a36..7a06860327 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java @@ -8,7 +8,6 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -18,6 +17,7 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ProfileInterface; +import info.nightscout.androidaps.logging.L; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.SP; @@ -26,7 +26,7 @@ import info.nightscout.utils.SP; */ public class LocalProfilePlugin extends PluginBase implements ProfileInterface { public static final String LOCAL_PROFILE = "LocalProfile"; - private static Logger log = LoggerFactory.getLogger(LocalProfilePlugin.class); + private static Logger log = LoggerFactory.getLogger(L.PROFILE); private static LocalProfilePlugin localProfilePlugin; @@ -81,13 +81,13 @@ public class LocalProfilePlugin extends PluginBase implements ProfileInterface { createAndStoreConvertedProfile(); edited = false; - if (Config.logPrefsChange) + if (L.isEnabled(L.PROFILE)) log.debug("Storing settings: " + getRawProfile().getData().toString()); MainApp.bus().post(new EventProfileStoreChanged()); } public synchronized void loadSettings() { - if (Config.logPrefsChange) + if (L.isEnabled(L.PROFILE)) log.debug("Loading stored settings"); mgdl = SP.getBoolean(LOCAL_PROFILE + "mgdl", false); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java index 6cc9fdf98e..b0f0700fe2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java @@ -27,7 +27,6 @@ import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI; import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileGraph; import info.nightscout.utils.DecimalFormatter; -import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.OKDialog; import static butterknife.OnItemSelected.Callback.NOTHING_SELECTED; @@ -62,24 +61,22 @@ public class NSProfileFragment extends SubscriberFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - try { - View view = inflater.inflate(R.layout.nsprofile_fragment, container, false); + View view = inflater.inflate(R.layout.nsprofile_fragment, container, false); - unbinder = ButterKnife.bind(this, view); - updateGUI(); - return view; - } catch (Exception e) { - FabricPrivacy.logException(e); - } - - return null; + unbinder = ButterKnife.bind(this, view); + updateGUI(); + return view; } @Subscribe public void onStatusEvent(final EventNSProfileUpdateGUI ev) { Activity activity = getActivity(); if (activity != null) - activity.runOnUiThread(() -> { synchronized (NSProfileFragment.this) { updateGUI(); } }); + activity.runOnUiThread(() -> { + synchronized (NSProfileFragment.this) { + updateGUI(); + } + }); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java index 522964e557..99e4ad9115 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java @@ -28,7 +28,7 @@ import info.nightscout.utils.SP; * Created by mike on 05.08.2016. */ public class NSProfilePlugin extends PluginBase implements ProfileInterface { - private static Logger log = LoggerFactory.getLogger(NSProfilePlugin.class); + private static Logger log = LoggerFactory.getLogger(L.PROFILE); private static NSProfilePlugin nsProfilePlugin; @@ -78,7 +78,7 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface { MainApp.bus().post(new EventProfileStoreChanged()); MainApp.bus().post(new EventNSProfileUpdateGUI()); } - if (L.isEnabled(L.NSCLIENT)) + if (L.isEnabled(L.PROFILE)) log.debug("Received profileStore: " + activeProfile + " " + profile); } catch (JSONException e) { log.error("Unhandled exception", e); @@ -87,31 +87,29 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface { private void storeNSProfile() { SP.putString("profile", profile.getData().toString()); - if (Config.logPrefsChange) + if (L.isEnabled(L.PROFILE)) log.debug("Storing profile"); } private void loadNSProfile() { - if (Config.logPrefsChange) + if (L.isEnabled(L.PROFILE)) log.debug("Loading stored profile"); String profileString = SP.getString("profile", null); if (profileString != null) { - if (Config.logPrefsChange) { + if (L.isEnabled(L.PROFILE)) log.debug("Loaded profile: " + profileString); - try { - profile = new ProfileStore(new JSONObject(profileString)); - } catch (JSONException e) { - log.error("Unhandled exception", e); - profile = null; - } + try { + profile = new ProfileStore(new JSONObject(profileString)); + } catch (JSONException e) { + log.error("Unhandled exception", e); + profile = null; } } else { - if (Config.logPrefsChange) { + if (L.isEnabled(L.PROFILE)) log.debug("Stored profile not found"); - // force restart of nsclient to fetch profile - Intent restartNSClient = new Intent(Intents.ACTION_RESTART); - MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); - } + // force restart of nsclient to fetch profile + Intent restartNSClient = new Intent(Intents.ACTION_RESTART); + MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java index 1315413e38..5e090cd9ba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfileFragment.java @@ -26,12 +26,9 @@ import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialo import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.SafeParse; public class SimpleProfileFragment extends SubscriberFragment { - private static Logger log = LoggerFactory.getLogger(SimpleProfileFragment.class); - EditText diaView; RadioButton mgdlView; RadioButton mmolView; @@ -46,92 +43,86 @@ public class SimpleProfileFragment extends SubscriberFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - try { - View layout = inflater.inflate(R.layout.simpleprofile_fragment, container, false); - diaView = (EditText) layout.findViewById(R.id.simpleprofile_dia); - mgdlView = (RadioButton) layout.findViewById(R.id.simpleprofile_mgdl); - mmolView = (RadioButton) layout.findViewById(R.id.simpleprofile_mmol); - icView = (EditText) layout.findViewById(R.id.simpleprofile_ic); - isfView = (EditText) layout.findViewById(R.id.simpleprofile_isf); - basalView = (EditText) layout.findViewById(R.id.simpleprofile_basalrate); - targetlowView = (EditText) layout.findViewById(R.id.simpleprofile_targetlow); - targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh); - profileswitchButton = (Button) layout.findViewById(R.id.simpleprofile_profileswitch); - invalidProfile = (TextView) layout.findViewById(R.id.invalidprofile); + View layout = inflater.inflate(R.layout.simpleprofile_fragment, container, false); + diaView = (EditText) layout.findViewById(R.id.simpleprofile_dia); + mgdlView = (RadioButton) layout.findViewById(R.id.simpleprofile_mgdl); + mmolView = (RadioButton) layout.findViewById(R.id.simpleprofile_mmol); + icView = (EditText) layout.findViewById(R.id.simpleprofile_ic); + isfView = (EditText) layout.findViewById(R.id.simpleprofile_isf); + basalView = (EditText) layout.findViewById(R.id.simpleprofile_basalrate); + targetlowView = (EditText) layout.findViewById(R.id.simpleprofile_targetlow); + targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh); + profileswitchButton = (Button) layout.findViewById(R.id.simpleprofile_profileswitch); + invalidProfile = (TextView) layout.findViewById(R.id.invalidprofile); - if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) { - layout.findViewById(R.id.simpleprofile_basalrate).setVisibility(View.GONE); - layout.findViewById(R.id.simpleprofile_basalrate_label).setVisibility(View.GONE); - } - - mgdlView.setChecked(SimpleProfilePlugin.getPlugin().mgdl); - mmolView.setChecked(SimpleProfilePlugin.getPlugin().mmol); - diaView.setText(SimpleProfilePlugin.getPlugin().dia.toString()); - icView.setText(SimpleProfilePlugin.getPlugin().ic.toString()); - isfView.setText(SimpleProfilePlugin.getPlugin().isf.toString()); - basalView.setText(SimpleProfilePlugin.getPlugin().basal.toString()); - targetlowView.setText(SimpleProfilePlugin.getPlugin().targetLow.toString()); - targethighView.setText(SimpleProfilePlugin.getPlugin().targetHigh.toString()); - - mgdlView.setOnClickListener(v -> { - SimpleProfilePlugin.getPlugin().mgdl = mgdlView.isChecked(); - SimpleProfilePlugin.getPlugin().mmol = !SimpleProfilePlugin.getPlugin().mgdl; - mmolView.setChecked(SimpleProfilePlugin.getPlugin().mmol); - SimpleProfilePlugin.getPlugin().storeSettings(); - }); - mmolView.setOnClickListener(v -> { - SimpleProfilePlugin.getPlugin().mmol = mmolView.isChecked(); - SimpleProfilePlugin.getPlugin().mgdl = !SimpleProfilePlugin.getPlugin().mmol; - mgdlView.setChecked(SimpleProfilePlugin.getPlugin().mgdl); - SimpleProfilePlugin.getPlugin().storeSettings(); - }); - - profileswitchButton.setOnClickListener(view -> { - NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); - final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCH; - profileswitch.executeProfileSwitch = true; - newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); - newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); - }); - - TextWatcher textWatch = new TextWatcher() { - - @Override - public void afterTextChanged(Editable s) { - } - - @Override - public void beforeTextChanged(CharSequence s, int start, - int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, - int before, int count) { - SimpleProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString()); - SimpleProfilePlugin.getPlugin().ic = SafeParse.stringToDouble(icView.getText().toString()); - SimpleProfilePlugin.getPlugin().isf = SafeParse.stringToDouble(isfView.getText().toString()); - SimpleProfilePlugin.getPlugin().basal = SafeParse.stringToDouble(basalView.getText().toString()); - SimpleProfilePlugin.getPlugin().targetLow = SafeParse.stringToDouble(targetlowView.getText().toString()); - SimpleProfilePlugin.getPlugin().targetHigh = SafeParse.stringToDouble(targethighView.getText().toString()); - SimpleProfilePlugin.getPlugin().storeSettings(); - updateGUI(); - } - }; - - diaView.addTextChangedListener(textWatch); - icView.addTextChangedListener(textWatch); - isfView.addTextChangedListener(textWatch); - basalView.addTextChangedListener(textWatch); - targetlowView.addTextChangedListener(textWatch); - targethighView.addTextChangedListener(textWatch); - - return layout; - } catch (Exception e) { - FabricPrivacy.logException(e); + if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) { + layout.findViewById(R.id.simpleprofile_basalrate).setVisibility(View.GONE); + layout.findViewById(R.id.simpleprofile_basalrate_label).setVisibility(View.GONE); } - return null; + mgdlView.setChecked(SimpleProfilePlugin.getPlugin().mgdl); + mmolView.setChecked(SimpleProfilePlugin.getPlugin().mmol); + diaView.setText(SimpleProfilePlugin.getPlugin().dia.toString()); + icView.setText(SimpleProfilePlugin.getPlugin().ic.toString()); + isfView.setText(SimpleProfilePlugin.getPlugin().isf.toString()); + basalView.setText(SimpleProfilePlugin.getPlugin().basal.toString()); + targetlowView.setText(SimpleProfilePlugin.getPlugin().targetLow.toString()); + targethighView.setText(SimpleProfilePlugin.getPlugin().targetHigh.toString()); + + mgdlView.setOnClickListener(v -> { + SimpleProfilePlugin.getPlugin().mgdl = mgdlView.isChecked(); + SimpleProfilePlugin.getPlugin().mmol = !SimpleProfilePlugin.getPlugin().mgdl; + mmolView.setChecked(SimpleProfilePlugin.getPlugin().mmol); + SimpleProfilePlugin.getPlugin().storeSettings(); + }); + mmolView.setOnClickListener(v -> { + SimpleProfilePlugin.getPlugin().mmol = mmolView.isChecked(); + SimpleProfilePlugin.getPlugin().mgdl = !SimpleProfilePlugin.getPlugin().mmol; + mgdlView.setChecked(SimpleProfilePlugin.getPlugin().mgdl); + SimpleProfilePlugin.getPlugin().storeSettings(); + }); + + profileswitchButton.setOnClickListener(view -> { + NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); + final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCH; + profileswitch.executeProfileSwitch = true; + newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); + newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); + }); + + TextWatcher textWatch = new TextWatcher() { + + @Override + public void afterTextChanged(Editable s) { + } + + @Override + public void beforeTextChanged(CharSequence s, int start, + int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, + int before, int count) { + SimpleProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString()); + SimpleProfilePlugin.getPlugin().ic = SafeParse.stringToDouble(icView.getText().toString()); + SimpleProfilePlugin.getPlugin().isf = SafeParse.stringToDouble(isfView.getText().toString()); + SimpleProfilePlugin.getPlugin().basal = SafeParse.stringToDouble(basalView.getText().toString()); + SimpleProfilePlugin.getPlugin().targetLow = SafeParse.stringToDouble(targetlowView.getText().toString()); + SimpleProfilePlugin.getPlugin().targetHigh = SafeParse.stringToDouble(targethighView.getText().toString()); + SimpleProfilePlugin.getPlugin().storeSettings(); + updateGUI(); + } + }; + + diaView.addTextChangedListener(textWatch); + icView.addTextChangedListener(textWatch); + isfView.addTextChangedListener(textWatch); + basalView.addTextChangedListener(textWatch); + targetlowView.addTextChangedListener(textWatch); + targethighView.addTextChangedListener(textWatch); + + return layout; } @Subscribe diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java index bb669289ee..09742bd3f9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java @@ -9,7 +9,6 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -19,13 +18,14 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ProfileInterface; +import info.nightscout.androidaps.logging.L; import info.nightscout.utils.SP; /** * Created by mike on 05.08.2016. */ public class SimpleProfilePlugin extends PluginBase implements ProfileInterface { - private static Logger log = LoggerFactory.getLogger(SimpleProfilePlugin.class); + private static Logger log = LoggerFactory.getLogger(L.PROFILE); private static SimpleProfilePlugin simpleProfilePlugin; @@ -58,7 +58,7 @@ public class SimpleProfilePlugin extends PluginBase implements ProfileInterface } public void storeSettings() { - if (Config.logPrefsChange) + if (L.isEnabled(L.PROFILE)) log.debug("Storing settings"); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences.Editor editor = settings.edit(); @@ -73,13 +73,13 @@ public class SimpleProfilePlugin extends PluginBase implements ProfileInterface editor.apply(); createConvertedProfile(); - if (Config.logPrefsChange) + if (L.isEnabled(L.PROFILE)) log.debug("Storing settings: " + getRawProfile().getData().toString()); MainApp.bus().post(new EventProfileStoreChanged()); } private void loadSettings() { - if (Config.logPrefsChange) + if (L.isEnabled(L.PROFILE)) log.debug("Loading stored settings"); mgdl = SP.getBoolean("SimpleProfile" + "mgdl", true);