Wear: add pref sync maxCarbs maxBolus

This commit is contained in:
Andries Smit 2022-01-24 20:59:32 +01:00
parent 2013332d70
commit eda1c097a9
8 changed files with 50 additions and 13 deletions

View file

@ -732,13 +732,16 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
boolean wearcontrol = sp.getBoolean(R.string.key_wear_control, false);
boolean mgdl = units.equals(GlucoseUnit.MGDL);
int percentage = sp.getInt(R.string.key_boluswizard_percentage, 100);
int maxCarbs = sp.getInt(R.string.key_treatmentssafety_maxcarbs, 48);
double maxBolus = sp.getDouble(R.string.key_treatmentssafety_maxbolus, 3.0);
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_PREFERENCES_PATH);
//unique content
dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis());
dataMapRequest.getDataMap().putBoolean(rh.gs(R.string.key_wear_control), wearcontrol);
dataMapRequest.getDataMap().putBoolean(rh.gs(R.string.key_units_mgdl), mgdl);
dataMapRequest.getDataMap().putInt(rh.gs(R.string.key_boluswizard_percentage), percentage);
dataMapRequest.getDataMap().putInt(rh.gs(R.string.key_treatmentssafety_maxcarbs), maxCarbs);
dataMapRequest.getDataMap().putDouble(rh.gs(R.string.key_treatmentssafety_maxbolus),maxBolus);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {

View file

@ -362,6 +362,19 @@ public class ListenerService extends WearableListenerService implements GoogleAp
editor.putBoolean(keyUnits, mgdl);
editor.apply();
}
String keyMaxCarbs = getString(R.string.key_treatmentssafety_maxcarbs);
if (dataMap.containsKey(keyMaxCarbs)) {
int maxCarbs = dataMap.getInt(keyMaxCarbs, 48);
editor.putInt(keyMaxCarbs, maxCarbs);
editor.apply();
}
String keyMaxBolus = getString(R.string.key_treatmentssafety_maxbolus);
if (dataMap.containsKey(keyMaxBolus)) {
float maxBolus = (float)dataMap.getDouble(keyMaxBolus, 3.0f);
editor.putFloat(keyMaxBolus, maxBolus);
editor.apply();
}
} else if (path.equals(QUICK_WIZARD_PATH)) {
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
Log.i(TAG, "onDataChanged: QUICK_WIZARD_PATH" + dataMap);

View file

@ -1,6 +1,8 @@
package info.nightscout.androidaps.interaction.actions;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.wearable.view.GridPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
@ -17,11 +19,14 @@ import info.nightscout.shared.SafeParse;
public class BolusActivity extends ViewSelectorActivity {
PlusMinusEditText editInsulin;
float maxBolus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setAdapter(new MyGridViewPagerAdapter());
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
maxBolus = sp.getFloat(getString(R.string.key_treatmentssafety_maxbolus), 3f);
}
@Override
@ -50,7 +55,7 @@ public class BolusActivity extends ViewSelectorActivity {
if (editInsulin != null) {
def = SafeParse.stringToDouble(editInsulin.editText.getText().toString());
}
editInsulin = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 30d, 0.1d, new DecimalFormat("#0.0"), false);
editInsulin = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, (double)maxBolus, 0.1d, new DecimalFormat("#0.0"),false);
setLabelToPlusMinusView(view, getString(R.string.action_insulin));
container.addView(view);
view.requestFocus();

View file

@ -1,6 +1,8 @@
package info.nightscout.androidaps.interaction.actions;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.wearable.view.GridPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
@ -23,11 +25,14 @@ public class ECarbActivity extends ViewSelectorActivity {
PlusMinusEditText editCarbs;
PlusMinusEditText editStartTime;
PlusMinusEditText editDuration;
int maxCarbs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setAdapter(new MyGridViewPagerAdapter());
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
maxCarbs = sp.getInt(getString(R.string.key_treatmentssafety_maxcarbs), 48);
}
@Override
@ -56,7 +61,7 @@ public class ECarbActivity extends ViewSelectorActivity {
if (editCarbs != null) {
def = SafeParse.stringToDouble(editCarbs.editText.getText().toString());
}
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 150d, 1d, new DecimalFormat("0"), true);
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, (double)maxCarbs, 1d, new DecimalFormat("0"), true);
setLabelToPlusMinusView(view, getString(R.string.action_carbs));
container.addView(view);
view.requestFocus();

View file

