fix NSCLIENT after plugin refactor

This commit is contained in:
Milos Kozak 2018-03-31 21:41:14 +02:00
parent a91aeec144
commit 34ec1225c6
19 changed files with 62 additions and 76 deletions

View file

@ -16,7 +16,6 @@ public class Config {
public static final boolean HWPUMPS = BuildConfig.PUMPDRIVERS; public static final boolean HWPUMPS = BuildConfig.PUMPDRIVERS;
public static final boolean ACTION = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER; public static final boolean ACTION = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
public static final boolean VIRTUALPUMP = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
public static final boolean MDI = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER; public static final boolean MDI = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
public static final boolean OTHERPROFILES = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER; public static final boolean OTHERPROFILES = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
public static final boolean SAFETY = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER; public static final boolean SAFETY = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;

View file

@ -162,7 +162,7 @@ public class MainApp extends Application {
if (Config.HWPUMPS && engineeringMode) if (Config.HWPUMPS && engineeringMode)
pluginsList.add(ComboPlugin.getPlugin()); // <-- Enable Combo plugin here pluginsList.add(ComboPlugin.getPlugin()); // <-- Enable Combo plugin here
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin());
if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getPlugin()); pluginsList.add(VirtualPumpPlugin.getPlugin());
if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); if (Config.APS) pluginsList.add(LoopPlugin.getPlugin());
if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin()); if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin());
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin()); if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());

View file

@ -1,15 +1,16 @@
package info.nightscout.androidaps.interfaces; package info.nightscout.androidaps.interfaces;
import java.util.Date; import org.slf4j.Logger;
import java.util.HashMap; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
/** /**
* Created by mike on 09.06.2016. * Created by mike on 09.06.2016.
*/ */
public abstract class PluginBase { public abstract class PluginBase {
private static Logger log = LoggerFactory.getLogger(PluginBase.class);
public enum State { public enum State {
NOT_INITIALIZED, NOT_INITIALIZED,
ENABLED, ENABLED,
@ -79,10 +80,6 @@ public abstract class PluginBase {
return false; return false;
} }
public boolean canBeHidden(PluginType type) {
return pluginDescription.canBeHidden;
}
public boolean hasFragment() { public boolean hasFragment() {
return pluginDescription.fragmentClass != null; return pluginDescription.fragmentClass != null;
} }
@ -100,6 +97,7 @@ public abstract class PluginBase {
if (state != State.ENABLED) { if (state != State.ENABLED) {
onStateChange(type, state, State.ENABLED); onStateChange(type, state, State.ENABLED);
state = State.ENABLED; state = State.ENABLED;
log.debug("Starting: " + getName());
onStart(); onStart();
} }
} else { // disabling plugin } else { // disabling plugin
@ -107,6 +105,7 @@ public abstract class PluginBase {
onStateChange(type, state, State.ENABLED); onStateChange(type, state, State.ENABLED);
state = State.DISABLED; state = State.DISABLED;
onStop(); onStop();
log.debug("Stopping: " + getName());
} }
} }
} else if (type == PluginType.PROFILE) { } else if (type == PluginType.PROFILE) {

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.interfaces;
public class PluginDescription { public class PluginDescription {
PluginType mainType = PluginType.GENERAL; PluginType mainType = PluginType.GENERAL;
String fragmentClass = null; String fragmentClass = null;
boolean canBeHidden = true;
public boolean alwayVisible = false; public boolean alwayVisible = false;
public boolean neverVisible = false; public boolean neverVisible = false;
public boolean alwaysEnabled = false; public boolean alwaysEnabled = false;
@ -25,11 +24,6 @@ public class PluginDescription {
return this; return this;
} }
public PluginDescription canBeHidden(boolean canBeHidden) {
this.canBeHidden = canBeHidden;
return this;
}
public PluginDescription alwaysEnabled(boolean alwaysEnabled) { public PluginDescription alwaysEnabled(boolean alwaysEnabled) {
this.alwaysEnabled = alwaysEnabled; this.alwaysEnabled = alwaysEnabled;
return this; return this;

View file

@ -26,9 +26,4 @@ public class CareportalPlugin extends PluginBase {
); );
} }
@Override
public boolean specialShowInListCondition() {
return !Config.NSCLIENT && !Config.G5UPLOADER;
}
} }

View file

