base ConfigBuilder plugin

This commit is contained in:
Milos Kozak 2016-06-13 22:53:41 +02:00
parent 7e3d1e6ad4
commit 32bfea8d18
19 changed files with 723 additions and 95 deletions

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps; package info.nightscout.androidaps;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
@ -7,9 +8,15 @@ import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.LowSuspend.LowSuspendFragment;
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment; import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment;
import info.nightscout.androidaps.plugins.Overview.OverviewFragment; import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
@ -26,7 +33,9 @@ public class MainActivity extends AppCompatActivity {
private Toolbar toolbar; private Toolbar toolbar;
private SlidingTabLayout mTabs; private SlidingTabLayout mTabs;
private ViewPager mPager; private ViewPager mPager;
private TabPageAdapter mAdapter; private static TabPageAdapter pageAdapter;
ArrayList<Fragment> pluginsList = new ArrayList<Fragment>();
public static TreatmentsFragment treatmentsFragment; public static TreatmentsFragment treatmentsFragment;
public static TempBasalsFragment tempBasalsFragment; public static TempBasalsFragment tempBasalsFragment;
@ -38,25 +47,51 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
// Register all tabs in app here // Register all tabs in app here
mAdapter = new TabPageAdapter(getSupportFragmentManager()); pluginsList.add(OverviewFragment.newInstance());
mAdapter.registerNewFragment("Overview", OverviewFragment.newInstance()); pluginsList.add((VirtualPumpFragment) MainApp.setActivePump(VirtualPumpFragment.newInstance()));
mAdapter.registerNewFragment("VirtualPump", (VirtualPumpFragment) MainApp.setActivePump(VirtualPumpFragment.newInstance())); pluginsList.add(LowSuspendFragment.newInstance());
mAdapter.registerNewFragment("LowSuspend", LowSuspendFragment.newInstance()); pluginsList.add(OpenAPSMAFragment.newInstance());
mAdapter.registerNewFragment("OpenAPS MA", OpenAPSMAFragment.newInstance()); pluginsList.add(treatmentsFragment = TreatmentsFragment.newInstance());
mAdapter.registerNewFragment("Treatments", treatmentsFragment = TreatmentsFragment.newInstance()); pluginsList.add(tempBasalsFragment = TempBasalsFragment.newInstance());
mAdapter.registerNewFragment("TempBasals", tempBasalsFragment = TempBasalsFragment.newInstance()); pluginsList.add(ProfileViewerFragment.newInstance());
mAdapter.registerNewFragment("Profile", ProfileViewerFragment.newInstance()); pluginsList.add(ObjectivesFragment.newInstance());
mAdapter.registerNewFragment("Objectives", 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); toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mTabs = (SlidingTabLayout) findViewById(R.id.tabs);
mTabs.setViewPager(mPager);
registerBus(); 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 @Override
@ -82,5 +117,7 @@ public class MainActivity extends AppCompatActivity {
MainApp.bus().register(this); MainApp.bus().register(this);
} }
public static TabPageAdapter getPageAdapter() {
return pageAdapter;
}
} }

View file

@ -12,10 +12,7 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date; import info.nightscout.androidaps.plugins.Pump;
import info.nightscout.androidaps.data.Pump;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DatabaseHelper;

View file

@ -0,0 +1,7 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 13.06.2016.
*/
public class EventRefreshGui {
}

View file

