Merge pull request #191 from MilosKozak/age

Age to prefs
This commit is contained in:
Milos Kozak 2017-02-22 20:41:02 +01:00 committed by GitHub
commit 16755e1478
12 changed files with 87 additions and 23 deletions

View file

@ -57,19 +57,7 @@ android {
} }
} }
productFlavors { productFlavors {
flavorDimensions "standard", "limits", "wear" flavorDimensions "standard", "wear"
adult {
dimension "limits"
buildConfigField "int", "MAXBOLUS", "17"
}
teenage {
dimension "limits"
buildConfigField "int", "MAXBOLUS", "10"
}
child {
dimension "limits"
buildConfigField "int", "MAXBOLUS", "5"
}
full { full {
dimension "standard" dimension "standard"
buildConfigField "boolean", "APS", "true" buildConfigField "boolean", "APS", "true"

View file

@ -9,18 +9,18 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import info.nightscout.utils.SP;
public class AgreementActivity extends Activity { public class AgreementActivity extends Activity {
boolean IUnderstand; boolean IUnderstand;
CheckBox agreeCheckBox; CheckBox agreeCheckBox;
Button saveButton; Button saveButton;
SharedPreferences prefs;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_agreement); setContentView(R.layout.activity_agreement);
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); IUnderstand = SP.getBoolean(R.string.key_i_understand, false);
IUnderstand = prefs.getBoolean("I_understand", false);
setContentView(R.layout.activity_agreement); setContentView(R.layout.activity_agreement);
agreeCheckBox = (CheckBox)findViewById(R.id.agreementCheckBox); agreeCheckBox = (CheckBox)findViewById(R.id.agreementCheckBox);
agreeCheckBox.setChecked(IUnderstand); agreeCheckBox.setChecked(IUnderstand);
@ -32,7 +32,7 @@ public class AgreementActivity extends Activity {
saveButton.setOnClickListener(new View.OnClickListener() { saveButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
prefs.edit().putBoolean("I_understand", agreeCheckBox.isChecked()).apply(); SP.putBoolean(R.string.key_i_understand, agreeCheckBox.isChecked());
Intent intent = new Intent(getApplicationContext(), MainActivity.class); Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent); startActivity(intent);

View file

@ -198,7 +198,8 @@ public class MainActivity extends AppCompatActivity {
} }
private void checkEula() { private void checkEula() {
boolean IUnderstand = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("I_understand", false); //SP.removeBoolean(R.string.key_i_understand);
boolean IUnderstand = SP.getBoolean(R.string.key_i_understand, false);
if (!IUnderstand) { if (!IUnderstand) {
Intent intent = new Intent(getApplicationContext(), AgreementActivity.class); Intent intent = new Intent(getApplicationContext(), AgreementActivity.class);
startActivity(intent); startActivity(intent);

View file

@ -70,7 +70,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
} }
} }
private static void initSummary(Preference p) { public static void initSummary(Preference p) {
if (p instanceof PreferenceGroup) { if (p instanceof PreferenceGroup) {
PreferenceGroup pGrp = (PreferenceGroup) p; PreferenceGroup pGrp = (PreferenceGroup) p;
for (int i = 0; i < pGrp.getPreferenceCount(); i++) { for (int i = 0; i < pGrp.getPreferenceCount(); i++) {
@ -86,8 +86,9 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_password); addPreferencesFromResource(R.xml.pref_password);
addPreferencesFromResource(R.xml.pref_quickwizard); addPreferencesFromResource(R.xml.pref_age);
addPreferencesFromResource(R.xml.pref_language); addPreferencesFromResource(R.xml.pref_language);
addPreferencesFromResource(R.xml.pref_quickwizard);
if (Config.CAREPORTALENABLED) if (Config.CAREPORTALENABLED)
addPreferencesFromResource(R.xml.pref_careportal); addPreferencesFromResource(R.xml.pref_careportal);
addPreferencesFromResource(R.xml.pref_treatments); addPreferencesFromResource(R.xml.pref_treatments);

View file

@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.utils.HardLimits;
public class MsgBolusStart extends MessageBase { public class MsgBolusStart extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgBolusStart.class); private static Logger log = LoggerFactory.getLogger(MsgBolusStart.class);
@ -20,7 +21,7 @@ public class MsgBolusStart extends MessageBase {
// HARDCODED LIMIT // HARDCODED LIMIT
amount = MainApp.getConfigBuilder().applyBolusConstraints(amount); amount = MainApp.getConfigBuilder().applyBolusConstraints(amount);
if (amount < 0) amount = 0d; if (amount < 0) amount = 0d;
if (amount > BuildConfig.MAXBOLUS) amount = BuildConfig.MAXBOLUS; if (amount > HardLimits.maxBolus()) amount = HardLimits.maxBolus();
AddParamInt((int) (amount * 100)); AddParamInt((int) (amount * 100));

View file

@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.utils.HardLimits;
public class MsgSetExtendedBolusStart extends MessageBase { public class MsgSetExtendedBolusStart extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSetExtendedBolusStart.class); private static Logger log = LoggerFactory.getLogger(MsgSetExtendedBolusStart.class);
@ -22,7 +23,7 @@ public class MsgSetExtendedBolusStart extends MessageBase {
if (halfhours > 16) halfhours = 16; if (halfhours > 16) halfhours = 16;
amount = MainApp.getConfigBuilder().applyBolusConstraints(amount); amount = MainApp.getConfigBuilder().applyBolusConstraints(amount);
if (amount < 0d) amount = 0d; if (amount < 0d) amount = 0d;
if (amount > BuildConfig.MAXBOLUS) amount = BuildConfig.MAXBOLUS; if (amount > HardLimits.maxBolus()) amount = HardLimits.maxBolus();
AddParamInt((int) (amount * 100)); AddParamInt((int) (amount * 100));
AddParamByte(halfhours); AddParamByte(halfhours);

View file

@ -11,6 +11,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.NSClientInternal.data.NSProfile; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.HardLimits;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -176,7 +177,7 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
} catch (Exception e) { } catch (Exception e) {
insulin = 0d; insulin = 0d;
} }
if (insulin > BuildConfig.MAXBOLUS) insulin = Double.valueOf(BuildConfig.MAXBOLUS); if (insulin > HardLimits.maxBolus()) insulin = HardLimits.maxBolus();
return insulin; return insulin;
} }

View file

@ -0,0 +1,24 @@
package info.nightscout.utils;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
/**
* Created by mike on 22.02.2017.
*/
public class HardLimits {
final static double MAXBOLUS_ADULT = 17d;
final static double MAXBOLUS_TEENAGE = 10d;
final static double MAXBOLUS_CHILD = 5d;
public static double maxBolus() {
String age = SP.getString(R.string.key_age, "");
if (age.equals(MainApp.sResources.getString(R.string.key_adult))) return MAXBOLUS_ADULT;
if (age.equals(MainApp.sResources.getString(R.string.key_teenage))) return MAXBOLUS_TEENAGE;
if (age.equals(MainApp.sResources.getString(R.string.key_child))) return MAXBOLUS_CHILD;
return MAXBOLUS_ADULT;
}
}

View file

@ -76,6 +76,12 @@ public class SP {
editor.apply(); editor.apply();
} }
static public void removeBoolean(int resourceID) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(MainApp.sResources.getString(resourceID));
editor.apply();
}
static public void putString(String key, String value) { static public void putString(String key, String value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value); editor.putString(key, value);
@ -87,4 +93,10 @@ public class SP {
editor.putString(MainApp.sResources.getString(resourceID), value); editor.putString(MainApp.sResources.getString(resourceID), value);
editor.apply(); editor.apply();
} }
static public void removeString(int resourceID) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(MainApp.sResources.getString(resourceID));
editor.apply();
}
} }

View file

@ -28,4 +28,16 @@
<item>ko</item> <item>ko</item>
<item>el</item> <item>el</item>
</string-array> </string-array>
<string-array name="ageArray">
<item>@string/child</item>
<item>@string/teenage</item>
<item>@string/adult</item>
</string-array>
<string-array name="ageValues" translatable="false">
<item>@string/key_child</item>
<item>@string/key_teenage</item>
<item>@string/key_adult</item>
</string-array>
</resources> </resources>

View file

@ -544,4 +544,14 @@
<string name="notavailable">Not available</string> <string name="notavailable">Not available</string>
<string name="key_smscommunicator_allowednumbers" translatable="false">smscommunicator_allowednumbers</string> <string name="key_smscommunicator_allowednumbers" translatable="false">smscommunicator_allowednumbers</string>
<string name="key_smscommunicator_remotecommandsallowed" translatable="false">smscommunicator_remotecommandsallowed</string> <string name="key_smscommunicator_remotecommandsallowed" translatable="false">smscommunicator_remotecommandsallowed</string>
<string name="patientage">Patient age</string>
<string name="child">Child</string>
<string name="teenage">Teenage</string>
<string name="adult">Adult</string>
<string name="key_age" translatable="false">age</string>
<string name="key_child" translatable="false">child</string>
<string name="key_teenage" translatable="false">teenage</string>
<string name="key_adult" translatable="false">adult</string>
<string name="patientage_summary">Please select patient age to setup safety limits</string>
<string name="key_i_understand">I_understand</string>
</resources> </resources>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/patientage">
<ListPreference
android:defaultValue="adult"
android:entries="@array/ageArray"
android:entryValues="@array/ageValues"
android:key="@string/key_age"
android:summary="@string/patientage_summary"
android:title="@string/patientage" />
</PreferenceCategory>
</PreferenceScreen>