From 13184dcb51e88a3ebd63307649072731023c8d3d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 17 Oct 2017 20:55:23 +0200 Subject: [PATCH 01/26] food plugin --- .../info/nightscout/androidaps/MainApp.java | 5 + .../androidaps/Services/DataService.java | 53 +++ .../nightscout/androidaps/db/FoodHelper.java | 2 + .../androidaps/plugins/Food/FoodFragment.java | 315 ++++++++++++++++++ .../androidaps/plugins/Food/FoodPlugin.java | 80 +++++ .../java/info/nightscout/utils/NSUpload.java | 19 ++ app/src/main/res/layout/food_fragment.xml | 90 +++++ app/src/main/res/layout/food_item.xml | 100 ++++++ app/src/main/res/values/strings.xml | 17 +- 9 files changed, 676 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java create mode 100644 app/src/main/res/layout/food_fragment.xml create mode 100644 app/src/main/res/layout/food_item.xml diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 4398f80e75..209adfe1c4 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -31,6 +31,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; +import info.nightscout.androidaps.plugins.Food.FoodPlugin; import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingPlugin; import info.nightscout.androidaps.plugins.Insulin.InsulinFastactingProlongedPlugin; import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin; @@ -149,6 +150,7 @@ public class MainApp extends Application { if (!Config.NSCLIENT) pluginsList.add(SourceGlimpPlugin.getPlugin()); if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin()); + pluginsList.add(FoodPlugin.getPlugin()); pluginsList.add(WearFragment.getPlugin(this)); pluginsList.add(StatuslinePlugin.getPlugin(this)); @@ -186,6 +188,9 @@ public class MainApp extends Application { lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_FOOD)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_FOOD)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_FOOD)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_STATUS)); diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index dc52107c26..5c152e8060 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -116,6 +116,9 @@ public class DataService extends IntentService { Intents.ACTION_REMOVED_TREATMENT.equals(action) || Intents.ACTION_NEW_STATUS.equals(action) || Intents.ACTION_NEW_DEVICESTATUS.equals(action) || + Intents.ACTION_NEW_FOOD.equals(action) || + Intents.ACTION_CHANGED_FOOD.equals(action) || + Intents.ACTION_REMOVED_FOOD.equals(action) || Intents.ACTION_NEW_CAL.equals(action) || Intents.ACTION_NEW_MBG.equals(action)) ) { @@ -413,6 +416,56 @@ public class DataService extends IntentService { log.error("Unhandled exception", e); } } + + if (intent.getAction().equals(Intents.ACTION_NEW_FOOD) || intent.getAction().equals(Intents.ACTION_CHANGED_FOOD)) { + try { + if (bundles.containsKey("food")) { + String trstring = bundles.getString("food"); + handleAddChangeFoodRecord(new JSONObject(trstring)); + } + if (bundles.containsKey("foods")) { + String trstring = bundles.getString("foods"); + JSONArray jsonArray = new JSONArray(trstring); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject trJson = jsonArray.getJSONObject(i); + handleAddChangeFoodRecord(trJson); + } + } + } catch (Exception e) { + log.error("Unhandled exception", e); + } + } + + if (intent.getAction().equals(Intents.ACTION_REMOVED_FOOD)) { + try { + if (bundles.containsKey("food")) { + String trstring = bundles.getString("food"); + JSONObject trJson = new JSONObject(trstring); + String _id = trJson.getString("_id"); + handleRemovedFoodRecord(_id); + } + + if (bundles.containsKey("foods")) { + String trstring = bundles.getString("foods"); + JSONArray jsonArray = new JSONArray(trstring); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject trJson = jsonArray.getJSONObject(i); + String _id = trJson.getString("_id"); + handleRemovedFoodRecord(_id); + } + } + } catch (Exception e) { + log.error("Unhandled exception", e); + } + } + } + + private void handleRemovedFoodRecord(String _id) { + MainApp.getDbHelper().foodHelper.deleteFoodById(_id); + } + + public void handleAddChangeFoodRecord(JSONObject trJson) throws JSONException { + MainApp.getDbHelper().foodHelper.createFoodFromJsonIfNotExists(trJson); } private void handleRemovedRecordFromNS(String _id) { diff --git a/app/src/main/java/info/nightscout/androidaps/db/FoodHelper.java b/app/src/main/java/info/nightscout/androidaps/db/FoodHelper.java index fd5406f974..992e328532 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/FoodHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/FoodHelper.java @@ -87,6 +87,8 @@ public class FoodHelper { log.debug("FOOD: Updating record by _id: " + old.toString()); scheduleFoodChange(); return true; + } else { + return false; } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java new file mode 100644 index 0000000000..558cf0d02f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodFragment.java @@ -0,0 +1,315 @@ +package info.nightscout.androidaps.plugins.Food; + +import android.app.Activity; +import android.content.DialogInterface; +import android.graphics.Paint; +import android.os.Bundle; +import android.support.v7.app.AlertDialog; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; + +import com.crashlytics.android.Crashlytics; +import com.squareup.otto.Subscribe; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.db.Food; +import info.nightscout.androidaps.events.EventFoodDatabaseChanged; +import info.nightscout.androidaps.plugins.Common.SubscriberFragment; +import info.nightscout.utils.NSUpload; +import info.nightscout.utils.SpinnerHelper; + +/** + * Created by mike on 16.10.2017. + */ + +public class FoodFragment extends SubscriberFragment { + private static Logger log = LoggerFactory.getLogger(FoodFragment.class); + + EditText filter; + ImageView clearFilter; + SpinnerHelper category; + SpinnerHelper subcategory; + RecyclerView recyclerView; + + List unfiltered; + List filtered; + ArrayList categories; + ArrayList subcategories; + + final String EMPTY = MainApp.sResources.getString(R.string.none); + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + try { + View view = inflater.inflate(R.layout.food_fragment, container, false); + + filter = (EditText) view.findViewById(R.id.food_filter); + clearFilter = (ImageView) view.findViewById(R.id.food_clearfilter); + category = new SpinnerHelper(view.findViewById(R.id.food_category)); + subcategory = new SpinnerHelper(view.findViewById(R.id.food_subcategory)); + recyclerView = (RecyclerView) view.findViewById(R.id.food_recyclerview); + recyclerView.setHasFixedSize(true); + LinearLayoutManager llm = new LinearLayoutManager(view.getContext()); + recyclerView.setLayoutManager(llm); + + clearFilter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + filter.setText(""); + category.setSelection(0); + subcategory.setSelection(0); + filterData(); + } + }); + + category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + fillSubcategories(); + filterData(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + fillSubcategories(); + filterData(); + } + }); + + subcategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + filterData(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + filterData(); + } + }); + + filter.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + filterData(); + } + + @Override + public void afterTextChanged(Editable s) { + } + }); + + RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().foodHelper.getFoodData()); + recyclerView.setAdapter(adapter); + + loadData(); + fillCategories(); + fillSubcategories(); + filterData(); + return view; + } catch (Exception e) { + Crashlytics.logException(e); + } + + return null; + } + + @Subscribe + @SuppressWarnings("unused") + public void onStatusEvent(final EventFoodDatabaseChanged ev) { + loadData(); + filterData(); + } + + void loadData() { + unfiltered = MainApp.getDbHelper().foodHelper.getFoodData(); + } + + void fillCategories() { + categories = new ArrayList<>(); + + for (Food f : unfiltered) { + if (f.category != null && !f.category.equals("")) + categories.add(f.category); + } + + // make it unique + categories = new ArrayList<>(new HashSet<>(categories)); + + categories.add(0, MainApp.sResources.getString(R.string.none)); + + ArrayAdapter adapterCategories = new ArrayAdapter<>(getContext(), + R.layout.spinner_centered, categories); + category.setAdapter(adapterCategories); + } + + void fillSubcategories() { + String categoryFilter = category.getSelectedItem().toString(); + subcategories = new ArrayList<>(); + + if (!categoryFilter.equals(EMPTY)) { + for (Food f : unfiltered) { + if (f.category != null && f.category.equals(categoryFilter)) + if (f.subcategory != null && !f.subcategory.equals("")) + subcategories.add(f.subcategory); + } + } + + // make it unique + subcategories = new ArrayList<>(new HashSet<>(subcategories)); + + subcategories.add(0, MainApp.sResources.getString(R.string.none)); + + ArrayAdapter adapterSubcategories = new ArrayAdapter<>(getContext(), + R.layout.spinner_centered, subcategories); + subcategory.setAdapter(adapterSubcategories); + } + + void filterData() { + String textFilter = filter.getText().toString(); + String categoryFilter = category.getSelectedItem().toString(); + String subcategoryFilter = subcategory.getSelectedItem().toString(); + + filtered = new ArrayList<>(); + + for (Food f : unfiltered) { + if (f.name == null || f.category == null || f.subcategory == null) + continue; + + if (!subcategoryFilter.equals(EMPTY) && !f.subcategory.equals(subcategoryFilter)) + continue; + if (!categoryFilter.equals(EMPTY) && !f.category.equals(categoryFilter)) + continue; + if (!textFilter.equals("") && !f.name.toLowerCase().contains(textFilter.toLowerCase())) + continue; + filtered.add(f); + } + + updateGUI(); + } + + @Override + protected void updateGUI() { + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + recyclerView.swapAdapter(new FoodFragment.RecyclerViewAdapter(filtered), true); + } + }); + } + + public class RecyclerViewAdapter extends RecyclerView.Adapter { + + List foodList; + + RecyclerViewAdapter(List foodList) { + this.foodList = foodList; + } + + @Override + public FoodsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { + View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.food_item, viewGroup, false); + return new FoodsViewHolder(v); + } + + @Override + public void onBindViewHolder(FoodsViewHolder holder, int position) { + Food food = foodList.get(position); + holder.ns.setVisibility(food._id != null ? View.VISIBLE : View.GONE); + holder.name.setText(food.name); + holder.portion.setText(food.portion + food.units); + holder.carbs.setText(food.carbs + MainApp.sResources.getString(R.string.shortgramm)); + holder.fat.setText(MainApp.sResources.getString(R.string.shortfat) + ": " + food.fat + MainApp.sResources.getString(R.string.shortgramm)); + if (food.fat == 0) + holder.fat.setVisibility(View.INVISIBLE); + holder.protein.setText(MainApp.sResources.getString(R.string.shortprotein) + ": " + food.protein + MainApp.sResources.getString(R.string.shortgramm)); + if (food.protein == 0) + holder.protein.setVisibility(View.INVISIBLE); + holder.energy.setText(MainApp.sResources.getString(R.string.shortenergy) + ": " + food.energy + MainApp.sResources.getString(R.string.shortkilojoul)); + if (food.energy == 0) + holder.energy.setVisibility(View.INVISIBLE); + holder.remove.setTag(food); + } + + @Override + public int getItemCount() { + return foodList.size(); + } + + class FoodsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + TextView name; + TextView portion; + TextView carbs; + TextView fat; + TextView protein; + TextView energy; + TextView ns; + TextView remove; + + FoodsViewHolder(View itemView) { + super(itemView); + name = (TextView) itemView.findViewById(R.id.food_name); + portion = (TextView) itemView.findViewById(R.id.food_portion); + carbs = (TextView) itemView.findViewById(R.id.food_carbs); + fat = (TextView) itemView.findViewById(R.id.food_fat); + protein = (TextView) itemView.findViewById(R.id.food_protein); + energy = (TextView) itemView.findViewById(R.id.food_energy); + ns = (TextView) itemView.findViewById(R.id.ns_sign); + remove = (TextView) itemView.findViewById(R.id.food_remove); + remove.setOnClickListener(this); + remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + } + + @Override + public void onClick(View v) { + final Food food = (Food) v.getTag(); + switch (v.getId()) { + + case R.id.food_remove: + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setTitle(MainApp.sResources.getString(R.string.confirmation)); + builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + food.name); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + final String _id = food._id; + if (_id != null && !_id.equals("")) { + NSUpload.removeFoodFromNS(_id); + } + MainApp.getDbHelper().foodHelper.delete(food); + } + }); + builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null); + builder.show(); + break; + + } + } + } + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java new file mode 100644 index 0000000000..dbd1549c11 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java @@ -0,0 +1,80 @@ +package info.nightscout.androidaps.plugins.Food; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interfaces.PluginBase; + +/** + * Created by mike on 05.08.2016. + */ +public class FoodPlugin implements PluginBase { + private boolean fragmentEnabled = true; + private boolean fragmentVisible = false; + + private static FoodPlugin plugin = null; + + public static FoodPlugin getPlugin() { + if (plugin == null) + plugin = new FoodPlugin(); + return plugin; + } + + @Override + public String getFragmentClass() { + return FoodFragment.class.getName(); + } + + @Override + public int getType() { + return PluginBase.GENERAL; + } + + @Override + public String getName() { + return MainApp.instance().getString(R.string.food); + } + + @Override + public String getNameShort() { + // use long name as fallback (not visible in tabs) + return getName(); + } + + + @Override + public boolean isEnabled(int type) { + return type == GENERAL && fragmentEnabled; + } + + @Override + public boolean isVisibleInTabs(int type) { + return type == GENERAL && fragmentVisible; + } + + @Override + public boolean canBeHidden(int type) { + return true; + } + + @Override + public boolean hasFragment() { + return true; + } + + @Override + public boolean showInList(int type) { + return true; + } + + @Override + public void setFragmentEnabled(int type, boolean fragmentEnabled) { + if (type == GENERAL) this.fragmentEnabled = fragmentEnabled; + } + + @Override + public void setFragmentVisible(int type, boolean fragmentVisible) { + if (type == GENERAL) this.fragmentVisible = fragmentVisible; + } + + +} diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index 98ce8632ff..e11102198f 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -404,4 +404,23 @@ public class NSUpload { DbLogger.dbAdd(intent, data.toString()); } } + + public static void removeFoodFromNS(String _id) { + try { + Context context = MainApp.instance().getApplicationContext(); + Bundle bundle = new Bundle(); + bundle.putString("action", "dbRemove"); + bundle.putString("collection", "food"); + bundle.putString("_id", _id); + Intent intent = new Intent(Intents.ACTION_DATABASE); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + DbLogger.dbRemove(intent, _id); + } catch (Exception e) { + log.error("Unhandled exception", e); + } + + } + } diff --git a/app/src/main/res/layout/food_fragment.xml b/app/src/main/res/layout/food_fragment.xml new file mode 100644 index 0000000000..7b42eff11f --- /dev/null +++ b/app/src/main/res/layout/food_fragment.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/food_item.xml b/app/src/main/res/layout/food_item.xml new file mode 100644 index 0000000000..d4efc403a3 --- /dev/null +++ b/app/src/main/res/layout/food_item.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b5f3037145..a0f33da8e0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -70,7 +70,7 @@ No pump available No change requested Request - Rate + Rate Duration Reason Glucose @@ -685,10 +685,10 @@ Pass the Overview Notifications through as wear confirmation messages. Enable broadcasts to other apps (like xDrip). Enable local Broadcasts. - ACTIVITY & FEEDBACK - CARBS & BOLUS - CGM & OPENAPS - PUMP + ACTIVITY & FEEDBACK + CARBS & BOLUS + CGM & OPENAPS + PUMP Basal value [U/h] Duration [min] insulin_oref_peak @@ -746,5 +746,12 @@ Controls from Watch Set Temp-Targets and enter Treatments from the watch. Connection timed out + Food + g + ]]> + kJ + En + Pr + Fat From d65a2d8f8c45bed1b32f0452f8d580e467fe476e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 18 Oct 2017 19:01:39 +0200 Subject: [PATCH 02/26] move preparing graph series to extra class --- .../plugins/Overview/OverviewFragment.java | 218 ++--------------- .../plugins/Overview/graphData/GraphData.java | 231 ++++++++++++++++++ 2 files changed, 252 insertions(+), 197 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java 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 67ab9227ed..fc668032b5 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 @@ -37,9 +37,7 @@ import com.crashlytics.android.Crashlytics; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; import com.jjoe64.graphview.GraphView; -import com.jjoe64.graphview.LabelFormatter; import com.jjoe64.graphview.ValueDependentColor; -import com.jjoe64.graphview.Viewport; import com.jjoe64.graphview.series.BarGraphSeries; import com.jjoe64.graphview.series.DataPoint; import com.jjoe64.graphview.series.LineGraphSeries; @@ -55,7 +53,6 @@ import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.concurrent.Executors; @@ -100,7 +97,6 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; @@ -114,9 +110,8 @@ import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries; +import info.nightscout.androidaps.plugins.Overview.graphData.GraphData; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint; import info.nightscout.androidaps.plugins.Overview.graphExtensions.FixedLineGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter; @@ -128,7 +123,6 @@ import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.NSUpload; import info.nightscout.utils.OKDialog; import info.nightscout.utils.Profiler; -import info.nightscout.utils.Round; import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; @@ -939,8 +933,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, return; } - Double lowLine = SP.getDouble("low_mark", 0d); - Double highLine = SP.getDouble("high_mark", 0d); + double lowLine = SP.getDouble("low_mark", 0d); + double highLine = SP.getDouble("high_mark", 0d); //Start with updating the BG as it is unaffected by loop. // **** BG value **** @@ -1251,7 +1245,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } // ****** GRAPH ******* - //log.debug("updateGUI checkpoint 1"); // allign to hours Calendar calendar = Calendar.getInstance(); @@ -1280,109 +1273,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, endTime = toTime; } - LineGraphSeries basalsLineSeries = null; - LineGraphSeries absoluteBasalsLineSeries = null; - LineGraphSeries baseBasalsSeries = null; - LineGraphSeries tempBasalsSeries = null; - AreaGraphSeries areaSeries; LineGraphSeries seriesNow, seriesNow2; - // **** TEMP BASALS graph **** - Double maxBasalValueFound = 0d; - long now = System.currentTimeMillis(); - if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) { - List baseBasalArray = new ArrayList<>(); - List tempBasalArray = new ArrayList<>(); - List basalLineArray = new ArrayList<>(); - List absoluteBasalLineArray = new ArrayList<>(); - double lastLineBasal = 0; - double lastAbsoluteLineBasal = 0; - double lastBaseBasal = 0; - double lastTempBasal = 0; - for (long time = fromTime; time < now; time += 60 * 1000L) { - BasalData basalData = IobCobCalculatorPlugin.getBasalData(time); - double baseBasalValue = basalData.basal; - double absoluteLineValue = baseBasalValue; - double tempBasalValue = 0; - double basal = 0d; - if (basalData.isTempBasalRunning) { - absoluteLineValue = tempBasalValue = basalData.tempBasalAbsolute; - if (tempBasalValue != lastTempBasal) { - tempBasalArray.add(new DataPoint(time, lastTempBasal)); - tempBasalArray.add(new DataPoint(time, basal = tempBasalValue)); - } - if (lastBaseBasal != 0d) { - baseBasalArray.add(new DataPoint(time, lastBaseBasal)); - baseBasalArray.add(new DataPoint(time, 0d)); - lastBaseBasal = 0d; - } - } else { - if (baseBasalValue != lastBaseBasal) { - baseBasalArray.add(new DataPoint(time, lastBaseBasal)); - baseBasalArray.add(new DataPoint(time, basal = baseBasalValue)); - lastBaseBasal = baseBasalValue; - } - if (lastTempBasal != 0) { - tempBasalArray.add(new DataPoint(time, lastTempBasal)); - tempBasalArray.add(new DataPoint(time, 0d)); - } - } - - if (baseBasalValue != lastLineBasal) { - basalLineArray.add(new DataPoint(time, lastLineBasal)); - basalLineArray.add(new DataPoint(time, baseBasalValue)); - } - if (absoluteLineValue != lastAbsoluteLineBasal) { - absoluteBasalLineArray.add(new DataPoint(time, lastAbsoluteLineBasal)); - absoluteBasalLineArray.add(new DataPoint(time, basal)); - } - - lastAbsoluteLineBasal = absoluteLineValue; - lastLineBasal = baseBasalValue; - lastTempBasal = tempBasalValue; - maxBasalValueFound = Math.max(maxBasalValueFound, basal); - } - basalLineArray.add(new DataPoint(now, lastLineBasal)); - baseBasalArray.add(new DataPoint(now, lastBaseBasal)); - tempBasalArray.add(new DataPoint(now, lastTempBasal)); - absoluteBasalLineArray.add(new DataPoint(now, lastAbsoluteLineBasal)); - - DataPoint[] baseBasal = new DataPoint[baseBasalArray.size()]; - baseBasal = baseBasalArray.toArray(baseBasal); - baseBasalsSeries = new LineGraphSeries<>(baseBasal); - baseBasalsSeries.setDrawBackground(true); - baseBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.basebasal)); - baseBasalsSeries.setThickness(0); - - DataPoint[] tempBasal = new DataPoint[tempBasalArray.size()]; - tempBasal = tempBasalArray.toArray(tempBasal); - tempBasalsSeries = new LineGraphSeries<>(tempBasal); - tempBasalsSeries.setDrawBackground(true); - tempBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.tempbasal)); - tempBasalsSeries.setThickness(0); - - DataPoint[] basalLine = new DataPoint[basalLineArray.size()]; - basalLine = basalLineArray.toArray(basalLine); - basalsLineSeries = new LineGraphSeries<>(basalLine); - Paint paint = new Paint(); - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(2); - paint.setPathEffect(new DashPathEffect(new float[]{2, 4}, 0)); - paint.setColor(MainApp.sResources.getColor(R.color.basal)); - basalsLineSeries.setCustomPaint(paint); - - DataPoint[] absoluteBasalLine = new DataPoint[absoluteBasalLineArray.size()]; - absoluteBasalLine = absoluteBasalLineArray.toArray(absoluteBasalLine); - absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine); - Paint absolutePaint = new Paint(); - absolutePaint.setStyle(Paint.Style.STROKE); - absolutePaint.setStrokeWidth(4); - absolutePaint.setColor(MainApp.sResources.getColor(R.color.basal)); - absoluteBasalsLineSeries.setCustomPaint(absolutePaint); - } - - //log.debug("updateGUI checkpoint 2"); // **** IOB COB DEV graph **** class DeviationDataPoint extends DataPoint { @@ -1545,23 +1438,21 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } else { iobGraph.setVisibility(View.GONE); } - //log.debug("updateGUI checkpoint 3"); // remove old data from graph bgGraph.getSecondScale().getSeries().clear(); bgGraph.getSeries().clear(); - //log.debug("updateGUI checkpoint 4"); - // **** Area **** - DoubleDataPoint[] areaDataPoints = new DoubleDataPoint[]{ - new DoubleDataPoint(fromTime, lowLine, highLine), - new DoubleDataPoint(endTime, lowLine, highLine) - }; - areaSeries = new AreaGraphSeries<>(areaDataPoints); - addSeriesWithoutInvalidate(areaSeries, bgGraph); - areaSeries.setColor(0); - areaSeries.setDrawBackground(true); - areaSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.inrangebackground)); + GraphData graphData = new GraphData(bgGraph); + + // **** In range Area **** + graphData.addInRangeArea(fromTime, endTime, lowLine, highLine); + + // **** BG **** + if (showPrediction) + graphData.addBgReadings(fromTime, toTime, lowLine, highLine, (DetermineBasalResultAMA) finalLastRun.constraintsProcessed); + else + graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null); // set manual x bounds to have nice steps bgGraph.getViewport().setMaxX(endTime); @@ -1575,41 +1466,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, iobGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH")); iobGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space - //log.debug("updateGUI checkpoint 5"); - // **** BG graph **** - List bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true); - List bgListArray = new ArrayList<>(); - if (bgReadingsArray.size() == 0) { - return; - } - - Iterator it = bgReadingsArray.iterator(); - Double maxBgValue = 0d; - while (it.hasNext()) { - BgReading bg = it.next(); - if (bg.value > maxBgValue) maxBgValue = bg.value; - bgListArray.add(bg); - } - if (showPrediction) { - DetermineBasalResultAMA amaResult = (DetermineBasalResultAMA) finalLastRun.constraintsProcessed; - List predArray = amaResult.getPredictions(); - bgListArray.addAll(predArray); - } - - maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units); - maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4; - if (highLine > maxBgValue) maxBgValue = highLine; - Integer numOfVertLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1); - - DataPointWithLabelInterface[] bg = new DataPointWithLabelInterface[bgListArray.size()]; - bg = bgListArray.toArray(bg); - - if (bg.length > 0) { - addSeriesWithoutInvalidate(new PointsWithLabelGraphSeries<>(bg), bgGraph); - } - - //log.debug("updateGUI checkpoint 6"); // Treatments List filteredTreatments = new ArrayList<>(); @@ -1618,11 +1475,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, for (int tx = 0; tx < treatments.size(); tx++) { Treatment t = treatments.get(tx); if (t.getX() < fromTime || t.getX() > endTime) continue; - t.setY(getNearestBg((long) t.getX(), bgReadingsArray)); + t.setY(graphData.getNearestBg((long) t.getX())); filteredTreatments.add(t); } - //log.debug("updateGUI checkpoint 7"); // ProfileSwitch List profileSwitches = MainApp.getConfigBuilder().getProfileSwitchesFromHistory().getList(); @@ -1632,7 +1488,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, filteredTreatments.add(t); } - //log.debug("updateGUI checkpoint 8"); // Extended bolus if (!pump.isFakingTempsByExtendedBoluses()) { List extendedBoluses = MainApp.getConfigBuilder().getExtendedBolusesFromHistory().getList(); @@ -1641,19 +1496,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, DataPointWithLabelInterface t = extendedBoluses.get(tx); if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue; if (t.getDuration() == 0) continue; - t.setY(getNearestBg((long) t.getX(), bgReadingsArray)); + t.setY(graphData.getNearestBg((long) t.getX())); filteredTreatments.add(t); } } - //log.debug("updateGUI checkpoint 9"); // Careportal List careportalEvents = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, true); for (int tx = 0; tx < careportalEvents.size(); tx++) { DataPointWithLabelInterface t = careportalEvents.get(tx); if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue; - t.setY(getNearestBg((long) t.getX(), bgReadingsArray)); + t.setY(graphData.getNearestBg((long) t.getX())); filteredTreatments.add(t); } @@ -1662,40 +1516,22 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (treatmentsArray.length > 0) { addSeriesWithoutInvalidate(new PointsWithLabelGraphSeries<>(treatmentsArray), bgGraph); } - //log.debug("updateGUI checkpoint 10"); // set manual y bounds to have nice steps - bgGraph.getViewport().setMaxY(maxBgValue); + bgGraph.getViewport().setMaxY(graphData.maxBgValue); bgGraph.getViewport().setMinY(0); bgGraph.getViewport().setYAxisBoundsManual(true); - bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfVertLines); + bgGraph.getGridLabelRenderer().setNumVerticalLabels(graphData.numOfVertLines); - // set second scale + // add basal data if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) { - bgGraph.getSecondScale().setMinY(0); - bgGraph.getSecondScale().setMaxY(maxBgValue / lowLine * maxBasalValueFound * 1.2d); - bgGraph.getSecondScale().addSeries(baseBasalsSeries); - bgGraph.getSecondScale().addSeries(tempBasalsSeries); - bgGraph.getSecondScale().addSeries(basalsLineSeries); - bgGraph.getSecondScale().addSeries(absoluteBasalsLineSeries); + graphData.addBasalsToSecondScale(fromTime, now, graphData.maxBgValue / lowLine * 1.2d); } - bgGraph.getSecondScale().setLabelFormatter(new LabelFormatter() { - @Override - public String formatLabel(double value, boolean isValueX) { - return ""; - } - @Override - public void setViewport(Viewport viewport) { - - } - }); - - //log.debug("updateGUI checkpoint 11"); // **** NOW line **** DataPoint[] nowPoints = new DataPoint[]{ new DataPoint(now, 0), - new DataPoint(now, maxBgValue) + new DataPoint(now, graphData.maxBgValue) }; addSeriesWithoutInvalidate(seriesNow = new LineGraphSeries<>(nowPoints), bgGraph); seriesNow.setDrawDataPoints(false); @@ -1720,18 +1556,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, Profiler.log(log, from, updateGUIStart); } - public double getNearestBg(long date, List bgReadingsArray) { - double bg = 0; - String units = MainApp.getConfigBuilder().getProfileUnits(); - for (int r = bgReadingsArray.size() - 1; r >= 0; r--) { - BgReading reading = bgReadingsArray.get(r); - if (reading.date > date) continue; - bg = Profile.fromMgdlToUnits(reading.value, units); - break; - } - return bg; - } - void addSeriesWithoutInvalidate(Series s, GraphView graph) { s.onGraphViewAttached(graph); graph.getSeries().add(s); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java new file mode 100644 index 0000000000..d586109564 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java @@ -0,0 +1,231 @@ +package info.nightscout.androidaps.plugins.Overview.graphData; + +import android.graphics.DashPathEffect; +import android.graphics.Paint; + +import com.jjoe64.graphview.GraphView; +import com.jjoe64.graphview.LabelFormatter; +import com.jjoe64.graphview.Viewport; +import com.jjoe64.graphview.series.DataPoint; +import com.jjoe64.graphview.series.LineGraphSeries; +import com.jjoe64.graphview.series.Series; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData; +import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; +import info.nightscout.utils.Round; + +/** + * Created by mike on 18.10.2017. + */ + +public class GraphData { + + public GraphData(GraphView bgGraph) { + this.bgGraph = bgGraph; + units = MainApp.getConfigBuilder().getProfileUnits(); + } + + private GraphView bgGraph; + public double maxBgValue = 0d; + public int numOfVertLines; + private List bgReadingsArray; + private String units; + + public void addBgReadings(long fromTime, long toTime, double lowLine, double highLine, DetermineBasalResultAMA amaResult) { + maxBgValue = 0d; + bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true); + List bgListArray = new ArrayList<>(); + + if (bgReadingsArray.size() == 0) { + return; + } + + Iterator it = bgReadingsArray.iterator(); + while (it.hasNext()) { + BgReading bg = it.next(); + if (bg.value > maxBgValue) maxBgValue = bg.value; + bgListArray.add(bg); + } + if (amaResult != null) { + List predArray = amaResult.getPredictions(); + bgListArray.addAll(predArray); + } + + maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units); + maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4; + if (highLine > maxBgValue) maxBgValue = highLine; + numOfVertLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1); + + DataPointWithLabelInterface[] bg = new DataPointWithLabelInterface[bgListArray.size()]; + bg = bgListArray.toArray(bg); + + if (bg.length > 0) { + addSeriesWithoutInvalidate(new PointsWithLabelGraphSeries<>(bg)); + } + + } + + public void addInRangeArea(long fromTime, long toTime, double lowLine, double highLine) { + AreaGraphSeries inRangeAreaSeries; + + DoubleDataPoint[] inRangeAreaDataPoints = new DoubleDataPoint[]{ + new DoubleDataPoint(fromTime, lowLine, highLine), + new DoubleDataPoint(toTime, lowLine, highLine) + }; + inRangeAreaSeries = new AreaGraphSeries<>(inRangeAreaDataPoints); + addSeriesWithoutInvalidate(inRangeAreaSeries); + inRangeAreaSeries.setColor(0); + inRangeAreaSeries.setDrawBackground(true); + inRangeAreaSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.inrangebackground)); + } + + public void addBasalsToSecondScale(long fromTime, long toTime, double scale) { + LineGraphSeries basalsLineSeries; + LineGraphSeries absoluteBasalsLineSeries; + LineGraphSeries baseBasalsSeries; + LineGraphSeries tempBasalsSeries; + + Double maxBasalValueFound = 0d; + + List baseBasalArray = new ArrayList<>(); + List tempBasalArray = new ArrayList<>(); + List basalLineArray = new ArrayList<>(); + List absoluteBasalLineArray = new ArrayList<>(); + double lastLineBasal = 0; + double lastAbsoluteLineBasal = 0; + double lastBaseBasal = 0; + double lastTempBasal = 0; + for (long time = fromTime; time < toTime; time += 60 * 1000L) { + BasalData basalData = IobCobCalculatorPlugin.getBasalData(time); + double baseBasalValue = basalData.basal; + double absoluteLineValue = baseBasalValue; + double tempBasalValue = 0; + double basal = 0d; + if (basalData.isTempBasalRunning) { + absoluteLineValue = tempBasalValue = basalData.tempBasalAbsolute; + if (tempBasalValue != lastTempBasal) { + tempBasalArray.add(new DataPoint(time, lastTempBasal)); + tempBasalArray.add(new DataPoint(time, basal = tempBasalValue)); + } + if (lastBaseBasal != 0d) { + baseBasalArray.add(new DataPoint(time, lastBaseBasal)); + baseBasalArray.add(new DataPoint(time, 0d)); + lastBaseBasal = 0d; + } + } else { + if (baseBasalValue != lastBaseBasal) { + baseBasalArray.add(new DataPoint(time, lastBaseBasal)); + baseBasalArray.add(new DataPoint(time, basal = baseBasalValue)); + lastBaseBasal = baseBasalValue; + } + if (lastTempBasal != 0) { + tempBasalArray.add(new DataPoint(time, lastTempBasal)); + tempBasalArray.add(new DataPoint(time, 0d)); + } + } + + if (baseBasalValue != lastLineBasal) { + basalLineArray.add(new DataPoint(time, lastLineBasal)); + basalLineArray.add(new DataPoint(time, baseBasalValue)); + } + if (absoluteLineValue != lastAbsoluteLineBasal) { + absoluteBasalLineArray.add(new DataPoint(time, lastAbsoluteLineBasal)); + absoluteBasalLineArray.add(new DataPoint(time, basal)); + } + + lastAbsoluteLineBasal = absoluteLineValue; + lastLineBasal = baseBasalValue; + lastTempBasal = tempBasalValue; + maxBasalValueFound = Math.max(maxBasalValueFound, basal); + } + + basalLineArray.add(new DataPoint(toTime, lastLineBasal)); + baseBasalArray.add(new DataPoint(toTime, lastBaseBasal)); + tempBasalArray.add(new DataPoint(toTime, lastTempBasal)); + absoluteBasalLineArray.add(new DataPoint(toTime, lastAbsoluteLineBasal)); + + DataPoint[] baseBasal = new DataPoint[baseBasalArray.size()]; + baseBasal = baseBasalArray.toArray(baseBasal); + baseBasalsSeries = new LineGraphSeries<>(baseBasal); + baseBasalsSeries.setDrawBackground(true); + baseBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.basebasal)); + baseBasalsSeries.setThickness(0); + + DataPoint[] tempBasal = new DataPoint[tempBasalArray.size()]; + tempBasal = tempBasalArray.toArray(tempBasal); + tempBasalsSeries = new LineGraphSeries<>(tempBasal); + tempBasalsSeries.setDrawBackground(true); + tempBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.tempbasal)); + tempBasalsSeries.setThickness(0); + + DataPoint[] basalLine = new DataPoint[basalLineArray.size()]; + basalLine = basalLineArray.toArray(basalLine); + basalsLineSeries = new LineGraphSeries<>(basalLine); + Paint paint = new Paint(); + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeWidth(2); + paint.setPathEffect(new DashPathEffect(new float[]{2, 4}, 0)); + paint.setColor(MainApp.sResources.getColor(R.color.basal)); + basalsLineSeries.setCustomPaint(paint); + + DataPoint[] absoluteBasalLine = new DataPoint[absoluteBasalLineArray.size()]; + absoluteBasalLine = absoluteBasalLineArray.toArray(absoluteBasalLine); + absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine); + Paint absolutePaint = new Paint(); + absolutePaint.setStyle(Paint.Style.STROKE); + absolutePaint.setStrokeWidth(4); + absolutePaint.setColor(MainApp.sResources.getColor(R.color.basal)); + absoluteBasalsLineSeries.setCustomPaint(absolutePaint); + + bgGraph.getSecondScale().setMinY(0); + bgGraph.getSecondScale().setMaxY(scale * maxBasalValueFound); + bgGraph.getSecondScale().addSeries(baseBasalsSeries); + bgGraph.getSecondScale().addSeries(tempBasalsSeries); + bgGraph.getSecondScale().addSeries(basalsLineSeries); + bgGraph.getSecondScale().addSeries(absoluteBasalsLineSeries); + + bgGraph.getSecondScale().setLabelFormatter(new LabelFormatter() { + @Override + public String formatLabel(double value, boolean isValueX) { + return ""; + } + + @Override + public void setViewport(Viewport viewport) { + + } + }); + } + + public double getNearestBg(long date) { + double bg = 0; + for (int r = bgReadingsArray.size() - 1; r >= 0; r--) { + BgReading reading = bgReadingsArray.get(r); + if (reading.date > date) continue; + bg = Profile.fromMgdlToUnits(reading.value, units); + break; + } + return bg; + } + + + private void addSeriesWithoutInvalidate(Series s) { + s.onGraphViewAttached(bgGraph); + bgGraph.getSeries().add(s); + } + +} From 19f107fe53a22be991689ab6217bbf3cd5ff73db Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 18 Oct 2017 23:56:13 +0200 Subject: [PATCH 03/26] move preparing graph series to extra class #2 --- .../plugins/Overview/OverviewFragment.java | 68 +------ .../plugins/Overview/graphData/GraphData.java | 172 ++++++++++++------ .../Overview/graphExtensions/Scale.java | 17 ++ .../graphExtensions/ScaledDataPoint.java | 46 +++++ 4 files changed, 182 insertions(+), 121 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java 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 fc668032b5..638b44374f 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 @@ -1440,19 +1440,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } // remove old data from graph - bgGraph.getSecondScale().getSeries().clear(); bgGraph.getSeries().clear(); - GraphData graphData = new GraphData(bgGraph); + GraphData graphData = new GraphData(); // **** In range Area **** - graphData.addInRangeArea(fromTime, endTime, lowLine, highLine); + graphData.addInRangeArea(bgGraph, fromTime, endTime, lowLine, highLine); // **** BG **** if (showPrediction) - graphData.addBgReadings(fromTime, toTime, lowLine, highLine, (DetermineBasalResultAMA) finalLastRun.constraintsProcessed); + graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, (DetermineBasalResultAMA) finalLastRun.constraintsProcessed); else - graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null); + graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, null); // set manual x bounds to have nice steps bgGraph.getViewport().setMaxX(endTime); @@ -1468,70 +1467,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, // Treatments - List filteredTreatments = new ArrayList<>(); - - List treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory(); - - for (int tx = 0; tx < treatments.size(); tx++) { - Treatment t = treatments.get(tx); - if (t.getX() < fromTime || t.getX() > endTime) continue; - t.setY(graphData.getNearestBg((long) t.getX())); - filteredTreatments.add(t); - } - - // ProfileSwitch - List profileSwitches = MainApp.getConfigBuilder().getProfileSwitchesFromHistory().getList(); - - for (int tx = 0; tx < profileSwitches.size(); tx++) { - DataPointWithLabelInterface t = profileSwitches.get(tx); - if (t.getX() < fromTime || t.getX() > endTime) continue; - filteredTreatments.add(t); - } - - // Extended bolus - if (!pump.isFakingTempsByExtendedBoluses()) { - List extendedBoluses = MainApp.getConfigBuilder().getExtendedBolusesFromHistory().getList(); - - for (int tx = 0; tx < extendedBoluses.size(); tx++) { - DataPointWithLabelInterface t = extendedBoluses.get(tx); - if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue; - if (t.getDuration() == 0) continue; - t.setY(graphData.getNearestBg((long) t.getX())); - filteredTreatments.add(t); - } - } - - // Careportal - List careportalEvents = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, true); - - for (int tx = 0; tx < careportalEvents.size(); tx++) { - DataPointWithLabelInterface t = careportalEvents.get(tx); - if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue; - t.setY(graphData.getNearestBg((long) t.getX())); - filteredTreatments.add(t); - } - - DataPointWithLabelInterface[] treatmentsArray = new DataPointWithLabelInterface[filteredTreatments.size()]; - treatmentsArray = filteredTreatments.toArray(treatmentsArray); - if (treatmentsArray.length > 0) { - addSeriesWithoutInvalidate(new PointsWithLabelGraphSeries<>(treatmentsArray), bgGraph); - } - - // set manual y bounds to have nice steps - bgGraph.getViewport().setMaxY(graphData.maxBgValue); - bgGraph.getViewport().setMinY(0); - bgGraph.getViewport().setYAxisBoundsManual(true); - bgGraph.getGridLabelRenderer().setNumVerticalLabels(graphData.numOfVertLines); + graphData.addTreatmnets(bgGraph, fromTime, endTime); // add basal data if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) { - graphData.addBasalsToSecondScale(fromTime, now, graphData.maxBgValue / lowLine * 1.2d); + graphData.addBasals(bgGraph, fromTime, now, lowLine / graphData.maxX / 1.2d); } // **** NOW line **** DataPoint[] nowPoints = new DataPoint[]{ new DataPoint(now, 0), - new DataPoint(now, graphData.maxBgValue) + new DataPoint(now, graphData.maxX) }; addSeriesWithoutInvalidate(seriesNow = new LineGraphSeries<>(nowPoints), bgGraph); seriesNow.setDrawDataPoints(false); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java index d586109564..ea6de9f9a4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java @@ -10,6 +10,8 @@ import com.jjoe64.graphview.series.DataPoint; import com.jjoe64.graphview.series.LineGraphSeries; import com.jjoe64.graphview.series.Series; +import org.mozilla.javascript.tools.debugger.Main; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -19,6 +21,10 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.db.CareportalEvent; +import info.nightscout.androidaps.db.ExtendedBolus; +import info.nightscout.androidaps.db.ProfileSwitch; +import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData; import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA; @@ -26,6 +32,8 @@ import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeri import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint; import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.Scale; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.ScaledDataPoint; import info.nightscout.utils.Round; /** @@ -34,19 +42,16 @@ import info.nightscout.utils.Round; public class GraphData { - public GraphData(GraphView bgGraph) { - this.bgGraph = bgGraph; + public GraphData() { units = MainApp.getConfigBuilder().getProfileUnits(); } - private GraphView bgGraph; - public double maxBgValue = 0d; - public int numOfVertLines; + public double maxX = 0; private List bgReadingsArray; private String units; - public void addBgReadings(long fromTime, long toTime, double lowLine, double highLine, DetermineBasalResultAMA amaResult) { - maxBgValue = 0d; + public void addBgReadings(GraphView bgGraph, long fromTime, long toTime, double lowLine, double highLine, DetermineBasalResultAMA amaResult) { + double maxBgValue = 0d; bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true); List bgListArray = new ArrayList<>(); @@ -68,18 +73,25 @@ public class GraphData { maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units); maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4; if (highLine > maxBgValue) maxBgValue = highLine; - numOfVertLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1); + int numOfVertLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1); DataPointWithLabelInterface[] bg = new DataPointWithLabelInterface[bgListArray.size()]; bg = bgListArray.toArray(bg); if (bg.length > 0) { - addSeriesWithoutInvalidate(new PointsWithLabelGraphSeries<>(bg)); + addSeriesWithoutInvalidate(bgGraph, new PointsWithLabelGraphSeries<>(bg)); } + maxX = maxBgValue; + // set manual y bounds to have nice steps + bgGraph.getViewport().setMaxY(maxX); + bgGraph.getViewport().setMinY(0); + bgGraph.getViewport().setYAxisBoundsManual(true); + bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfVertLines); + } - public void addInRangeArea(long fromTime, long toTime, double lowLine, double highLine) { + public void addInRangeArea(GraphView bgGraph, long fromTime, long toTime, double lowLine, double highLine) { AreaGraphSeries inRangeAreaSeries; DoubleDataPoint[] inRangeAreaDataPoints = new DoubleDataPoint[]{ @@ -87,24 +99,26 @@ public class GraphData { new DoubleDataPoint(toTime, lowLine, highLine) }; inRangeAreaSeries = new AreaGraphSeries<>(inRangeAreaDataPoints); - addSeriesWithoutInvalidate(inRangeAreaSeries); + addSeriesWithoutInvalidate(bgGraph, inRangeAreaSeries); inRangeAreaSeries.setColor(0); inRangeAreaSeries.setDrawBackground(true); inRangeAreaSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.inrangebackground)); } - public void addBasalsToSecondScale(long fromTime, long toTime, double scale) { - LineGraphSeries basalsLineSeries; - LineGraphSeries absoluteBasalsLineSeries; - LineGraphSeries baseBasalsSeries; - LineGraphSeries tempBasalsSeries; + // scale in % of vertical size (like 0.3) + public void addBasals(GraphView bgGraph, long fromTime, long toTime, double scale) { + LineGraphSeries basalsLineSeries; + LineGraphSeries absoluteBasalsLineSeries; + LineGraphSeries baseBasalsSeries; + LineGraphSeries tempBasalsSeries; - Double maxBasalValueFound = 0d; + double maxBasalValueFound = 0d; + Scale basalScale = new Scale(); - List baseBasalArray = new ArrayList<>(); - List tempBasalArray = new ArrayList<>(); - List basalLineArray = new ArrayList<>(); - List absoluteBasalLineArray = new ArrayList<>(); + List baseBasalArray = new ArrayList<>(); + List tempBasalArray = new ArrayList<>(); + List basalLineArray = new ArrayList<>(); + List absoluteBasalLineArray = new ArrayList<>(); double lastLineBasal = 0; double lastAbsoluteLineBasal = 0; double lastBaseBasal = 0; @@ -118,33 +132,33 @@ public class GraphData { if (basalData.isTempBasalRunning) { absoluteLineValue = tempBasalValue = basalData.tempBasalAbsolute; if (tempBasalValue != lastTempBasal) { - tempBasalArray.add(new DataPoint(time, lastTempBasal)); - tempBasalArray.add(new DataPoint(time, basal = tempBasalValue)); + tempBasalArray.add(new ScaledDataPoint(time, lastTempBasal, basalScale)); + tempBasalArray.add(new ScaledDataPoint(time, basal = tempBasalValue, basalScale)); } if (lastBaseBasal != 0d) { - baseBasalArray.add(new DataPoint(time, lastBaseBasal)); - baseBasalArray.add(new DataPoint(time, 0d)); + baseBasalArray.add(new ScaledDataPoint(time, lastBaseBasal, basalScale)); + baseBasalArray.add(new ScaledDataPoint(time, 0d, basalScale)); lastBaseBasal = 0d; } } else { if (baseBasalValue != lastBaseBasal) { - baseBasalArray.add(new DataPoint(time, lastBaseBasal)); - baseBasalArray.add(new DataPoint(time, basal = baseBasalValue)); + baseBasalArray.add(new ScaledDataPoint(time, lastBaseBasal, basalScale)); + baseBasalArray.add(new ScaledDataPoint(time, basal = baseBasalValue, basalScale)); lastBaseBasal = baseBasalValue; } if (lastTempBasal != 0) { - tempBasalArray.add(new DataPoint(time, lastTempBasal)); - tempBasalArray.add(new DataPoint(time, 0d)); + tempBasalArray.add(new ScaledDataPoint(time, lastTempBasal, basalScale)); + tempBasalArray.add(new ScaledDataPoint(time, 0d, basalScale)); } } if (baseBasalValue != lastLineBasal) { - basalLineArray.add(new DataPoint(time, lastLineBasal)); - basalLineArray.add(new DataPoint(time, baseBasalValue)); + basalLineArray.add(new ScaledDataPoint(time, lastLineBasal, basalScale)); + basalLineArray.add(new ScaledDataPoint(time, baseBasalValue, basalScale)); } if (absoluteLineValue != lastAbsoluteLineBasal) { - absoluteBasalLineArray.add(new DataPoint(time, lastAbsoluteLineBasal)); - absoluteBasalLineArray.add(new DataPoint(time, basal)); + absoluteBasalLineArray.add(new ScaledDataPoint(time, lastAbsoluteLineBasal, basalScale)); + absoluteBasalLineArray.add(new ScaledDataPoint(time, basal, basalScale)); } lastAbsoluteLineBasal = absoluteLineValue; @@ -153,26 +167,26 @@ public class GraphData { maxBasalValueFound = Math.max(maxBasalValueFound, basal); } - basalLineArray.add(new DataPoint(toTime, lastLineBasal)); - baseBasalArray.add(new DataPoint(toTime, lastBaseBasal)); - tempBasalArray.add(new DataPoint(toTime, lastTempBasal)); - absoluteBasalLineArray.add(new DataPoint(toTime, lastAbsoluteLineBasal)); + basalLineArray.add(new ScaledDataPoint(toTime, lastLineBasal, basalScale)); + baseBasalArray.add(new ScaledDataPoint(toTime, lastBaseBasal, basalScale)); + tempBasalArray.add(new ScaledDataPoint(toTime, lastTempBasal, basalScale)); + absoluteBasalLineArray.add(new ScaledDataPoint(toTime, lastAbsoluteLineBasal, basalScale)); - DataPoint[] baseBasal = new DataPoint[baseBasalArray.size()]; + ScaledDataPoint[] baseBasal = new ScaledDataPoint[baseBasalArray.size()]; baseBasal = baseBasalArray.toArray(baseBasal); baseBasalsSeries = new LineGraphSeries<>(baseBasal); baseBasalsSeries.setDrawBackground(true); baseBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.basebasal)); baseBasalsSeries.setThickness(0); - DataPoint[] tempBasal = new DataPoint[tempBasalArray.size()]; + ScaledDataPoint[] tempBasal = new ScaledDataPoint[tempBasalArray.size()]; tempBasal = tempBasalArray.toArray(tempBasal); tempBasalsSeries = new LineGraphSeries<>(tempBasal); tempBasalsSeries.setDrawBackground(true); tempBasalsSeries.setBackgroundColor(MainApp.sResources.getColor(R.color.tempbasal)); tempBasalsSeries.setThickness(0); - DataPoint[] basalLine = new DataPoint[basalLineArray.size()]; + ScaledDataPoint[] basalLine = new ScaledDataPoint[basalLineArray.size()]; basalLine = basalLineArray.toArray(basalLine); basalsLineSeries = new LineGraphSeries<>(basalLine); Paint paint = new Paint(); @@ -182,7 +196,7 @@ public class GraphData { paint.setColor(MainApp.sResources.getColor(R.color.basal)); basalsLineSeries.setCustomPaint(paint); - DataPoint[] absoluteBasalLine = new DataPoint[absoluteBasalLineArray.size()]; + ScaledDataPoint[] absoluteBasalLine = new ScaledDataPoint[absoluteBasalLineArray.size()]; absoluteBasalLine = absoluteBasalLineArray.toArray(absoluteBasalLine); absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine); Paint absolutePaint = new Paint(); @@ -191,27 +205,65 @@ public class GraphData { absolutePaint.setColor(MainApp.sResources.getColor(R.color.basal)); absoluteBasalsLineSeries.setCustomPaint(absolutePaint); - bgGraph.getSecondScale().setMinY(0); - bgGraph.getSecondScale().setMaxY(scale * maxBasalValueFound); - bgGraph.getSecondScale().addSeries(baseBasalsSeries); - bgGraph.getSecondScale().addSeries(tempBasalsSeries); - bgGraph.getSecondScale().addSeries(basalsLineSeries); - bgGraph.getSecondScale().addSeries(absoluteBasalsLineSeries); + basalScale.setValue(maxX * scale / maxBasalValueFound); - bgGraph.getSecondScale().setLabelFormatter(new LabelFormatter() { - @Override - public String formatLabel(double value, boolean isValueX) { - return ""; - } - - @Override - public void setViewport(Viewport viewport) { - - } - }); + addSeriesWithoutInvalidate(bgGraph, baseBasalsSeries); + addSeriesWithoutInvalidate(bgGraph, tempBasalsSeries); + addSeriesWithoutInvalidate(bgGraph, basalsLineSeries); + addSeriesWithoutInvalidate(bgGraph, absoluteBasalsLineSeries); } - public double getNearestBg(long date) { + public void addTreatmnets(GraphView bgGraph, long fromTime, long endTime) { + List filteredTreatments = new ArrayList<>(); + + List treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory(); + + for (int tx = 0; tx < treatments.size(); tx++) { + Treatment t = treatments.get(tx); + if (t.getX() < fromTime || t.getX() > endTime) continue; + t.setY(getNearestBg((long) t.getX())); + filteredTreatments.add(t); + } + + // ProfileSwitch + List profileSwitches = MainApp.getConfigBuilder().getProfileSwitchesFromHistory().getList(); + + for (int tx = 0; tx < profileSwitches.size(); tx++) { + DataPointWithLabelInterface t = profileSwitches.get(tx); + if (t.getX() < fromTime || t.getX() > endTime) continue; + filteredTreatments.add(t); + } + + // Extended bolus + if (!MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) { + List extendedBoluses = MainApp.getConfigBuilder().getExtendedBolusesFromHistory().getList(); + + for (int tx = 0; tx < extendedBoluses.size(); tx++) { + DataPointWithLabelInterface t = extendedBoluses.get(tx); + if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue; + if (t.getDuration() == 0) continue; + t.setY(getNearestBg((long) t.getX())); + filteredTreatments.add(t); + } + } + + // Careportal + List careportalEvents = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, true); + + for (int tx = 0; tx < careportalEvents.size(); tx++) { + DataPointWithLabelInterface t = careportalEvents.get(tx); + if (t.getX() + t.getDuration() < fromTime || t.getX() > endTime) continue; + t.setY(getNearestBg((long) t.getX())); + filteredTreatments.add(t); + } + + DataPointWithLabelInterface[] treatmentsArray = new DataPointWithLabelInterface[filteredTreatments.size()]; + treatmentsArray = filteredTreatments.toArray(treatmentsArray); + if (treatmentsArray.length > 0) { + addSeriesWithoutInvalidate(bgGraph, new PointsWithLabelGraphSeries<>(treatmentsArray)); + } } + + double getNearestBg(long date) { double bg = 0; for (int r = bgReadingsArray.size() - 1; r >= 0; r--) { BgReading reading = bgReadingsArray.get(r); @@ -223,7 +275,7 @@ public class GraphData { } - private void addSeriesWithoutInvalidate(Series s) { + private void addSeriesWithoutInvalidate(GraphView bgGraph, Series s) { s.onGraphViewAttached(bgGraph); bgGraph.getSeries().add(s); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java new file mode 100644 index 0000000000..1acb357a4b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java @@ -0,0 +1,17 @@ +package info.nightscout.androidaps.plugins.Overview.graphExtensions; + +/** + * Created by mike on 18.10.2017. + */ + +public class Scale { + private double value; + + public void setValue(double value) { + this.value = value; + } + + public double getValue() { + return value; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java new file mode 100644 index 0000000000..e5d2364be7 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java @@ -0,0 +1,46 @@ +package info.nightscout.androidaps.plugins.Overview.graphExtensions; + +import com.jjoe64.graphview.series.DataPointInterface; + +import java.io.Serializable; +import java.util.Date; + +/** + * Created by mike on 18.10.2017. + */ + +public class ScaledDataPoint implements DataPointInterface, Serializable { + private static final long serialVersionUID=1428263342645L; + + private double x; + private double y; + + private Scale scale; + + public ScaledDataPoint(double x, double y, Scale scale) { + this.x=x; + this.y=y; + this.scale = scale; + } + + public ScaledDataPoint(Date x, double y, Scale scale) { + this.x = x.getTime(); + this.y = y; + this.scale = scale; + } + + @Override + public double getX() { + return x; + } + + @Override + public double getY() { + return y * scale.getValue(); + } + + @Override + public String toString() { + return "["+x+"/"+y+"]"; + } +} From 1ad409754f7021c4d9baa61ffcd11b225e4865f7 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 23 Oct 2017 22:41:12 +0200 Subject: [PATCH 04/26] move preparing graph series to extra class #2 --- .../plugins/Overview/OverviewFragment.java | 233 +++--------------- .../plugins/Overview/graphData/GraphData.java | 208 +++++++++++++++- .../Overview/graphExtensions/Scale.java | 23 +- .../graphExtensions/ScaledDataPoint.java | 2 +- .../TimeAsXAxisLabelFormatter.java | 2 +- 5 files changed, 251 insertions(+), 217 deletions(-) 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 638b44374f..393dc29de5 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 @@ -74,11 +74,9 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.ExtendedBolus; -import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventCareportalEventChange; import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventInitializationChanged; @@ -111,9 +109,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock; import info.nightscout.androidaps.plugins.Overview.graphData.GraphData; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.Overview.graphExtensions.FixedLineGraphSeries; -import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog; @@ -1273,167 +1269,40 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, endTime = toTime; } - LineGraphSeries seriesNow, seriesNow2; long now = System.currentTimeMillis(); - // **** IOB COB DEV graph **** - class DeviationDataPoint extends DataPoint { - public int color; + // 2nd graph + // remove old data + iobGraph.getSeries().clear(); - public DeviationDataPoint(double x, double y, int color) { - super(x, y); - this.color = color; - } + GraphData secondGraphData = new GraphData(); + + boolean useIobForScale = false; + boolean useCobForScale = false; + boolean useDevForScale = false; + boolean useRatioForScale = false; + + if (showIobView.isChecked()) { + useIobForScale = true; + } else if (showCobView.isChecked()) { + useCobForScale = true; + } else if (showDeviationsView.isChecked()) { + useDevForScale = true; + } else if (showRatiosView.isChecked()) { + useRatioForScale = true; } - FixedLineGraphSeries iobSeries; - FixedLineGraphSeries cobSeries; - BarGraphSeries devSeries; - LineGraphSeries ratioSeries; - Double maxIobValueFound = 0d; - Double maxCobValueFound = 0d; - Double maxDevValueFound = 0d; - Double maxRatioValueFound = 0d; + + if (showIobView.isChecked()) + secondGraphData.addIob(iobGraph, fromTime, now, useIobForScale, 1d); + if (showCobView.isChecked()) + secondGraphData.addCob(iobGraph, fromTime, now, useCobForScale, useCobForScale ? 1d : 0.5d); + if (showDeviationsView.isChecked()) + secondGraphData.addDeviations(iobGraph, fromTime, now, useDevForScale, 1d); + if (showRatiosView.isChecked()) + secondGraphData.addRatio(iobGraph, fromTime, now, useRatioForScale, 1d); if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) { - //Date start = new Date(); - List iobArray = new ArrayList<>(); - List cobArray = new ArrayList<>(); - List devArray = new ArrayList<>(); - List ratioArray = new ArrayList<>(); - double lastIob = 0; - int lastCob = 0; - for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) { - if (showIobView.isChecked()) { - double iob = IobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time).iob; - if (Math.abs(lastIob - iob) > 0.02) { - if (Math.abs(lastIob - iob) > 0.2) - iobArray.add(new DataPoint(time, lastIob)); - iobArray.add(new DataPoint(time, iob)); - maxIobValueFound = Math.max(maxIobValueFound, Math.abs(iob)); - lastIob = iob; - } - } - if (showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) { - AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time); - if (autosensData != null && showCobView.isChecked()) { - int cob = (int) autosensData.cob; - if (cob != lastCob) { - if (autosensData.carbsFromBolus > 0) - cobArray.add(new DataPoint(time, lastCob)); - cobArray.add(new DataPoint(time, cob)); - maxCobValueFound = Math.max(maxCobValueFound, cob); - lastCob = cob; - } - } - if (autosensData != null && showDeviationsView.isChecked()) { - int color = Color.BLACK; // "=" - if (autosensData.pastSensitivity.equals("C")) color = Color.GRAY; - if (autosensData.pastSensitivity.equals("+")) color = Color.GREEN; - if (autosensData.pastSensitivity.equals("-")) color = Color.RED; - devArray.add(new DeviationDataPoint(time, autosensData.deviation, color)); - maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation)); - } - if (autosensData != null && showRatiosView.isChecked()) { - ratioArray.add(new DataPoint(time, autosensData.autosensRatio)); - maxRatioValueFound = Math.max(maxRatioValueFound, Math.abs(autosensData.autosensRatio)); - } - } - } - //Profiler.log(log, "IOB processed", start); - DataPoint[] iobData = new DataPoint[iobArray.size()]; - iobData = iobArray.toArray(iobData); - iobSeries = new FixedLineGraphSeries<>(iobData); - iobSeries.setDrawBackground(true); - iobSeries.setBackgroundColor(0x80FFFFFF & MainApp.sResources.getColor(R.color.iob)); //50% - iobSeries.setColor(MainApp.sResources.getColor(R.color.iob)); - iobSeries.setThickness(3); - - - Double maxByScale = null; - int graphsToShow = 0; - if (showIobView.isChecked()) { - if (maxByScale == null) maxByScale = maxIobValueFound; - graphsToShow++; - } - if (showCobView.isChecked()) { - if (maxByScale == null) maxByScale = maxCobValueFound; - graphsToShow++; - } - if (showDeviationsView.isChecked()) { - if (maxByScale == null) maxByScale = maxDevValueFound; - graphsToShow++; - } - if (showRatiosView.isChecked()) { - if (maxByScale == null) maxByScale = maxRatioValueFound; - graphsToShow++; - } - - if (graphsToShow > 1) { - if (!maxByScale.equals(maxCobValueFound)) { - List cobArrayRescaled = new ArrayList<>(); - for (int ci = 0; ci < cobArray.size(); ci++) { - cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxByScale / maxCobValueFound / 2)); - } - cobArray = cobArrayRescaled; - } - if (!maxByScale.equals(maxDevValueFound)) { - List devArrayRescaled = new ArrayList<>(); - for (int ci = 0; ci < devArray.size(); ci++) { - devArrayRescaled.add(new DeviationDataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxByScale / maxDevValueFound, devArray.get(ci).color)); - } - devArray = devArrayRescaled; - } - if (!maxByScale.equals(maxRatioValueFound)) { - List ratioArrayRescaled = new ArrayList<>(); - for (int ci = 0; ci < ratioArray.size(); ci++) { - ratioArrayRescaled.add(new DataPoint(ratioArray.get(ci).getX(), (ratioArray.get(ci).getY() - 1) * maxByScale / maxRatioValueFound)); - } - ratioArray = ratioArrayRescaled; - } - } - - // COB - DataPoint[] cobData = new DataPoint[cobArray.size()]; - cobData = cobArray.toArray(cobData); - cobSeries = new FixedLineGraphSeries<>(cobData); - cobSeries.setDrawBackground(true); - cobSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50% - cobSeries.setColor(MainApp.sResources.getColor(R.color.cob)); - cobSeries.setThickness(3); - - // DEVIATIONS - DeviationDataPoint[] devData = new DeviationDataPoint[devArray.size()]; - devData = devArray.toArray(devData); - devSeries = new BarGraphSeries<>(devData); - devSeries.setValueDependentColor(new ValueDependentColor() { - @Override - public int get(DeviationDataPoint data) { - return data.color; - } - }); - - // RATIOS - DataPoint[] ratioData = new DataPoint[ratioArray.size()]; - ratioData = ratioArray.toArray(ratioData); - ratioSeries = new LineGraphSeries<>(ratioData); - ratioSeries.setColor(MainApp.sResources.getColor(R.color.ratio)); - ratioSeries.setThickness(3); - - iobGraph.getSeries().clear(); - - if (showIobView.isChecked() && iobData.length > 0) { - addSeriesWithoutInvalidate(iobSeries, iobGraph); - } - if (showCobView.isChecked() && cobData.length > 0) { - addSeriesWithoutInvalidate(cobSeries, iobGraph); - } - if (showDeviationsView.isChecked() && devData.length > 0) { - addSeriesWithoutInvalidate(devSeries, iobGraph); - } - if (showRatiosView.isChecked() && ratioData.length > 0) { - addSeriesWithoutInvalidate(ratioSeries, iobGraph); - } iobGraph.setVisibility(View.VISIBLE); } else { iobGraph.setVisibility(View.GONE); @@ -1454,60 +1323,28 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, graphData.addBgReadings(bgGraph, fromTime, toTime, lowLine, highLine, null); // set manual x bounds to have nice steps - bgGraph.getViewport().setMaxX(endTime); - bgGraph.getViewport().setMinX(fromTime); - bgGraph.getViewport().setXAxisBoundsManual(true); - bgGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH")); - bgGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space - iobGraph.getViewport().setMaxX(endTime); - iobGraph.getViewport().setMinX(fromTime); - iobGraph.getViewport().setXAxisBoundsManual(true); - iobGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH")); - iobGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space - + graphData.formatAxis(bgGraph, fromTime, endTime); + secondGraphData.formatAxis(iobGraph, fromTime, endTime); // Treatments - graphData.addTreatmnets(bgGraph, fromTime, endTime); + graphData.addTreatments(bgGraph, fromTime, endTime); // add basal data if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) { - graphData.addBasals(bgGraph, fromTime, now, lowLine / graphData.maxX / 1.2d); + graphData.addBasals(bgGraph, fromTime, now, lowLine / graphData.maxY / 1.2d); } // **** NOW line **** - DataPoint[] nowPoints = new DataPoint[]{ - new DataPoint(now, 0), - new DataPoint(now, graphData.maxX) - }; - addSeriesWithoutInvalidate(seriesNow = new LineGraphSeries<>(nowPoints), bgGraph); - seriesNow.setDrawDataPoints(false); - DataPoint[] nowPoints2 = new DataPoint[]{ - new DataPoint(now, 0), - new DataPoint(now, maxIobValueFound) - }; - addSeriesWithoutInvalidate(seriesNow2 = new LineGraphSeries<>(nowPoints2), iobGraph); - seriesNow2.setDrawDataPoints(false); - //seriesNow.setThickness(1); - // custom paint to make a dotted line - Paint paint = new Paint(); - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(2); - paint.setPathEffect(new DashPathEffect(new float[]{10, 20}, 0)); - paint.setColor(Color.WHITE); - seriesNow.setCustomPaint(paint); - seriesNow2.setCustomPaint(paint); + graphData.addNowLine(bgGraph, now); + secondGraphData.addNowLine(iobGraph, now); + + // finaly enforce drawing of graphs bgGraph.onDataChanged(false, false); iobGraph.onDataChanged(false, false); Profiler.log(log, from, updateGUIStart); } - void addSeriesWithoutInvalidate(Series s, GraphView graph) { - s.onGraphViewAttached(graph); - graph.getSeries().add(s); - } - - //Notifications static class RecyclerViewAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java index ea6de9f9a4..f4be1fd351 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java @@ -1,17 +1,16 @@ package info.nightscout.androidaps.plugins.Overview.graphData; +import android.graphics.Color; import android.graphics.DashPathEffect; import android.graphics.Paint; import com.jjoe64.graphview.GraphView; -import com.jjoe64.graphview.LabelFormatter; -import com.jjoe64.graphview.Viewport; +import com.jjoe64.graphview.ValueDependentColor; +import com.jjoe64.graphview.series.BarGraphSeries; import com.jjoe64.graphview.series.DataPoint; import com.jjoe64.graphview.series.LineGraphSeries; import com.jjoe64.graphview.series.Series; -import org.mozilla.javascript.tools.debugger.Main; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -25,15 +24,18 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData; import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA; import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DoubleDataPoint; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.FixedLineGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.Scale; import info.nightscout.androidaps.plugins.Overview.graphExtensions.ScaledDataPoint; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter; import info.nightscout.utils.Round; /** @@ -46,7 +48,7 @@ public class GraphData { units = MainApp.getConfigBuilder().getProfileUnits(); } - public double maxX = 0; + public double maxY = 0; private List bgReadingsArray; private String units; @@ -82,9 +84,9 @@ public class GraphData { addSeriesWithoutInvalidate(bgGraph, new PointsWithLabelGraphSeries<>(bg)); } - maxX = maxBgValue; + maxY = maxBgValue; // set manual y bounds to have nice steps - bgGraph.getViewport().setMaxY(maxX); + bgGraph.getViewport().setMaxY(maxY); bgGraph.getViewport().setMinY(0); bgGraph.getViewport().setYAxisBoundsManual(true); bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfVertLines); @@ -205,7 +207,7 @@ public class GraphData { absolutePaint.setColor(MainApp.sResources.getColor(R.color.basal)); absoluteBasalsLineSeries.setCustomPaint(absolutePaint); - basalScale.setValue(maxX * scale / maxBasalValueFound); + basalScale.setMultiplier(maxY * scale / maxBasalValueFound); addSeriesWithoutInvalidate(bgGraph, baseBasalsSeries); addSeriesWithoutInvalidate(bgGraph, tempBasalsSeries); @@ -213,7 +215,7 @@ public class GraphData { addSeriesWithoutInvalidate(bgGraph, absoluteBasalsLineSeries); } - public void addTreatmnets(GraphView bgGraph, long fromTime, long endTime) { + public void addTreatments(GraphView bgGraph, long fromTime, long endTime) { List filteredTreatments = new ArrayList<>(); List treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory(); @@ -261,7 +263,8 @@ public class GraphData { treatmentsArray = filteredTreatments.toArray(treatmentsArray); if (treatmentsArray.length > 0) { addSeriesWithoutInvalidate(bgGraph, new PointsWithLabelGraphSeries<>(treatmentsArray)); - } } + } + } double getNearestBg(long date) { double bg = 0; @@ -274,10 +277,191 @@ public class GraphData { return bg; } + // scale in % of vertical size (like 0.3) + public void addIob(GraphView graph, long fromTime, long toTime, boolean useForScale, double scale) { + FixedLineGraphSeries iobSeries; + List iobArray = new ArrayList<>(); + Double maxIobValueFound = 0d; + double lastIob = 0; + Scale iobScale = new Scale(); + + for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) { + double iob = IobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time).iob; + if (Math.abs(lastIob - iob) > 0.02) { + if (Math.abs(lastIob - iob) > 0.2) + iobArray.add(new ScaledDataPoint(time, lastIob, iobScale)); + iobArray.add(new ScaledDataPoint(time, iob, iobScale)); + maxIobValueFound = Math.max(maxIobValueFound, Math.abs(iob)); + lastIob = iob; + } + } + + ScaledDataPoint[] iobData = new ScaledDataPoint[iobArray.size()]; + iobData = iobArray.toArray(iobData); + iobSeries = new FixedLineGraphSeries<>(iobData); + iobSeries.setDrawBackground(true); + iobSeries.setBackgroundColor(0x80FFFFFF & MainApp.sResources.getColor(R.color.iob)); //50% + iobSeries.setColor(MainApp.sResources.getColor(R.color.iob)); + iobSeries.setThickness(3); + + if (useForScale) + maxY = maxIobValueFound; + + iobScale.setMultiplier(maxY * scale / maxIobValueFound); + + addSeriesWithoutInvalidate(graph, iobSeries); + } + + // scale in % of vertical size (like 0.3) + public void addCob(GraphView graph, long fromTime, long toTime, boolean useForScale, double scale) { + FixedLineGraphSeries cobSeries; + List cobArray = new ArrayList<>(); + Double maxCobValueFound = 0d; + int lastCob = 0; + Scale cobScale = new Scale(); + + for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) { + AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time); + if (autosensData != null) { + int cob = (int) autosensData.cob; + if (cob != lastCob) { + if (autosensData.carbsFromBolus > 0) + cobArray.add(new ScaledDataPoint(time, lastCob, cobScale)); + cobArray.add(new ScaledDataPoint(time, cob, cobScale)); + maxCobValueFound = Math.max(maxCobValueFound, cob); + lastCob = cob; + } + } + } + + // COB + ScaledDataPoint[] cobData = new ScaledDataPoint[cobArray.size()]; + cobData = cobArray.toArray(cobData); + cobSeries = new FixedLineGraphSeries<>(cobData); + cobSeries.setDrawBackground(true); + cobSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50% + cobSeries.setColor(MainApp.sResources.getColor(R.color.cob)); + cobSeries.setThickness(3); + + if (useForScale) + maxY = maxCobValueFound; + + cobScale.setMultiplier(maxY * scale / maxCobValueFound); + + addSeriesWithoutInvalidate(graph, cobSeries); + } + + // scale in % of vertical size (like 0.3) + public void addDeviations(GraphView graph, long fromTime, long toTime, boolean useForScale, double scale) { + class DeviationDataPoint extends ScaledDataPoint { + public int color; + + public DeviationDataPoint(double x, double y, int color, Scale scale) { + super(x, y, scale); + this.color = color; + } + } + + BarGraphSeries devSeries; + List devArray = new ArrayList<>(); + Double maxDevValueFound = 0d; + Scale devScale = new Scale(); + + for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) { + AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time); + if (autosensData != null) { + int color = Color.BLACK; // "=" + if (autosensData.pastSensitivity.equals("C")) color = Color.GRAY; + if (autosensData.pastSensitivity.equals("+")) color = Color.GREEN; + if (autosensData.pastSensitivity.equals("-")) color = Color.RED; + devArray.add(new DeviationDataPoint(time, autosensData.deviation, color, devScale)); + maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation)); + } + } + + // DEVIATIONS + DeviationDataPoint[] devData = new DeviationDataPoint[devArray.size()]; + devData = devArray.toArray(devData); + devSeries = new BarGraphSeries<>(devData); + devSeries.setValueDependentColor(new ValueDependentColor() { + @Override + public int get(DeviationDataPoint data) { + return data.color; + } + }); + + if (useForScale) + maxY = maxDevValueFound; + + devScale.setMultiplier(maxY * scale / maxDevValueFound); + + addSeriesWithoutInvalidate(graph, devSeries); + } + + // scale in % of vertical size (like 0.3) + public void addRatio(GraphView graph, long fromTime, long toTime, boolean useForScale, double scale) { + LineGraphSeries ratioSeries; + List ratioArray = new ArrayList<>(); + Double maxRatioValueFound = 0d; + Scale ratioScale = new Scale(-1d); + + for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) { + AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time); + if (autosensData != null) { + ratioArray.add(new DataPoint(time, autosensData.autosensRatio)); + maxRatioValueFound = Math.max(maxRatioValueFound, Math.abs(autosensData.autosensRatio)); + } + } + + // RATIOS + DataPoint[] ratioData = new DataPoint[ratioArray.size()]; + ratioData = ratioArray.toArray(ratioData); + ratioSeries = new LineGraphSeries<>(ratioData); + ratioSeries.setColor(MainApp.sResources.getColor(R.color.ratio)); + ratioSeries.setThickness(3); + + if (useForScale) + maxY = maxRatioValueFound; + + ratioScale.setMultiplier(maxY * scale / maxRatioValueFound); + + addSeriesWithoutInvalidate(graph, ratioSeries); + } + + // scale in % of vertical size (like 0.3) + public void addNowLine(GraphView graph, long now) { + LineGraphSeries seriesNow; + DataPoint[] nowPoints = new DataPoint[]{ + new DataPoint(now, 0), + new DataPoint(now, maxY) + }; + + seriesNow = new LineGraphSeries<>(nowPoints); + seriesNow.setDrawDataPoints(false); + // custom paint to make a dotted line + Paint paint = new Paint(); + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeWidth(2); + paint.setPathEffect(new DashPathEffect(new float[]{10, 20}, 0)); + paint.setColor(Color.WHITE); + seriesNow.setCustomPaint(paint); + + addSeriesWithoutInvalidate(graph, seriesNow); + } + + public void formatAxis(GraphView graph, long fromTime, long endTime) { + graph.getViewport().setMaxX(endTime); + graph.getViewport().setMinX(fromTime); + graph.getViewport().setXAxisBoundsManual(true); + graph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter("HH")); + graph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space + } private void addSeriesWithoutInvalidate(GraphView bgGraph, Series s) { - s.onGraphViewAttached(bgGraph); - bgGraph.getSeries().add(s); + if (!s.isEmpty()) { + s.onGraphViewAttached(bgGraph); + bgGraph.getSeries().add(s); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java index 1acb357a4b..4aa1271679 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/Scale.java @@ -5,13 +5,26 @@ package info.nightscout.androidaps.plugins.Overview.graphExtensions; */ public class Scale { - private double value; + private double multiplier; + private double shift; - public void setValue(double value) { - this.value = value; + public Scale() { + shift = 0; } - public double getValue() { - return value; + public Scale(double shift) { + this.shift = shift; + } + + public void setMultiplier(double value) { + this.multiplier = value; + } + + public double transform(double original) { + return original * multiplier + shift; + } + + public double getShift() { + return shift; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java index e5d2364be7..61f4102a30 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/ScaledDataPoint.java @@ -36,7 +36,7 @@ public class ScaledDataPoint implements DataPointInterface, Serializable { @Override public double getY() { - return y * scale.getValue(); + return scale.transform(y); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java index 881e472a1d..323751e4c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/TimeAsXAxisLabelFormatter.java @@ -15,7 +15,7 @@ public class TimeAsXAxisLabelFormatter extends DefaultLabelFormatter { protected final String mFormat; - public TimeAsXAxisLabelFormatter(Context context, String format) { + public TimeAsXAxisLabelFormatter(String format) { mFormat = format; } From 4767809931a746c08b3417595dca53f32d5affba Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 25 Oct 2017 17:49:23 +0200 Subject: [PATCH 05/26] Start KeepAliveService after pump init. --- app/src/main/java/info/nightscout/androidaps/MainApp.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 209adfe1c4..d3c68dbb25 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -167,9 +167,6 @@ public class MainApp extends Application { else Answers.getInstance().logCustom(new CustomEvent("AppStart")); - - startKeepAliveService(); - Thread t = new Thread(new Runnable() { @Override public void run() { @@ -177,8 +174,9 @@ public class MainApp extends Application { PumpInterface pump = MainApp.getConfigBuilder(); if (pump != null) pump.refreshDataFromPump("Initialization"); + startKeepAliveService(); } - }); + }, "pump-initialization"); t.start(); } From 707d2df345064533699b019832c0c371cd2f006a Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 25 Oct 2017 20:10:59 +0200 Subject: [PATCH 06/26] No explicit service start --- app/src/main/java/info/nightscout/androidaps/MainApp.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index d3c68dbb25..4e2afd65d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -209,12 +209,6 @@ public class MainApp extends Application { private void startKeepAliveService() { if (keepAliveReceiver == null) { keepAliveReceiver = new KeepAliveReceiver(); - if (Config.DANAR) { - startService(new Intent(this, DanaRExecutionService.class)); - startService(new Intent(this, DanaRKoreanExecutionService.class)); - startService(new Intent(this, DanaRv2ExecutionService.class)); - startService(new Intent(this, DanaRSService.class)); - } keepAliveReceiver.setAlarm(this); } } From 5a446c9ab51a015203a2f9ca8bb7e63429f9411b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 15:24:41 +0200 Subject: [PATCH 07/26] Log posted events. --- .../info/nightscout/androidaps/Config.java | 1 + .../nightscout/androidaps/LoggingBus.java | 22 +++++++++++++++++++ .../info/nightscout/androidaps/MainApp.java | 4 +++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/LoggingBus.java diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index abda0ca941..6bbc908188 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -40,6 +40,7 @@ public class Config { public static final boolean logPumpActions = true; public static final boolean logCongigBuilderActions = true; public static final boolean logAutosensData = false; + public static final boolean logEvents = true; // DanaR specific public static final boolean logDanaBTComm = true; diff --git a/app/src/main/java/info/nightscout/androidaps/LoggingBus.java b/app/src/main/java/info/nightscout/androidaps/LoggingBus.java new file mode 100644 index 0000000000..8b5664b511 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/LoggingBus.java @@ -0,0 +1,22 @@ +package info.nightscout.androidaps; + +import com.squareup.otto.Bus; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class LoggingBus extends Bus { + private static Logger log = LoggerFactory.getLogger(LoggingBus.class); + + private final Bus delegate; + + public LoggingBus(Bus bus) { + delegate = bus; + } + + @Override + public void post(Object event) { + log.debug("Event posted: " + event); + super.post(event); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 209adfe1c4..3392a0193a 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -104,7 +104,9 @@ public class MainApp extends Application { log.info("Version: " + BuildConfig.VERSION_NAME); log.info("BuildVersion: " + BuildConfig.BUILDVERSION); - sBus = new Bus(ThreadEnforcer.ANY); + Bus bus = new Bus(ThreadEnforcer.ANY); + sBus = Config.logEvents ? new LoggingBus(bus) : bus; + sInstance = this; sResources = getResources(); From 8ad223e5e1b46322afb3083d68be59338181f399 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 15:31:03 +0200 Subject: [PATCH 08/26] Add base event class. --- app/build.gradle | 1 + .../java/info/nightscout/androidaps/events/Event.java | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 app/src/main/java/info/nightscout/androidaps/events/Event.java diff --git a/app/build.gradle b/app/build.gradle index 30158bf591..6d877e80a4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -150,6 +150,7 @@ dependencies { compile('com.github.tony19:logback-android-classic:1.1.1-6') { exclude group: 'com.google.android', module: 'android' } + compile 'org.apache.commons:commons-lang3:3.6' compile 'org.slf4j:slf4j-api:1.7.12' compile 'com.jjoe64:graphview:4.0.1' compile 'com.eclipsesource.j2v8:j2v8:3.1.6@aar' diff --git a/app/src/main/java/info/nightscout/androidaps/events/Event.java b/app/src/main/java/info/nightscout/androidaps/events/Event.java new file mode 100644 index 0000000000..dc35856253 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/events/Event.java @@ -0,0 +1,10 @@ +package info.nightscout.androidaps.events; + +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; + +abstract class Event { + @Override + public String toString() { + return ReflectionToStringBuilder.toString(this); + } +} From 302ed695643d5d9d03f709b0564a3b425f8dd35b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 16:06:01 +0200 Subject: [PATCH 09/26] Let event classes extend Event(UpdageGui) classes. --- .../info/nightscout/androidaps/LoggingBus.java | 14 +++++++++++++- .../info/nightscout/androidaps/events/Event.java | 2 +- .../nightscout/androidaps/events/EventAppExit.java | 2 +- .../androidaps/events/EventBolusRequested.java | 2 +- .../events/EventCareportalEventChange.java | 2 +- .../events/EventConfigBuilderChange.java | 2 +- .../events/EventExtendedBolusChange.java | 2 +- .../events/EventFoodDatabaseChanged.java | 2 +- .../events/EventInitializationChanged.java | 2 +- .../nightscout/androidaps/events/EventNewBG.java | 2 +- .../androidaps/events/EventNewBasalProfile.java | 2 +- .../androidaps/events/EventPreferenceChange.java | 2 +- .../events/EventProfileSwitchChange.java | 2 +- .../androidaps/events/EventPumpStatusChanged.java | 2 +- .../androidaps/events/EventRefreshGui.java | 2 +- .../androidaps/events/EventRefreshOverview.java | 2 +- .../events/EventReloadProfileSwitchData.java | 2 +- .../events/EventReloadTempBasalData.java | 2 +- .../events/EventReloadTreatmentData.java | 2 +- .../androidaps/events/EventTempBasalChange.java | 2 +- .../androidaps/events/EventTempTargetChange.java | 2 +- .../androidaps/events/EventTreatmentChange.java | 2 +- .../androidaps/events/EventUpdateGui.java | 4 ++++ .../events/EventAutosensCalculationFinished.java | 4 +++- .../events/EventNewHistoryData.java | 4 +++- .../Loop/events/EventLoopSetLastRunGui.java | 4 +++- .../plugins/Loop/events/EventLoopUpdateGui.java | 4 +++- .../Loop/events/EventNewOpenLoopNotification.java | 4 +++- .../plugins/NSClientInternal/acks/NSAddAck.java | 4 ++-- .../plugins/NSClientInternal/acks/NSAuthAck.java | 3 ++- .../plugins/NSClientInternal/acks/NSUpdateAck.java | 3 ++- .../events/EventNSClientNewLog.java | 10 +++------- .../events/EventNSClientRestart.java | 4 +++- .../events/EventNSClientStatus.java | 4 +++- .../events/EventNSClientUpdateGUI.java | 4 +++- .../OpenAPSMA/events/EventOpenAPSUpdateGui.java | 4 +++- .../events/EventOpenAPSUpdateResultGui.java | 4 +++- .../events/EventDismissBolusprogressIfRunning.java | 3 ++- .../Overview/events/EventDismissNotification.java | 4 +++- .../Overview/events/EventNewNotification.java | 3 ++- .../events/EventOverviewBolusProgress.java | 3 ++- .../Overview/events/EventQuickWizardChange.java | 4 +++- .../plugins/Overview/events/EventSetWakeLock.java | 4 +++- .../ProfileNS/events/EventNSProfileUpdateGUI.java | 4 +++- .../PumpDanaR/events/EventDanaRBolusStart.java | 4 +++- .../PumpDanaR/events/EventDanaRNewStatus.java | 4 +++- .../PumpDanaR/events/EventDanaRSyncStatus.java | 4 +++- .../events/EventVirtualPumpUpdateGui.java | 4 +++- .../SmsCommunicator/events/EventNewSMS.java | 4 +++- .../events/EventSmsCommunicatorUpdateGui.java | 4 +++- 50 files changed, 113 insertions(+), 56 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/events/EventUpdateGui.java diff --git a/app/src/main/java/info/nightscout/androidaps/LoggingBus.java b/app/src/main/java/info/nightscout/androidaps/LoggingBus.java index 8b5664b511..249e273c3d 100644 --- a/app/src/main/java/info/nightscout/androidaps/LoggingBus.java +++ b/app/src/main/java/info/nightscout/androidaps/LoggingBus.java @@ -1,10 +1,13 @@ package info.nightscout.androidaps; import com.squareup.otto.Bus; +import com.squareup.otto.DeadEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.events.Event; + class LoggingBus extends Bus { private static Logger log = LoggerFactory.getLogger(LoggingBus.class); @@ -16,7 +19,16 @@ class LoggingBus extends Bus { @Override public void post(Object event) { + if (event instanceof DeadEvent) { + log.debug("Event has no receiver:" + ((DeadEvent) event).event + ", source: " + ((DeadEvent) event).source); + return; + } + + if (!(event instanceof Event)) { + log.error("Posted event not an event class: " + event.getClass()); + } + log.debug("Event posted: " + event); - super.post(event); + delegate.post(event); } } diff --git a/app/src/main/java/info/nightscout/androidaps/events/Event.java b/app/src/main/java/info/nightscout/androidaps/events/Event.java index dc35856253..1bbbf8971a 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/Event.java +++ b/app/src/main/java/info/nightscout/androidaps/events/Event.java @@ -2,7 +2,7 @@ package info.nightscout.androidaps.events; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -abstract class Event { +public abstract class Event { @Override public String toString() { return ReflectionToStringBuilder.toString(this); diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventAppExit.java b/app/src/main/java/info/nightscout/androidaps/events/EventAppExit.java index 0f23643fef..9ce91a9a39 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventAppExit.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventAppExit.java @@ -3,5 +3,5 @@ package info.nightscout.androidaps.events; /** * Created by mike on 07.07.2016. */ -public class EventAppExit { +public class EventAppExit extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventBolusRequested.java b/app/src/main/java/info/nightscout/androidaps/events/EventBolusRequested.java index 1f41119b4b..cb727758bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventBolusRequested.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventBolusRequested.java @@ -4,7 +4,7 @@ package info.nightscout.androidaps.events; * Created by adrian on 07/02/17. */ -public class EventBolusRequested { +public class EventBolusRequested extends Event { private double amount; public EventBolusRequested (double amount){ diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventCareportalEventChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventCareportalEventChange.java index d86fe679fb..9b47ed39cb 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventCareportalEventChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventCareportalEventChange.java @@ -4,5 +4,5 @@ package info.nightscout.androidaps.events; * Created by mike on 25.05.2017. */ -public class EventCareportalEventChange { +public class EventCareportalEventChange extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventConfigBuilderChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventConfigBuilderChange.java index 38331ca581..ad5f558fe8 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventConfigBuilderChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventConfigBuilderChange.java @@ -4,5 +4,5 @@ package info.nightscout.androidaps.events; * Created by mike on 17.02.2017. */ -public class EventConfigBuilderChange { +public class EventConfigBuilderChange extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventExtendedBolusChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventExtendedBolusChange.java index 78dee60388..8881b0ecc1 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventExtendedBolusChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventExtendedBolusChange.java @@ -4,5 +4,5 @@ package info.nightscout.androidaps.events; * Created by mike on 15.05.2017. */ -public class EventExtendedBolusChange { +public class EventExtendedBolusChange extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventFoodDatabaseChanged.java b/app/src/main/java/info/nightscout/androidaps/events/EventFoodDatabaseChanged.java index 075993c530..48e6be3a14 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventFoodDatabaseChanged.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventFoodDatabaseChanged.java @@ -4,5 +4,5 @@ package info.nightscout.androidaps.events; * Created by mike on 20.09.2017. */ -public class EventFoodDatabaseChanged { +public class EventFoodDatabaseChanged extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventInitializationChanged.java b/app/src/main/java/info/nightscout/androidaps/events/EventInitializationChanged.java index e9a9ce511d..f2bef1d3d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventInitializationChanged.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventInitializationChanged.java @@ -4,5 +4,5 @@ package info.nightscout.androidaps.events; * Created by mike on 13.12.2016. */ -public class EventInitializationChanged { +public class EventInitializationChanged extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java b/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java index 2d6454406a..eb304a81b2 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java @@ -3,5 +3,5 @@ package info.nightscout.androidaps.events; /** * Created by mike on 05.06.2016. */ -public class EventNewBG { +public class EventNewBG extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java b/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java index 1309625b98..f26a310b6b 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java @@ -3,5 +3,5 @@ package info.nightscout.androidaps.events; /** * Created by mike on 04.06.2016. */ -public class EventNewBasalProfile { +public class EventNewBasalProfile extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventPreferenceChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventPreferenceChange.java index 76da0a4e67..f99cb54568 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventPreferenceChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventPreferenceChange.java @@ -5,7 +5,7 @@ import info.nightscout.androidaps.MainApp; /** * Created by mike on 19.06.2016. */ -public class EventPreferenceChange { +public class EventPreferenceChange extends Event { public String changedKey; public EventPreferenceChange(String key) { changedKey = key; diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventProfileSwitchChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventProfileSwitchChange.java index 476a571d70..7bab9d4518 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventProfileSwitchChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventProfileSwitchChange.java @@ -4,5 +4,5 @@ package info.nightscout.androidaps.events; * Created by mike on 02.06.2017. */ -public class EventProfileSwitchChange { +public class EventProfileSwitchChange extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.java b/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.java index 3cfe7cc6a7..52c3183821 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.java @@ -7,7 +7,7 @@ import info.nightscout.androidaps.R; * Created by mike on 19.02.2017. */ -public class EventPumpStatusChanged { +public class EventPumpStatusChanged extends Event { public static final int CONNECTING = 0; public static final int CONNECTED = 1; public static final int PERFORMING = 2; diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventRefreshGui.java b/app/src/main/java/info/nightscout/androidaps/events/EventRefreshGui.java index f20dfb9329..1dae34d2af 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventRefreshGui.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventRefreshGui.java @@ -3,5 +3,5 @@ package info.nightscout.androidaps.events; /** * Created by mike on 13.06.2016. */ -public class EventRefreshGui { +public class EventRefreshGui extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventRefreshOverview.java b/app/src/main/java/info/nightscout/androidaps/events/EventRefreshOverview.java index bf14f5f585..2ba78fa9ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventRefreshOverview.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventRefreshOverview.java @@ -4,7 +4,7 @@ package info.nightscout.androidaps.events; * Created by mike on 16.06.2017. */ -public class EventRefreshOverview { +public class EventRefreshOverview extends Event { public String from; public EventRefreshOverview(String from) { diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventReloadProfileSwitchData.java b/app/src/main/java/info/nightscout/androidaps/events/EventReloadProfileSwitchData.java index 20073a7cf0..212e8856d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventReloadProfileSwitchData.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventReloadProfileSwitchData.java @@ -4,5 +4,5 @@ package info.nightscout.androidaps.events; * Created by mike on 12.06.2017. */ -public class EventReloadProfileSwitchData { +public class EventReloadProfileSwitchData extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventReloadTempBasalData.java b/app/src/main/java/info/nightscout/androidaps/events/EventReloadTempBasalData.java index 38b1b86186..80125cbb4a 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventReloadTempBasalData.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventReloadTempBasalData.java @@ -4,5 +4,5 @@ package info.nightscout.androidaps.events; * Created by mike on 29.05.2017. */ -public class EventReloadTempBasalData { +public class EventReloadTempBasalData extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventReloadTreatmentData.java b/app/src/main/java/info/nightscout/androidaps/events/EventReloadTreatmentData.java index d4ea0d3f70..0ba9b95ad7 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventReloadTreatmentData.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventReloadTreatmentData.java @@ -4,7 +4,7 @@ package info.nightscout.androidaps.events; * Created by mike on 29.05.2017. */ -public class EventReloadTreatmentData { +public class EventReloadTreatmentData extends Event { public Object next; public EventReloadTreatmentData(Object next) { diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventTempBasalChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventTempBasalChange.java index 5d8f961e75..8efd1d46e2 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventTempBasalChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventTempBasalChange.java @@ -3,5 +3,5 @@ package info.nightscout.androidaps.events; /** * Created by mike on 05.06.2016. */ -public class EventTempBasalChange { +public class EventTempBasalChange extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventTempTargetChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventTempTargetChange.java index d0ef42d830..4e3bf5c5f8 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventTempTargetChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventTempTargetChange.java @@ -4,5 +4,5 @@ package info.nightscout.androidaps.events; * Created by mike on 13.01.2017. */ -public class EventTempTargetChange { +public class EventTempTargetChange extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java index a8597189bc..dd5eb519e3 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java @@ -3,5 +3,5 @@ package info.nightscout.androidaps.events; /** * Created by mike on 04.06.2016. */ -public class EventTreatmentChange { +public class EventTreatmentChange extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/events/EventUpdateGui.java new file mode 100644 index 0000000000..5edb7b7a9a --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/events/EventUpdateGui.java @@ -0,0 +1,4 @@ +package info.nightscout.androidaps.events; + +public abstract class EventUpdateGui extends Event { +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java index f2977c90c5..c94021e185 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java @@ -1,8 +1,10 @@ package info.nightscout.androidaps.plugins.IobCobCalculator.events; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 30.04.2017. */ -public class EventAutosensCalculationFinished { +public class EventAutosensCalculationFinished extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventNewHistoryData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventNewHistoryData.java index 7499fad383..8814741099 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventNewHistoryData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventNewHistoryData.java @@ -1,10 +1,12 @@ package info.nightscout.androidaps.plugins.IobCobCalculator.events; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 26.04.2017. */ -public class EventNewHistoryData { +public class EventNewHistoryData extends Event { public long time = 0; public EventNewHistoryData(long time) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopSetLastRunGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopSetLastRunGui.java index 7baf556546..1ef5dc4c94 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopSetLastRunGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopSetLastRunGui.java @@ -1,9 +1,11 @@ package info.nightscout.androidaps.plugins.Loop.events; +import info.nightscout.androidaps.events.EventUpdateGui; + /** * Created by mike on 05.08.2016. */ -public class EventLoopSetLastRunGui { +public class EventLoopSetLastRunGui extends EventUpdateGui { public String text = null; public EventLoopSetLastRunGui(String text) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopUpdateGui.java index d671b3bd64..d4417dbb12 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopUpdateGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventLoopUpdateGui.java @@ -1,7 +1,9 @@ package info.nightscout.androidaps.plugins.Loop.events; +import info.nightscout.androidaps.events.EventUpdateGui; + /** * Created by mike on 05.08.2016. */ -public class EventLoopUpdateGui { +public class EventLoopUpdateGui extends EventUpdateGui { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventNewOpenLoopNotification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventNewOpenLoopNotification.java index 7a6184e406..001d11661e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventNewOpenLoopNotification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/events/EventNewOpenLoopNotification.java @@ -1,7 +1,9 @@ package info.nightscout.androidaps.plugins.Loop.events; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 07.08.2016. */ -public class EventNewOpenLoopNotification { +public class EventNewOpenLoopNotification extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java index 709c53f6d4..e90dce3bec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java @@ -7,14 +7,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart; -import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; import io.socket.client.Ack; /** * Created by mike on 29.12.2015. */ -public class NSAddAck implements Ack { +public class NSAddAck extends Event implements Ack { private static Logger log = LoggerFactory.getLogger(NSAddAck.class); public String _id = null; public String nsClientID = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAuthAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAuthAck.java index 3c3b173173..56055351d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAuthAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAuthAck.java @@ -3,13 +3,14 @@ package info.nightscout.androidaps.plugins.NSClientInternal.acks; import org.json.JSONObject; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog; import io.socket.client.Ack; /** * Created by mike on 02.01.2016. */ -public class NSAuthAck implements Ack{ +public class NSAuthAck extends Event implements Ack{ public boolean read = false; public boolean write = false; public boolean write_treatment = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java index 5aef754d8c..2bf520da64 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSUpdateAck.java @@ -6,12 +6,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.events.Event; import io.socket.client.Ack; /** * Created by mike on 21.02.2016. */ -public class NSUpdateAck implements Ack { +public class NSUpdateAck extends Event implements Ack { private static Logger log = LoggerFactory.getLogger(NSUpdateAck.class); public boolean result = false; public String _id = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java index 7caafbd28a..82b11a812d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientNewLog.java @@ -1,19 +1,15 @@ package info.nightscout.androidaps.plugins.NSClientInternal.events; -import android.text.Html; -import android.text.Spanned; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.text.SimpleDateFormat; import java.util.Date; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 15.02.2017. */ -public class EventNSClientNewLog { +public class EventNSClientNewLog extends Event { public Date date = new Date(); public String action; public String logText; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java index 9bf90be31b..b968878da8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientRestart.java @@ -1,8 +1,10 @@ package info.nightscout.androidaps.plugins.NSClientInternal.events; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 15.02.2017. */ -public class EventNSClientRestart { +public class EventNSClientRestart extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java index 6a1c721535..977c0e31fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientStatus.java @@ -1,9 +1,11 @@ package info.nightscout.androidaps.plugins.NSClientInternal.events; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 02.01.2016. */ -public class EventNSClientStatus { +public class EventNSClientStatus extends Event { public String status = ""; public EventNSClientStatus(String status) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java index 8f00bd3424..dd78d2cd28 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/events/EventNSClientUpdateGUI.java @@ -1,8 +1,10 @@ package info.nightscout.androidaps.plugins.NSClientInternal.events; +import info.nightscout.androidaps.events.EventUpdateGui; + /** * Created by mike on 17.02.2017. */ -public class EventNSClientUpdateGUI { +public class EventNSClientUpdateGUI extends EventUpdateGui { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateGui.java index 65b3b49d53..40f3c31973 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateGui.java @@ -1,7 +1,9 @@ package info.nightscout.androidaps.plugins.OpenAPSMA.events; +import info.nightscout.androidaps.events.EventUpdateGui; + /** * Created by mike on 05.08.2016. */ -public class EventOpenAPSUpdateGui { +public class EventOpenAPSUpdateGui extends EventUpdateGui { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateResultGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateResultGui.java index 2aa2365eff..e65cdd2c57 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateResultGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/events/EventOpenAPSUpdateResultGui.java @@ -1,9 +1,11 @@ package info.nightscout.androidaps.plugins.OpenAPSMA.events; +import info.nightscout.androidaps.events.EventUpdateGui; + /** * Created by mike on 05.08.2016. */ -public class EventOpenAPSUpdateResultGui { +public class EventOpenAPSUpdateResultGui extends EventUpdateGui { public String text = null; public EventOpenAPSUpdateResultGui(String text) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java index 9d8435eaf1..af336cd74c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissBolusprogressIfRunning.java @@ -1,12 +1,13 @@ package info.nightscout.androidaps.plugins.Overview.events; import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.events.Event; /** * Created by adrian on 20/02/17. */ -public class EventDismissBolusprogressIfRunning { +public class EventDismissBolusprogressIfRunning extends Event { public final PumpEnactResult result; public EventDismissBolusprogressIfRunning(PumpEnactResult result) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissNotification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissNotification.java index f2414e2a4e..1fa71febbe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissNotification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventDismissNotification.java @@ -1,10 +1,12 @@ package info.nightscout.androidaps.plugins.Overview.events; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 03.12.2016. */ -public class EventDismissNotification { +public class EventDismissNotification extends Event { public int id; public EventDismissNotification(int did) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventNewNotification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventNewNotification.java index 8a80019f3e..59ad1a335d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventNewNotification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventNewNotification.java @@ -1,12 +1,13 @@ package info.nightscout.androidaps.plugins.Overview.events; +import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.plugins.Overview.Notification; /** * Created by mike on 03.12.2016. */ -public class EventNewNotification { +public class EventNewNotification extends Event { public Notification notification; public EventNewNotification(Notification n) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventOverviewBolusProgress.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventOverviewBolusProgress.java index 0882032362..e0fd53a1fd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventOverviewBolusProgress.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventOverviewBolusProgress.java @@ -4,8 +4,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.events.Event; -public class EventOverviewBolusProgress { +public class EventOverviewBolusProgress extends Event { private static Logger log = LoggerFactory.getLogger(EventOverviewBolusProgress.class); public String status = ""; public Treatment t = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventQuickWizardChange.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventQuickWizardChange.java index 1a9923f606..b72c2548e2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventQuickWizardChange.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventQuickWizardChange.java @@ -1,8 +1,10 @@ package info.nightscout.androidaps.plugins.Overview.events; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 20.10.2016. */ -public class EventQuickWizardChange { +public class EventQuickWizardChange extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventSetWakeLock.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventSetWakeLock.java index 519341172d..49ccf9fbfb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventSetWakeLock.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/events/EventSetWakeLock.java @@ -1,10 +1,12 @@ package info.nightscout.androidaps.plugins.Overview.events; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 02.07.2017. */ -public class EventSetWakeLock { +public class EventSetWakeLock extends Event { public boolean lock = false; public EventSetWakeLock(boolean val) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/events/EventNSProfileUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/events/EventNSProfileUpdateGUI.java index 7bb5df792f..d24c59e511 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/events/EventNSProfileUpdateGUI.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/events/EventNSProfileUpdateGUI.java @@ -1,7 +1,9 @@ package info.nightscout.androidaps.plugins.ProfileNS.events; +import info.nightscout.androidaps.events.EventUpdateGui; + /** * Created by mike on 05.08.2016. */ -public class EventNSProfileUpdateGUI { +public class EventNSProfileUpdateGUI extends EventUpdateGui { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRBolusStart.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRBolusStart.java index 8217b51432..9e3af48fb2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRBolusStart.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRBolusStart.java @@ -1,7 +1,9 @@ package info.nightscout.androidaps.plugins.PumpDanaR.events; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 03.08.2016. */ -public class EventDanaRBolusStart { +public class EventDanaRBolusStart extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRNewStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRNewStatus.java index a04f27f2d6..55b0ab0998 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRNewStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRNewStatus.java @@ -1,7 +1,9 @@ package info.nightscout.androidaps.plugins.PumpDanaR.events; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 08.07.2016. */ -public class EventDanaRNewStatus { +public class EventDanaRNewStatus extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRSyncStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRSyncStatus.java index b64cf22748..4e3f28de9d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRSyncStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/events/EventDanaRSyncStatus.java @@ -1,9 +1,11 @@ package info.nightscout.androidaps.plugins.PumpDanaR.events; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 20.07.2016. */ -public class EventDanaRSyncStatus { +public class EventDanaRSyncStatus extends Event { public String message; public EventDanaRSyncStatus() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/events/EventVirtualPumpUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/events/EventVirtualPumpUpdateGui.java index 110e0f4a56..e035ea3aba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/events/EventVirtualPumpUpdateGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/events/EventVirtualPumpUpdateGui.java @@ -1,7 +1,9 @@ package info.nightscout.androidaps.plugins.PumpVirtual.events; +import info.nightscout.androidaps.events.EventUpdateGui; + /** * Created by mike on 05.08.2016. */ -public class EventVirtualPumpUpdateGui { +public class EventVirtualPumpUpdateGui extends EventUpdateGui { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventNewSMS.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventNewSMS.java index 2b890fb59c..dfaebb3942 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventNewSMS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventNewSMS.java @@ -2,10 +2,12 @@ package info.nightscout.androidaps.plugins.SmsCommunicator.events; import android.os.Bundle; +import info.nightscout.androidaps.events.Event; + /** * Created by mike on 13.07.2016. */ -public class EventNewSMS { +public class EventNewSMS extends Event { public Bundle bundle; public EventNewSMS(Bundle bundle) { this.bundle = bundle; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java index 7c1d480e72..02956a5d67 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/events/EventSmsCommunicatorUpdateGui.java @@ -1,7 +1,9 @@ package info.nightscout.androidaps.plugins.SmsCommunicator.events; +import info.nightscout.androidaps.events.EventUpdateGui; + /** * Created by mike on 05.08.2016. */ -public class EventSmsCommunicatorUpdateGui { +public class EventSmsCommunicatorUpdateGui extends EventUpdateGui { } From 3e24a6069db661195b738cc50489d2eeb3c00557 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 16:11:19 +0200 Subject: [PATCH 10/26] Remove dead NSPingAck class. --- .../NSClientInternal/acks/NSPingAck.java | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java deleted file mode 100644 index 1ec6e3991c..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java +++ /dev/null @@ -1,44 +0,0 @@ -package info.nightscout.androidaps.plugins.NSClientInternal.acks; - -import android.os.SystemClock; - -import org.json.JSONException; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.socket.client.Ack; - -/** - * Created by mike on 29.12.2015. - */ -public class NSPingAck implements Ack { - private static Logger log = LoggerFactory.getLogger(NSPingAck.class); - - public long mills = 0; - public boolean received = false; - public boolean auth_received = false; - public boolean read = false; - public boolean write = false; - public boolean write_treatment = false; - - public void call(Object...args) { - JSONObject response = (JSONObject)args[0]; - mills = response.optLong("mills"); - if (response.has("authorization")) { - auth_received = true; - try { - JSONObject authorization = response.getJSONObject("authorization"); - read = authorization.optBoolean("read"); - write = authorization.optBoolean("write"); - write_treatment = authorization.optBoolean("write_treatment"); - } catch (JSONException e) { - log.error("Unhandled exception", e); - } - } - received = true; - synchronized(this) { - this.notify(); - } - } -} From 9d10563bd984946cb487b2d130bff0a85a64a33d Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 16:19:36 +0200 Subject: [PATCH 11/26] Group events in type hierarchy related to the LoopPlugin. --- .../main/java/info/nightscout/androidaps/events/Event.java | 1 + .../java/info/nightscout/androidaps/events/EventLoop.java | 5 +++++ .../java/info/nightscout/androidaps/events/EventNewBG.java | 2 +- .../nightscout/androidaps/events/EventTempBasalChange.java | 2 +- .../nightscout/androidaps/events/EventTreatmentChange.java | 2 +- .../info/nightscout/androidaps/events/EventUpdateGui.java | 1 + .../events/EventAutosensCalculationFinished.java | 4 ++-- 7 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/events/EventLoop.java diff --git a/app/src/main/java/info/nightscout/androidaps/events/Event.java b/app/src/main/java/info/nightscout/androidaps/events/Event.java index 1bbbf8971a..77d1215362 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/Event.java +++ b/app/src/main/java/info/nightscout/androidaps/events/Event.java @@ -2,6 +2,7 @@ package info.nightscout.androidaps.events; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +/** Base class for all events posted on the event bus. */ public abstract class Event { @Override public String toString() { diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventLoop.java b/app/src/main/java/info/nightscout/androidaps/events/EventLoop.java new file mode 100644 index 0000000000..d694d52537 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/events/EventLoop.java @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.events; + +/** Supeclass for all events concerned with input or output into or from the LoopPlugin. */ +public abstract class EventLoop extends Event { +} diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java b/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java index eb304a81b2..2fb9919b00 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventNewBG.java @@ -3,5 +3,5 @@ package info.nightscout.androidaps.events; /** * Created by mike on 05.06.2016. */ -public class EventNewBG extends Event { +public class EventNewBG extends EventLoop { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventTempBasalChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventTempBasalChange.java index 8efd1d46e2..73660bb00e 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventTempBasalChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventTempBasalChange.java @@ -3,5 +3,5 @@ package info.nightscout.androidaps.events; /** * Created by mike on 05.06.2016. */ -public class EventTempBasalChange extends Event { +public class EventTempBasalChange extends EventLoop { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java b/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java index dd5eb519e3..439d9a7124 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventTreatmentChange.java @@ -3,5 +3,5 @@ package info.nightscout.androidaps.events; /** * Created by mike on 04.06.2016. */ -public class EventTreatmentChange extends Event { +public class EventTreatmentChange extends EventLoop { } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventUpdateGui.java b/app/src/main/java/info/nightscout/androidaps/events/EventUpdateGui.java index 5edb7b7a9a..3471d2e851 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventUpdateGui.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventUpdateGui.java @@ -1,4 +1,5 @@ package info.nightscout.androidaps.events; +/** Base class for events to update the UI, mostly a specific tab. */ public abstract class EventUpdateGui extends Event { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java index c94021e185..ea73915436 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/events/EventAutosensCalculationFinished.java @@ -1,10 +1,10 @@ package info.nightscout.androidaps.plugins.IobCobCalculator.events; -import info.nightscout.androidaps.events.Event; +import info.nightscout.androidaps.events.EventLoop; /** * Created by mike on 30.04.2017. */ -public class EventAutosensCalculationFinished extends Event { +public class EventAutosensCalculationFinished extends EventLoop { } From d83009648235e8654647413611f1b0750e8868d0 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 16:29:33 +0200 Subject: [PATCH 12/26] Better log messages for events. --- .../main/java/info/nightscout/androidaps/events/Event.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/events/Event.java b/app/src/main/java/info/nightscout/androidaps/events/Event.java index 77d1215362..864d55d6f7 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/Event.java +++ b/app/src/main/java/info/nightscout/androidaps/events/Event.java @@ -1,9 +1,14 @@ package info.nightscout.androidaps.events; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; /** Base class for all events posted on the event bus. */ public abstract class Event { + static { + ReflectionToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE); + } + @Override public String toString() { return ReflectionToStringBuilder.toString(this); From a6ae3ddd2d443700c18d88c948f9baa8d91b910d Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 16:49:41 +0200 Subject: [PATCH 13/26] Debug: wider thread column in log to improve readability. --- app/src/main/assets/logback.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/assets/logback.xml b/app/src/main/assets/logback.xml index c34ff08b80..d089eb7f64 100644 --- a/app/src/main/assets/logback.xml +++ b/app/src/main/assets/logback.xml @@ -15,7 +15,7 @@ 120 - %d{HH:mm:ss.SSS} [%thread] %-5level [%file:%line]: %msg%n + %d{HH:mm:ss.SSS} [%-40thread] %-5level [%file:%line]: %msg%n @@ -24,7 +24,7 @@ %logger{0} - [%thread] %-5level [%file:%line]: %msg%n + [%-40thread] %-5level [%file:%line]: %msg%n From 9a1d7fd512d27f7371a312947d863edb9b9311f8 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 16:54:21 +0200 Subject: [PATCH 14/26] Log source of event. --- .../main/java/info/nightscout/androidaps/LoggingBus.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/LoggingBus.java b/app/src/main/java/info/nightscout/androidaps/LoggingBus.java index 249e273c3d..390ee5b7e7 100644 --- a/app/src/main/java/info/nightscout/androidaps/LoggingBus.java +++ b/app/src/main/java/info/nightscout/androidaps/LoggingBus.java @@ -29,6 +29,14 @@ class LoggingBus extends Bus { } log.debug("Event posted: " + event); + try { + StackTraceElement caller = new Throwable().getStackTrace()[1]; + String className = caller.getClassName(); + className = className.substring(className.lastIndexOf(".") + 1); + log.debug(" source: " + className + "." + caller.getMethodName() + ":" + caller.getLineNumber()); + } catch (RuntimeException e) { + log.debug(" source: "); + } delegate.post(event); } } From 785a8f21deff99b468af99b1a3586131d41f9fe2 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 17:24:01 +0200 Subject: [PATCH 15/26] Log receivers of event. --- .../java/com/squareup/otto/LoggingBus.java | 57 +++++++++++++++++++ .../nightscout/androidaps/LoggingBus.java | 42 -------------- .../info/nightscout/androidaps/MainApp.java | 4 +- 3 files changed, 59 insertions(+), 44 deletions(-) create mode 100644 app/src/main/java/com/squareup/otto/LoggingBus.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/LoggingBus.java diff --git a/app/src/main/java/com/squareup/otto/LoggingBus.java b/app/src/main/java/com/squareup/otto/LoggingBus.java new file mode 100644 index 0000000000..6fa53a60f9 --- /dev/null +++ b/app/src/main/java/com/squareup/otto/LoggingBus.java @@ -0,0 +1,57 @@ +package com.squareup.otto; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import info.nightscout.androidaps.events.Event; + +public class LoggingBus extends Bus { + private static Logger log = LoggerFactory.getLogger(LoggingBus.class); + + public LoggingBus(ThreadEnforcer enforcer) { + super(enforcer); + } + + @Override + public void post(Object event) { + if (event instanceof DeadEvent) { + log.debug("Event has no receiver: " + ((DeadEvent) event).event + ", source: " + ((DeadEvent) event).source); + return; + } + + if (!(event instanceof Event)) { + log.error("Posted event not an event class: " + event.getClass()); + } + + log.debug("<<< " + event); + try { + StackTraceElement caller = new Throwable().getStackTrace()[1]; + String className = caller.getClassName(); + className = className.substring(className.lastIndexOf(".") + 1); + log.debug(" source: " + className + "." + caller.getMethodName() + ":" + caller.getLineNumber()); + } catch (RuntimeException e) { + log.debug(" source: "); + } + + super.post(event); + } + + @Override + protected void dispatch(Object event, EventHandler wrapper) { + try { + log.debug(">>> " + event); + Field methodField = wrapper.getClass().getDeclaredField("method"); + methodField.setAccessible(true); + Method targcetMethod = (Method) methodField.get(wrapper); + String className = targcetMethod.getDeclaringClass().getSimpleName(); + String methodName = targcetMethod.getName(); + log.debug(" receiver: " + className + "." + methodName); + } catch (ReflectiveOperationException e) { + log.debug(" receiver: "); + } + super.dispatch(event, wrapper); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/LoggingBus.java b/app/src/main/java/info/nightscout/androidaps/LoggingBus.java deleted file mode 100644 index 390ee5b7e7..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/LoggingBus.java +++ /dev/null @@ -1,42 +0,0 @@ -package info.nightscout.androidaps; - -import com.squareup.otto.Bus; -import com.squareup.otto.DeadEvent; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import info.nightscout.androidaps.events.Event; - -class LoggingBus extends Bus { - private static Logger log = LoggerFactory.getLogger(LoggingBus.class); - - private final Bus delegate; - - public LoggingBus(Bus bus) { - delegate = bus; - } - - @Override - public void post(Object event) { - if (event instanceof DeadEvent) { - log.debug("Event has no receiver:" + ((DeadEvent) event).event + ", source: " + ((DeadEvent) event).source); - return; - } - - if (!(event instanceof Event)) { - log.error("Posted event not an event class: " + event.getClass()); - } - - log.debug("Event posted: " + event); - try { - StackTraceElement caller = new Throwable().getStackTrace()[1]; - String className = caller.getClassName(); - className = className.substring(className.lastIndexOf(".") + 1); - log.debug(" source: " + className + "." + caller.getMethodName() + ":" + caller.getLineNumber()); - } catch (RuntimeException e) { - log.debug(" source: "); - } - delegate.post(event); - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 3392a0193a..bd9b57c9ae 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -13,6 +13,7 @@ import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; import com.j256.ormlite.android.apptools.OpenHelperManager; import com.squareup.otto.Bus; +import com.squareup.otto.LoggingBus; import com.squareup.otto.ThreadEnforcer; import org.slf4j.Logger; @@ -104,8 +105,7 @@ public class MainApp extends Application { log.info("Version: " + BuildConfig.VERSION_NAME); log.info("BuildVersion: " + BuildConfig.BUILDVERSION); - Bus bus = new Bus(ThreadEnforcer.ANY); - sBus = Config.logEvents ? new LoggingBus(bus) : bus; + sBus = Config.logEvents ? new LoggingBus(ThreadEnforcer.ANY) : new Bus(ThreadEnforcer.ANY); sInstance = this; sResources = getResources(); From 82dd8c2c5e4ecf00d98eb851d919143e9eecef39 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 18:07:12 +0200 Subject: [PATCH 16/26] Log summary after 10s, then every 60s. --- .../java/com/squareup/otto/LoggingBus.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/squareup/otto/LoggingBus.java b/app/src/main/java/com/squareup/otto/LoggingBus.java index 6fa53a60f9..044911363d 100644 --- a/app/src/main/java/com/squareup/otto/LoggingBus.java +++ b/app/src/main/java/com/squareup/otto/LoggingBus.java @@ -5,12 +5,24 @@ import org.slf4j.LoggerFactory; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import info.nightscout.androidaps.events.Event; +/** Logs events has they're being posted to and dispatched from the event bus. + * + * A summary of references between sender and event and event and receiver is printed + * after 10s (after startup) and then again every 60s. + * */ public class LoggingBus extends Bus { private static Logger log = LoggerFactory.getLogger(LoggingBus.class); + private static long everyMinute = System.currentTimeMillis() + 10 * 1000; + private Map> event2Receiver = new HashMap<>(); + public LoggingBus(ThreadEnforcer enforcer) { super(enforcer); } @@ -48,10 +60,28 @@ public class LoggingBus extends Bus { Method targcetMethod = (Method) methodField.get(wrapper); String className = targcetMethod.getDeclaringClass().getSimpleName(); String methodName = targcetMethod.getName(); - log.debug(" receiver: " + className + "." + methodName); + String receiverMethod = className + "." + methodName; + log.debug(" receiver: " + receiverMethod); + + String key = event.getClass().getSimpleName(); + if (!event2Receiver.containsKey(key)) event2Receiver.put(key, new HashSet()); + event2Receiver.get(key).add(receiverMethod); } catch (ReflectiveOperationException e) { log.debug(" receiver: "); } + + if (everyMinute < System.currentTimeMillis()) { + log.debug("***************** The story so far ****************"); + for (Map.Entry> stringSetEntry : event2Receiver.entrySet()) { + log.debug(" " + stringSetEntry.getKey()); + for (String s : stringSetEntry.getValue()) { + log.debug(" -> " + s); + } + } + log.debug("***************************************************"); + everyMinute = System.currentTimeMillis() + 60 * 1000; + } + super.dispatch(event, wrapper); } } From e5cb5386e361ec3cd6fd65ba4c394a286e1a4065 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 20 Oct 2017 01:50:42 +0200 Subject: [PATCH 17/26] Disable event logging by default. --- app/src/main/java/info/nightscout/androidaps/Config.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index 6bbc908188..0ccb932e57 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -40,7 +40,7 @@ public class Config { public static final boolean logPumpActions = true; public static final boolean logCongigBuilderActions = true; public static final boolean logAutosensData = false; - public static final boolean logEvents = true; + public static final boolean logEvents = false; // DanaR specific public static final boolean logDanaBTComm = true; From 79316bf94803ddcce31560bab960a230f7430775 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 21 Oct 2017 15:00:47 +0200 Subject: [PATCH 18/26] Revert "Debug: wider thread column in log to improve readability." This reverts commit 5fe2d19e6363c4efcaad90fe5aa627b58d230cd1. --- app/src/main/assets/logback.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/assets/logback.xml b/app/src/main/assets/logback.xml index d089eb7f64..c34ff08b80 100644 --- a/app/src/main/assets/logback.xml +++ b/app/src/main/assets/logback.xml @@ -15,7 +15,7 @@ 120 - %d{HH:mm:ss.SSS} [%-40thread] %-5level [%file:%line]: %msg%n + %d{HH:mm:ss.SSS} [%thread] %-5level [%file:%line]: %msg%n @@ -24,7 +24,7 @@ %logger{0} - [%-40thread] %-5level [%file:%line]: %msg%n + [%thread] %-5level [%file:%line]: %msg%n From 91df07ca8f3a2ea8905029f759935bab5436420f Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 21 Oct 2017 15:02:53 +0200 Subject: [PATCH 19/26] Cleanup. --- app/src/main/java/com/squareup/otto/LoggingBus.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/squareup/otto/LoggingBus.java b/app/src/main/java/com/squareup/otto/LoggingBus.java index 044911363d..3417e7dd41 100644 --- a/app/src/main/java/com/squareup/otto/LoggingBus.java +++ b/app/src/main/java/com/squareup/otto/LoggingBus.java @@ -14,7 +14,7 @@ import info.nightscout.androidaps.events.Event; /** Logs events has they're being posted to and dispatched from the event bus. * - * A summary of references between sender and event and event and receiver is printed + * A summary of event-receiver calls that occurred so far is logged * after 10s (after startup) and then again every 60s. * */ public class LoggingBus extends Bus { @@ -57,9 +57,9 @@ public class LoggingBus extends Bus { log.debug(">>> " + event); Field methodField = wrapper.getClass().getDeclaredField("method"); methodField.setAccessible(true); - Method targcetMethod = (Method) methodField.get(wrapper); - String className = targcetMethod.getDeclaringClass().getSimpleName(); - String methodName = targcetMethod.getName(); + Method targetMethod = (Method) methodField.get(wrapper); + String className = targetMethod.getDeclaringClass().getSimpleName(); + String methodName = targetMethod.getName(); String receiverMethod = className + "." + methodName; log.debug(" receiver: " + receiverMethod); @@ -71,14 +71,14 @@ public class LoggingBus extends Bus { } if (everyMinute < System.currentTimeMillis()) { - log.debug("***************** The story so far ****************"); + log.debug("***************** Event -> receiver pairings seen so far ****************"); for (Map.Entry> stringSetEntry : event2Receiver.entrySet()) { log.debug(" " + stringSetEntry.getKey()); for (String s : stringSetEntry.getValue()) { log.debug(" -> " + s); } } - log.debug("***************************************************"); + log.debug("*************************************************************************"); everyMinute = System.currentTimeMillis() + 60 * 1000; } From 88e22c5f1733814649a6237dfbf09a6b526cadca Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Fri, 27 Oct 2017 16:56:17 +0200 Subject: [PATCH 20/26] NSTreatments NPE fix When the dialog was open and the phone goes to sleep/lock screen, Android may garbage collect and options is no longer available. -> NPE I think as quick fix it is ok to not show a dialog at all. If the user stopped using the dialog and lets the phone sleep for a longer while with the phone going to sleep... he can open it again, if he wants it. --- .../plugins/Careportal/Dialogs/NewNSTreatmentDialog.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index 1b976195ae..16cfd89404 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -138,6 +138,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + if (options==null) return null; getDialog().setTitle(getString(options.eventName)); setStyle(DialogFragment.STYLE_NORMAL, getTheme()); View view = inflater.inflate(R.layout.careportal_newnstreatment_dialog, container, false); From 7d82870203de0ea4bded19dfdde61ba804de6409 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 28 Oct 2017 02:16:30 +0200 Subject: [PATCH 21/26] Show remaining time of TT --- .../androidaps/plugins/Overview/OverviewFragment.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 393dc29de5..47cfa1fc1a 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 @@ -994,10 +994,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, // temp target TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); if (tempTarget != null) { + long remainingTimeMinutes = (tempTarget.end()- System.currentTimeMillis())/(1000*60); + long remainingTimeHours = remainingTimeMinutes/60; + remainingTimeMinutes = remainingTimeMinutes%60; + String remaining = " (" + ((remainingTimeHours >0)?(remainingTimeHours + "h "):"") + remainingTimeMinutes + "')"; tempTargetView.setTextColor(Color.BLACK); tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground)); tempTargetView.setVisibility(View.VISIBLE); - tempTargetView.setText(Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units)); + tempTargetView.setText(Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units) + remaining); } else { tempTargetView.setTextColor(Color.WHITE); tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetDisabledBackground)); From 9e8752b096b9f271185d231356482ca4d47d3c3f Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 29 Oct 2017 02:06:06 +0200 Subject: [PATCH 22/26] timeframe strings --- .../java/info/nightscout/utils/DateUtil.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index 3e32557adb..691a4f371e 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -146,4 +146,20 @@ public class DateUtil { } -} \ No newline at end of file + public static String timeFrameString(long timeInMillis){ + long remainingTimeMinutes = timeInMillis/(1000*60); + long remainingTimeHours = remainingTimeMinutes/60; + remainingTimeMinutes = remainingTimeMinutes%60; + return "(" + ((remainingTimeHours >0)?(remainingTimeHours + "h "):"") + remainingTimeMinutes + "')"; + } + + public static String sinceString(long timestamp){ + return timeFrameString(System.currentTimeMillis()-timestamp); + } + + public static String untilString(long timestamp){ + return timeFrameString(timestamp- System.currentTimeMillis()); + } + + +} From 3121fa3e8468662dc05290dc275873927ecab84b Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 29 Oct 2017 02:07:17 +0200 Subject: [PATCH 23/26] use DateUtil#untilString --- .../androidaps/plugins/Overview/OverviewFragment.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 47cfa1fc1a..8b08d76dd2 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 @@ -994,14 +994,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, // temp target TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); if (tempTarget != null) { - long remainingTimeMinutes = (tempTarget.end()- System.currentTimeMillis())/(1000*60); - long remainingTimeHours = remainingTimeMinutes/60; - remainingTimeMinutes = remainingTimeMinutes%60; - String remaining = " (" + ((remainingTimeHours >0)?(remainingTimeHours + "h "):"") + remainingTimeMinutes + "')"; tempTargetView.setTextColor(Color.BLACK); tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground)); tempTargetView.setVisibility(View.VISIBLE); - tempTargetView.setText(Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units) + remaining); + tempTargetView.setText(Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units) + " " + DateUtil.untilString(tempTarget.end())); } else { tempTargetView.setTextColor(Color.WHITE); tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetDisabledBackground)); From f9ed104fe33d12ea434c23a4b22d59c1b3321feb Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 29 Oct 2017 02:08:43 +0200 Subject: [PATCH 24/26] use DateUtil#agoString --- .../nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java index d48013b0e6..0c4a5beded 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java @@ -226,7 +226,7 @@ public class DanaRFragment extends SubscriberFragment { Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime(); double agoHours = agoMsec / 60d / 60d / 1000d; if (agoHours < 6) // max 6h back - lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U"); + lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime.getTime()) + " " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U"); else lastBolusView.setText(""); } From 60699eddbb99fa859a196a837f608596ad64df5d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 1 Nov 2017 20:43:59 +0100 Subject: [PATCH 25/26] preferences update --- .../info/nightscout/androidaps/Config.java | 6 - .../nightscout/androidaps/MainActivity.java | 1 + .../info/nightscout/androidaps/MainApp.java | 18 +- .../androidaps/PreferencesActivity.java | 158 +++++++++--------- .../androidaps/interfaces/PluginBase.java | 1 + .../plugins/Actions/ActionsPlugin.java | 5 + .../Careportal/CareportalFragment.java | 9 - .../plugins/Careportal/CareportalPlugin.java | 14 ++ .../ConfigBuilder/ConfigBuilderFragment.java | 30 +++- .../ConfigBuilder/ConfigBuilderPlugin.java | 7 +- .../ObjectivesPlugin.java | 5 + .../ConstraintsSafety/SafetyPlugin.java | 5 + .../Insulin/InsulinFastactingPlugin.java | 5 + .../InsulinFastactingProlongedPlugin.java | 5 + .../Insulin/InsulinOrefFreePeakPlugin.java | 5 + .../Insulin/InsulinOrefRapidActingPlugin.java | 5 + .../InsulinOrefUltraRapidActingPlugin.java | 5 + .../IobCobCalculatorPlugin.java | 5 + .../androidaps/plugins/Loop/LoopPlugin.java | 5 + .../NSClientInternalPlugin.java | 5 + .../plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 5 + .../plugins/OpenAPSMA/OpenAPSMAPlugin.java | 5 + .../plugins/Overview/OverviewPlugin.java | 5 + .../PersistentNotificationPlugin.java | 5 + .../CircadianPercentageProfilePlugin.java | 5 + .../ProfileLocal/LocalProfilePlugin.java | 5 + .../plugins/ProfileNS/NSProfilePlugin.java | 5 + .../ProfileSimple/SimpleProfilePlugin.java | 5 + .../plugins/PumpDanaR/DanaRPlugin.java | 5 + .../PumpDanaRKorean/DanaRKoreanPlugin.java | 5 + .../plugins/PumpDanaRS/DanaRSPlugin.java | 5 + .../plugins/PumpDanaRv2/DanaRv2Plugin.java | 5 + .../androidaps/plugins/PumpMDI/MDIPlugin.java | 5 + .../PumpVirtual/VirtualPumpFragment.java | 2 +- .../PumpVirtual/VirtualPumpPlugin.java | 15 +- .../SensitivityAAPSPlugin.java | 5 + .../SensitivityOref0Plugin.java | 5 + .../SensitivityWeightedAveragePlugin.java | 5 + .../SmsCommunicatorPlugin.java | 5 + .../SourceGlimp/SourceGlimpPlugin.java | 5 + .../SourceMM640g/SourceMM640gPlugin.java | 5 + .../SourceNSClient/SourceNSClientPlugin.java | 5 + .../SourceXdrip/SourceXdripPlugin.java | 5 + .../plugins/Treatments/TreatmentsPlugin.java | 5 + .../plugins/Wear/ActionStringHandler.java | 10 +- .../androidaps/plugins/Wear/WearFragment.java | 15 +- .../androidaps/plugins/Wear/WearPlugin.java | 19 +++ .../XDripStatusline/StatuslinePlugin.java | 11 +- .../res/drawable-hdpi-v11/ic_settings.png | Bin 0 -> 526 bytes .../main/res/drawable-hdpi-v9/ic_settings.png | Bin 0 -> 580 bytes .../main/res/drawable-hdpi/ic_settings.png | Bin 0 -> 980 bytes .../res/drawable-mdpi-v11/ic_settings.png | Bin 0 -> 357 bytes .../main/res/drawable-mdpi-v9/ic_settings.png | Bin 0 -> 395 bytes .../main/res/drawable-mdpi/ic_settings.png | Bin 0 -> 669 bytes .../res/drawable-xhdpi-v11/ic_settings.png | Bin 0 -> 688 bytes .../res/drawable-xhdpi-v9/ic_settings.png | Bin 0 -> 756 bytes .../main/res/drawable-xhdpi/ic_settings.png | Bin 0 -> 1328 bytes .../res/drawable-xxhdpi-v11/ic_settings.png | Bin 0 -> 1075 bytes .../res/drawable-xxhdpi-v9/ic_settings.png | Bin 0 -> 1113 bytes .../main/res/drawable-xxhdpi/ic_settings.png | Bin 0 -> 862 bytes .../res/layout/configbuilder_simpleitem.xml | 11 ++ app/src/main/res/xml/pref_openapsama.xml | 12 ++ .../{pref_treatments.xml => pref_safety.xml} | 0 63 files changed, 373 insertions(+), 131 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi-v11/ic_settings.png create mode 100644 app/src/main/res/drawable-hdpi-v9/ic_settings.png create mode 100644 app/src/main/res/drawable-hdpi/ic_settings.png create mode 100644 app/src/main/res/drawable-mdpi-v11/ic_settings.png create mode 100644 app/src/main/res/drawable-mdpi-v9/ic_settings.png create mode 100644 app/src/main/res/drawable-mdpi/ic_settings.png create mode 100644 app/src/main/res/drawable-xhdpi-v11/ic_settings.png create mode 100644 app/src/main/res/drawable-xhdpi-v9/ic_settings.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_settings.png create mode 100644 app/src/main/res/drawable-xxhdpi-v11/ic_settings.png create mode 100644 app/src/main/res/drawable-xxhdpi-v9/ic_settings.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_settings.png rename app/src/main/res/xml/{pref_treatments.xml => pref_safety.xml} (100%) diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index abda0ca941..2cfc2d96ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -9,13 +9,9 @@ public class Config { // MAIN FUCTIONALITY public static final boolean APS = BuildConfig.APS; // PLUGINS - public static final boolean OPENAPSENABLED = APS; - public static final boolean LOOPENABLED = APS; - public static final boolean NSCLIENT = BuildConfig.NSCLIENTOLNY; public static final boolean DANAR = true && BuildConfig.PUMPDRIVERS; - public static final boolean DANARv2 = true && BuildConfig.PUMPDRIVERS; public static final boolean ACTION = !BuildConfig.NSCLIENTOLNY; public static final boolean VIRTUALPUMP = !BuildConfig.NSCLIENTOLNY; @@ -26,8 +22,6 @@ public class Config { public static final boolean SMSCOMMUNICATORENABLED = !BuildConfig.NSCLIENTOLNY; - public static final boolean ALLPREFERENCES = !BuildConfig.NSCLIENTOLNY; - public static final boolean detailedLog = true; public static final boolean logFunctionCalls = true; public static final boolean logIncommingData = true; diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index 291cdd94ac..8f08d284dc 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -336,6 +336,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe @Override public void run() { Intent i = new Intent(v.getContext(), PreferencesActivity.class); + i.putExtra("id", -1); startActivity(i); } }, null); diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 4398f80e75..cafeec6dd6 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -26,7 +26,7 @@ import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Actions.ActionsFragment; -import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; +import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; @@ -67,7 +67,7 @@ import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin; import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; -import info.nightscout.androidaps.plugins.Wear.WearFragment; +import info.nightscout.androidaps.plugins.Wear.WearPlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.KeepAliveReceiver; @@ -127,12 +127,12 @@ public class MainApp extends Application { if (Config.DANAR) pluginsList.add(DanaRKoreanPlugin.getPlugin()); if (Config.DANAR) pluginsList.add(DanaRv2Plugin.getPlugin()); if (Config.DANAR) pluginsList.add(DanaRSPlugin.getPlugin()); - pluginsList.add(CareportalFragment.getPlugin()); + pluginsList.add(CareportalPlugin.getPlugin()); if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); - if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getInstance()); - if (Config.LOOPENABLED) pluginsList.add(LoopPlugin.getPlugin()); - if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSMAPlugin.getPlugin()); - if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSAMAPlugin.getPlugin()); + if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getPlugin()); + if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); + if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin()); + if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin()); pluginsList.add(NSProfilePlugin.getPlugin()); if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin()); if (Config.OTHERPROFILES) pluginsList.add(LocalProfileFragment.getPlugin()); @@ -150,8 +150,8 @@ public class MainApp extends Application { pluginsList.add(SourceGlimpPlugin.getPlugin()); if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin()); - pluginsList.add(WearFragment.getPlugin(this)); - pluginsList.add(StatuslinePlugin.getPlugin(this)); + pluginsList.add(WearPlugin.initPlugin(this)); + pluginsList.add(StatuslinePlugin.initPlugin(this)); pluginsList.add(new PersistentNotificationPlugin(this)); pluginsList.add(NSClientInternalPlugin.getPlugin()); diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index d77338d36d..181cb3fa77 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -1,5 +1,6 @@ package info.nightscout.androidaps; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.EditTextPreference; @@ -15,18 +16,23 @@ import android.text.TextUtils; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin; +import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin; +import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin; +import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; +import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.BluetoothDevicePreference; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin; -import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin; import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; +import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.utils.LocaleHelper; @@ -40,6 +46,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myPreferenceFragment = new MyPreferenceFragment(); + myPreferenceFragment.setCaller(getIntent()); getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit(); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); } @@ -72,15 +79,14 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre if (pref.getKey().contains("password") || pref.getKey().contains("secret")) { pref.setSummary("******"); } else if (pref.getKey().equals(MainApp.sResources.getString(R.string.key_danars_name))) { - pref.setSummary(SP.getString(R.string.key_danars_name,"")); + pref.setSummary(SP.getString(R.string.key_danars_name, "")); } else if (editTextPref.getText() != null && !editTextPref.getText().equals("")) { ((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage()); pref.setSummary(editTextPref.getText()); - } - else if(pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().toString().trim())){ + } else if (pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().toString().trim())) { pref.setSummary(MainApp.sResources.getString(R.string.smscommunicator_allowednumbers_summary)); } - } + } if (pref instanceof MultiSelectListPreference) { EditTextPreference editTextPref = (EditTextPreference) pref; pref.setSummary(editTextPref.getText()); @@ -99,85 +105,79 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre } public static class MyPreferenceFragment extends PreferenceFragment { + Intent caller; + + public void setCaller(Intent i) { + caller = i; + } + + void addPreferencesFromResourceIfEnabled(PluginBase p, int type) { + if (p.isEnabled(type) && p.getPreferencesId() != -1) + addPreferencesFromResource(p.getPreferencesId()); + } + @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (Config.ALLPREFERENCES) { - addPreferencesFromResource(R.xml.pref_password); - } - addPreferencesFromResource(R.xml.pref_age); - addPreferencesFromResource(R.xml.pref_language); - if (Config.ALLPREFERENCES) { - addPreferencesFromResource(R.xml.pref_quickwizard); - } - addPreferencesFromResource(R.xml.pref_careportal); - if (Config.ALLPREFERENCES) { - addPreferencesFromResource(R.xml.pref_treatments); - } - if (Config.APS) - addPreferencesFromResource(R.xml.pref_closedmode); - if (Config.OPENAPSENABLED) { - addPreferencesFromResource(R.xml.pref_openapsma); - if (MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class) != null && MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class).isEnabled(PluginBase.APS)) - addPreferencesFromResource(R.xml.pref_openapsama); - } - if (MainApp.getSpecificPlugin(SensitivityAAPSPlugin.class) != null && MainApp.getSpecificPlugin(SensitivityAAPSPlugin.class).isEnabled(PluginBase.SENSITIVITY) - || MainApp.getSpecificPlugin(SensitivityWeightedAveragePlugin.class) != null && MainApp.getSpecificPlugin(SensitivityWeightedAveragePlugin.class).isEnabled(PluginBase.SENSITIVITY)) - addPreferencesFromResource(R.xml.pref_absorption_aaps); - if (MainApp.getSpecificPlugin(SensitivityOref0Plugin.class) != null && MainApp.getSpecificPlugin(SensitivityOref0Plugin.class).isEnabled(PluginBase.SENSITIVITY)) - addPreferencesFromResource(R.xml.pref_absorption_oref0); - if (Config.ALLPREFERENCES) { - addPreferencesFromResource(R.xml.pref_profile); - } - if (Config.DANAR) { - DanaRPlugin danaRPlugin = MainApp.getSpecificPlugin(DanaRPlugin.class); - DanaRKoreanPlugin danaRKoreanPlugin = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class); - DanaRv2Plugin danaRv2Plugin = MainApp.getSpecificPlugin(DanaRv2Plugin.class); - DanaRSPlugin danaRSPlugin = MainApp.getSpecificPlugin(DanaRSPlugin.class); - if (danaRPlugin.isEnabled(PluginBase.PUMP)) { - addPreferencesFromResource(R.xml.pref_danar); - } - if (danaRKoreanPlugin.isEnabled(PluginBase.PUMP)) { - addPreferencesFromResource(R.xml.pref_danarkorean); - } - if (danaRv2Plugin != null && danaRv2Plugin.isEnabled(PluginBase.PUMP)) { - addPreferencesFromResource(R.xml.pref_danarv2); - } - if (danaRSPlugin != null && danaRSPlugin.isEnabled(PluginBase.PUMP)) { - addPreferencesFromResource(R.xml.pref_danars); - } - if (danaRPlugin.isEnabled(PluginBase.PROFILE) || danaRKoreanPlugin.isEnabled(PluginBase.PROFILE) || danaRv2Plugin != null && danaRv2Plugin.isEnabled(PluginBase.PROFILE)) { - addPreferencesFromResource(R.xml.pref_danarprofile); - } - } - VirtualPumpPlugin virtualPumpPlugin = MainApp.getSpecificPlugin(VirtualPumpPlugin.class); - if (virtualPumpPlugin != null && virtualPumpPlugin.isEnabled(PluginBase.PUMP)) { - addPreferencesFromResource(R.xml.pref_virtualpump); - } - InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin = MainApp.getSpecificPlugin(InsulinOrefFreePeakPlugin.class); - if (insulinOrefFreePeakPlugin.isEnabled(PluginBase.INSULIN)) { - addPreferencesFromResource(R.xml.pref_insulinoreffreepeak); - } - NSClientInternalPlugin nsClientInternalPlugin = MainApp.getSpecificPlugin(NSClientInternalPlugin.class); - if (nsClientInternalPlugin != null && nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) { - addPreferencesFromResource(R.xml.pref_nsclientinternal); - } - if (Config.SMSCOMMUNICATORENABLED) - addPreferencesFromResource(R.xml.pref_smscommunicator); - if (Config.ALLPREFERENCES) { - addPreferencesFromResource(R.xml.pref_others); - } - addPreferencesFromResource(R.xml.pref_advanced); + Integer id = caller.getIntExtra("id", -1); - WearPlugin wearPlugin = MainApp.getSpecificPlugin(WearPlugin.class); - if (wearPlugin != null && wearPlugin.isEnabled(PluginBase.GENERAL)) { - addPreferencesFromResource(R.xml.pref_wear); - } + if (id != -1) { + addPreferencesFromResource(id); + } else { + if (!Config.NSCLIENT) { + addPreferencesFromResource(R.xml.pref_password); + } + addPreferencesFromResource(R.xml.pref_age); + addPreferencesFromResource(R.xml.pref_language); - StatuslinePlugin statuslinePlugin = MainApp.getSpecificPlugin(StatuslinePlugin.class); - if (statuslinePlugin != null && statuslinePlugin.isEnabled(PluginBase.GENERAL)) { - addPreferencesFromResource(R.xml.pref_xdripstatus); + if (!Config.NSCLIENT) { + addPreferencesFromResource(R.xml.pref_quickwizard); + } + addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginBase.GENERAL); + addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginBase.CONSTRAINTS); + if (Config.APS) { + addPreferencesFromResourceIfEnabled(LoopPlugin.getPlugin(), PluginBase.LOOP); + addPreferencesFromResourceIfEnabled(OpenAPSMAPlugin.getPlugin(), PluginBase.APS); + addPreferencesFromResourceIfEnabled(OpenAPSAMAPlugin.getPlugin(), PluginBase.APS); + } + + addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginBase.SENSITIVITY); + addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginBase.SENSITIVITY); + addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginBase.SENSITIVITY); + + if (!Config.NSCLIENT) { + addPreferencesFromResource(R.xml.pref_profile); + } + + if (Config.DANAR) { + addPreferencesFromResourceIfEnabled(DanaRPlugin.getPlugin(), PluginBase.PUMP); + addPreferencesFromResourceIfEnabled(DanaRKoreanPlugin.getPlugin(), PluginBase.PUMP); + addPreferencesFromResourceIfEnabled(DanaRv2Plugin.getPlugin(), PluginBase.PUMP); + addPreferencesFromResourceIfEnabled(DanaRSPlugin.getPlugin(), PluginBase.PUMP); + + if (DanaRPlugin.getPlugin().isEnabled(PluginBase.PROFILE) + || DanaRKoreanPlugin.getPlugin().isEnabled(PluginBase.PROFILE) + || DanaRv2Plugin.getPlugin().isEnabled(PluginBase.PROFILE) + || DanaRSPlugin.getPlugin().isEnabled(PluginBase.PROFILE)) { + addPreferencesFromResource(R.xml.pref_danarprofile); + } + } + + addPreferencesFromResourceIfEnabled(VirtualPumpPlugin.getPlugin(), PluginBase.PUMP); + + addPreferencesFromResourceIfEnabled(InsulinOrefFreePeakPlugin.getPlugin(), PluginBase.INSULIN); + + addPreferencesFromResourceIfEnabled(NSClientInternalPlugin.getPlugin(), PluginBase.GENERAL); + addPreferencesFromResourceIfEnabled(SmsCommunicatorPlugin.getPlugin(), PluginBase.GENERAL); + + if (!Config.NSCLIENT) { + addPreferencesFromResource(R.xml.pref_others); + } + addPreferencesFromResource(R.xml.pref_advanced); + + addPreferencesFromResourceIfEnabled(WearPlugin.getPlugin(), PluginBase.GENERAL); + addPreferencesFromResourceIfEnabled(StatuslinePlugin.getPlugin(), PluginBase.GENERAL); } initSummary(getPreferenceScreen()); diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java index bf5e66f2a1..08db6210d4 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java @@ -30,4 +30,5 @@ public interface PluginBase { boolean showInList(int type); void setFragmentEnabled(int type, boolean fragmentEnabled); void setFragmentVisible(int type, boolean fragmentVisible); + int getPreferencesId(); } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java index 74252e2689..3c71626e64 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java @@ -74,4 +74,9 @@ public class ActionsPlugin implements PluginBase { if (type == GENERAL) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + } 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 d832d2aab0..bee1c3b923 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 @@ -26,8 +26,6 @@ import info.nightscout.androidaps.plugins.Overview.OverviewFragment; public class CareportalFragment extends SubscriberFragment implements View.OnClickListener { - static CareportalPlugin careportalPlugin; - TextView iage; TextView cage; TextView sage; @@ -37,13 +35,6 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli LinearLayout butonsLayout; View noProfileView; - static public CareportalPlugin getPlugin() { - if (careportalPlugin == null) { - careportalPlugin = new CareportalPlugin(); - } - return careportalPlugin; - } - // date,bg,insulin,carbs,prebolus,duration,percent,absolute,profile,split,temptarget public static final OptionsToShow BGCHECK = new OptionsToShow(R.id.careportal_bgcheck, R.string.careportal_bgcheck).date().bg(); public static final OptionsToShow SNACKBOLUS = new OptionsToShow(R.id.careportal_snackbolus, R.string.careportal_snackbolus).date().bg().insulin().carbs().prebolus(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java index ceab1b1650..fc6dd7fd05 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java @@ -10,6 +10,15 @@ public class CareportalPlugin implements PluginBase { private boolean fragmentEnabled = true; private boolean fragmentVisible = true; + static CareportalPlugin careportalPlugin; + + static public CareportalPlugin getPlugin() { + if (careportalPlugin == null) { + careportalPlugin = new CareportalPlugin(); + } + return careportalPlugin; + } + @Override public int getType() { return PluginBase.GENERAL; @@ -71,4 +80,9 @@ public class CareportalPlugin implements PluginBase { if (type == GENERAL) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_careportal; + } + } 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 4c868bcc3f..46c2083d0b 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 @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.ConfigBuilder; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; @@ -10,6 +11,7 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListAdapter; import android.widget.ListView; @@ -22,6 +24,7 @@ import com.crashlytics.android.answers.CustomEvent; import java.util.ArrayList; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.PreferencesActivity; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventRefreshGui; @@ -194,7 +197,7 @@ public class ConfigBuilderFragment extends Fragment { public PluginCustomAdapter(Context context, int textViewResourceId, ArrayList pluginList, int type) { super(context, textViewResourceId, pluginList); - this.pluginList = new ArrayList(); + this.pluginList = new ArrayList<>(); this.pluginList.addAll(pluginList); this.type = type; } @@ -203,12 +206,14 @@ public class ConfigBuilderFragment extends Fragment { TextView name; CheckBox checkboxEnabled; CheckBox checkboxVisible; + ImageView settings; } @Override public View getView(int position, View view, ViewGroup parent) { PluginViewHolder holder = null; + PluginBase plugin = pluginList.get(position); if (view == null) { view = LayoutInflater.from(parent.getContext()).inflate(R.layout.configbuilder_simpleitem, null); @@ -217,6 +222,13 @@ public class ConfigBuilderFragment extends Fragment { holder.name = (TextView) view.findViewById(R.id.configbuilder_simpleitem_name); holder.checkboxEnabled = (CheckBox) view.findViewById(R.id.configbuilder_simpleitem_checkboxenabled); holder.checkboxVisible = (CheckBox) view.findViewById(R.id.configbuilder_simpleitem_checkboxvisible); + holder.settings = (ImageView) view.findViewById(R.id.configbuilder_simpleitem_settings); + + if (plugin.isEnabled(type) && plugin.getPreferencesId() != -1) + holder.settings.setVisibility(View.VISIBLE); + else + holder.settings.setVisibility(View.INVISIBLE); + view.setTag(holder); holder.checkboxEnabled.setOnClickListener(new View.OnClickListener() { @@ -244,17 +256,31 @@ public class ConfigBuilderFragment extends Fragment { getPlugin().logPluginStatus(); } }); + + holder.settings.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + final PluginBase plugin = (PluginBase) v.getTag(); + PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() { + @Override + public void run() { + Intent i = new Intent(getContext(), PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + startActivity(i); + } + }, null); + } + }); } else { holder = (PluginViewHolder) view.getTag(); } - PluginBase plugin = pluginList.get(position); holder.name.setText(plugin.getName()); holder.checkboxEnabled.setChecked(plugin.isEnabled(type)); holder.checkboxVisible.setChecked(plugin.isVisibleInTabs(type)); holder.name.setTag(plugin); holder.checkboxEnabled.setTag(plugin); holder.checkboxVisible.setTag(plugin); + holder.settings.setTag(plugin); if (!plugin.canBeHidden(type)) { holder.checkboxEnabled.setEnabled(false); 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 b9e13f0426..12f1f46c1c 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 @@ -146,6 +146,11 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain // Always visible } + @Override + public int getPreferencesId() { + return -1; + } + public void initialize() { pluginList = MainApp.getPluginsList(); loadSettings(); @@ -301,7 +306,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.PUMP); activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PUMP); if (activePump == null) - activePump = VirtualPumpPlugin.getInstance(); // for NSClient build + activePump = VirtualPumpPlugin.getPlugin(); // for NSClient build if (Config.logConfigBuilder) log.debug("Selected pump interface: " + ((PluginBase) activePump).getName()); for (PluginBase p : pluginsInCategory) { 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 7c353e48e2..04edeb43a1 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 @@ -104,6 +104,11 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { if (type == CONSTRAINTS) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + class Objective { Integer num; String objective; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java index 6880d1a21e..a64241a4b9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java @@ -86,6 +86,11 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface { public void setFragmentVisible(int type, boolean fragmentVisible) { } + @Override + public int getPreferencesId() { + return R.xml.pref_safety; + } + @Override public boolean isLoopEnabled() { return MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java index 46f0b46864..c7164ea60e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java @@ -80,6 +80,11 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface { if (type == INSULIN) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + // Insulin interface @Override public int getId() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java index 540151e237..99c35a6c0b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java @@ -80,6 +80,11 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte if (type == INSULIN) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + // Insulin interface @Override public int getId() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java index 8d19eeb4af..3cc2e6b9ca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java @@ -68,6 +68,11 @@ public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin { if (type == INSULIN) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_insulinoreffreepeak; + } + @Override int getPeak() { return SP.getInt(R.string.key_insulin_oref_peak, DEFAULT_PEAK); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java index be6f70c01f..cae9ac540d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java @@ -67,6 +67,11 @@ public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin { if (type == INSULIN) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + @Override int getPeak() { return PEAK; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java index 453620933e..0d390a3ba2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java @@ -67,6 +67,11 @@ public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin { if (type == INSULIN) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + @Override int getPeak() { return PEAK; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index a76e694372..bf4cef2c39 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -126,6 +126,11 @@ public class IobCobCalculatorPlugin implements PluginBase { } + @Override + public int getPreferencesId() { + return -1; + } + IobCobCalculatorPlugin() { MainApp.bus().register(this); if (sHandlerThread == null) { 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 f1fc88625e..1b6d05664e 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 @@ -148,6 +148,11 @@ public class LoopPlugin implements PluginBase { if (type == LOOP) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_closedmode; + } + @Subscribe public void onStatusEvent(final EventTreatmentChange ev) { invoke("EventTreatmentChange", true); 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 7e8a76ce1b..d5ca87a479 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 @@ -135,6 +135,11 @@ public class NSClientInternalPlugin implements PluginBase { if (type == GENERAL) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_nsclientinternal; + } + private ServiceConnection mConnection = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { 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 be7b830880..b64d4b6b08 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 @@ -103,6 +103,11 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { if (type == APS) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_openapsama; + } + @Override public void setFragmentEnabled(int type, boolean fragmentEnabled) { if (type == APS) this.fragmentEnabled = fragmentEnabled; 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 4d5f97c1b0..a0d5cddd88 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 @@ -101,6 +101,11 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { if (type == APS) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_openapsma; + } + @Override public void setFragmentEnabled(int type, boolean fragmentEnabled) { if (type == APS) this.fragmentEnabled = fragmentEnabled; 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 d779b82ae9..7eecbada25 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 @@ -103,6 +103,11 @@ public class OverviewPlugin implements PluginBase { // Always visible } + @Override + public int getPreferencesId() { + return -1; + } + @Override public int getType() { return PluginBase.GENERAL; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java index 9432552c1a..f0745afe94 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java @@ -205,6 +205,11 @@ public class PersistentNotificationPlugin implements PluginBase { //no visible fragment } + @Override + public int getPreferencesId() { + return -1; + } + private String deltastring(double deltaMGDL, double deltaMMOL, String units) { String deltastring = ""; if (deltaMGDL >= 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java index 2afb47e034..ea4f32e794 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java @@ -119,6 +119,11 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte if (type == PROFILE) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + void storeSettings() { if (Config.logPrefsChange) log.debug("Storing settings"); 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 61bff582a5..b9780d7493 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 @@ -108,6 +108,11 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface { if (type == PROFILE) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + public void storeSettings() { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences.Editor editor = settings.edit(); 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 53900da781..e4fdabecf9 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 @@ -104,6 +104,11 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface { if (type == PROFILE) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + @Override public int getType() { return PluginBase.PROFILE; 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 8f38cecb92..d0b36d34ca 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 @@ -111,6 +111,11 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface { if (type == PROFILE) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + public void storeSettings() { if (Config.logPrefsChange) log.debug("Storing settings"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index 65dd5192e4..115f612f6c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -217,6 +217,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C fragmentPumpVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_danar; + } + @Override public boolean isFakingTempsByExtendedBoluses() { return useExtendedBoluses; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index c8b2d04759..c0071ecfca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -219,6 +219,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf this.fragmentPumpVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_danarkorean; + } + @Override public boolean isFakingTempsByExtendedBoluses() { return useExtendedBoluses; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index 468626fe26..5f97999bfa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -137,6 +137,11 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, this.fragmentPumpVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_danars; + } + static boolean fragmentPumpEnabled = false; static boolean fragmentProfileEnabled = false; static boolean fragmentPumpVisible = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 4a224bd57b..f9156bb430 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -204,6 +204,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, this.fragmentPumpVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_danarv2; + } + @Override public boolean isFakingTempsByExtendedBoluses() { return false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java index ca3f7a62a0..da4ea8157d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java @@ -99,6 +99,11 @@ public class MDIPlugin implements PluginBase, PumpInterface { if (type == PUMP) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + @Override public int getType() { return PluginBase.PUMP; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java index 9d19f9f132..3590af80fe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java @@ -79,7 +79,7 @@ public class VirtualPumpFragment extends SubscriberFragment { activity.runOnUiThread(new Runnable() { @Override public void run() { - VirtualPumpPlugin virtualPump = VirtualPumpPlugin.getInstance(); + VirtualPumpPlugin virtualPump = VirtualPumpPlugin.getPlugin(); basaBasalRateView.setText(virtualPump.getBaseBasalRate() + "U"); if (MainApp.getConfigBuilder().isTempBasalInProgress()) { tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index e7323f48af..2e3be7ab95 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -64,12 +64,12 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { return fromNSAreCommingFakedExtendedBoluses; } - private static VirtualPumpPlugin instance = null; - public static VirtualPumpPlugin getInstance() { + private static VirtualPumpPlugin plugin = null; + public static VirtualPumpPlugin getPlugin() { loadFakingStatus(); - if (instance == null) - instance = new VirtualPumpPlugin(); - return instance; + if (plugin == null) + plugin = new VirtualPumpPlugin(); + return plugin; } private VirtualPumpPlugin() { @@ -154,6 +154,11 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { if (type == PUMP) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_virtualpump; + } + @Override public int getType() { return PluginBase.PUMP; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java index 2cf6b5a4e4..39af16e0ee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java @@ -96,6 +96,11 @@ public class SensitivityAAPSPlugin implements PluginBase, SensitivityInterface{ if (type == SENSITIVITY) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_absorption_aaps; + } + @Override public AutosensResult detectSensitivity(long fromTime, long toTime) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java index da89882a27..6817e17503 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java @@ -94,6 +94,11 @@ public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface if (type == SENSITIVITY) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_absorption_oref0; + } + @Override public AutosensResult detectSensitivity(long fromTime, long toTime) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java index 68537cf47c..596c2477f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java @@ -93,6 +93,11 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity if (type == SENSITIVITY) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_absorption_aaps; + } + @Override public AutosensResult detectSensitivity(long fromTime, long toTime) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java index 67c497a06d..9fdb0152d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java @@ -186,6 +186,11 @@ public class SmsCommunicatorPlugin implements PluginBase { if (type == GENERAL) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_smscommunicator; + } + @Subscribe public void processSettings(final EventPreferenceChange ev) { if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java index 2fbe60cbf5..934635f03b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java @@ -75,5 +75,10 @@ public class SourceGlimpPlugin implements PluginBase, BgSourceInterface { } + @Override + public int getPreferencesId() { + return -1; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java index 57b32c1ad1..aba07ffe05 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java @@ -75,5 +75,10 @@ public class SourceMM640gPlugin implements PluginBase, BgSourceInterface { } + @Override + public int getPreferencesId() { + return -1; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java index cc2cb15878..0e85793850 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java @@ -77,5 +77,10 @@ public class SourceNSClientPlugin implements PluginBase, BgSourceInterface { } + @Override + public int getPreferencesId() { + return -1; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java index 0d0fb07c45..8363f13566 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java @@ -75,5 +75,10 @@ public class SourceXdripPlugin implements PluginBase, BgSourceInterface { public void setFragmentVisible(int type, boolean fragmentVisible) { } + @Override + public int getPreferencesId() { + return -1; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index 6422ec3589..d7c9d1eafe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -121,6 +121,11 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { if (type == TREATMENT) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + @Override public int getType() { return PluginBase.TREATMENT; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index 9fbcc31685..a7b90775f1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -324,7 +324,7 @@ public class ActionStringHandler { // send result - WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation(rTitle, rMessage, rAction); + WearPlugin.getPlugin().requestActionConfirmation(rTitle, rMessage, rAction); lastSentTimestamp = System.currentTimeMillis(); lastConfirmActionString = rAction; } @@ -596,7 +596,7 @@ public class ActionStringHandler { msg += MainApp.sResources.getString(R.string.cpp_valuesnotstored); String rTitle = "STATUS"; String rAction = "statusmessage"; - WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation(rTitle, msg, rAction); + WearPlugin.getPlugin().requestActionConfirmation(rTitle, msg, rAction); lastSentTimestamp = System.currentTimeMillis(); lastConfirmActionString = rAction; return; @@ -667,14 +667,14 @@ public class ActionStringHandler { } private synchronized static void sendError(String errormessage) { - WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation("ERROR", errormessage, "error"); + WearPlugin.getPlugin().requestActionConfirmation("ERROR", errormessage, "error"); lastSentTimestamp = System.currentTimeMillis(); lastConfirmActionString = null; lastBolusWizard = null; } private synchronized static void sendStatusmessage(String title, String message) { - WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation(title, message, "statusmessage"); + WearPlugin.getPlugin().requestActionConfirmation(title, message, "statusmessage"); lastSentTimestamp = System.currentTimeMillis(); lastConfirmActionString = null; lastBolusWizard = null; @@ -682,7 +682,7 @@ public class ActionStringHandler { public synchronized static void expectNotificationAction(String message, int id) { String actionstring = "dismissoverviewnotification " + id; - WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation("DISMISS", message, actionstring); + WearPlugin.getPlugin().requestActionConfirmation("DISMISS", message, actionstring); lastSentTimestamp = System.currentTimeMillis(); lastConfirmActionString = actionstring; lastBolusWizard = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java index d243da7d60..b1b47a4ae2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearFragment.java @@ -15,17 +15,6 @@ import info.nightscout.androidaps.R; public class WearFragment extends Fragment { - private static WearPlugin wearPlugin; - - public static WearPlugin getPlugin(Context ctx) { - - if (wearPlugin == null) { - wearPlugin = new WearPlugin(ctx); - } - - return wearPlugin; - } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -34,14 +23,14 @@ public class WearFragment extends Fragment { view.findViewById(R.id.wear_resend).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - getPlugin(getContext()).resendDataToWatch(); + WearPlugin.getPlugin().resendDataToWatch(); } }); view.findViewById(R.id.wear_opensettings).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - getPlugin(getContext()).openSettings(); + WearPlugin.getPlugin().openSettings(); } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index e0d8d9210d..00f62bd2c0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -34,6 +34,20 @@ public class WearPlugin implements PluginBase { private static WatchUpdaterService watchUS; private final Context ctx; + private static WearPlugin wearPlugin; + + public static WearPlugin getPlugin() { + return wearPlugin; + } + public static WearPlugin initPlugin(Context ctx) { + + if (wearPlugin == null) { + wearPlugin = new WearPlugin(ctx); + } + + return wearPlugin; + } + WearPlugin(Context ctx) { this.ctx = ctx; MainApp.bus().register(this); @@ -105,6 +119,11 @@ public class WearPlugin implements PluginBase { if (type == GENERAL) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return R.xml.pref_wear; + } + private void sendDataToWatch(boolean status, boolean basals, boolean bgValue) { if (isEnabled(getType())) { //only start service when this plugin is enabled diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java index 38bb014274..300a2827c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java @@ -47,7 +47,11 @@ public class StatuslinePlugin implements PluginBase { private static StatuslinePlugin statuslinePlugin; - public static StatuslinePlugin getPlugin(Context ctx) { + public static StatuslinePlugin getPlugin() { + return statuslinePlugin; + } + + public static StatuslinePlugin initPlugin(Context ctx) { if (statuslinePlugin == null) { statuslinePlugin = new StatuslinePlugin(ctx); @@ -138,6 +142,11 @@ public class StatuslinePlugin implements PluginBase { // do nothing, no gui } + @Override + public int getPreferencesId() { + return R.xml.pref_xdripstatus; + } + private void sendStatus() { diff --git a/app/src/main/res/drawable-hdpi-v11/ic_settings.png b/app/src/main/res/drawable-hdpi-v11/ic_settings.png new file mode 100644 index 0000000000000000000000000000000000000000..8a55c0221f8074631b8ede47067cd19e4fe8a116 GIT binary patch literal 526 zcmV+p0`dKcP))hV?v;!$D-112bXE{E~V|nAGhhUb48`CCc_$$5*+0ZrU(lxYhFfl*kWsn6Gk5WLzs;;36 z%?S@c(xpv-BTfCWuAxD(m{$})heY40VJdG_Jn?Wl*p+NS9oPze%0s)u=l5HS&WK4% zn%WAXb%Ivv5;5tXrZ!7xFM}F7B_=IuYRfu1$cAS8^g|BObX5%(z9E{qg0D*eL=)gcB>9rqN=qEuSA~%muqj#@OSHV_q5~ZZ zQW)dZuff=g!qB4Rt;he?t;566@Nc`9#YB=*QET|k_1pJqiokCD^YL%u3z5o~R5(CG Qf&c&j07*qoM6N<$f~chLrT_o{ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-hdpi-v9/ic_settings.png b/app/src/main/res/drawable-hdpi-v9/ic_settings.png new file mode 100644 index 0000000000000000000000000000000000000000..23b7ef35297c27367440607f77cbe6d56143f754 GIT binary patch literal 580 zcmV-K0=xZ*P)X_$w zUyH?JFQ3mV9r$kGd=U=MX?Qz4_a%o_fW9sgD8Y(ARjbwhP^t1K??cvvBiw!*Li5Jt z*=+U=y}q<1dn^z;NA&eQ0hE(M$mMc2oB>w=uWjQ=4sxx<3@>s4Le~=L(c59|T@B-F zTDaX(sr25~rYZ0XC=I82a$SVAwvXEZlYu9R3Rd+Xw(JCOU7x`6gZF?|4G6GZs{p5F zK!E=%4~>LL5_U3~jOv4+lUA$s($pd@+?mdG9Ooye=&dn13-et6u2iB2$&34p=^~OG zmnUmFS7JHp*I@3R0F|fG>9jIIMgs{?fFq!oQ}NmO?0Vfa&_-FjvIR+XwBQc%+r|SI z#)~GFN~J#d$bSP889B6VA#m6satL<8Od^q(;JE>MK>5%k;Wu_Oo=hfZ`M(Da0*9S# ztm0000n6S&hI&|Q)BeLdFs3PP0#Q7d_8`bb52y$PyCP3)6?^-sHn)Aot^FV ziy|a1m|(NU8XFsJ4Gj&{+uKWHV`DTiG4Z7W11vDX*6P?}e}6xXkB>)GV1msW>+9>I z;o)H#85xPFzyzB$hPEQ#W6+5SN z06TJKW=1s!8-+7>b#*0np>ht`tg-6qYO1TNQ>nSRSsbLw*x1;R=0jUsTdMrs-Cgl7 zljVcW8mp+NpqiQ*sjx1Tf$h)bqif2*BIokKW{s7WmQrP9rBo=YjLFGKHXo*y(b3Vt z=7Y@|D=sdkva&Lj&}J-fW#G`1#F?C%}uJRs*>h|%^LGRNs5GEVaJ@EokGmbYzM5@>lGbRa=>Pd;pHGNFHfbpxw)_zo0^)EGQehy zWn^SX-(+%fa_HpbByfoz92^A3T5)`QOoxYuflC}?)RHm4W{st#rHKTYa5`gcl$V!_ zaaL9qSu7UT6mEpf%uJDsIk>$2Z$fN+uvud%DJhhin)+#>;Pdmd%GA@-6Q!r8>#7Ad zYb+@#iIS6(b?N5jMrF+HcI&PKHfzjaFi>J*qAuY{!Q=6S2v4?p>wwJ~i;s^N3Ev^G zS!1!Wv6PUIKyh(#5fzwVYjx}qXG%;=OhlENn~RR|p9uUHtgWrBO`O7LZFF?>mkJE9 z!1S}7nxCQkXVY)1)#_VVSfEG^WpklzXb0000+gPz+)-Q`3T=|Cqp^nif=Gv7nTa;P3}xE-0T9h&N-gU?UK7K-F+V z^)M4-K_=9I_dq-Yi0}T#4emnKyod7B2pKL2#IOI84_*SX06q&Q;L-dKh;IY&9Vi|KZ8#$C4zeYnIKh)YHsiBk5`koT6N>RA(|&vw z2m$dM3NqR&P-Z0*4_Q#fAAoo^5I?|U;613Ck5GOFv4tI|c;a!c4sEEbeevpxvMVnG14t4tjvtPK(y84U&i!L^fq<=Hxy00000NkvXXu0mjf DeENX1^@s6IQ*`u0003}NkldD*sl(g1x$q6Qy_4xX<7jo7&k{mY+7n-%5Ci+&-1MT z7C36^SmuNqsH%F@+<}12E+8-h$s3GyTN$xWd*C`2`U!f~ukeOu;|YZ8x*M2|z!>+U zs!=X#u4+%AD9Q(5Rru1Haq!mKfhdYyS(Y`>15aQDSjiGakC literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_settings.png b/app/src/main/res/drawable-mdpi/ic_settings.png new file mode 100644 index 0000000000000000000000000000000000000000..60b53e614e51173e08b49bd6f327e498602303dd GIT binary patch literal 669 zcmV;O0%HA%P)P000>X1^@s6#OZ}&0007HNkljK7=`l_L{XvyK@Fmy5RqsIS{OtFH-R92VhS}NB7*px+QM3`wDT{-I$hG-Ul6dq zDvCA+L{ReHdj?!~85M5q^1?yf_snxP?!_(8#(E{ z3{pHE->Yu7OXBKuItTsWaUod8NF*W%GikM2luD)O@$r$~-`^!6Z*OnxI{NUzFCGux zt_M$nKtNEt-Da@WYDLrOly()aqmODfo09S1aUp)cpYHGPnZn^P&F6FapPJ2P6bgj| z26$YE$KzoQs9Y}7X0wq%CX)%(YBjbD&(F`?-N9cfl>`QOT!`E4rkk4^L4`trK0iMN z2msUti?)dL=!d&nJX@e0*?Y!Q(>gb~|fq zmC0n-47ZidW+nYxE+@GY_{DwjxDcz=N;aE~38!|wUQ5<|G#atj#`X0z`y7wQl0N)6 z>01VPT!`6hCX2gc_EX@#QN~TFCGsb7oyQ<=FMcSU0q#Kuh$cV=XS^s9v32)%So+PlR}|5THt`kh3NJAKbM!6 zq*N+NCX;N}k72X#5mwWHI_Z^#>V#SIT>p((? zgukY2Ht>#M;El}&z7q^=*;@P&utPBL2PAAXa8}T?50X(A*A5C` z8k_^ouHSpWf}m?2bh~0SgFY||^5AHg1|B++SHTBx9UKD>z;9u$Utm0(V4k)r#@cy-HjI1<^P?4_f>s*Rn<}nR}31d;)wCjn^h<;TX6RAn6_`gDl8_ ziaPvU-QpP7U?yAi>hr1@ykN%s$T2Vgei$Yiao-Uhy?)d%<~GQ1&%r6MLQJ%vE8b;- zx)N_eSI|x*5A&4T*SbA_#_(>b`ox=H9bQe+*P4VSM!bq9UcMghp;b-7IYzvkZtENd z1KFqzywW5rGUAmr@m_{mcncW!ImEl*v_Z@yA>RGKhZq4m!Lq>{pV~$ji7{p4ILR$O zL;S{d>K@@D8!?Re4P4+DSZ7}Q^IqFY-V=sjZBDIm4BQRy_>z0LD7%xQ0hSkEU!y_FB+9!RTURINu>Q0-}^7Rj(Kv&XJw{RD1+6Kdr0 zmr=N!bd0GOH`PIRZr8~$Z{rR*lm$<~d5^(X+VE@Z8Ay5D5&ht)+P2Y-;nl>BdN5Nq z&PLl*|ECOhTWy_CZy(z6x-#&dU|`8+1G5AJk8Cy|TjG$KTzhd%cC`54p|N7c`mcY} WK=WM)F)tnf0000BVp%=OKq8EaQO=xpIpHH*~TWlfEAtK%=7K*pl z!wc9nt*ITqB?*Mh-g|aJ_uXFbGs(>Q*ZOD8tV!$hdFGjCo_Xfkkk)KA#~Y2tgIcY& zFo=4+eqYvH7eKNn<#Jh>0bxt73n&(gYpGO9nW0oFt-3CtP$=wJ31DsOT#|5}m#Wq3 z?N+OG(UAN~HkM2y64S8&2(KuoV*JLLuQE;xkW$mkupUGsbTU9A_0jKBS)FMEeQchd(2|jC6i7wm~$)UZ7?B*UN zJ^^YF1gYz|u~=-=$OFf4=ZAWXAa#v_c!ZX9Jbe5n0y;y#hGqhIBeVkOcfU#Hj)zK4 zH{79=CqNB?Hmd2k_-q(?pu?}_oHnss5R$L3i>^r!xxsDLr)`-Tr77K+tG)LfyoC|T*!DSiNUr19HW2@gkj%(A4241yj@l6C z0F_YSM>rf_6H$zh`TnanZwKK#B-s?7*TGMjC+17X??5mZybNicam?`6UuAyJCi!PL zb2S1F#CXjfbX%fv8=GLkd>F0vxlEO+$ zOL=2W177fhCmAFoBjdWDpn#Q?m1!*SQ+eKzL2`0(SaESND=8__Sm2kNo6E=`+1c5w zsHjNefhQRxD=UlNR7$|7*3i(v8XFtmfn)fe(*6NFFNAT3TXqwYa#* zS8KFE+m@CVwz|5?c6WDqNV)L=Jjoyl2?>1KDEj;R--%sZT(HT>N&ac8TaS;Ayv^n1 z<-6m3eSNay19*}_;^N}?w28no{Qmx)eN^4u-SL&1ascoogG5J1^JxR#c*9Hv9q(or(M(@|HEvF>g42v-|UnFfF~J5 z_4dWnQebK!ELGST%C*PLN)@&?=v%HmfF~Km&(Dtq1_sJ9H8mx9V<#mg$+pECp40;X zn@x4b2Jj?<`1ttnv~q}oV4;$0i?C8b#>dCi8XLfq4C3YG#nVz?YPYtwBrlJ;x;okR z_4W0VZ8tVHSa5K#Y3 z$sqRj_RPu2NyymP*oSW#hlhtr2LMkph^?(HKS>0h;n+faRNdU%@W(6V0N_amv9hw_ zCsA~Db-f!LTb9AWLH@F&Zaq9auz`UAc6N65?s#Wsr|kFuo@5XU3kzm#ZB63f;J|NO zEQ;9KqGKEn4Gkr~3i_{bd1Adl8??>K%VX2i)BFK}Pg`z$08cWAnVA{0w6y$f@by3S z%8QwRh>|e?Jjo!Yrl$NPB^)0g3xgaS94PJ|z>^GOVq(HiQo`KaoG{4D%#7mx0X)ed z#>U3{Bqj9p^az7=cXuo9AHb6gVq|2*Pf~)pxjDb_e*~LNToy|E2k<0=7#JAvlQbQ8 zl0o$K_4!Gf4m`;qy1Kf|(9n?S>FH@K@Pj8AL`O&G8jFqUug3DP-!&OTwOEbd#RyZU zt*xzbzzcrxl>5rmO0`}89v>giS7|iV($f0tzym(;f*(9(e>6~7SZLbb-agdP(eYIU m(;&XW3x1!!Px-7rRQ~{QA{srMDg1~400005#2pQkV>C7wWna7ITJx&n^sl50b-RP!{;^!k}+pLKqC1FWhTp z7z`@WFlc=k3_74;(B3c@bWX#d(?Pq~F(3mZIsAMwc&K5}9j7}PJ~xOKbuh{=b0&iq za(8J4%fYZ1#w-SH;FpF$^tY{G5gE`=tl?lKxGZK z1;Hyas)^#r7)c-p)PR>!K7Yh(b7sfMWqyE*U^n z^CS~TkRr`>#4pj9SDQ9xv|N~jswW`Tq(QYJ_^LEz&Q#Ew00wnaio$IUC0%Dl;^>sq zGNvAUF%Z9j)1WQP zGpG|3D#V`#9y8CNjhqHiD!&$dVi;UUtXUIhHgTBr0jy$OgZ}#_J2ZEY0?qh3x7&S{ znd^3t<77|A%`LZ|A%4BfEV>b-d0CH@%N@w6D2E!)5IaM0ccU4%1El!T@~Bf7XbWT9 zHifuVes&a9rh6r0+*&VhYn_1}RTyXqW85-@xQG2T=$OJliy7mV2F0L53InZRj9a4+ zx5iI{R0i727`N4rFGgj6DPX%|(nj0-Sccf?is?ml}Ws!z3Cu15SqIV0Tau1@@T#p()K=;`VKl`Af9txksc@4zzdhS}yg&z;AF7m3OHDl_ zplg}O-L!8?pr-v9_J$e$VV+|CF;GRjV3w(E{$K(aRBbX3q61T}0&LDRFOtP#5!}NI z<`032zJuVm187jYXKhymnk)JaNySRUuF7h^+u%jh;jDe&dYoBJhrMQaUC}p08OR&C zkmrfNNAU6$+Y?T83FQ1!3gyfG)Y~YZJ?=-#gU%tomNSVASOZ4HXphh#&sz-Z$PKWx zzxD-wp9uU!&r2(HjCp?lh>x|)O8J!M3-i= zSsez0Hfb2NAq)mB&@gCL7!1melSB0nP3W{@9RX`vRm|;mR3kHM9t1QDO;2YpMCV$5jd|zMR z4pQS?*r`l?2=ce!ngmYao+pU$=H_OruC7iQ!Y6&CFI?vcbRW;_@QvaxB)+6gYisKp zL~U~{00+gg^sRI*pGg66{tE|x9q9xgEkrnkO9ZXvO9snP@DOK0`rT=8Zh^s?W@gfy zg+*}m*Q>8N$O3z5~ z#Nlj;Q7hw_)7aRUBJlhDxqPkw(@uHe36V)fF$GY#C+V=@(9tldm$VjlO-)TQZ5}z~ zo~NJ-l+uXC1>lR014ey_Dc%x`TiQ4f@yX}&9n~siracq9P;@YfgG5#C@Jy(t(=(9a zXfI%g+)7}L2nhjeEin3}y4>(q*l_|We!t4Bs?5f;oimoXY+X)@GB<{R3D-`evJ~1l zTGUCO6#`^+T9a3b)-?fkj=*nLhrPO-au|#uV8KlRwkgC}CCkADD94Ty0r97h6cC$- zPl}i{vDN~?lsGsnmf3O2?8q(8@x_M2T!w7l)oNI;tj9PZJ$XC%>QN`Y4f=dt!_ zluDwdP*Xvt+~KxMRKR^c9&J}TT210p`M(&ecJf1KmQPgMsIgfHs@b~C}g zl1MN^(pHCCVqu~9f$)5lv(Q-`@@NqRIKd#4z>_7blLXD@Y{ZrFZc;b+6(U0PKdp3} zW~+Yu9Gr^YtoVLEj(j}lGyfK{0s?_R zKDleDK>1*{o+ig{f(t1KSmI3My&w6c&002t}1^@s6I8J)%0009eNklhA6~9j4O(QDCoh1c#6s_hljM)Q$Jl@uc|r-6h%=KMNt$* zQ4~c{6h&bZhT#@?6W)rE{=V7wpfd1f$m5CcVNHkMm|=Z^Q+y7qHstdMF7`RB^`RX( zpTpW?8CFL*hOiW_hS`{Fvhb{BSf}BHm^LTEHK`e{_@OglpXuBSco5DXH3R11{m_kj za2>T1X>%bw1YenJ-oY7Z2N>k!y}i530@tBY_|E zI*?poUI}G!DLPywg_Sq8kR)ihu9X(lBwCJyGI>C=q@=KRC)~l`3AfiFC8$dHIf3EQ z1KVIdtcDG+9rh+Ldwzh^B!o2&el4LR{idYI#7rE`@M8)0phfs>DNolb_}Ve3TIM~L zI|fFD@k(hg`8n{a<x}t%1yt>}9lFfQRGOrjkP2 z&*)IAW83YFws)mz*P)Zqp=FM3H!#}XmZq@wF^0(k$F{2(b=VGlvi`MQUv5vuy0G+EYJv@uvIEhw6y zo;y_6ecTN?b8Ob{aF3^Og_NM?nzffJ6j*MIwPD^dsQ(OzsN~H7#XtgEGV~5>p;?m3 z3iEHPsq{iVnRgs$L4Lm|S z1*3*5h4$DnsE6j*KKiZ0B6t+OHP^fsSGmUoRzruIakG%wRqe72>dY8l=2Vyhw @@ -20,6 +21,16 @@ android:layout_weight="1" android:text="ConfigBuilder plugin text" /> + + + + Date: Wed, 1 Nov 2017 20:47:16 +0100 Subject: [PATCH 26/26] add getPreferenceId to food plugin --- .../info/nightscout/androidaps/plugins/Food/FoodPlugin.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java index dbd1549c11..255b4fd951 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java @@ -76,5 +76,10 @@ public class FoodPlugin implements PluginBase { if (type == GENERAL) this.fragmentVisible = fragmentVisible; } + @Override + public int getPreferencesId() { + return -1; + } + }