@ -24,6 +24,7 @@ import java.util.ArrayList;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.PreferencesActivity; import info.nightscout.androidaps.PreferencesActivity;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
@ -142,8 +143,10 @@ public class ConfigBuilderFragment extends SubscriberFragment {
setListViewHeightBasedOnChildren(bgsourceListView); setListViewHeightBasedOnChildren(bgsourceListView);
pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP), PluginType.PUMP); pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP), PluginType.PUMP);
pumpListView.setAdapter(pumpDataAdapter); pumpListView.setAdapter(pumpDataAdapter);
if (MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP).size() == 0) if (MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP).size() == 0 || Config.NSCLIENT || Config.G5UPLOADER) {
pumpLabel.setVisibility(View.GONE); pumpLabel.setVisibility(View.GONE);
pumpListView.setVisibility(View.GONE);
}
setListViewHeightBasedOnChildren(pumpListView); setListViewHeightBasedOnChildren(pumpListView);
loopDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP), PluginType.LOOP); loopDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP), PluginType.LOOP);
loopListView.setAdapter(loopDataAdapter); loopListView.setAdapter(loopDataAdapter);
@ -278,9 +281,12 @@ public class ConfigBuilderFragment extends SubscriberFragment {
holder.checkboxVisible.setTag(plugin); holder.checkboxVisible.setTag(plugin);
holder.settings.setTag(plugin); holder.settings.setTag(plugin);
if (!plugin.canBeHidden(type)) { if (plugin.pluginDescription.alwaysEnabled) {
holder.checkboxEnabled.setEnabled(false);
}
if (plugin.pluginDescription.alwayVisible) {
holder.checkboxEnabled.setEnabled(false); holder.checkboxEnabled.setEnabled(false);
holder.checkboxVisible.setEnabled(false);
} }
if (!plugin.isEnabled(type)) { if (!plugin.isEnabled(type)) {

View file

@ -177,7 +177,7 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa
String settingEnabled = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Enabled"; String settingEnabled = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
if (SP.contains(settingEnabled)) if (SP.contains(settingEnabled))
p.setPluginEnabled(type, SP.getBoolean(settingEnabled, false)); p.setPluginEnabled(type, SP.getBoolean(settingEnabled, false));
else if (p.getType() == type && p.pluginDescription.enableByDefault) { else if (p.getType() == type && (p.pluginDescription.enableByDefault || p.pluginDescription.alwaysEnabled)) {
p.setPluginEnabled(type, true); p.setPluginEnabled(type, true);
} }
log.debug("Loaded: " + settingEnabled + ":" + p.isEnabled(type)); log.debug("Loaded: " + settingEnabled + ":" + p.isEnabled(type));

View file

@ -49,7 +49,8 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.CONSTRAINTS) .mainType(PluginType.CONSTRAINTS)
.fragmentClass(ObjectivesFragment.class.getName()) .fragmentClass(ObjectivesFragment.class.getName())
.alwaysEnabled(true) .alwaysEnabled(!Config.NSCLIENT && !Config.G5UPLOADER)
.showInList(!Config.NSCLIENT && !Config.G5UPLOADER)
.pluginName(R.string.objectives) .pluginName(R.string.objectives)
.shortName(R.string.objectives_shortname) .shortName(R.string.objectives_shortname)
); );
@ -63,11 +64,6 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
return pump == null || pump.getPumpDescription().isTempBasalCapable; return pump == null || pump.getPumpDescription().isTempBasalCapable;
} }
@Override
public boolean specialShowInListCondition() {
return !Config.NSCLIENT && !Config.G5UPLOADER;
}
public class Objective { public class Objective {
Integer num; Integer num;
String objective; String objective;

View file

@ -18,6 +18,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config; 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;
@ -65,6 +66,10 @@ public class NSClientPlugin extends PluginBase {
.shortName(R.string.nsclientinternal_shortname) .shortName(R.string.nsclientinternal_shortname)
.preferencesId(R.xml.pref_nsclientinternal) .preferencesId(R.xml.pref_nsclientinternal)
); );
if (Config.NSCLIENT || Config.G5UPLOADER) {
pluginDescription.alwaysEnabled(true).visibleByDefault(true);
}
paused = SP.getBoolean(R.string.key_nsclientinternal_paused, false); paused = SP.getBoolean(R.string.key_nsclientinternal_paused, false);
autoscroll = SP.getBoolean(R.string.key_nsclientinternal_autoscroll, true); autoscroll = SP.getBoolean(R.string.key_nsclientinternal_autoscroll, true);
@ -90,11 +95,6 @@ public class NSClientPlugin extends PluginBase {
context.unbindService(mConnection); context.unbindService(mConnection);
} }
@Override
public boolean specialShowInListCondition() {
return !Config.NSCLIENT && !Config.G5UPLOADER;
}
private ServiceConnection mConnection = new ServiceConnection() { private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
@ -105,7 +105,8 @@ public class NSClientPlugin extends PluginBase {
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
log.debug("Service is connected"); log.debug("Service is connected");
NSClientService.LocalBinder mLocalBinder = (NSClientService.LocalBinder) service; NSClientService.LocalBinder mLocalBinder = (NSClientService.LocalBinder) service;
nsClientService = mLocalBinder.getServiceInstance(); if (mLocalBinder != null) // is null when running in roboelectric
nsClientService = mLocalBinder.getServiceInstance();
} }
}; };

