detect ns versions

This commit is contained in:
Milos Kozak 2016-06-26 14:56:43 +02:00
parent 2f16c9b998
commit a4bdebdedf
10 changed files with 109 additions and 9 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View file

@ -44,6 +44,10 @@
<action android:name="info.nightscout.client.NEW_PROFILE" /> <action android:name="info.nightscout.client.NEW_PROFILE" />
<action android:name="info.nightscout.client.NEW_SGV" /> <action android:name="info.nightscout.client.NEW_SGV" />
<action android:name="info.nightscout.client.NEW_STATUS" /> <action android:name="info.nightscout.client.NEW_STATUS" />
<action android:name="info.nightscout.client.NEW_MBG" />
<action android:name="info.nightscout.client.NEW_DEVICESTATUS" />
<action android:name="info.nightscout.client.NEW_CAL" />
<action android:name="info.nightscout.client.NEW_STATUS" />
</intent-filter> </intent-filter>
</receiver> </receiver>

View file

@ -10,6 +10,7 @@ public class Config {
public static final boolean LOWSUSPEDENABLED = APS && true; public static final boolean LOWSUSPEDENABLED = APS && true;
public static final boolean OPENAPSMAENABLED = APS && true; public static final boolean OPENAPSMAENABLED = APS && true;
public static final boolean LOOPENABLED = APS && true; public static final boolean LOOPENABLED = APS && true;
public static final boolean OBJECTIVESENABLED = APS && true;
public static final boolean detailedLog = true; public static final boolean detailedLog = true;
public static final boolean logFunctionCalls = true; public static final boolean logFunctionCalls = true;

View file

@ -59,18 +59,15 @@ public class MainActivity extends AppCompatActivity {
// Register all tabs in app here // Register all tabs in app here
pluginsList.add(OverviewFragment.newInstance()); pluginsList.add(OverviewFragment.newInstance());
pluginsList.add(VirtualPumpFragment.newInstance()); pluginsList.add(VirtualPumpFragment.newInstance());
if (Config.LOOPENABLED) if (Config.LOOPENABLED) pluginsList.add(LoopFragment.newInstance());
pluginsList.add(LoopFragment.newInstance()); if (Config.LOWSUSPEDENABLED) pluginsList.add(LowSuspendFragment.newInstance());
if (Config.LOWSUSPEDENABLED) if (Config.OPENAPSMAENABLED) pluginsList.add(OpenAPSMAFragment.newInstance());
pluginsList.add(LowSuspendFragment.newInstance());
if (Config.OPENAPSMAENABLED)
pluginsList.add(OpenAPSMAFragment.newInstance());
pluginsList.add(NSProfileViewerFragment.newInstance()); pluginsList.add(NSProfileViewerFragment.newInstance());
pluginsList.add(SimpleProfileFragment.newInstance()); pluginsList.add(SimpleProfileFragment.newInstance());
pluginsList.add(TreatmentsFragment.newInstance()); pluginsList.add(TreatmentsFragment.newInstance());
pluginsList.add(TempBasalsFragment.newInstance()); pluginsList.add(TempBasalsFragment.newInstance());
pluginsList.add(SafetyFragment.newInstance()); pluginsList.add(SafetyFragment.newInstance());
pluginsList.add(ObjectivesFragment.newInstance()); if (Config.OPENAPSMAENABLED) pluginsList.add(ObjectivesFragment.newInstance());
pluginsList.add(SourceXdripFragment.newInstance()); pluginsList.add(SourceXdripFragment.newInstance());
pluginsList.add(SourceNSClientFragment.newInstance()); pluginsList.add(SourceNSClientFragment.newInstance());
pluginsList.add(configBuilderFragment = ConfigBuilderFragment.newInstance()); pluginsList.add(configBuilderFragment = ConfigBuilderFragment.newInstance());
@ -162,4 +159,14 @@ public class MainActivity extends AppCompatActivity {
} }
return newList; return newList;
} }
public static PluginBase getSpecificPlugin(Class pluginClass) {
Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getClass() == pluginClass)
return p;
}
return null;
}
} }

