diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index 096a936fe8..a9538c7572 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -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; } diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index 5aae374ccb..98779179f6 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -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 pluginsList = new ArrayList(); + private static ArrayList pluginsList = new ArrayList(); - 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,15 +81,15 @@ 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); mTabs = (SlidingTabLayout) findViewById(R.id.tabs); mTabs.setViewPager(mPager); if (switchToLast) - mPager.setCurrentItem(pageAdapter.getCount()-1, false); + mPager.setCurrentItem(pageAdapter.getCount() - 1, false); } @Override @@ -120,4 +118,20 @@ public class MainActivity extends AppCompatActivity { public static TabPageAdapter getPageAdapter() { return pageAdapter; } + + public static ArrayList getPluginsList() { + return pluginsList; + } + + public static ArrayList getSpecificPluginsList(int type) { + ArrayList newList = new ArrayList(); + + Iterator it = pluginsList.iterator(); + while (it.hasNext()) { + PluginBase p = it.next(); + if (p.getType() == type) + newList.add(p); + } + return newList; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 76ec59bbdb..5b15182e92 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -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; - } - } \ No newline at end of file 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 17adbfb736..fc30c242b5 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -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 { diff --git a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java index 8aebee1513..071f1b28af 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java @@ -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; 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 5e74e80d03..61feaa0897 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventNewBasalProfile.java @@ -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; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/APSBase.java b/app/src/main/java/info/nightscout/androidaps/interfaces/APSInterface.java similarity index 56% rename from app/src/main/java/info/nightscout/androidaps/plugins/APSBase.java rename to app/src/main/java/info/nightscout/androidaps/interfaces/APSInterface.java index 1babc44f25..f6fd43388c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/APSBase.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/APSInterface.java @@ -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(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PluginBase.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/plugins/PluginBase.java rename to app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java index 74b332df5c..26f15883d3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PluginBase.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins; +package info.nightscout.androidaps.interfaces; import java.util.Date; diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/ProfileInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/ProfileInterface.java new file mode 100644 index 0000000000..ae28697834 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/ProfileInterface.java @@ -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(); +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Pump.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/plugins/Pump.java rename to app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java index e2f0308765..5081b8c919 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Pump.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -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(); } diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/TempBasalsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/TempBasalsInterface.java new file mode 100644 index 0000000000..3676f0cd7e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/TempBasalsInterface.java @@ -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(); +} diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java new file mode 100644 index 0000000000..f13ff5dad7 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java @@ -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(); +} 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 db3026f741..cfb1d08539 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,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 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 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 { private ArrayList 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 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 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 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(); + } + + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java index fe2d609fef..5d8adecc35 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java @@ -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"; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileViewer/ProfileViewerFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerFragment.java similarity index 59% rename from app/src/main/java/info/nightscout/androidaps/plugins/ProfileViewer/ProfileViewerFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerFragment.java index 9ff4f7aa78..45a303a028 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileViewer/ProfileViewerFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerFragment.java @@ -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; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java index 9c467193e1..29ee7bfb13 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java @@ -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; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java index 225300bc96..4b029f5cd5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java @@ -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) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java index 9fe9f57072..6a09ff978e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java @@ -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); 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 1a623fa344..1ff3b6b0ac 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 @@ -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; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java new file mode 100644 index 0000000000..e26a588d5d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java @@ -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; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java index e2118b66ef..e0c82fe344 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java @@ -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 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Dialogs/NewTreatmentDialogFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Dialogs/NewTreatmentDialogFragment.java index f39577891c..ac5bbb336d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Dialogs/NewTreatmentDialogFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Dialogs/NewTreatmentDialogFragment.java @@ -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); - } - } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Dialogs/WizardDialogFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Dialogs/WizardDialogFragment.java index 64cb5e3bd4..bb7280f214 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Dialogs/WizardDialogFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/Dialogs/WizardDialogFragment.java @@ -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); - } - } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java index a7f0f78313..7e0e596ef3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java @@ -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 - } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpFragment.java index 9809b4529b..345e093501 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpFragment.java @@ -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; } diff --git a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java index 4b4da9988d..e952e1d66f 100644 --- a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java @@ -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 getPluginsList() { - return fragmentList; - } - - public ArrayList getSpecificPluginsList(int type) { - ArrayList newList = new ArrayList(); - - Iterator it = fragmentList.iterator(); - while (it.hasNext()) { - PluginBase p = it.next(); - if (p.getType() == type) - newList.add(p); - } - return newList; - } } diff --git a/app/src/main/java/info/nightscout/client/data/NSProfile.java b/app/src/main/java/info/nightscout/client/data/NSProfile.java index 8f3e6776cb..472aa796de 100644 --- a/app/src/main/java/info/nightscout/client/data/NSProfile.java +++ b/app/src/main/java/info/nightscout/client/data/NSProfile.java @@ -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(); } diff --git a/app/src/main/res/layout/configbuilder_fragment.xml b/app/src/main/res/layout/configbuilder_fragment.xml index d6fc7f4343..e5dd0b4b7f 100644 --- a/app/src/main/res/layout/configbuilder_fragment.xml +++ b/app/src/main/res/layout/configbuilder_fragment.xml @@ -4,8 +4,6 @@ android:layout_height="match_parent" tools:context="info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment"> - - - - -