fix some crashes

This commit is contained in:
Milos Kozak 2016-08-07 13:07:13 +02:00
parent b711648bee
commit ff2e9a82bc
4 changed files with 22 additions and 10 deletions

View file

@ -188,6 +188,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
// PluginBase.APS // PluginBase.APS
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(APSInterface.class); pluginsInCategory = MainApp.getSpecificPluginsListByInterface(APSInterface.class);
activeAPS = (APSInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.APS); activeAPS = (APSInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.APS);
if (activeAPS != null) {
if (Config.logConfigBuilder) if (Config.logConfigBuilder)
log.debug("Selected APS interface: " + ((PluginBase) activeAPS).getName()); log.debug("Selected APS interface: " + ((PluginBase) activeAPS).getName());
for (PluginBase p : pluginsInCategory) { for (PluginBase p : pluginsInCategory) {
@ -195,6 +196,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
p.setFragmentVisible(PluginBase.APS, false); p.setFragmentVisible(PluginBase.APS, false);
} }
} }
}
// PluginBase.PROFILE // PluginBase.PROFILE
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(ProfileInterface.class); pluginsInCategory = MainApp.getSpecificPluginsListByInterface(ProfileInterface.class);

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.utils.SafeParse;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
@ -196,12 +197,12 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
for (int num = 0; num < objectives.size(); num++) { for (int num = 0; num < objectives.size(); num++) {
Objective o = objectives.get(num); Objective o = objectives.get(num);
o.started = new Date(settings.getLong("Objectives" + num + "started", 0)); o.started = new Date(SafeParse.stringToLong(settings.getString("Objectives" + num + "started", "0")));
o.accomplished = new Date(settings.getLong("Objectives" + num + "accomplished", 0)); o.accomplished = new Date(SafeParse.stringToLong(settings.getString("Objectives" + num + "accomplished", "0")));
} }
bgIsAvailableInNS = settings.getBoolean("Objectives" + "bgIsAvailableInNS", false); bgIsAvailableInNS = settings.getBoolean("Objectives" + "bgIsAvailableInNS", false);
pumpStatusIsAvailableInNS = settings.getBoolean("Objectives" + "pumpStatusIsAvailableInNS", false); pumpStatusIsAvailableInNS = settings.getBoolean("Objectives" + "pumpStatusIsAvailableInNS", false);
manualEnacts = settings.getInt("Objectives" + "manualEnacts", 0); manualEnacts = SafeParse.stringToInt(settings.getString("Objectives" + "manualEnacts", "0"));
if (Config.logPrefsChange) if (Config.logPrefsChange)
log.debug("Objectives loaded"); log.debug("Objectives loaded");
} }

View file

@ -23,4 +23,14 @@ public class SafeParse {
} }
return result; return result;
} }
public static Long stringToLong(String input) {
Long result = 0L;
input = input.replace(",", ".");
try {
result = Long.parseLong(input);
} catch (Exception e) {
}
return result;
}
} }

View file

@ -13,8 +13,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Enable fake time and progress" android:text="Enable fake time and progress"
android:id="@+id/objectives_fake" android:id="@+id/objectives_fake" />
android:visibility="gone" />
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/objectives_recyclerview" android:id="@+id/objectives_recyclerview"