Merge pull request #12 from MilosKozak/master

dev
This commit is contained in:
LadyViktoria 2016-06-15 12:58:05 +02:00 committed by GitHub
commit 0ca6e96f39
32 changed files with 810 additions and 377 deletions

View file

@ -10,4 +10,6 @@ public class Config {
public static final boolean logIncommingData = true;
public static final boolean logAPSResult = true;
public static final boolean logPumpComm = true;
public static final boolean logPrefsChange = true;
public static final boolean logConfigBuilder = true;
}

View file

@ -14,13 +14,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Iterator;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.LowSuspend.LowSuspendFragment;
import info.nightscout.androidaps.plugins.NSProfileViewer.NSProfileViewerFragment;
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment;
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
import info.nightscout.androidaps.plugins.ProfileViewer.ProfileViewerFragment;
import info.nightscout.androidaps.plugins.SimpleProfile.SimpleProfileFragment;
import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpFragment;
@ -35,44 +38,39 @@ public class MainActivity extends AppCompatActivity {
private ViewPager mPager;
private static TabPageAdapter pageAdapter;
ArrayList<Fragment> pluginsList = new ArrayList<Fragment>();
private static ArrayList<PluginBase> pluginsList = new ArrayList<PluginBase>();
public static TreatmentsFragment treatmentsFragment;
public static TempBasalsFragment tempBasalsFragment;
private static ConfigBuilderFragment configBuilderFragment;
public static ConfigBuilderFragment getConfigBuilder() {
return configBuilderFragment;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Config.logFunctionCalls)
log.debug("onCreate");
// Register all tabs in app here
pluginsList.add(OverviewFragment.newInstance());
pluginsList.add((VirtualPumpFragment) MainApp.setActivePump(VirtualPumpFragment.newInstance()));
pluginsList.add(VirtualPumpFragment.newInstance());
pluginsList.add(LowSuspendFragment.newInstance());
pluginsList.add(OpenAPSMAFragment.newInstance());
pluginsList.add(treatmentsFragment = TreatmentsFragment.newInstance());
pluginsList.add(tempBasalsFragment = TempBasalsFragment.newInstance());
pluginsList.add(ProfileViewerFragment.newInstance());
pluginsList.add(NSProfileViewerFragment.newInstance());
pluginsList.add(SimpleProfileFragment.newInstance());
pluginsList.add(TreatmentsFragment.newInstance());
pluginsList.add(TempBasalsFragment.newInstance());
pluginsList.add(ObjectivesFragment.newInstance());
pluginsList.add(ConfigBuilderFragment.newInstance());
pluginsList.add(configBuilderFragment = ConfigBuilderFragment.newInstance());
/*
pageAdapter.registerNewFragment(OverviewFragment.newInstance());
pageAdapter.registerNewFragment((VirtualPumpFragment) MainApp.setActivePump(VirtualPumpFragment.newInstance()));
pageAdapter.registerNewFragment(LowSuspendFragment.newInstance());
pageAdapter.registerNewFragment(OpenAPSMAFragment.newInstance());
pageAdapter.registerNewFragment(treatmentsFragment = TreatmentsFragment.newInstance());
pageAdapter.registerNewFragment(tempBasalsFragment = TempBasalsFragment.newInstance());
pageAdapter.registerNewFragment(ProfileViewerFragment.newInstance());
pageAdapter.registerNewFragment(ObjectivesFragment.newInstance());
pageAdapter.registerNewFragment(ConfigBuilderFragment.newInstance());
*/
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
registerBus();
configBuilderFragment.initialize();
setUpTabs(false);
}
@ -83,8 +81,8 @@ public class MainActivity extends AppCompatActivity {
private void setUpTabs(boolean switchToLast) {
pageAdapter = new TabPageAdapter(getSupportFragmentManager());
for(Fragment f: pluginsList) {
pageAdapter.registerNewFragment(f);
for (PluginBase f : pluginsList) {
pageAdapter.registerNewFragment((Fragment) f);
}
mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(pageAdapter);
@ -120,4 +118,20 @@ public class MainActivity extends AppCompatActivity {
public static TabPageAdapter getPageAdapter() {
return pageAdapter;
}
public static ArrayList<PluginBase> getPluginsList() {
return pluginsList;
}
public static ArrayList<PluginBase> getSpecificPluginsList(int type) {
ArrayList<PluginBase> newList = new ArrayList<PluginBase>();
Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getType() == type)
newList.add(p);
}
return newList;
}
}

View file

@ -1,36 +1,23 @@
package info.nightscout.androidaps;
import android.app.Application;
import android.content.SharedPreferences;
import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.squareup.otto.Bus;
import com.squareup.otto.ThreadEnforcer;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.plugins.Pump;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.db.DatabaseHelper;
public class MainApp extends Application {
private static Logger log = LoggerFactory.getLogger(MainApp.class);
public static final String PREFS_NAME = "NightscoutProfile";
private static Bus sBus;
private static MainApp sInstance;
private static NSProfile nsProfile = null;
private static String activeProfile = null;
private static Pump activePump = null;
private static DatabaseHelper databaseHelper = null;
@Override
@ -39,21 +26,6 @@ public class MainApp extends Application {
sBus = new Bus(ThreadEnforcer.ANY);
sInstance = this;
log.debug("Loading stored profile");
SharedPreferences store = getSharedPreferences(PREFS_NAME, 0);
activeProfile = store.getString("activeProfile", null);
String profileString = store.getString("profile", null);
if (profileString != null) {
try {
log.debug("Loaded profile: " + profileString);
log.debug("Loaded active profile: " + activeProfile);
setNSProfile(new NSProfile(new JSONObject(profileString), activeProfile));
} catch (JSONException e) {
}
} else
log.debug("Stored profile not found");
}
public static Bus bus() {
@ -82,27 +54,4 @@ public class MainApp extends Application {
super.onTerminate();
databaseHelper.close();
}
public static NSProfile getNSProfile() {
return nsProfile;
}
public static void setNSProfile(NSProfile profile) {
nsProfile = profile;
}
public static String getActiveProfile() {
return activeProfile;
}
public static void setActiveProfile(String activeprofile) {
activeProfile = activeprofile;
}
public static Pump getActivePump() {
return activePump;
}
public static Pump setActivePump(Pump activepump) {
activePump = activepump;
return activepump;
}
}

View file

@ -23,6 +23,7 @@ import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.Treatment;
@ -30,6 +31,7 @@ import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.client.data.NSProfile;
import info.nightscout.client.data.NSSgv;
@ -133,17 +135,16 @@ public class DataService extends IntentService {
String activeProfile = bundles.getString("activeprofile");
String profile = bundles.getString("profile");
NSProfile nsProfile = new NSProfile(new JSONObject(profile), activeProfile);
MainApp.instance().setNSProfile(nsProfile);
MainApp.instance().setActiveProfile(activeProfile);
storeNSProfile();
if (MainApp.getActivePump() != null) {
MainApp.getActivePump().setNewBasalProfile(MainApp.getNSProfile());
EventNewBasalProfile event = new EventNewBasalProfile(nsProfile);
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
if (pump != null) {
pump.setNewBasalProfile(nsProfile);
} else {
log.error("No active pump selected");
}
if (Config.logIncommingData)
log.debug("Received profile: " + activeProfile + " " + profile);
MainApp.bus().post(new EventNewBasalProfile());
MainApp.bus().post(event);
} catch (JSONException e) {
e.printStackTrace();
}
@ -325,14 +326,6 @@ public class DataService extends IntentService {
}
}
public void storeNSProfile() {
SharedPreferences settings = MainApp.instance().getApplicationContext().getSharedPreferences(MainApp.instance().PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("profile", MainApp.instance().getNSProfile().getData().toString());
editor.putString("activeProfile", MainApp.instance().getActiveProfile());
editor.commit();
}
@Nullable
public static Treatment findById(String _id) {
try {

View file

@ -10,6 +10,7 @@ import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
@ -55,7 +56,7 @@ public class TempBasal {
public IobTotal iobCalc(Date time) {
IobTotal result = new IobTotal();
NSProfile profile = MainApp.getNSProfile();
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null)
return result;

View file

@ -1,8 +1,14 @@
package info.nightscout.androidaps.events;
import info.nightscout.client.data.NSProfile;
/**
* Created by mike on 04.06.2016.
*/
public class EventNewBasalProfile {
// TODO: implement proper GUI update
public NSProfile newNSProfile = null;
public EventNewBasalProfile(NSProfile newProfile) {
newNSProfile = newProfile;
}
}

View file

@ -1,11 +1,13 @@
package info.nightscout.androidaps.plugins;
package info.nightscout.androidaps.interfaces;
import java.util.Date;
import info.nightscout.androidaps.plugins.APSResult;
/**
* Created by mike on 10.06.2016.
*/
public interface APSBase {
public interface APSInterface {
public APSResult getLastAPSResult();
public Date getLastAPSRun();

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins;
package info.nightscout.androidaps.interfaces;
import java.util.Date;

View file

@ -0,0 +1,13 @@
package info.nightscout.androidaps.interfaces;
import android.support.annotation.Nullable;
import info.nightscout.client.data.NSProfile;
/**
* Created by mike on 14.06.2016.
*/
public interface ProfileInterface {
@Nullable
NSProfile getProfile();
}

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins;
package info.nightscout.androidaps.interfaces;
import org.json.JSONObject;
@ -8,7 +8,7 @@ import info.nightscout.client.data.NSProfile;
/**
* Created by mike on 04.06.2016.
*/
public interface Pump {
public interface PumpInterface {
boolean isTempBasalInProgress();
boolean isExtendedBoluslInProgress();
@ -30,5 +30,6 @@ public interface Pump {
Result cancelTempBasal();
Result cancelExtendedBolus();
// Status to be passed to NS
JSONObject getJSONStatus();
}

View file

@ -0,0 +1,11 @@
package info.nightscout.androidaps.interfaces;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
/**
* Created by mike on 14.06.2016.
*/
public interface TempBasalsInterface {
void updateTotalIOBIfNeeded();
IobTotal getLastCalculation();
}

View file

@ -0,0 +1,13 @@
package info.nightscout.androidaps.interfaces;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
/**
* Created by mike on 14.06.2016.
*/
public interface TreatmentsInterface {
void updateTotalIOBIfNeeded();
IobTotal getLastCalculation();
TreatmentsFragment.MealData getMealData();
}

View file

@ -2,7 +2,9 @@ package info.nightscout.androidaps.plugins.ConfigBuilder;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
@ -14,23 +16,37 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Result;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.plugins.PluginBase;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.client.data.NSProfile;
/**
* A simple {@link Fragment} subclass.
*/
public class ConfigBuilderFragment extends Fragment implements PluginBase {
public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpInterface {
private static Logger log = LoggerFactory.getLogger(ConfigBuilderFragment.class);
private static final String PREFS_NAME = "Settings";
ListView pumpListView;
ListView treatmentsListView;
ListView tempsListView;
@ -46,6 +62,37 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase {
PluginCustomAdapter generalDataAdapter = null;
PumpInterface activePump;
ProfileInterface activeProfile;
TreatmentsInterface activeTreatments;
TempBasalsInterface activeTempBasals;
ArrayList<PluginBase> pluginList;
public ConfigBuilderFragment() {
super();
registerBus();
}
public void initialize() {
pluginList = MainActivity.getPluginsList();
loadSettings();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
private void registerBus() {
try {
MainApp.bus().unregister(this);
} catch (RuntimeException x) {
// Ignore
}
MainApp.bus().register(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -57,19 +104,22 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase {
apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview);
generalListView = (ListView) view.findViewById(R.id.configbuilder_generallistview);
//Array list of countries
ArrayList<PluginBase> pluginList = MainActivity.getPageAdapter().getPluginsList();
pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getPageAdapter().getSpecificPluginsList(PluginBase.PUMP));
setViews();
return view;
}
void setViews() {
pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.PUMP));
pumpListView.setAdapter(pumpDataAdapter);
treatmentsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getPageAdapter().getSpecificPluginsList(PluginBase.TREATMENT));
treatmentsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.TREATMENT));
treatmentsListView.setAdapter(treatmentsDataAdapter);
tempsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getPageAdapter().getSpecificPluginsList(PluginBase.TEMPBASAL));
tempsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.TEMPBASAL));
tempsListView.setAdapter(tempsDataAdapter);
profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getPageAdapter().getSpecificPluginsList(PluginBase.PROFILE));
profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.PROFILE));
profileListView.setAdapter(profileDataAdapter);
apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getPageAdapter().getSpecificPluginsList(PluginBase.APS));
apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.APS));
apsListView.setAdapter(apsDataAdapter);
generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getPageAdapter().getSpecificPluginsList(PluginBase.GENERAL));
generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.GENERAL));
generalListView.setAdapter(generalDataAdapter);
@ -83,10 +133,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase {
Toast.LENGTH_LONG).show();
}
});
return view;
}
/*
* PluginBase interface
*/
@Override
public int getType() {
return PluginBase.GENERAL;
@ -127,6 +178,100 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase {
return fragment;
}
/*
* Pump interface
*
* Config builder return itself as a pump and check constrains before it passes command to pump driver
*/
@Nullable
public PumpInterface getActivePump() {
return this;
}
@Override
public boolean isTempBasalInProgress() {
return activePump.isTempBasalInProgress();
}
@Override
public boolean isExtendedBoluslInProgress() {
return activePump.isExtendedBoluslInProgress();
}
@Override
public Integer getBatteryPercent() {
return activePump.getBatteryPercent();
}
@Override
public Integer getReservoirValue() {
return activePump.getReservoirValue();
}
@Override
public void setNewBasalProfile(NSProfile profile) {
activePump.setNewBasalProfile(profile);
}
@Override
public double getBaseBasalRate() {
return activePump.getBaseBasalRate();
}
@Override
public double getTempBasalAbsoluteRate() {
return activePump.getTempBasalAbsoluteRate();
}
@Override
public double getTempBasalRemainingMinutes() {
return activePump.getTempBasalRemainingMinutes();
}
@Override
public Result deliverTreatment(Double insulin, Double carbs) {
// TODO: constrains here
return activePump.deliverTreatment(insulin, carbs);
}
@Override
public Result setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
// TODO: constrains here
return activePump.setTempBasalAbsolute(absoluteRate, durationInMinutes);
}
@Override
public Result setTempBasalPercent(Integer percent, Integer durationInMinutes) {
// TODO: constrains here
return activePump.setTempBasalPercent(percent, durationInMinutes);
}
@Override
public Result setExtendedBolus(Double insulin, Integer durationInMinutes) {
// TODO: constrains here
return activePump.setExtendedBolus(insulin, durationInMinutes);
}
@Override
public Result cancelTempBasal() {
return activePump.cancelTempBasal();
}
@Override
public Result cancelExtendedBolus() {
return activePump.cancelExtendedBolus();
}
@Override
public JSONObject getJSONStatus() {
return activePump.getJSONStatus();
}
/*
* ConfigBuilderFragment code
*/
private class PluginCustomAdapter extends ArrayAdapter<PluginBase> {
private ArrayList<PluginBase> pluginList;
@ -167,6 +312,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase {
" is " + cb.isChecked(),
Toast.LENGTH_LONG).show();
plugin.setFragmentEnabled(cb.isChecked());
onEnabledCategoryChanged(plugin);
}
});
@ -180,6 +326,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase {
Toast.LENGTH_LONG).show();
plugin.setFragmentVisible(cb.isChecked());
MainApp.bus().post(new EventRefreshGui());
storeSettings();
}
});
} else {
@ -199,12 +346,139 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase {
holder.checkboxVisible.setEnabled(false);
}
int type = plugin.getType();
if (type == PluginBase.PUMP || type == PluginBase.TREATMENT || type == PluginBase.TEMPBASAL || type == PluginBase.PROFILE)
if (pluginList.size() < 2)
holder.checkboxEnabled.setEnabled(false);
return convertView;
}
}
private void displayListView() {
@Nullable
public ProfileInterface getActiveProfile() {
return activeProfile;
}
@Nullable
public TreatmentsInterface getActiveTreatments() {
return activeTreatments;
}
@Nullable
public TempBasalsInterface getActiveTempBasals() {
return activeTempBasals;
}
void onEnabledCategoryChanged(PluginBase changedPlugin) {
int category = changedPlugin.getType();
ArrayList<PluginBase> pluginsInCategory = MainActivity.getSpecificPluginsList(category);
switch (category) {
// Multiple selection allowed
case PluginBase.APS:
case PluginBase.GENERAL:
break;
// Single selection allowed
case PluginBase.PROFILE:
case PluginBase.PUMP:
case PluginBase.TEMPBASAL:
case PluginBase.TREATMENT:
boolean newSelection = changedPlugin.isEnabled();
if (newSelection) { // new plugin selected -> disable others
for (PluginBase p : pluginsInCategory) {
if (p.getName().equals(changedPlugin.getName())) {
// this is new selected
} else {
p.setFragmentEnabled(false);
setViews();
}
}
} else { // enable first plugin in list
pluginsInCategory.get(0).setFragmentEnabled(true);
}
break;
}
storeSettings();
}
private void verifySelectionInCategories() {
for (int category : new int[]{PluginBase.GENERAL, PluginBase.APS, PluginBase.PROFILE, PluginBase.PUMP, PluginBase.TEMPBASAL, PluginBase.TREATMENT}) {
ArrayList<PluginBase> pluginsInCategory = MainActivity.getSpecificPluginsList(category);
switch (category) {
// Multiple selection allowed
case PluginBase.APS:
case PluginBase.GENERAL:
break;
// Single selection allowed
case PluginBase.PROFILE:
activeProfile = (ProfileInterface) getTheOneEnabledInArray(pluginsInCategory);
if (Config.logConfigBuilder)
log.debug("Selected profile interface: " + ((PluginBase) activeProfile).getName());
break;
case PluginBase.PUMP:
activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory);
if (Config.logConfigBuilder)
log.debug("Selected pump interface: " + ((PluginBase) activePump).getName());
break;
case PluginBase.TEMPBASAL:
activeTempBasals = (TempBasalsInterface) getTheOneEnabledInArray(pluginsInCategory);
if (Config.logConfigBuilder)
log.debug("Selected tempbasal interface: " + ((PluginBase) activeTempBasals).getName());
break;
case PluginBase.TREATMENT:
activeTreatments = (TreatmentsInterface) getTheOneEnabledInArray(pluginsInCategory);
if (Config.logConfigBuilder)
log.debug("Selected treatment interface: " + ((PluginBase) activeTreatments).getName());
break;
}
}
}
private PluginBase getTheOneEnabledInArray(ArrayList<PluginBase> pluginsInCategory) {
PluginBase found = null;
for (PluginBase p : pluginsInCategory) {
if (p.isEnabled() && found == null) {
found = p;
continue;
} else if (p.isEnabled()) {
// set others disabled
p.setFragmentEnabled(false);
}
}
// If none enabled, enable first one
if (found == null)
found = pluginsInCategory.get(0);
return found;
}
private void storeSettings() {
if (Config.logPrefsChange)
log.debug("Storing settings");
SharedPreferences settings = MainApp.instance().getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
for (PluginBase p : pluginList) {
editor.putBoolean(p.getName() + "Enabled", p.isEnabled());
editor.putBoolean(p.getName() + "Visible", p.isVisibleInTabs());
}
editor.commit();
verifySelectionInCategories();
}
private void loadSettings() {
if (Config.logPrefsChange)
log.debug("Loading stored settings");
SharedPreferences settings = MainApp.instance().getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
for (PluginBase p : pluginList) {
if (settings.contains(p.getName() + "Enabled"))
p.setFragmentEnabled(settings.getBoolean(p.getName() + "Enabled", true));
if (settings.contains(p.getName() + "Visible"))
p.setFragmentVisible(settings.getBoolean(p.getName() + "Visible", true));
}
verifySelectionInCategories();
}
}