View file

@ -26,6 +26,7 @@ import java.util.List;
import info.nightscout.androidaps.Constants; 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.db.BgReading; import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
@ -34,12 +35,14 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesFragment;
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment; import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
import info.nightscout.androidaps.receivers.NSClientDataReceiver; import info.nightscout.androidaps.receivers.NSClientDataReceiver;
import info.nightscout.androidaps.receivers.xDripReceiver; import info.nightscout.androidaps.receivers.xDripReceiver;
import info.nightscout.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
import info.nightscout.client.data.NSSgv; import info.nightscout.client.data.NSSgv;
import info.nightscout.utils.ToastUtils;
public class DataService extends IntentService { public class DataService extends IntentService {
@ -78,7 +81,11 @@ public class DataService extends IntentService {
Intents.ACTION_NEW_TREATMENT.equals(action) || Intents.ACTION_NEW_TREATMENT.equals(action) ||
Intents.ACTION_CHANGED_TREATMENT.equals(action) || Intents.ACTION_CHANGED_TREATMENT.equals(action) ||
Intents.ACTION_REMOVED_TREATMENT.equals(action) || Intents.ACTION_REMOVED_TREATMENT.equals(action) ||
Intents.ACTION_NEW_SGV.equals(action) Intents.ACTION_NEW_SGV.equals(action) ||
Intents.ACTION_NEW_STATUS.equals(action) ||
Intents.ACTION_NEW_DEVICESTATUS.equals(action) ||
Intents.ACTION_NEW_CAL.equals(action) ||
Intents.ACTION_NEW_MBG.equals(action)
) { ) {
handleNewDataFromNSClient(intent); handleNewDataFromNSClient(intent);
NSClientDataReceiver.completeWakefulIntent(intent); NSClientDataReceiver.completeWakefulIntent(intent);
@ -145,6 +152,22 @@ public class DataService extends IntentService {
if (bundles == null) return; if (bundles == null) return;
if (intent.getAction().equals(Intents.ACTION_NEW_STATUS)) {
if (Config.logIncommingData)
log.debug("Received status: " + bundles);
if (bundles.containsKey("nsclientversioncode")) {
ConfigBuilderFragment configBuilderFragment = MainApp.getConfigBuilder();
configBuilderFragment.nightscoutVersionCode = bundles.getInt("nightscoutversioncode"); // for ver 1.2.3 contains 10203
configBuilderFragment.nightscoutVersionName = bundles.getString("nightscoutversionname");
configBuilderFragment.nsClientVersionCode = bundles.getInt("nsclientversioncode"); // for ver 1.17 contains 117
configBuilderFragment.nsClientVersionName = bundles.getString("nsclientversionname");
log.debug("Got versions: NSClient: " + configBuilderFragment.nsClientVersionName + " Nightscout: " + configBuilderFragment.nightscoutVersionName);
if (configBuilderFragment.nsClientVersionCode < 117)
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.resources.getString(R.string.unsupportedclientver));
} else {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.resources.getString(R.string.unsupportedclientver));
}
}
// Handle profile // Handle profile
if (intent.getAction().equals(Intents.ACTION_NEW_PROFILE)) { if (intent.getAction().equals(Intents.ACTION_NEW_PROFILE)) {
try { try {
@ -354,6 +377,9 @@ public class DataService extends IntentService {
} }
MainApp.bus().post(new EventNewBG()); MainApp.bus().post(new EventNewBG());
} }
// Objectives 0
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class);
if (objectivesFragment != null) objectivesFragment.bgIsAvailableInNS = true;
} }
} }

View file