@ -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<PluginBase> 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<PluginBase> {
private ArrayList<PluginBase> pluginList;
public PluginCustomAdapter(Context context, int textViewResourceId,
ArrayList<PluginBase> pluginList) {
super(context, textViewResourceId, pluginList);
this.pluginList = new ArrayList<PluginBase>();
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() {
}
}

View file

@ -1,9 +1,7 @@
package info.nightscout.androidaps.plugins.LowSuspend; package info.nightscout.androidaps.plugins.LowSuspend;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -25,7 +23,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; 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.db.DatabaseHelper;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.plugins.APSBase; import info.nightscout.androidaps.plugins.APSBase;
@ -46,17 +44,44 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener
Date lastAPSRun = null; Date lastAPSRun = null;
APSResult lastAPSResult = 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 @Override
public int getType() { public int getType() {
return PluginBase.APS; return PluginBase.APS;
} }
@Override
public boolean isFragmentVisible() {
return true;
}
@Override @Override
public APSResult getLastAPSResult() { public APSResult getLastAPSResult() {
return lastAPSResult; return lastAPSResult;

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.Objectives; package info.nightscout.androidaps.plugins.Objectives;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
@ -15,6 +14,7 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PluginBase; import info.nightscout.androidaps.plugins.PluginBase;
@ -22,16 +22,42 @@ public class ObjectivesFragment extends Fragment implements PluginBase {
RecyclerView recyclerView; RecyclerView recyclerView;
LinearLayoutManager llm; LinearLayoutManager llm;
boolean fragmentVisible = true;
@Override @Override
public int getType() { public int getType() {
return PluginBase.GENERAL; return PluginBase.GENERAL;
} }
@Override @Override
public boolean isFragmentVisible() { public String getName() {
return MainApp.instance().getString(R.string.objectives);
}
@Override
public boolean isEnabled() {
return true; 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 { class Objective {
String objective; String objective;
String gate; String gate;

View file

@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import info.nightscout.androidaps.Config; 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.db.DatabaseHelper;
import info.nightscout.androidaps.plugins.ScriptReader; import info.nightscout.androidaps.plugins.ScriptReader;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment; import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;

View file

@ -25,8 +25,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.plugins.Pump;
import info.nightscout.androidaps.data.Pump;
import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
@ -54,16 +53,44 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
Date lastAPSRun = null; Date lastAPSRun = null;
APSResult lastAPSResult = null; APSResult lastAPSResult = null;
boolean fragmentEnabled = false;
boolean fragmentVisible = true;
@Override @Override
public int getType() { public String getName() {
return PluginBase.APS; return MainApp.instance().getString(R.string.openapsma);
} }
@Override @Override
public boolean isFragmentVisible() { public boolean isEnabled() {
return fragmentEnabled;
}
@Override
public boolean isVisibleInTabs() {
return fragmentVisible;
}
@Override
public boolean canBeHidden() {
return true; 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 @Override
public APSResult getLastAPSResult() { public APSResult getLastAPSResult() {
return lastAPSResult; return lastAPSResult;

View file

@ -44,17 +44,41 @@ public class OverviewFragment extends Fragment implements PluginBase {
TextView deltaView; TextView deltaView;
GraphView bgGraph; 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 @Override
public int getType() { public int getType() {
return PluginBase.GENERAL; return PluginBase.GENERAL;
} }
@Override
public boolean isFragmentVisible() {
return true;
}
public static OverviewFragment newInstance() { public static OverviewFragment newInstance() {
OverviewFragment fragment = new OverviewFragment(); OverviewFragment fragment = new OverviewFragment();
return fragment; return fragment;

View file

@ -7,10 +7,18 @@ import java.util.Date;
*/ */
public interface PluginBase { public interface PluginBase {
int GENERAL = 1; int GENERAL = 1;
int PROFILE = 2; int TREATMENT = 2;
int APS = 3; int TEMPBASAL = 3;
int PUMP = 4; int PROFILE = 4;
int APS = 5;
int PUMP = 6;
public int getType(); public int getType();
public boolean isFragmentVisible();
String getName();
boolean isEnabled();
boolean isVisibleInTabs();
boolean canBeHidden();
void setFragmentEnabled(boolean fragmentEnabled);
void setFragmentVisible(boolean fragmentVisible);
} }

View file

@ -35,17 +35,44 @@ public class ProfileViewerFragment extends Fragment implements PluginBase {
private static DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00"); 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 @Override
public int getType() { public int getType() {
return PluginBase.PROFILE; return PluginBase.PROFILE;
} }
@Override
public boolean isFragmentVisible() {
return true;
}
public static ProfileViewerFragment newInstance(String param1, String param2) { public static ProfileViewerFragment newInstance(String param1, String param2) {
ProfileViewerFragment fragment = new ProfileViewerFragment(); ProfileViewerFragment fragment = new ProfileViewerFragment();
return fragment; return fragment;

View file

@ -1,8 +1,8 @@
package info.nightscout.androidaps.data; package info.nightscout.androidaps.plugins;
import org.json.JSONObject; import org.json.JSONObject;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.data.Result;
import info.nightscout.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
/** /**
@ -16,7 +16,7 @@ public interface Pump {
Integer getBatteryPercent(); Integer getBatteryPercent();
Integer getReservoirValue(); Integer getReservoirValue();
// Upload to pump new basal profile from MainApp.getNSProfile() // Upload to pump new basal profile
void setNewBasalProfile(NSProfile profile); void setNewBasalProfile(NSProfile profile);
double getBaseBasalRate(); // base basal rate, not temp basal double getBaseBasalRate(); // base basal rate, not temp basal

View file

@ -1,8 +1,6 @@
package info.nightscout.androidaps.plugins.TempBasals; package info.nightscout.androidaps.plugins.TempBasals;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
@ -31,7 +29,6 @@ import java.util.Locale;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
@ -56,17 +53,44 @@ public class TempBasalsFragment extends Fragment implements PluginBase {
private List<TempBasal> tempBasals; private List<TempBasal> tempBasals;
boolean fragmentEnabled = true;
boolean fragmentVisible = true;
@Override @Override
public int getType() { public String getName() {
return PluginBase.GENERAL; return MainApp.instance().getString(R.string.tempbasals);
} }
@Override @Override
public boolean isFragmentVisible() { public boolean isEnabled() {
return fragmentEnabled;
}
@Override
public boolean isVisibleInTabs() {
return fragmentVisible;
}
@Override
public boolean canBeHidden() {
return true; 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() { private void initializeData() {
try { try {
Dao<TempBasal, Long> dao = MainApp.getDbHelper().getDaoTempBasals(); Dao<TempBasal, Long> dao = MainApp.getDbHelper().getDaoTempBasals();

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.Treatments; package info.nightscout.androidaps.plugins.Treatments;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@ -32,7 +31,6 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.data.Iob;
@ -64,17 +62,44 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
private List<Treatment> treatments; private List<Treatment> treatments;
boolean fragmentEnabled = true;
boolean fragmentVisible = true;
@Override @Override
public int getType() { public String getName() {
return PluginBase.GENERAL; return MainApp.instance().getString(R.string.treatments);
} }
@Override @Override
public boolean isFragmentVisible() { public boolean isEnabled() {
return fragmentEnabled;
}
@Override
public boolean isVisibleInTabs() {
return fragmentVisible;
}
@Override
public boolean canBeHidden() {
return true; 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() { private void initializeData() {
try { try {
Dao<Treatment, Long> dao = MainApp.getDbHelper().getDaoTreatments(); Dao<Treatment, Long> dao = MainApp.getDbHelper().getDaoTreatments();

View file

@ -20,10 +20,9 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; 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.data.Result;
import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
@ -47,16 +46,43 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, Pump {
TextView batteryView; TextView batteryView;
TextView reservoirView; TextView reservoirView;
boolean fragmentEnabled = true;
boolean fragmentVisible = true;
@Override @Override
public int getType() { public String getName() {
return PluginBase.PUMP; return MainApp.instance().getString(R.string.virtualpump);
} }
@Override @Override
public boolean isFragmentVisible() { public boolean isEnabled() {
return fragmentEnabled;
}
@Override
public boolean isVisibleInTabs() {
return fragmentVisible;
}
@Override
public boolean canBeHidden() {
return true; 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() { public static VirtualPumpFragment newInstance() {
VirtualPumpFragment fragment = new VirtualPumpFragment(); VirtualPumpFragment fragment = new VirtualPumpFragment();
return fragment; return fragment;

View file

@ -1,58 +1,69 @@
package info.nightscout.androidaps.tabs; package info.nightscout.androidaps.tabs;
import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.PluralsRes;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; 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.ArrayList;
import java.util.List; import java.util.Iterator;
import info.nightscout.androidaps.plugins.PluginBase; import info.nightscout.androidaps.plugins.PluginBase;
/** /**
* Created by mike on 30.05.2016. * Created by mike on 30.05.2016.
*/ */
public class TabPageAdapter extends FragmentPagerAdapter { public class TabPageAdapter extends FragmentStatePagerAdapter {
int registeredTabs = 0; ArrayList<PluginBase> fragmentList = new ArrayList<PluginBase>();
List<Fragment> fragmentList = new ArrayList<Fragment>(); ArrayList<PluginBase> visibleFragmentList = new ArrayList<PluginBase>();
FragmentManager fm;
public TabPageAdapter(FragmentManager fm) { public TabPageAdapter(FragmentManager fm) {
super(fm); super(fm);
this.fm = fm;
} }
@Override @Override
@Nullable @Nullable
public Fragment getItem(int position) { public Fragment getItem(int position) {
if (position > registeredTabs) Fragment fragment = (Fragment) visibleFragmentList.get(position);
return null;
Fragment fragment = fragmentList.get(position);
return fragment; return fragment;
} }
@Override @Override
public CharSequence getPageTitle(int position) { public CharSequence getPageTitle(int position) {
return fragmentList.get(position).getArguments().getString("name"); return visibleFragmentList.get(position).getName();
} }
@Override @Override
public int getCount() { public int getCount() {
return registeredTabs; return visibleFragmentList.size();
} }
public int registerNewFragment(String name, Fragment fragment) { public void registerNewFragment(Fragment fragment) {
if (((PluginBase) fragment).isFragmentVisible()){ PluginBase plugin = (PluginBase) fragment;
fragmentList.add(fragment); fragmentList.add(plugin);
Bundle args = new Bundle(); if (plugin.isVisibleInTabs()) {
args.putString("name", name); visibleFragmentList.add(plugin);
fragment.setArguments(args);
registeredTabs++;
notifyDataSetChanged(); notifyDataSetChanged();
return registeredTabs - 1; }
} }
return registeredTabs;
public ArrayList<PluginBase> getPluginsList() {
return fragmentList;
}
public ArrayList<PluginBase> getSpecificPluginsList(int type) {
ArrayList<PluginBase> newList = new ArrayList<PluginBase>();
Iterator<PluginBase> it = fragmentList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getType() == type)
newList.add(p);
}
return newList;
} }
} }

View file

@ -0,0 +1,89 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/configbuilder_pump"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ListView
android:id="@+id/configbuilder_pumplistview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginRight="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/configbuilder_treatments"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ListView
android:id="@+id/configbuilder_treatmentslistview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/configbuilder_tempbasals"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ListView
android:id="@+id/configbuilder_tempslistview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/configbuilder_profile"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ListView
android:id="@+id/configbuilder_profilelistview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/configbuilder_aps"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ListView
android:id="@+id/configbuilder_apslistview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/configbuilder_general"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<ListView
android:id="@+id/configbuilder_generallistview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/configbuilder_simpleitem_checkboxenabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Enabled" />
<CheckBox
android:id="@+id/configbuilder_simpleitem_checkboxvisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Visible" />
<ImageView
android:id="@+id/configbuilder_simpleitem_upimage"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@android:drawable/arrow_up_float" />
<TextView
android:id="@+id/configbuilder_simpleitem_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Plugin name"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>

View file

@ -88,4 +88,20 @@
<string name="avgdelta">Avg. delta:</string> <string name="avgdelta">Avg. delta:</string>
<string name="minago">min ago</string> <string name="minago">min ago</string>
<string name="configbuilder">Config Builder</string>
<string name="lowsuspend">Low Suspend</string>
<string name="objectives">Objectives</string>
<string name="openapsma">OpenAPS MA</string>
<string name="overview">Overview</string>
<string name="profileviewer">Profile Viewer</string>
<string name="tempbasals">Temp Basals</string>
<string name="treatments">Treatments</string>
<string name="virtualpump">Virtual Pump</string>
<string name="configbuilder_pump">Pump</string>
<string name="configbuilder_treatments">Treatments</string>
<string name="configbuilder_tempbasals">Temp Basals</string>
<string name="configbuilder_profile">Profile</string>
<string name="configbuilder_aps">APS</string>
<string name="configbuilder_general">General</string>
</resources> </resources>