Wear: send units wiz % preference to watch

This commit is contained in:
Andries Smit 2022-01-15 14:44:13 +01:00
parent b5e338423a
commit baf0784df8
6 changed files with 33 additions and 22 deletions

View file

@ -720,16 +720,21 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
private void sendPreferences() {
if (googleApiClient != null && googleApiClient.isConnected()) {
GlucoseUnit units = profileFunction.getUnits();
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);
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);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
Log.e("SendStatus", "No connection to wearable available!");
Log.e("SendPreferences", "No connection to wearable available!");
}
}

View file

@ -27,6 +27,7 @@
<string name="key_virtualpump_type" translatable="false">virtualpump_type</string>
<string name="key_quickwizard" translatable="false">QuickWizard</string>
<string name="key_wear_control" translatable="false">wearcontrol</string>
<string name="key_units_mgdl" translatable="false">units_mgdl</string>
<string name="key_show_notes_entry_dialogs" translatable="false">show_notes_entry_dialogs</string>
<string name="key_openapsama_autosens_max" translatable="false">autosens_max</string>
<string name="key_openapsama_autosens_min" translatable="false">autosens_min</string>

View file

@ -544,14 +544,27 @@ public class ListenerService extends WearableListenerService implements GoogleAp
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
} else if (path.equals(NEW_PREFERENCES_PATH)) {
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
if (dataMap.containsKey("wearcontrol")) {
boolean wearcontrol = dataMap.getBoolean("wearcontrol", false);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("wearcontrol", wearcontrol);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
String keyControl = getString(R.string.key_wear_control);
if (dataMap.containsKey(keyControl)) {
boolean wearControl = dataMap.getBoolean(keyControl, false);
editor.putBoolean(keyControl, wearControl);
editor.apply();
updateTiles();
}
String keyPercentage = getString(R.string.key_boluswizard_percentage);
if (dataMap.containsKey(keyPercentage)) {
int wpercentage = dataMap.getInt(keyPercentage, 100);
editor.putInt(keyPercentage, wpercentage);
editor.apply();
}
String keyUnits = getString(R.string.key_units_mgdl);
if (dataMap.containsKey(keyUnits)) {
boolean mgdl = dataMap.getBoolean(keyUnits, true);
editor.putBoolean(keyUnits, mgdl);
editor.apply();
}
} else if (path.equals(NEW_CHANGECONFIRMATIONREQUEST_PATH)) {
String title = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("title");
String message = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("message");

View file

@ -26,6 +26,7 @@ public class WizardActivity extends ViewSelectorActivity {
PlusMinusEditText editPercentage;
boolean hasPercentage;
double percentage;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -33,6 +34,7 @@ public class WizardActivity extends ViewSelectorActivity {
setAdapter(new MyGridViewPagerAdapter());
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
hasPercentage = sp.getBoolean("wizardpercentage", false);
percentage = sp.getInt(getString(R.string.key_boluswizard_percentage), 100);
}
@Override
@ -70,7 +72,7 @@ public class WizardActivity extends ViewSelectorActivity {
} else if (col == 1 && hasPercentage) {
final View view = getInflatedPlusMinusView(container);
if (editPercentage == null) {
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 100d, 50d, 150d, 1d, new DecimalFormat("0"), false);
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, percentage, 50d, 150d, 1d, new DecimalFormat("0"), false);
} else {
double def = SafeParse.stringToDouble(editPercentage.editText.getText().toString());
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 50d, 150d, 1d, new DecimalFormat("0"), false);
@ -83,13 +85,9 @@ public class WizardActivity extends ViewSelectorActivity {
final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false);
final ImageView confirmbutton = view.findViewById(R.id.confirmbutton);
confirmbutton.setOnClickListener((View v) -> {
// check if it can happen that the fragment is never created that hold data?
// (you have to swipe past them anyways - but still)
int percentage = 100;
if (editPercentage != null)
if (editPercentage != null) {
percentage = SafeParse.stringToInt(editPercentage.editText.getText().toString());
}
String actionstring = "wizard2 " + SafeParse.stringToInt(editCarbs.editText.getText().toString())
+ " " + percentage;

View file

@ -166,6 +166,9 @@
<string name="bolus_progress_channel_description">Bolus progress and cancel</string>
<string name="bolus_progress_silent_channel_description">Bolus progress and cancel with less vibrations</string>
<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="simple_ui_off">Off</string>
<string name="simple_ui_charging">During Charging</string>
<string name="simple_ui_always_on">Always On Mode</string>

View file

@ -101,15 +101,6 @@
android:summary="Chart Timeframe"
android:title="@string/pref_chart_timeframe" />
<CheckBoxPreference
android:defaultValue="true"
android:key="units_mgdl"
android:summaryOff="mmol/l"
android:summaryOn="mg/dl"
android:title="@string/pref_units_for_actions"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<ListPreference
android:defaultValue="1"
android:entries="@array/input_design"