View file

@ -21,17 +21,18 @@ import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Pump;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.plugins.APSBase;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.plugins.APSResult;
import info.nightscout.androidaps.plugins.PluginBase;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.client.data.NSProfile;
public class LowSuspendFragment extends Fragment implements View.OnClickListener, PluginBase, APSBase {
public class LowSuspendFragment extends Fragment implements View.OnClickListener, PluginBase, APSInterface {
private static Logger log = LoggerFactory.getLogger(LowSuspendFragment.class);
Button run;
@ -47,6 +48,11 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener
boolean fragmentEnabled = false;
boolean fragmentVisible = true;
public LowSuspendFragment() {
super();
registerBus();
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.lowsuspend);
@ -100,7 +106,6 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerBus();
}
@Override
@ -157,8 +162,8 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
DecimalFormat formatNumber1decimalplaces = new DecimalFormat("0.0");
NSProfile profile = MainApp.getNSProfile();
Pump pump = MainApp.getActivePump();
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
if (glucoseStatus == null) {
resultView.setText(getString(R.string.openapsma_noglucosedata));
@ -179,7 +184,7 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener
}
String minBgDefault = "90";
if (!MainApp.getNSProfile().getUnits().equals(Constants.MGDL)) {
if (!profile.getUnits().equals(Constants.MGDL)) {
minBgDefault = "5";
}

View file

@ -1,7 +1,9 @@
package info.nightscout.androidaps.plugins.ProfileViewer;
package info.nightscout.androidaps.plugins.NSProfileViewer;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
@ -10,19 +12,23 @@ import android.widget.TextView;
import com.squareup.otto.Subscribe;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.plugins.PluginBase;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.client.data.NSProfile;
public class ProfileViewerFragment extends Fragment implements PluginBase {
private static Logger log = LoggerFactory.getLogger(ProfileViewerFragment.class);
public class NSProfileViewerFragment extends Fragment implements PluginBase, ProfileInterface {
private static Logger log = LoggerFactory.getLogger(NSProfileViewerFragment.class);
private static TextView noProfile;
private static TextView units;
@ -33,11 +39,20 @@ public class ProfileViewerFragment extends Fragment implements PluginBase {
private static TextView basal;
private static TextView target;
private static final String PREFS_NAME = "NightscoutProfile";
private static DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
boolean fragmentEnabled = true;
boolean fragmentVisible = true;
NSProfile profile = null;
public NSProfileViewerFragment () {
super();
loadNSProfile();
registerBus();
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.profileviewer);
@ -73,21 +88,15 @@ public class ProfileViewerFragment extends Fragment implements PluginBase {
return PluginBase.PROFILE;
}
public static ProfileViewerFragment newInstance(String param1, String param2) {
ProfileViewerFragment fragment = new ProfileViewerFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerBus();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.profileviewer_fragment, container, false);
View layout = inflater.inflate(R.layout.nsprofileviewer_fragment, container, false);
noProfile = (TextView) layout.findViewById(R.id.profileview_noprofile);
units = (TextView) layout.findViewById(R.id.profileview_units);
@ -102,13 +111,12 @@ public class ProfileViewerFragment extends Fragment implements PluginBase {
return layout;
}
public static ProfileViewerFragment newInstance() {
ProfileViewerFragment fragment = new ProfileViewerFragment();
public static NSProfileViewerFragment newInstance() {
NSProfileViewerFragment fragment = new NSProfileViewerFragment();
return fragment;
}
private void setContent() {
NSProfile profile = MainApp.getNSProfile();
if (profile == null) {
noProfile.setVisibility(View.VISIBLE);
return;
@ -135,6 +143,8 @@ public class ProfileViewerFragment extends Fragment implements PluginBase {
@Subscribe
public void onStatusEvent(final EventNewBasalProfile ev) {
profile = new NSProfile(ev.newNSProfile.getData(), ev.newNSProfile.getActiveProfile());
storeNSProfile();
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@ -146,4 +156,44 @@ public class ProfileViewerFragment extends Fragment implements PluginBase {
else
log.debug("EventNewBG: Activity is null");
}
private void storeNSProfile() {
SharedPreferences settings = MainApp.instance().getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("profile", profile.getData().toString());
editor.putString("activeProfile", profile.getActiveProfile());
editor.commit();
if (Config.logPrefsChange)
log.debug("Storing profile");
}
private void loadNSProfile() {
if (Config.logPrefsChange)
log.debug("Loading stored profile");
SharedPreferences store = MainApp.instance().getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
String activeProfile = store.getString("activeProfile", null);
String profileString = store.getString("profile", null);
if (profileString != null) {
if (Config.logPrefsChange) {
log.debug("Loaded profile: " + profileString);
log.debug("Loaded active profile: " + activeProfile);
try {
profile = new NSProfile(new JSONObject(profileString), activeProfile);
} catch (JSONException e) {
e.printStackTrace();
profile = null;
}
}
} else {
if (Config.logPrefsChange) {
log.debug("Stored profile not found");
}
}
}
@Nullable
@Override
public NSProfile getProfile() {
return profile;
}
}

View file

@ -16,7 +16,7 @@ import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PluginBase;
import info.nightscout.androidaps.interfaces.PluginBase;
public class ObjectivesFragment extends Fragment implements PluginBase {
RecyclerView recyclerView;

View file

@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.Pump;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.plugins.ScriptReader;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
@ -204,7 +204,7 @@ public class DetermineBasalAdapterJS {
double maxBasal,
double minBg,
double maxBg,
Pump pump,
PumpInterface pump,
IobTotal iobData,
DatabaseHelper.GlucoseStatus glucoseStatus,
TreatmentsFragment.MealData mealData) {

View file

@ -25,19 +25,22 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Pump;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.plugins.APSBase;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.APSResult;
import info.nightscout.androidaps.plugins.PluginBase;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.ScriptReader;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil;
public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, PluginBase, APSBase {
public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, PluginBase, APSInterface {
private static Logger log = LoggerFactory.getLogger(OpenAPSMAFragment.class);
Button run;
@ -56,6 +59,11 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
boolean fragmentEnabled = false;
boolean fragmentVisible = true;
public OpenAPSMAFragment() {
super();
registerBus();
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.openapsma);
@ -109,7 +117,6 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerBus();
}
@Override
@ -189,8 +196,8 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
}
DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
NSProfile profile = MainApp.getNSProfile();
Pump pump = MainApp.getActivePump();
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
if (glucoseStatus == null) {
resultView.setText(getString(R.string.openapsma_noglucosedata));
@ -227,14 +234,16 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
double minBg = NSProfile.toMgdl(Double.parseDouble(SP.getString("min_bg", minBgDefault).replace(",", ".")), units);
double maxBg = NSProfile.toMgdl(Double.parseDouble(SP.getString("max_bg", maxBgDefault).replace(",", ".")), units);
MainActivity.treatmentsFragment.updateTotalIOBIfNeeded();
MainActivity.tempBasalsFragment.updateTotalIOBIfNeeded();
IobTotal bolusIob = MainActivity.treatmentsFragment.lastCalculation;
IobTotal basalIob = MainActivity.tempBasalsFragment.lastCalculation;
TreatmentsInterface treatments = MainActivity.getConfigBuilder().getActiveTreatments();
TempBasalsInterface tempBasals = MainActivity.getConfigBuilder().getActiveTempBasals();
treatments.updateTotalIOBIfNeeded();
tempBasals.updateTotalIOBIfNeeded();
IobTotal bolusIob = treatments.getLastCalculation();
IobTotal basalIob = tempBasals.getLastCalculation();
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob);
TreatmentsFragment.MealData mealData = MainActivity.treatmentsFragment.getMealData();
TreatmentsFragment.MealData mealData = treatments.getMealData();
determineBasalAdapterJS.setData(profile, maxIob, maxBasal, minBg, maxBg, pump, iobTotal, glucoseStatus, mealData);

View file

@ -26,13 +26,14 @@ import java.util.Iterator;
import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.plugins.PluginBase;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.client.data.NSProfile;
@ -44,6 +45,11 @@ public class OverviewFragment extends Fragment implements PluginBase {
TextView deltaView;
GraphView bgGraph;
public OverviewFragment() {
super();
registerBus();
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.overview);
@ -87,7 +93,6 @@ public class OverviewFragment extends Fragment implements PluginBase {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerBus();
}
@Override
@ -112,10 +117,12 @@ public class OverviewFragment extends Fragment implements PluginBase {
MainApp.bus().register(this);
}
private void updateData() {
public void updateData() {
BgReading actualBG = MainApp.getDbHelper().actualBg();
BgReading lastBG = MainApp.getDbHelper().lastBg();
NSProfile profile = MainApp.getNSProfile();
if (MainActivity.getConfigBuilder() == null || MainActivity.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
return;
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null)
return;

View file

@ -0,0 +1,96 @@
package info.nightscout.androidaps.plugins.SimpleProfile;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.client.data.NSProfile;
public class SimpleProfileFragment extends Fragment implements PluginBase, ProfileInterface {
private static Logger log = LoggerFactory.getLogger(SimpleProfileFragment.class);
boolean fragmentEnabled = true;
boolean fragmentVisible = true;
public SimpleProfileFragment() {
super();
registerBus();
}
@Override
public int getType() {
return PluginBase.PROFILE;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.simpleprofile);
}
@Override
public boolean isEnabled() {
return fragmentEnabled;
}
@Override
public boolean isVisibleInTabs() {
return fragmentVisible;
}
@Override
public boolean canBeHidden() {
return true;
}
@Override
public void setFragmentEnabled(boolean fragmentEnabled) {
this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(boolean fragmentVisible) {
this.fragmentVisible = fragmentVisible;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.simpleprofile_fragment, container, false);
return layout;
}
public static SimpleProfileFragment newInstance() {
SimpleProfileFragment fragment = new SimpleProfileFragment();
return fragment;
}
private void registerBus() {
try {
MainApp.bus().unregister(this);
} catch (RuntimeException x) {
// Ignore
}
MainApp.bus().register(this);
}
@Override
public NSProfile getProfile() {
return null;
}
}

View file

@ -32,11 +32,12 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.PluginBase;
import info.nightscout.androidaps.interfaces.PluginBase;
public class TempBasalsFragment extends Fragment implements PluginBase {
public class TempBasalsFragment extends Fragment implements PluginBase, TempBasalsInterface {
private static Logger log = LoggerFactory.getLogger(TempBasalsFragment.class);
RecyclerView recyclerView;
@ -118,7 +119,6 @@ public class TempBasalsFragment extends Fragment implements PluginBase {
if (recyclerView != null) {
recyclerView.swapAdapter(new RecyclerViewAdapter(tempBasals), false);
}
updateTotalIOB();
}
/*
@ -130,6 +130,11 @@ public class TempBasalsFragment extends Fragment implements PluginBase {
updateTotalIOB();
}
@Override
public IobTotal getLastCalculation() {
return lastCalculation;
}
private void updateTotalIOB() {
Date now = new Date();
IobTotal total = new IobTotal();
@ -223,6 +228,7 @@ public class TempBasalsFragment extends Fragment implements PluginBase {
public TempBasalsFragment() {
super();
registerBus();
initializeData();
}
@ -234,7 +240,6 @@ public class TempBasalsFragment extends Fragment implements PluginBase {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerBus();
}
@Override

View file

@ -10,31 +10,16 @@ import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
public class NewTreatmentDialogFragment extends DialogFragment implements OnClickListener {
Button deliverButton;
Communicator communicator;
TextView insulin;
TextView carbs;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof Communicator) {
communicator = (Communicator) getActivity();
} else {
throw new ClassCastException(activity.toString()
+ " must implemenet NewTreatmentDialogFragment.Communicator");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -70,15 +55,11 @@ public class NewTreatmentDialogFragment extends DialogFragment implements OnClic
this.carbs.setText("");
} else if (insulin > 0d || carbs > 0d) {
dismiss();
communicator.treatmentDeliverRequest(insulin, carbs);
MainActivity.getConfigBuilder().getActivePump().deliverTreatment(insulin, carbs);
}
break;
}
}
public interface Communicator {
void treatmentDeliverRequest(Double insulin, Double carbs);
}
}

View file

@ -24,6 +24,8 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.client.data.NSProfile;
@ -32,7 +34,6 @@ import info.nightscout.utils.*;
public class WizardDialogFragment extends DialogFragment implements OnClickListener {
Button wizardDialogDeliverButton;
Communicator communicator;
TextView correctionInput;
TextView carbsInput;
TextView bgInput;
@ -70,21 +71,6 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
}
};
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof Communicator) {
communicator = (Communicator) getActivity();
} else {
throw new ClassCastException(activity.toString()
+ " must implemenet WizardDialogFragment.Communicator");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -129,7 +115,7 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
case R.id.treatments_wizard_deliverButton:
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d){
dismiss();
communicator.treatmentDialogDeliver(calculatedTotalInsulin, calculatedCarbs);
MainActivity.getConfigBuilder().getActivePump().deliverTreatment(calculatedTotalInsulin, calculatedCarbs);
}
break;
}
@ -139,8 +125,9 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
private void initDialog() {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
String units = SP.getString("ns_units", Constants.MGDL);
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
if (MainApp.getNSProfile() == null) {
if (profile == null) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), "No profile loaded from NS yet");
dismiss();
return;
@ -153,9 +140,9 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
Double lastBgValue = lastBg.valueToUnits(units);
if (lastBg != null) {
Double sens = MainApp.getNSProfile().getIsf(MainApp.getNSProfile().secondsFromMidnight());
Double targetBGLow = MainApp.getNSProfile().getTargetLow(MainApp.getNSProfile().secondsFromMidnight());
Double targetBGHigh = MainApp.getNSProfile().getTargetHigh(MainApp.getNSProfile().secondsFromMidnight());
Double sens = profile.getIsf(NSProfile.secondsFromMidnight());
Double targetBGLow = profile.getTargetLow(NSProfile.secondsFromMidnight());
Double targetBGHigh = profile.getTargetHigh(NSProfile.secondsFromMidnight());
Double bgDiff;
if (lastBgValue <= targetBGLow) {
bgDiff = lastBgValue - targetBGLow;
@ -173,11 +160,13 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
}
// IOB calculation
MainActivity.treatmentsFragment.updateTotalIOBIfNeeded();
MainActivity.tempBasalsFragment.updateTotalIOBIfNeeded();
TreatmentsInterface treatments = MainActivity.getConfigBuilder().getActiveTreatments();
TempBasalsInterface tempBasals = MainActivity.getConfigBuilder().getActiveTempBasals();
treatments.updateTotalIOBIfNeeded();
tempBasals.updateTotalIOBIfNeeded();
IobTotal bolusIob = treatments.getLastCalculation();
IobTotal basalIob = tempBasals.getLastCalculation();
IobTotal bolusIob = MainActivity.treatmentsFragment.lastCalculation;
IobTotal basalIob = MainActivity.tempBasalsFragment.lastCalculation;
Double iobTotal = bolusIob.iob + basalIob.iob;
iobInsulin.setText("-" + numberFormat.format(iobTotal) + "U");
@ -192,7 +181,7 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
Double maxcarbs = Double.parseDouble(SP.getString("safety_maxcarbs", "48"));
String units = SP.getString("ns_units", Constants.MGDL);
NSProfile profile = MainApp.instance().getNSProfile();
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
// Entered values
String i_bg = this.bgInput.getText().toString().replace("," , ".");
@ -218,9 +207,9 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
// Insulin from BG
Double sens = profile.getIsf(MainApp.getNSProfile().secondsFromMidnight());
Double targetBGLow = profile.getTargetLow(MainApp.getNSProfile().secondsFromMidnight());
Double targetBGHigh = profile.getTargetHigh(MainApp.getNSProfile().secondsFromMidnight());
Double sens = profile.getIsf(NSProfile.secondsFromMidnight());
Double targetBGLow = profile.getTargetLow(NSProfile.secondsFromMidnight());
Double targetBGHigh = profile.getTargetHigh(NSProfile.secondsFromMidnight());
Double bgDiff;
if (c_bg <= targetBGLow) {
bgDiff = c_bg - targetBGLow;
@ -232,17 +221,19 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
bgInsulin.setText(numberFormat.format(insulinFromBG) + "U");
// Insuling from carbs
Double ic = profile.getIc(MainApp.getNSProfile().secondsFromMidnight());
Double ic = profile.getIc(NSProfile.secondsFromMidnight());
Double insulinFromCarbs = c_carbs / ic;
carbs.setText(intFormat.format(c_carbs) + "g IC: " + intFormat.format(ic));
carbsInsulin.setText(numberFormat.format(insulinFromCarbs) + "U");
// Insulin from IOB
MainActivity.treatmentsFragment.updateTotalIOBIfNeeded();
MainActivity.tempBasalsFragment.updateTotalIOBIfNeeded();
TreatmentsInterface treatments = MainActivity.getConfigBuilder().getActiveTreatments();
TempBasalsInterface tempBasals = MainActivity.getConfigBuilder().getActiveTempBasals();
treatments.updateTotalIOBIfNeeded();
tempBasals.updateTotalIOBIfNeeded();
IobTotal bolusIob = treatments.getLastCalculation();
IobTotal basalIob = tempBasals.getLastCalculation();
IobTotal bolusIob = MainActivity.treatmentsFragment.lastCalculation;
IobTotal basalIob = MainActivity.tempBasalsFragment.lastCalculation;
Double iobTotal = bolusIob.iob + basalIob.iob;
Double insulingFromIOB = iobCheckbox.isChecked() ? iobTotal : 0d;
iobInsulin.setText("-" + numberFormat.format(insulingFromIOB) + "U");
@ -288,9 +279,4 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
}
return 0d;
}
public interface Communicator {
void treatmentDialogDeliver(Double insulin, Double carbs);
}
}

View file

@ -31,19 +31,20 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.PluginBase;
import info.nightscout.androidaps.plugins.Treatments.Dialogs.NewTreatmentDialogFragment;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.client.data.NSProfile;
public class TreatmentsFragment extends Fragment implements View.OnClickListener, NewTreatmentDialogFragment.Communicator, PluginBase {
public class TreatmentsFragment extends Fragment implements View.OnClickListener, PluginBase, TreatmentsInterface {
private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class);
RecyclerView recyclerView;
@ -53,8 +54,8 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
TextView activityTotal;
Button refreshFromNS;
public long lastCalculationTimestamp = 0;
public IobTotal lastCalculation;
private long lastCalculationTimestamp = 0;
private IobTotal lastCalculation;
private static DecimalFormat formatNumber0decimalplaces = new DecimalFormat("0");
private static DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
@ -115,22 +116,29 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
if (recyclerView != null) {
recyclerView.swapAdapter(new RecyclerViewAdapter(treatments), false);
}
updateTotalIOB();
}
/*
* Recalculate IOB if value is older than 1 minute
*/
@Override
public void updateTotalIOBIfNeeded() {
if (lastCalculationTimestamp > new Date().getTime() - 60 * 1000)
return;
updateTotalIOB();
}
@Override
public IobTotal getLastCalculation() {
return lastCalculation;
}
private void updateTotalIOB() {
IobTotal total = new IobTotal();
NSProfile profile = MainApp.getNSProfile();
if (MainActivity.getConfigBuilder() == null || MainActivity.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
return;
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null) {
lastCalculation = total;
return;
@ -161,9 +169,10 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
public double carbs = 0d;
}
@Override
public MealData getMealData() {
MealData result = new MealData();
NSProfile profile = MainApp.getNSProfile();
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null)
return result;
@ -200,7 +209,9 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
@Override
public void onBindViewHolder(TreatmentsViewHolder holder, int position) {
NSProfile profile = MainApp.getNSProfile();
if (MainActivity.getConfigBuilder() == null || MainActivity.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
return;
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null)
return;
// TODO: implement locales
@ -245,6 +256,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
public TreatmentsFragment() {
super();
registerBus();
initializeData();
}
@ -256,7 +268,6 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerBus();
}
@Override
@ -348,10 +359,4 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
if (isVisibleToUser)
updateTotalIOBIfNeeded();
}
@Override
public void treatmentDeliverRequest(Double insulin, Double carbs) {
// TODO: implement treatment delivery
}
}

View file

@ -20,17 +20,18 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Pump;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.data.Result;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.plugins.PluginBase;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil;
public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInterface {
private static Logger log = LoggerFactory.getLogger(VirtualPumpFragment.class);
Double defaultBasalValue = 0.2d;
@ -102,7 +103,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
extendedBolusView = (TextView) view.findViewById(R.id.virtualpump_extendedbolus);
batteryView = (TextView) view.findViewById(R.id.virtualpump_battery);
reservoirView = (TextView) view.findViewById(R.id.virtualpump_reservoir);
updateView();
return view;
}
@ -137,6 +138,14 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
reservoirView.setText(getReservoirValue() + "U");
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser)
updateView();
}
void checkForExpiredTempsAndExtended() {
long now = new Date().getTime();
if (isTempBasalInProgress()) {
@ -193,12 +202,12 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
@Override
public void setNewBasalProfile(NSProfile profile) {
// Do nothing here. we are using MainApp.getNSProfile();
// Do nothing here. we are using MainActivity.getConfigBuilder().getActiveProfile().getProfile();
}
@Override
public double getBaseBasalRate() {
NSProfile profile = MainApp.getNSProfile();
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null)
return defaultBasalValue;
return profile.getBasal(profile.secondsFromMidnight());
@ -211,7 +220,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
if (tempBasal.isAbsolute) {
return tempBasal.absolute;
} else {
NSProfile profile = MainApp.getNSProfile();
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null)
return defaultBasalValue;
Double baseRate = profile.getBasal(profile.secondsFromMidnight());
@ -247,6 +256,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
}
if (Config.logPumpComm)
log.debug("Delivering treatment: " + t + " " + result);
updateView();
return result;
}
@ -272,6 +282,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
}
if (Config.logPumpComm)
log.debug("Setting temp basal absolute: " + result);
updateView();
return result;
}
@ -297,6 +308,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
}
if (Config.logPumpComm)
log.debug("Settings temp basal percent: " + result);
updateView();
return result;
}
@ -322,6 +334,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
}
if (Config.logPumpComm)
log.debug("Setting extended bolus: " + result);
updateView();
return result;
}
@ -344,6 +357,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
tempBasal = null;
if (Config.logPumpComm)
log.debug("Canceling temp basal: " + result);
updateView();
return result;
}
@ -366,6 +380,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
extendedBolus = null;
if (Config.logPumpComm)
log.debug("Canceling extended basal: " + result);
updateView();
return result;
}

View file

@ -8,7 +8,7 @@ import android.support.v4.app.FragmentStatePagerAdapter;
import java.util.ArrayList;
import java.util.Iterator;
import info.nightscout.androidaps.plugins.PluginBase;
import info.nightscout.androidaps.interfaces.PluginBase;
/**
* Created by mike on 30.05.2016.
@ -50,20 +50,4 @@ public class TabPageAdapter extends FragmentStatePagerAdapter {
notifyDataSetChanged();
}
}
public ArrayList<PluginBase> getPluginsList() {
return fragmentList;
}
public ArrayList<PluginBase> getSpecificPluginsList(int type) {
ArrayList<PluginBase> newList = new ArrayList<PluginBase>();
Iterator<PluginBase> it = fragmentList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getType() == type)
newList.add(p);
}
return newList;
}
}

View file

@ -167,7 +167,7 @@ public class NSProfile {
JSONObject profile = getDefaultProfile();
if (profile != null) {
try {
return getValuesList(profile.getJSONArray("sens"), null, new DecimalFormat("0"), getUnits() + "/U");
return getValuesList(profile.getJSONArray("sens"), null, new DecimalFormat("0.0"), getUnits() + "/U");
} catch (JSONException e) {
e.printStackTrace();
}

View file

@ -4,8 +4,6 @@
android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -22,8 +20,8 @@
android:id="@+id/configbuilder_pumplistview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/cardColorBackground" />
<TextView

View file

@ -4,6 +4,10 @@
android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.plugins.LowSuspend.LowSuspendFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -123,5 +127,5 @@
</LinearLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>

View file

@ -2,7 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".plugins.ProfileViewer.ProfileViewerFragment">
tools:context=".plugins.NSProfileViewer.NSProfileViewerFragment">
<ScrollView
android:layout_width="match_parent"
@ -17,7 +17,7 @@
android:id="@+id/profileview_noprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/profileview_noprofile_text"
android:text="@string/nsprofileview_noprofile_text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_light"
android:textStyle="bold"
@ -26,7 +26,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/profileview_activeprofile_label"
android:text="@string/nsprofileview_activeprofile_label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="10dp" />
@ -39,7 +39,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/profileview_units_label"
android:text="@string/nsprofileview_units_label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="10dp" />
@ -52,7 +52,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/profileview_dia_label"
android:text="@string/nsprofileview_dia_label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="10dp" />
@ -65,7 +65,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/profileview_ic_label"
android:text="@string/nsprofileview_ic_label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="10dp" />
@ -78,7 +78,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/profileview_isf_label"
android:text="@string/nsprofileview_isf_label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="10dp" />
@ -91,7 +91,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/profileview_basal_label"
android:text="@string/nsprofileview_basal_label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="10dp" />
@ -104,7 +104,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/profileview_target_label"
android:text="@string/nsprofileview_target_label"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="10dp" />

View file

@ -0,0 +1,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".plugins.SimpleProfile.SimpleProfileFragment">
</FrameLayout>

View file

@ -25,13 +25,14 @@
<string name="objectives_gate_label_string">Gate:</string>
<string name="objectives_button_start">Start</string>
<string name="objectives_button_verify">Verify</string>
<string name="profileview_dia_label">DIA:</string>
<string name="profileview_activeprofile_label">Active profile:</string>
<string name="profileview_ic_label">IC:</string>
<string name="profileview_isf_label">ISF:</string>
<string name="profileview_basal_label">Basal:</string>
<string name="profileview_target_label">Target:</string>
<string name="profileview_noprofile_text">NO PROFILE SET</string>
<string name="nsprofileview_units_label">Units:</string>
<string name="nsprofileview_dia_label">DIA:</string>
<string name="nsprofileview_activeprofile_label">Active profile:</string>
<string name="nsprofileview_ic_label">IC:</string>
<string name="nsprofileview_isf_label">ISF:</string>
<string name="nsprofileview_basal_label">Basal:</string>
<string name="nsprofileview_target_label">Target:</string>
<string name="nsprofileview_noprofile_text">NO PROFILE SET</string>
<string name="treatments_insulin_label_string">Insulin:</string>
<string name="treatments_carbs_label_string">Carbs:</string>
<string name="treatments_iob_label_string">IOB:</string>
@ -51,7 +52,6 @@
<string name="treatments_wizard_unit_label">U</string>
<string name="treatments_wizard_iob_label">IOB</string>
<string name="treatments_wizard_total_label">TOTAL</string>
<string name="profileview_units_label">Units:</string>
<string name="openapsma_run">Run now</string>
<string name="vitualpump_label">VIRTUAL PUMP</string>
<string name="virtualpump_basebasalrate_label">Base basal rate:</string>
@ -93,10 +93,12 @@
<string name="objectives">Objectives</string>
<string name="openapsma">OpenAPS MA</string>
<string name="overview">Overview</string>
<string name="profileviewer">Profile Viewer</string>
<string name="profileviewer">NS Profile</string>
<string name="simpleprofile">Simple profile</string>
<string name="tempbasals">Temp Basals</string>
<string name="treatments">Treatments</string>
<string name="virtualpump">Virtual Pump</string>
<string name="configbuilder_pump">Pump</string>
<string name="configbuilder_treatments">Treatments</string>
<string name="configbuilder_tempbasals">Temp Basals</string>