diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index 8628ce75bf..5aae374ccb 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -1,5 +1,6 @@ package info.nightscout.androidaps; +import android.support.v4.app.Fragment; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; @@ -7,9 +8,15 @@ import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; +import com.squareup.otto.Subscribe; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; + +import info.nightscout.androidaps.events.EventRefreshGui; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.LowSuspend.LowSuspendFragment; import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment; import info.nightscout.androidaps.plugins.Overview.OverviewFragment; @@ -26,7 +33,9 @@ public class MainActivity extends AppCompatActivity { private Toolbar toolbar; private SlidingTabLayout mTabs; private ViewPager mPager; - private TabPageAdapter mAdapter; + private static TabPageAdapter pageAdapter; + + ArrayList pluginsList = new ArrayList(); public static TreatmentsFragment treatmentsFragment; public static TempBasalsFragment tempBasalsFragment; @@ -38,25 +47,51 @@ public class MainActivity extends AppCompatActivity { setContentView(R.layout.activity_main); // Register all tabs in app here - mAdapter = new TabPageAdapter(getSupportFragmentManager()); - mAdapter.registerNewFragment("Overview", OverviewFragment.newInstance()); - mAdapter.registerNewFragment("VirtualPump", (VirtualPumpFragment) MainApp.setActivePump(VirtualPumpFragment.newInstance())); - mAdapter.registerNewFragment("LowSuspend", LowSuspendFragment.newInstance()); - mAdapter.registerNewFragment("OpenAPS MA", OpenAPSMAFragment.newInstance()); - mAdapter.registerNewFragment("Treatments", treatmentsFragment = TreatmentsFragment.newInstance()); - mAdapter.registerNewFragment("TempBasals", tempBasalsFragment = TempBasalsFragment.newInstance()); - mAdapter.registerNewFragment("Profile", ProfileViewerFragment.newInstance()); - mAdapter.registerNewFragment("Objectives", ObjectivesFragment.newInstance()); + pluginsList.add(OverviewFragment.newInstance()); + pluginsList.add((VirtualPumpFragment) MainApp.setActivePump(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(ObjectivesFragment.newInstance()); + pluginsList.add(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); - mPager = (ViewPager) findViewById(R.id.pager); - mPager.setAdapter(mAdapter); - mTabs = (SlidingTabLayout) findViewById(R.id.tabs); - mTabs.setViewPager(mPager); registerBus(); + setUpTabs(false); + } + + @Subscribe + public void onStatusEvent(final EventRefreshGui ev) { + setUpTabs(true); + } + + private void setUpTabs(boolean switchToLast) { + pageAdapter = new TabPageAdapter(getSupportFragmentManager()); + for(Fragment f: pluginsList) { + pageAdapter.registerNewFragment(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); } @Override @@ -82,5 +117,7 @@ public class MainActivity extends AppCompatActivity { MainApp.bus().register(this); } - + public static TabPageAdapter getPageAdapter() { + return pageAdapter; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 756d20dcf8..76ec59bbdb 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -12,10 +12,7 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Date; - -import info.nightscout.androidaps.data.Pump; -import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment; +import info.nightscout.androidaps.plugins.Pump; import info.nightscout.client.data.NSProfile; import info.nightscout.androidaps.db.DatabaseHelper; 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 e5e8aac528..17adbfb736 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -6,6 +6,7 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; +import android.support.annotation.Nullable; import com.j256.ormlite.dao.Dao; import com.j256.ormlite.stmt.PreparedQuery; @@ -332,6 +333,7 @@ public class DataService extends IntentService { editor.commit(); } + @Nullable public static Treatment findById(String _id) { try { QueryBuilder qb = null; @@ -355,6 +357,7 @@ public class DataService extends IntentService { return null; } + @Nullable public static Treatment findByTimeIndex(Long timeIndex) { try { QueryBuilder qb = null; diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 0f7fb1ef48..558381b061 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -8,6 +8,7 @@ import java.util.List; import android.content.Context; import android.database.sqlite.SQLiteDatabase; +import android.support.annotation.Nullable; import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; import com.j256.ormlite.dao.Dao; @@ -109,6 +110,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { /* * Return last BgReading from database or null if db is empty */ + @Nullable public BgReading lastBg() { List bgList = null; @@ -133,6 +135,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { * Return bg reading if not old ( <9 min ) * or null if older */ + @Nullable public BgReading actualBg() { BgReading lastBg = lastBg(); @@ -182,6 +185,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + @Nullable public GlucoseStatus getGlucoseStatusData() { GlucoseStatus result = new GlucoseStatus(); try { diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventRefreshGui.java b/app/src/main/java/info/nightscout/androidaps/events/EventRefreshGui.java new file mode 100644 index 0000000000..f20dfb9329 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/events/EventRefreshGui.java @@ -0,0 +1,7 @@ +package info.nightscout.androidaps.events; + +/** + * Created by mike on 13.06.2016. + */ +public class EventRefreshGui { +} 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 new file mode 100644 index 0000000000..db3026f741 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java @@ -0,0 +1,210 @@ +package info.nightscout.androidaps.plugins.ConfigBuilder; + + +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.CheckBox; +import android.widget.ListView; +import android.widget.TextView; +import android.widget.Toast; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; + +import info.nightscout.androidaps.MainActivity; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.events.EventRefreshGui; +import info.nightscout.androidaps.plugins.PluginBase; + +/** + * A simple {@link Fragment} subclass. + */ +public class ConfigBuilderFragment extends Fragment implements PluginBase { + private static Logger log = LoggerFactory.getLogger(ConfigBuilderFragment.class); + + ListView pumpListView; + ListView treatmentsListView; + ListView tempsListView; + ListView profileListView; + ListView apsListView; + ListView generalListView; + + PluginCustomAdapter pumpDataAdapter = null; + PluginCustomAdapter treatmentsDataAdapter = null; + PluginCustomAdapter tempsDataAdapter = null; + PluginCustomAdapter profileDataAdapter = null; + PluginCustomAdapter apsDataAdapter = null; + PluginCustomAdapter generalDataAdapter = null; + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.configbuilder_fragment, container, false); + pumpListView = (ListView) view.findViewById(R.id.configbuilder_pumplistview); + treatmentsListView = (ListView) view.findViewById(R.id.configbuilder_treatmentslistview); + tempsListView = (ListView) view.findViewById(R.id.configbuilder_tempslistview); + profileListView = (ListView) view.findViewById(R.id.configbuilder_profilelistview); + 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)); + pumpListView.setAdapter(pumpDataAdapter); + treatmentsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getPageAdapter().getSpecificPluginsList(PluginBase.TREATMENT)); + treatmentsListView.setAdapter(treatmentsDataAdapter); + tempsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getPageAdapter().getSpecificPluginsList(PluginBase.TEMPBASAL)); + tempsListView.setAdapter(tempsDataAdapter); + profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getPageAdapter().getSpecificPluginsList(PluginBase.PROFILE)); + profileListView.setAdapter(profileDataAdapter); + apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getPageAdapter().getSpecificPluginsList(PluginBase.APS)); + apsListView.setAdapter(apsDataAdapter); + generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getPageAdapter().getSpecificPluginsList(PluginBase.GENERAL)); + generalListView.setAdapter(generalDataAdapter); + + + apsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView parent, View view, + int position, long id) { + // When clicked, show a toast with the TextView text + PluginBase plugin = (PluginBase) parent.getItemAtPosition(position); + Toast.makeText(MainApp.instance().getApplicationContext(), + "Clicked on Row: " + plugin.getName(), + Toast.LENGTH_LONG).show(); + } + }); + + return view; + } + + @Override + public int getType() { + return PluginBase.GENERAL; + } + + @Override + public String getName() { + return MainApp.instance().getString(R.string.configbuilder); + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public boolean isVisibleInTabs() { + return true; + } + + @Override + public boolean canBeHidden() { + return false; + } + + @Override + public void setFragmentEnabled(boolean fragmentEnabled) { + // Always enabled + } + + @Override + public void setFragmentVisible(boolean fragmentVisible) { + // Always visible + } + + public static ConfigBuilderFragment newInstance() { + ConfigBuilderFragment fragment = new ConfigBuilderFragment(); + return fragment; + } + + private class PluginCustomAdapter extends ArrayAdapter { + + private ArrayList pluginList; + + public PluginCustomAdapter(Context context, int textViewResourceId, + ArrayList pluginList) { + super(context, textViewResourceId, pluginList); + this.pluginList = new ArrayList(); + this.pluginList.addAll(pluginList); + } + + private class PluginViewHolder { + TextView name; + CheckBox checkboxEnabled; + CheckBox checkboxVisible; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + PluginViewHolder holder = null; + + if (convertView == null) { + convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.configbuilder_simpleitem, null); + + holder = new PluginViewHolder(); + holder.name = (TextView) convertView.findViewById(R.id.configbuilder_simpleitem_name); + holder.checkboxEnabled = (CheckBox) convertView.findViewById(R.id.configbuilder_simpleitem_checkboxenabled); + holder.checkboxVisible = (CheckBox) convertView.findViewById(R.id.configbuilder_simpleitem_checkboxvisible); + convertView.setTag(holder); + + holder.checkboxEnabled.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + CheckBox cb = (CheckBox) v; + PluginBase plugin = (PluginBase) cb.getTag(); + Toast.makeText(MainApp.instance().getApplicationContext(), + "Clicked on ENABLED: " + plugin.getName() + + " is " + cb.isChecked(), + Toast.LENGTH_LONG).show(); + plugin.setFragmentEnabled(cb.isChecked()); + } + }); + + holder.checkboxVisible.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + CheckBox cb = (CheckBox) v; + PluginBase plugin = (PluginBase) cb.getTag(); + Toast.makeText(MainApp.instance().getApplicationContext(), + "Clicked on VISIBLE: " + plugin.getName() + + " is " + cb.isChecked(), + Toast.LENGTH_LONG).show(); + plugin.setFragmentVisible(cb.isChecked()); + MainApp.bus().post(new EventRefreshGui()); + } + }); + } else { + holder = (PluginViewHolder) convertView.getTag(); + } + + PluginBase plugin = pluginList.get(position); + holder.name.setText(plugin.getName()); + holder.checkboxEnabled.setChecked(plugin.isEnabled()); + holder.checkboxVisible.setChecked(plugin.isVisibleInTabs()); + holder.name.setTag(plugin); + holder.checkboxEnabled.setTag(plugin); + holder.checkboxVisible.setTag(plugin); + + if (!plugin.canBeHidden()) { + holder.checkboxEnabled.setEnabled(false); + holder.checkboxVisible.setEnabled(false); + } + + return convertView; + + } + } + + private void displayListView() { + + } +} 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 c2d863c6d0..fe2d609fef 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 @@ -1,9 +1,7 @@ package info.nightscout.androidaps.plugins.LowSuspend; import android.app.Activity; -import android.content.Context; import android.content.SharedPreferences; -import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; @@ -25,7 +23,7 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Pump; +import info.nightscout.androidaps.plugins.Pump; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.plugins.APSBase; @@ -46,17 +44,44 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener Date lastAPSRun = null; APSResult lastAPSResult = null; + boolean fragmentEnabled = false; + boolean fragmentVisible = true; + + @Override + public String getName() { + return MainApp.instance().getString(R.string.lowsuspend); + } + + @Override + public boolean isEnabled() { + return fragmentEnabled; + } + + @Override + public boolean isVisibleInTabs() { + return fragmentVisible; + } + + @Override + public boolean canBeHidden() { + return true; + } + + @Override + public void setFragmentEnabled(boolean selected) { + this.fragmentEnabled = selected; + } + + @Override + public void setFragmentVisible(boolean fragmentVisible) { + this.fragmentVisible = fragmentVisible; + } @Override public int getType() { return PluginBase.APS; } - @Override - public boolean isFragmentVisible() { - return true; - } - @Override public APSResult getLastAPSResult() { return lastAPSResult; 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 bd958f0441..9c467193e1 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 @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.Objectives; -import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.CardView; @@ -15,6 +14,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.PluginBase; @@ -22,16 +22,42 @@ public class ObjectivesFragment extends Fragment implements PluginBase { RecyclerView recyclerView; LinearLayoutManager llm; + boolean fragmentVisible = true; + @Override public int getType() { return PluginBase.GENERAL; } @Override - public boolean isFragmentVisible() { + public String getName() { + return MainApp.instance().getString(R.string.objectives); + } + + @Override + public boolean isEnabled() { return true; } + @Override + public boolean isVisibleInTabs() { + return fragmentVisible; + } + + @Override + public boolean canBeHidden() { + return true; + } + + @Override + public void setFragmentEnabled(boolean fragmentEnabled) { + } + + @Override + public void setFragmentVisible(boolean fragmentVisible) { + this.fragmentVisible = fragmentVisible; + } + class Objective { String objective; String gate; @@ -92,7 +118,7 @@ public class ObjectivesFragment extends Fragment implements PluginBase { @Override public void onBindViewHolder(ObjectiveViewHolder holder, int position) { - holder.position.setText(String.valueOf(position+1)); + holder.position.setText(String.valueOf(position + 1)); holder.objective.setText(objectives.get(position).objective); holder.gate.setText(objectives.get(position).gate); holder.started.setText(objectives.get(position).started.toString()); 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 68b14089c3..225300bc96 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.data.Pump; +import info.nightscout.androidaps.plugins.Pump; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.plugins.ScriptReader; import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment; 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 258625d077..9fe9f57072 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,8 +25,7 @@ import info.nightscout.androidaps.Constants; 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.data.Pump; +import info.nightscout.androidaps.plugins.Pump; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTreatmentChange; @@ -54,16 +53,44 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, Date lastAPSRun = null; APSResult lastAPSResult = null; + boolean fragmentEnabled = false; + boolean fragmentVisible = true; + @Override - public int getType() { - return PluginBase.APS; + public String getName() { + return MainApp.instance().getString(R.string.openapsma); } @Override - public boolean isFragmentVisible() { + public boolean isEnabled() { + return fragmentEnabled; + } + + @Override + public boolean isVisibleInTabs() { + return fragmentVisible; + } + + @Override + public boolean canBeHidden() { return true; } + @Override + public void setFragmentVisible(boolean fragmentVisible) { + this.fragmentVisible = fragmentVisible; + } + + @Override + public void setFragmentEnabled(boolean fragmentEnabled) { + this.fragmentEnabled = fragmentEnabled; + } + + @Override + public int getType() { + return PluginBase.APS; + } + @Override public APSResult getLastAPSResult() { return lastAPSResult; @@ -153,7 +180,7 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, @Override public void invoke() { - DetermineBasalAdapterJS determineBasalAdapterJS = null; + DetermineBasalAdapterJS determineBasalAdapterJS = null; try { determineBasalAdapterJS = new DetermineBasalAdapterJS(new ScriptReader(MainApp.instance().getBaseContext())); } catch (IOException e) { 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 baf09c344a..1a623fa344 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 @@ -44,17 +44,41 @@ public class OverviewFragment extends Fragment implements PluginBase { TextView deltaView; GraphView bgGraph; + @Override + public String getName() { + return MainApp.instance().getString(R.string.overview); + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public boolean isVisibleInTabs() { + return true; + } + + @Override + public boolean canBeHidden() { + return false; + } + + @Override + public void setFragmentEnabled(boolean fragmentEnabled) { + // Always enabled + } + + @Override + public void setFragmentVisible(boolean fragmentVisible) { + // Always visible + } @Override public int getType() { return PluginBase.GENERAL; } - @Override - public boolean isFragmentVisible() { - return true; - } - public static OverviewFragment newInstance() { OverviewFragment fragment = new OverviewFragment(); return fragment; @@ -101,15 +125,16 @@ public class OverviewFragment extends Fragment implements PluginBase { if (bgGraph == null) return; + // **** BG value **** if (profile != null && lastBG != null && bgView != null) { bgView.setText(lastBG.valueToUnitsToString(profile.getUnits())); DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData(); - deltaView.setText(NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units); + if (glucoseStatus != null) + deltaView.setText("Δ " + NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units); BgReading.units = profile.getUnits(); } else return; - // **** BG value **** Integer flag = bgView.getPaintFlags(); if (actualBG == null) { flag |= Paint.STRIKE_THRU_TEXT_FLAG; @@ -118,7 +143,7 @@ public class OverviewFragment extends Fragment implements PluginBase { bgView.setPaintFlags(flag); Long agoMsec = new Date().getTime() - lastBG.timestamp; - int agoMin = (int) (agoMsec / 60d / 60d / 1000d); + int agoMin = (int) (agoMsec / 60d / 1000d); timeAgoView.setText(agoMin + " " + getString(R.string.minago)); // **** BG graph **** @@ -135,7 +160,7 @@ public class OverviewFragment extends Fragment implements PluginBase { Double lowLine = NSProfile.toUnits(80d, 4d, units); // TODO: make this customisable Double highLine = NSProfile.toUnits(180d, 10d, units); - Double maxY = NSProfile.toUnits(400d , 20d, units); // TODO: add some scale support + Double maxY = NSProfile.toUnits(400d, 20d, units); // TODO: add some scale support List bgReadingsArray = MainApp.getDbHelper().getDataFromTime(fromTime); List inRangeArray = new ArrayList(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PluginBase.java b/app/src/main/java/info/nightscout/androidaps/plugins/PluginBase.java index 5a9abee63d..74b332df5c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PluginBase.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PluginBase.java @@ -7,10 +7,18 @@ import java.util.Date; */ public interface PluginBase { int GENERAL = 1; - int PROFILE = 2; - int APS = 3; - int PUMP = 4; + int TREATMENT = 2; + int TEMPBASAL = 3; + int PROFILE = 4; + int APS = 5; + int PUMP = 6; public int getType(); - public boolean isFragmentVisible(); -} + + String getName(); + boolean isEnabled(); + boolean isVisibleInTabs(); + boolean canBeHidden(); + void setFragmentEnabled(boolean fragmentEnabled); + void setFragmentVisible(boolean fragmentVisible); +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileViewer/ProfileViewerFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileViewer/ProfileViewerFragment.java index 0d79caa3d0..9ff4f7aa78 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileViewer/ProfileViewerFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileViewer/ProfileViewerFragment.java @@ -35,17 +35,44 @@ public class ProfileViewerFragment extends Fragment implements PluginBase { private static DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00"); + boolean fragmentEnabled = true; + boolean fragmentVisible = true; + + @Override + public String getName() { + return MainApp.instance().getString(R.string.profileviewer); + } + + @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 int getType() { return PluginBase.PROFILE; } - @Override - public boolean isFragmentVisible() { - return true; - } - public static ProfileViewerFragment newInstance(String param1, String param2) { ProfileViewerFragment fragment = new ProfileViewerFragment(); return fragment; diff --git a/app/src/main/java/info/nightscout/androidaps/data/Pump.java b/app/src/main/java/info/nightscout/androidaps/plugins/Pump.java similarity index 84% rename from app/src/main/java/info/nightscout/androidaps/data/Pump.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Pump.java index 1d883de806..e2f0308765 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Pump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Pump.java @@ -1,8 +1,8 @@ -package info.nightscout.androidaps.data; +package info.nightscout.androidaps.plugins; import org.json.JSONObject; -import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.data.Result; import info.nightscout.client.data.NSProfile; /** @@ -16,7 +16,7 @@ public interface Pump { Integer getBatteryPercent(); Integer getReservoirValue(); - // Upload to pump new basal profile from MainApp.getNSProfile() + // Upload to pump new basal profile void setNewBasalProfile(NSProfile profile); double getBaseBasalRate(); // base basal rate, not temp basal 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 f30a4083a0..e2118b66ef 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 @@ -1,8 +1,6 @@ package info.nightscout.androidaps.plugins.TempBasals; import android.app.Activity; -import android.content.Context; -import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.CardView; @@ -31,7 +29,6 @@ import java.util.Locale; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTempBasalChange; @@ -56,17 +53,44 @@ public class TempBasalsFragment extends Fragment implements PluginBase { private List tempBasals; + boolean fragmentEnabled = true; + boolean fragmentVisible = true; @Override - public int getType() { - return PluginBase.GENERAL; + public String getName() { + return MainApp.instance().getString(R.string.tempbasals); } @Override - public boolean isFragmentVisible() { + 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 int getType() { + return PluginBase.TEMPBASAL; + } + private void initializeData() { try { Dao dao = MainApp.getDbHelper().getDaoTempBasals(); 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 abbc2e642b..a7f0f78313 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 @@ -1,7 +1,6 @@ package info.nightscout.androidaps.plugins.Treatments; import android.app.Activity; -import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; @@ -32,7 +31,6 @@ 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; @@ -64,17 +62,44 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener private List treatments; + boolean fragmentEnabled = true; + boolean fragmentVisible = true; @Override - public int getType() { - return PluginBase.GENERAL; + public String getName() { + return MainApp.instance().getString(R.string.treatments); } @Override - public boolean isFragmentVisible() { + 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 int getType() { + return PluginBase.TREATMENT; + } + private void initializeData() { try { Dao dao = MainApp.getDbHelper().getDaoTreatments(); 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 b142c095da..9809b4529b 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,10 +20,9 @@ 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.data.Pump; +import info.nightscout.androidaps.plugins.Pump; import info.nightscout.androidaps.data.Result; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.Treatment; @@ -47,16 +46,43 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump { TextView batteryView; TextView reservoirView; + boolean fragmentEnabled = true; + boolean fragmentVisible = true; + @Override - public int getType() { - return PluginBase.PUMP; + public String getName() { + return MainApp.instance().getString(R.string.virtualpump); } @Override - public boolean isFragmentVisible() { + public boolean isEnabled() { + return fragmentEnabled; + } + + @Override + public boolean isVisibleInTabs() { + return fragmentVisible; + } + + @Override + public boolean canBeHidden() { return true; } + public void setFragmentEnabled(boolean fragmentEnabled) { + this.fragmentEnabled = fragmentEnabled; + } + + @Override + public void setFragmentVisible(boolean fragmentVisible) { + this.fragmentVisible = fragmentVisible; + } + + @Override + public int getType() { + return PluginBase.PUMP; + } + public static VirtualPumpFragment newInstance() { VirtualPumpFragment fragment = new VirtualPumpFragment(); return fragment; @@ -128,7 +154,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump { tempBasal = null; } } - if (isExtendedBoluslInProgress()) { + if (isExtendedBoluslInProgress()) { long plannedTimeEnd = extendedBolus.getPlannedTimeEnd().getTime(); if (plannedTimeEnd < now) { extendedBolus.timeEnd = new Date(plannedTimeEnd); @@ -344,7 +370,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump { } @Override - public JSONObject getJSONStatus(){ + public JSONObject getJSONStatus() { JSONObject pump = new JSONObject(); JSONObject battery = new JSONObject(); JSONObject status = new JSONObject(); 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 550065bcc2..4b4da9988d 100644 --- a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java @@ -1,56 +1,69 @@ package info.nightscout.androidaps.tabs; -import android.os.Bundle; -import android.support.annotation.PluralsRes; +import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.app.FragmentStatePagerAdapter; import java.util.ArrayList; -import java.util.List; +import java.util.Iterator; import info.nightscout.androidaps.plugins.PluginBase; /** * Created by mike on 30.05.2016. */ -public class TabPageAdapter extends FragmentPagerAdapter { +public class TabPageAdapter extends FragmentStatePagerAdapter { - int registeredTabs = 0; - List fragmentList = new ArrayList(); + ArrayList fragmentList = new ArrayList(); + ArrayList visibleFragmentList = new ArrayList(); + + FragmentManager fm; public TabPageAdapter(FragmentManager fm) { super(fm); + this.fm = fm; } @Override + @Nullable public Fragment getItem(int position) { - if (position > registeredTabs) - return null; - Fragment fragment = fragmentList.get(position); + Fragment fragment = (Fragment) visibleFragmentList.get(position); return fragment; } @Override public CharSequence getPageTitle(int position) { - return fragmentList.get(position).getArguments().getString("name"); + return visibleFragmentList.get(position).getName(); } @Override public int getCount() { - return registeredTabs; + return visibleFragmentList.size(); } - public int registerNewFragment(String name, Fragment fragment) { - if (((PluginBase) fragment).isFragmentVisible()){ - fragmentList.add(fragment); - Bundle args = new Bundle(); - args.putString("name", name); - fragment.setArguments(args); - registeredTabs++; + public void registerNewFragment(Fragment fragment) { + PluginBase plugin = (PluginBase) fragment; + fragmentList.add(plugin); + if (plugin.isVisibleInTabs()) { + visibleFragmentList.add(plugin); notifyDataSetChanged(); - return registeredTabs - 1; } - return registeredTabs; + } + + 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/res/layout/configbuilder_fragment.xml b/app/src/main/res/layout/configbuilder_fragment.xml new file mode 100644 index 0000000000..d6fc7f4343 --- /dev/null +++ b/app/src/main/res/layout/configbuilder_fragment.xml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/configbuilder_simpleitem.xml b/app/src/main/res/layout/configbuilder_simpleitem.xml new file mode 100644 index 0000000000..3d8894ed94 --- /dev/null +++ b/app/src/main/res/layout/configbuilder_simpleitem.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 64ebdaf10c..79ecc20a63 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -88,4 +88,20 @@ Avg. delta: min ago + Config Builder + Low Suspend + Objectives + OpenAPS MA + Overview + Profile Viewer + Temp Basals + Treatments + Virtual Pump + Pump + Treatments + Temp Basals + Profile + APS + General +