@ -1,6 +1,8 @@
package info.nightscout.androidaps.interaction.actions;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.wearable.view.GridPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
@ -22,11 +24,16 @@ public class TreatmentActivity extends ViewSelectorActivity {
PlusMinusEditText editCarbs;
PlusMinusEditText editInsulin;
int maxCarbs;
float maxBolus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setAdapter(new MyGridViewPagerAdapter());
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
maxCarbs = sp.getInt(getString(R.string.key_treatmentssafety_maxcarbs), 48);
maxBolus = sp.getFloat(getString(R.string.key_treatmentssafety_maxbolus), 3f);
}
@Override
@ -56,7 +63,7 @@ public class TreatmentActivity extends ViewSelectorActivity {
if (editInsulin != null) {
def = SafeParse.stringToDouble(editInsulin.editText.getText().toString());
}
editInsulin = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 30d, 0.1d, new DecimalFormat("#0.0"), false);
editInsulin = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, (double) maxBolus, 0.1d, new DecimalFormat("#0.0"),false);
setLabelToPlusMinusView(view, getString(R.string.action_insulin));
container.addView(view);
view.requestFocus();
@ -67,7 +74,7 @@ public class TreatmentActivity extends ViewSelectorActivity {
if (editCarbs != null) {
def = SafeParse.stringToDouble(editCarbs.editText.getText().toString());
}
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 150d, 1d, new DecimalFormat("0"), false);
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, (double)maxCarbs, 1d, new DecimalFormat("0"),false);
setLabelToPlusMinusView(view, getString(R.string.action_carbs));
container.addView(view);
return view;

View file

@ -27,6 +27,7 @@ public class WizardActivity extends ViewSelectorActivity {
boolean hasPercentage;
int percentage;
int maxCarbs;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -35,6 +36,7 @@ public class WizardActivity extends ViewSelectorActivity {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
hasPercentage = sp.getBoolean("wizardpercentage", false);
percentage = sp.getInt(getString(R.string.key_boluswizard_percentage), 100);
maxCarbs = sp.getInt(getString(R.string.key_treatmentssafety_maxcarbs), 48);
}
@Override
@ -60,10 +62,10 @@ public class WizardActivity extends ViewSelectorActivity {
if (col == 0) {
final View view = getInflatedPlusMinusView(container);
if (editCarbs == null) {
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 0d, 0d, 150d, 1d, new DecimalFormat("0"), false);
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 0d, 0d, (double)maxCarbs, 1d, new DecimalFormat("0"), false);
} else {
double def = SafeParse.stringToDouble(editCarbs.editText.getText().toString());
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 150d, 1d, new DecimalFormat("0"), false);
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, (double)maxCarbs, 1d, new DecimalFormat("0"),false);
}
setLabelToPlusMinusView(view, getString(R.string.action_carbs));
container.addView(view);

View file

@ -32,7 +32,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
Double minValue = 0d;
Double maxValue = 1d;
Double step = 1d;
NumberFormat formater;
NumberFormat formatter;
boolean allowZero = false;
boolean roundRobin;
@ -74,11 +74,11 @@ public class PlusMinusEditText implements View.OnKeyListener,
private static final int MSG_INC = 0;
private static final int MSG_DEC = 1;
public PlusMinusEditText(View view, int editTextID, int plusID, int minusID, Double initValue, Double minValue, Double maxValue, Double step, NumberFormat formater, boolean allowZero) {
this(view, editTextID, plusID, minusID, initValue, minValue, maxValue, step, formater, allowZero, false);
public PlusMinusEditText(View view, int editTextID, int plusID, int minusID, Double initValue, Double minValue, Double maxValue, Double step, NumberFormat formatter, boolean allowZero) {
this(view, editTextID, plusID, minusID, initValue, minValue, maxValue, step, formatter, allowZero, false);
}
public PlusMinusEditText(View view, int editTextID, int plusID, int minusID, Double initValue, Double minValue, Double maxValue, Double step, NumberFormat formater, boolean allowZero, boolean roundRobin) {
public PlusMinusEditText(View view, int editTextID, int plusID, int minusID, Double initValue, Double minValue, Double maxValue, Double step, NumberFormat formatter, boolean allowZero, boolean roundRobin) {
editText = view.findViewById(editTextID);
minusImage = view.findViewById(minusID);
plusImage = view.findViewById(plusID);
@ -87,7 +87,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
this.minValue = minValue;
this.maxValue = maxValue;
this.step = step;
this.formater = formater;
this.formatter = formatter;
this.allowZero = allowZero;
this.roundRobin = roundRobin;
@ -159,7 +159,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
if (value == 0d && !allowZero)
editText.setText("");
else
editText.setText(formater.format(value));
editText.setText(formatter.format(value));
}
private void startUpdating(boolean inc) {

View file

@ -172,6 +172,8 @@
<string name="key_wear_control" translatable="false">wearcontrol</string>
<string name="key_units_mgdl" translatable="false">units_mgdl</string>
<string name="key_boluswizard_percentage" translatable="false">boluswizard_percentage</string>
<string name="key_treatmentssafety_maxcarbs" translatable="false">treatmentssafety_maxcarbs</string>
<string name="key_treatmentssafety_maxbolus" translatable="false">treatmentssafety_maxbolus</string>
<string name="simple_ui_off">Off</string>
<string name="simple_ui_charging">During Charging</string>
<string name="simple_ui_always_on">Always On Mode</string>