@ -7,6 +7,9 @@ public interface Intents {
String ACTION_REMOVED_TREATMENT = "info.nightscout.client.REMOVED_TREATMENT"; String ACTION_REMOVED_TREATMENT = "info.nightscout.client.REMOVED_TREATMENT";
String ACTION_NEW_PROFILE = "info.nightscout.client.NEW_PROFILE"; String ACTION_NEW_PROFILE = "info.nightscout.client.NEW_PROFILE";
String ACTION_NEW_SGV = "info.nightscout.client.NEW_SGV"; String ACTION_NEW_SGV = "info.nightscout.client.NEW_SGV";
String ACTION_NEW_DEVICESTATUS = "info.nightscout.client.NEW_DEVICESTATUS";
String ACTION_NEW_MBG = "info.nightscout.client.NEW_MBG";
String ACTION_NEW_CAL = "info.nightscout.client.NEW_CAL";
String ACTION_NEW_STATUS = "info.nightscout.client.NEW_STATUS"; String ACTION_NEW_STATUS = "info.nightscout.client.NEW_STATUS";

View file

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -66,6 +67,8 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
ListView apsListView; ListView apsListView;
ListView constraintsListView; ListView constraintsListView;
ListView generalListView; ListView generalListView;
TextView nsclientVerView;
TextView nightscoutVerView;
PluginCustomAdapter bgsourceDataAdapter = null; PluginCustomAdapter bgsourceDataAdapter = null;
PluginCustomAdapter pumpDataAdapter = null; PluginCustomAdapter pumpDataAdapter = null;
@ -85,6 +88,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
TempBasalsInterface activeTempBasals; TempBasalsInterface activeTempBasals;
LoopFragment activeLoop; LoopFragment activeLoop;
public String nightscoutVersionName = "";
public Integer nightscoutVersionCode = 0;
public String nsClientVersionName = "";
public Integer nsClientVersionCode = 0;
ArrayList<PluginBase> pluginList; ArrayList<PluginBase> pluginList;
public ConfigBuilderFragment() { public ConfigBuilderFragment() {
@ -124,7 +132,13 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview); apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview);
constraintsListView = (ListView) view.findViewById(R.id.configbuilder_constraintslistview); constraintsListView = (ListView) view.findViewById(R.id.configbuilder_constraintslistview);
generalListView = (ListView) view.findViewById(R.id.configbuilder_generallistview); generalListView = (ListView) view.findViewById(R.id.configbuilder_generallistview);
nsclientVerView = (TextView) view.findViewById(R.id.configbuilder_nsclientversion);
nightscoutVerView = (TextView) view.findViewById(R.id.configbuilder_nightscoutversion);
nsclientVerView.setText(nsClientVersionName);
nightscoutVerView.setText(nightscoutVersionName);
if (nsClientVersionCode < 117) nsclientVerView.setTextColor(Color.RED);
if (nightscoutVersionCode < 900) nightscoutVerView.setTextColor(Color.RED);
setViews(); setViews();
return view; return view;
} }

View file

@ -99,6 +99,11 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
} }
} }
// Objective 0
public boolean bgIsAvailableInNS = false;
public boolean pumpStatusIsAvailableInNS = false;
private List<Objective> objectives; private List<Objective> objectives;
private void initializeData() { private void initializeData() {

View file

@ -13,6 +13,45 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="NSClient version:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/configbuilder_nsclientversion"
android:layout_marginLeft="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Nightscout version:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/configbuilder_nightscoutversion"
android:layout_marginLeft="10dp" />
</LinearLayout>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View file

@ -149,5 +149,6 @@
<string name="closedloop">Closed Loop</string> <string name="closedloop">Closed Loop</string>
<string name="openloop">Open Loop</string> <string name="openloop">Open Loop</string>
<string name="openloop_newsuggestion">New suggestion available</string> <string name="openloop_newsuggestion">New suggestion available</string>
<string name="unsupportedclientver">Unsupported version of NSClient</string>
</resources> </resources>