age from product flavor to prefs
This commit is contained in:
parent
d9225ccc8a
commit
15d6de4701
12 changed files with 87 additions and 23 deletions
|
@ -57,19 +57,7 @@ android {
|
|||
}
|
||||
}
|
||||
productFlavors {
|
||||
flavorDimensions "standard", "limits", "wear"
|
||||
adult {
|
||||
dimension "limits"
|
||||
buildConfigField "int", "MAXBOLUS", "17"
|
||||
}
|
||||
teenage {
|
||||
dimension "limits"
|
||||
buildConfigField "int", "MAXBOLUS", "10"
|
||||
}
|
||||
child {
|
||||
dimension "limits"
|
||||
buildConfigField "int", "MAXBOLUS", "5"
|
||||
}
|
||||
flavorDimensions "standard", "wear"
|
||||
full {
|
||||
dimension "standard"
|
||||
buildConfigField "boolean", "APS", "true"
|
||||
|
|
|
@ -9,18 +9,18 @@ import android.view.View;
|
|||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
public class AgreementActivity extends Activity {
|
||||
boolean IUnderstand;
|
||||
CheckBox agreeCheckBox;
|
||||
Button saveButton;
|
||||
SharedPreferences prefs;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_agreement);
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
IUnderstand = prefs.getBoolean("I_understand", false);
|
||||
IUnderstand = SP.getBoolean(R.string.key_i_understand, false);
|
||||
setContentView(R.layout.activity_agreement);
|
||||
agreeCheckBox = (CheckBox)findViewById(R.id.agreementCheckBox);
|
||||
agreeCheckBox.setChecked(IUnderstand);
|
||||
|
@ -32,7 +32,7 @@ public class AgreementActivity extends Activity {
|
|||
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||
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);
|
||||
startActivity(intent);
|
||||
|
|
|
@ -198,7 +198,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
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) {
|
||||
Intent intent = new Intent(getApplicationContext(), AgreementActivity.class);
|
||||
startActivity(intent);
|
||||
|
|
|
@ -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) {
|
||||
PreferenceGroup pGrp = (PreferenceGroup) p;
|
||||
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) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.pref_password);
|
||||
addPreferencesFromResource(R.xml.pref_quickwizard);
|
||||
addPreferencesFromResource(R.xml.pref_age);
|
||||
addPreferencesFromResource(R.xml.pref_language);
|
||||
addPreferencesFromResource(R.xml.pref_quickwizard);
|
||||
if (Config.CAREPORTALENABLED)
|
||||
addPreferencesFromResource(R.xml.pref_careportal);
|
||||
addPreferencesFromResource(R.xml.pref_treatments);
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.BuildConfig;
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.utils.HardLimits;
|
||||
|
||||
public class MsgBolusStart extends MessageBase {
|
||||
private static Logger log = LoggerFactory.getLogger(MsgBolusStart.class);
|
||||
|
@ -20,7 +21,7 @@ public class MsgBolusStart extends MessageBase {
|
|||
// HARDCODED LIMIT
|
||||
amount = MainApp.getConfigBuilder().applyBolusConstraints(amount);
|
||||
if (amount < 0) amount = 0d;
|
||||
if (amount > BuildConfig.MAXBOLUS) amount = BuildConfig.MAXBOLUS;
|
||||
if (amount > HardLimits.maxBolus()) amount = HardLimits.maxBolus();
|
||||
|
||||
AddParamInt((int) (amount * 100));
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.BuildConfig;
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.utils.HardLimits;
|
||||
|
||||
public class MsgSetExtendedBolusStart extends MessageBase {
|
||||
private static Logger log = LoggerFactory.getLogger(MsgSetExtendedBolusStart.class);
|
||||
|
@ -22,7 +23,7 @@ public class MsgSetExtendedBolusStart extends MessageBase {
|
|||
if (halfhours > 16) halfhours = 16;
|
||||
amount = MainApp.getConfigBuilder().applyBolusConstraints(amount);
|
||||
if (amount < 0d) amount = 0d;
|
||||
if (amount > BuildConfig.MAXBOLUS) amount = BuildConfig.MAXBOLUS;
|
||||
if (amount > HardLimits.maxBolus()) amount = HardLimits.maxBolus();
|
||||
|
||||
AddParamInt((int) (amount * 100));
|
||||
AddParamByte(halfhours);
|
||||
|
|
|
@ -11,6 +11,7 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||
import info.nightscout.utils.HardLimits;
|
||||
import info.nightscout.utils.Round;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
|
@ -176,7 +177,7 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
|
|||
} catch (Exception e) {
|
||||
insulin = 0d;
|
||||
}
|
||||
if (insulin > BuildConfig.MAXBOLUS) insulin = Double.valueOf(BuildConfig.MAXBOLUS);
|
||||
if (insulin > HardLimits.maxBolus()) insulin = HardLimits.maxBolus();
|
||||
return insulin;
|
||||
}
|
||||
|
||||
|
|
24
app/src/main/java/info/nightscout/utils/HardLimits.java
Normal file
24
app/src/main/java/info/nightscout/utils/HardLimits.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -76,6 +76,12 @@ public class SP {
|
|||
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) {
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString(key, value);
|
||||
|
@ -87,4 +93,10 @@ public class SP {
|
|||
editor.putString(MainApp.sResources.getString(resourceID), value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
static public void removeString(int resourceID) {
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.remove(MainApp.sResources.getString(resourceID));
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,4 +28,16 @@
|
|||
<item>ko</item>
|
||||
<item>el</item>
|
||||
</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>
|
|
@ -544,4 +544,14 @@
|
|||
<string name="notavailable">Not available</string>
|
||||
<string name="key_smscommunicator_allowednumbers" translatable="false">smscommunicator_allowednumbers</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>
|
||||
|
|
13
app/src/main/res/xml/pref_age.xml
Normal file
13
app/src/main/res/xml/pref_age.xml
Normal 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>
|
Loading…
Reference in a new issue