View file

@ -45,7 +45,6 @@ public class OverviewPlugin extends PluginBase {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.GENERAL) .mainType(PluginType.GENERAL)
.fragmentClass(OverviewFragment.class.getName()) .fragmentClass(OverviewFragment.class.getName())
.canBeHidden(false)
.alwayVisible(true) .alwayVisible(true)
.alwaysEnabled(true) .alwaysEnabled(true)
.pluginName(R.string.overview) .pluginName(R.string.overview)

View file

@ -45,6 +45,9 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface {
.fragmentClass(NSProfileFragment.class.getName()) .fragmentClass(NSProfileFragment.class.getName())
.pluginName(R.string.profileviewer) .pluginName(R.string.profileviewer)
.shortName(R.string.profileviewer_shortname) .shortName(R.string.profileviewer_shortname)
.alwaysEnabled(Config.NSCLIENT)
.alwayVisible(Config.NSCLIENT)
.showInList(!Config.NSCLIENT)
); );
loadNSProfile(); loadNSProfile();
} }
@ -59,11 +62,6 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface {
MainApp.bus().unregister(this); MainApp.bus().unregister(this);
} }
@Override
public boolean specialShowInListCondition() {
return !Config.NSCLIENT && !Config.G5UPLOADER;
}
@Subscribe @Subscribe
public void storeNewProfile(ProfileStore newProfile) { public void storeNewProfile(ProfileStore newProfile) {
profile = new ProfileStore(newProfile.getData()); profile = new ProfileStore(newProfile.getData());

View file

@ -27,15 +27,11 @@ public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterfac
.fragmentClass(BGSourceFragment.class.getName()) .fragmentClass(BGSourceFragment.class.getName())
.pluginName(R.string.DexcomG5) .pluginName(R.string.DexcomG5)
.shortName(R.string.dexcomG5_shortname) .shortName(R.string.dexcomG5_shortname)
.showInList(!Config.NSCLIENT)
.preferencesId(R.xml.pref_dexcomg5) .preferencesId(R.xml.pref_dexcomg5)
); );
} }
@Override
public boolean specialShowInListCondition() {
return !Config.G5UPLOADER;
}
@Override @Override
public boolean advancedFilteringSupported() { public boolean advancedFilteringSupported() {
return true; return true;

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.Source; package info.nightscout.androidaps.plugins.Source;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
@ -24,6 +25,8 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac
.mainType(PluginType.BGSOURCE) .mainType(PluginType.BGSOURCE)
.fragmentClass(BGSourceFragment.class.getName()) .fragmentClass(BGSourceFragment.class.getName())
.pluginName(R.string.nsclientbg) .pluginName(R.string.nsclientbg)
.showInList(!Config.NSCLIENT)
.alwaysEnabled(Config.NSCLIENT)
); );
} }

View file

@ -76,11 +76,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
); );
} }
@Override
public boolean specialShowInListCondition() {
return !Config.NSCLIENT && !Config.G5UPLOADER;
}
@Override @Override
protected void onStart() { protected void onStart() {
MainApp.bus().register(this); MainApp.bus().register(this);

View file

@ -73,11 +73,6 @@ public class StatuslinePlugin extends PluginBase {
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx); this.mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
} }
@Override
public boolean specialShowInListCondition() {
return !Config.NSCLIENT && !Config.G5UPLOADER;
}
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();

View file

@ -5,6 +5,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
@ -27,8 +29,8 @@ public class MainAppTest {
@Test @Test
public void gsTest() { public void gsTest() {
Assert.assertEquals("AndroidAPS", mainApp.gs(R.string.app_name)); Assert.assertNotNull(mainApp.gs(R.string.app_name));
Assert.assertEquals("AndroidAPS", mainApp.gs(R.string.app_name, "")); Assert.assertNotNull(mainApp.gs(R.string.app_name, ""));
} }
@Test @Test
@ -70,25 +72,45 @@ public class MainAppTest {
@Test @Test
public void getSpecificPluginsListTest() { public void getSpecificPluginsListTest() {
// currently MDI, VP, R, Rv2, KoreanR, RS // currently MDI, VP, R, Rv2, KoreanR, RS
Assert.assertEquals(6, mainApp.getSpecificPluginsList(PluginType.PUMP).size()); int expected;
if (Config.NSCLIENT || Config.G5UPLOADER)
expected = 1; // VirtualPump only
else
expected = 6;
Assert.assertEquals(expected, mainApp.getSpecificPluginsList(PluginType.PUMP).size());
} }
@Test @Test
public void getSpecificPluginsVisibleInListTest() { public void getSpecificPluginsVisibleInListTest() {
// currently MDI, VP, R, Rv2, KoreanR, RS // currently MDI, VP, R, Rv2, KoreanR, RS
Assert.assertEquals(6, mainApp.getSpecificPluginsVisibleInList(PluginType.PUMP).size()); int expected;
if (Config.NSCLIENT || Config.G5UPLOADER)
expected = 1; // VirtualPump only
else
expected = 6;
Assert.assertEquals(expected, mainApp.getSpecificPluginsVisibleInList(PluginType.PUMP).size());
} }
@Test @Test
public void getSpecificPluginsListByInterfaceTest() { public void getSpecificPluginsListByInterfaceTest() {
// currently MDI, VP, R, Rv2, KoreanR, RS // currently MDI, VP, R, Rv2, KoreanR, RS
Assert.assertEquals(6, mainApp.getSpecificPluginsListByInterface(PumpInterface.class).size()); int expected;
if (Config.NSCLIENT || Config.G5UPLOADER)
expected = 1; // VirtualPump only
else
expected = 6;
Assert.assertEquals(expected, mainApp.getSpecificPluginsListByInterface(PumpInterface.class).size());
} }
@Test @Test
public void getSpecificPluginsVisibleInListByInterfaceTest() { public void getSpecificPluginsVisibleInListByInterfaceTest() {
// currently MDI, VP, R, Rv2, KoreanR, RS // currently MDI, VP, R, Rv2, KoreanR, RS
Assert.assertEquals(6, mainApp.getSpecificPluginsVisibleInListByInterface(PumpInterface.class, PluginType.PUMP).size()); int expected;
if (Config.NSCLIENT || Config.G5UPLOADER)
expected = 1; // VirtualPump only
else
expected = 6;
Assert.assertEquals(expected, mainApp.getSpecificPluginsVisibleInListByInterface(PumpInterface.class, PluginType.PUMP).size());
} }
@Test @Test
@ -99,7 +121,7 @@ public class MainAppTest {
@Test @Test
public void isEngineeringModeOrReleaseTest() { public void isEngineeringModeOrReleaseTest() {
Assert.assertEquals(false, mainApp.isEngineeringModeOrRelease()); Assert.assertEquals(!BuildConfig.APS, mainApp.isEngineeringModeOrRelease());
} }
@Test @Test

View file

@ -26,12 +26,6 @@ public class PluginDescriptionTest {
Assert.assertEquals(NSProfileFragment.class.getName(), pluginDescription.getFragmentClass()); Assert.assertEquals(NSProfileFragment.class.getName(), pluginDescription.getFragmentClass());
} }
@Test
public void canBeHiddenTest() {
PluginDescription pluginDescription = new PluginDescription().canBeHidden(false);
Assert.assertEquals(false, pluginDescription.canBeHidden);
}
@Test @Test
public void alwaysEnabledTest() { public void alwaysEnabledTest() {
PluginDescription pluginDescription = new PluginDescription().alwaysEnabled(true); PluginDescription pluginDescription = new PluginDescription().alwaysEnabled(true);

View file

@ -42,7 +42,6 @@ public class LoopPluginTest {
Assert.assertEquals(PluginType.LOOP, loopPlugin.getType()); Assert.assertEquals(PluginType.LOOP, loopPlugin.getType());
Assert.assertEquals("Loop", loopPlugin.getName()); Assert.assertEquals("Loop", loopPlugin.getName());
Assert.assertEquals("LOOP", loopPlugin.getNameShort()); Assert.assertEquals("LOOP", loopPlugin.getNameShort());
Assert.assertEquals(true, loopPlugin.canBeHidden(PluginType.LOOP));
Assert.assertEquals(true, loopPlugin.hasFragment()); Assert.assertEquals(true, loopPlugin.hasFragment());
Assert.assertEquals(true, loopPlugin.showInList(PluginType.LOOP)); Assert.assertEquals(true, loopPlugin.showInList(PluginType.LOOP));
Assert.assertEquals(R.xml.pref_closedmode, loopPlugin.getPreferencesId()); Assert.assertEquals(R.xml.pref_closedmode, loopPlugin.getPreferencesId());

View file

@ -15,11 +15,6 @@ public class SourceDexcomG5PluginTest {
Assert.assertNotEquals(null, SourceDexcomG5Plugin.getPlugin()); Assert.assertNotEquals(null, SourceDexcomG5Plugin.getPlugin());
} }
@Test
public void specialShowInListCondition() {
Assert.assertEquals(!Config.G5UPLOADER, SourceDexcomG5Plugin.getPlugin().specialShowInListCondition());
}
@Test @Test
public void advancedFilteringSupported() { public void advancedFilteringSupported() {
Assert.assertEquals(true, SourceDexcomG5Plugin.getPlugin().advancedFilteringSupported()); Assert.assertEquals(true, SourceDexcomG5Plugin.getPlugin().advancedFilteringSupported());