diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index 2cb22a29fd..3e9026331b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -65,12 +65,12 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.circadianpercentageprofile_fragment, container, false); - diaView = (EditText) layout.findViewById(R.id.simpleprofile_dia); - mgdlView = (RadioButton) layout.findViewById(R.id.simpleprofile_mgdl); - mmolView = (RadioButton) layout.findViewById(R.id.simpleprofile_mmol); - carView = (EditText) layout.findViewById(R.id.simpleprofile_car); - targetlowView = (EditText) layout.findViewById(R.id.simpleprofile_targetlow); - targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh); + diaView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_dia); + mgdlView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mgdl); + mmolView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mmol); + carView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_car); + targetlowView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targetlow); + targethighView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targethigh); percentageView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_percentage); timeshiftView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_timeshift); profileView = (TextView) layout.findViewById(R.id.circadianpercentageprofile_profileview); @@ -133,7 +133,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag @Override public void onFocusChange(View view, boolean b) { if(b) - ToastUtils.showToastInUiThread(getContext(), "Time in hours by which the profile will be shifted round robin."); + ToastUtils.showToastInUiThread(getContext(), getString(R.string.timeshift_hint)); } }); @@ -142,7 +142,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag @Override public void onFocusChange(View view, boolean b) { if(b) - ToastUtils.showToastInUiThread(getContext(), "Percentage factor by which the base profile will be multiplied."); + ToastUtils.showToastInUiThread(getContext(), getString(R.string.percentagefactor_hint)); } }); @@ -169,24 +169,24 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag basaleditIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - BasalEditDialog basalEditDialog = new BasalEditDialog(getPlugin().basebasal, "Edit Base-Basal:"); - basalEditDialog.show(getFragmentManager(), "Edit Basal"); + BasalEditDialog basalEditDialog = new BasalEditDialog(getPlugin().basebasal, getString(R.string.edit_base_basal)); + basalEditDialog.show(getFragmentManager(), getString(R.string.edit_base_basal)); } }); isfeditIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - BasalEditDialog basalEditDialog = new BasalEditDialog(getPlugin().baseisf, "Edit Base-ISF:"); - basalEditDialog.show(getFragmentManager(), "Edit ISF"); + BasalEditDialog basalEditDialog = new BasalEditDialog(getPlugin().baseisf, getString(R.string.edit_base_isf)); + basalEditDialog.show(getFragmentManager(), getString(R.string.edit_base_isf)); } }); iceditIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - BasalEditDialog basalEditDialog = new BasalEditDialog(getPlugin().baseic, "Edit Base-IC:"); - basalEditDialog.show(getFragmentManager(), "Edit IC"); + BasalEditDialog basalEditDialog = new BasalEditDialog(getPlugin().baseic, getString(R.string.edit_base_ic)); + basalEditDialog.show(getFragmentManager(), getString(R.string.edit_base_ic)); } }); @@ -234,16 +234,23 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag private void updateProfileInfo() { StringBuilder sb = new StringBuilder(); sb.append("

"); - sb.append("Active Profile:"); + sb.append(getString(R.string.nsprofileview_activeprofile_label)); sb.append("

"); - sb.append("

Basal:

" + circadianPercentageProfilePlugin.basalString()); - sb.append("

IC:

" + circadianPercentageProfilePlugin.icString()); - sb.append("

ISF:

" + circadianPercentageProfilePlugin.isfString()); + sb.append("

"); + sb.append(getString(R.string.nsprofileview_basal_label)); + sb.append("

" + circadianPercentageProfilePlugin.basalString()); + sb.append("

"); + sb.append(getString(R.string.nsprofileview_ic_label)); + sb.append("

" + circadianPercentageProfilePlugin.icString()); + sb.append("

"); + sb.append(getString(R.string.nsprofileview_isf_label)); + sb.append("

" + circadianPercentageProfilePlugin.isfString()); profileView.setText(Html.fromHtml(sb.toString())); - baseprofileBasal.setText(Html.fromHtml("

Base Profile:

Basal:

" + circadianPercentageProfilePlugin.baseBasalString())); - baseprofileIC.setText(Html.fromHtml("

IC:

" + circadianPercentageProfilePlugin.baseIcString())); - baseprofileISF.setText(Html.fromHtml("

ISF:

" + circadianPercentageProfilePlugin.baseIsfString())); + baseprofileBasal.setText(Html.fromHtml("

" + getString(R.string.base_profile_label) + "

" + + "

" + getString(R.string.nsprofileview_basal_label) + "

" + circadianPercentageProfilePlugin.baseBasalString())); + baseprofileIC.setText(Html.fromHtml("

" + getString(R.string.nsprofileview_ic_label) + "

" + circadianPercentageProfilePlugin.baseIcString())); + baseprofileISF.setText(Html.fromHtml("

" + getString(R.string.nsprofileview_isf_label) + "

" + circadianPercentageProfilePlugin.baseIsfString())); } private class BasalEditDialog extends DialogFragment{ @@ -307,7 +314,6 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag } }); - return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java index 671d35c3a9..a3dcc73940 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.client.data.NSProfile; @@ -59,9 +60,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte @Override public String getName() { - // TODO Adrian: stringify! (omitted to prevent merge conflicts) - return "CPP"; - //return MainApp.instance().getString(R.string.simpleprofile); + return MainApp.instance().getString(R.string.circadian_percentage_profile); } @Override @@ -89,7 +88,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte this.fragmentVisible = fragmentVisible; } - public void storeSettings() { + void storeSettings() { if (Config.logPrefsChange) log.debug("Storing settings"); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); @@ -100,11 +99,11 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte editor.putString(SETTINGS_PREFIX + "car", car.toString()); editor.putString(SETTINGS_PREFIX + "targetlow", targetLow.toString()); editor.putString(SETTINGS_PREFIX + "targethigh", targetHigh.toString()); - editor.putString(SETTINGS_PREFIX + "timeshift", timeshift+""); - editor.putString(SETTINGS_PREFIX + "percentage", percentage+""); + editor.putString(SETTINGS_PREFIX + "timeshift", timeshift + ""); + editor.putString(SETTINGS_PREFIX + "percentage", percentage + ""); - for (int i = 0; i<24; i++) { + for (int i = 0; i < 24; i++) { editor.putString(SETTINGS_PREFIX + "basebasal" + i, DecimalFormatter.to2Decimal(basebasal[i])); editor.putString(SETTINGS_PREFIX + "baseisf" + i, DecimalFormatter.to2Decimal(baseisf[i])); editor.putString(SETTINGS_PREFIX + "baseic" + i, DecimalFormatter.to2Decimal(baseic[i])); @@ -113,12 +112,12 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte createConvertedProfile(); } - private void loadSettings() { + void loadSettings() { if (Config.logPrefsChange) log.debug("Loading stored settings"); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); - if (settings.contains(SETTINGS_PREFIX+ "mgdl")) + if (settings.contains(SETTINGS_PREFIX + "mgdl")) try { mgdl = settings.getBoolean(SETTINGS_PREFIX + "mgdl", true); } catch (Exception e) { @@ -176,7 +175,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte } else timeshift = 0; - for (int i = 0; i<24; i++){ + for (int i = 0; i < 24; i++) { try { basebasal[i] = SafeParse.stringToDouble(settings.getString(SETTINGS_PREFIX + "basebasal" + i, DecimalFormatter.to2Decimal(basebasal[i]))); } catch (Exception e) { @@ -197,7 +196,8 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte createConvertedProfile(); } - void createConvertedProfile() { + + private void createConvertedProfile() { JSONObject json = new JSONObject(); JSONObject store = new JSONObject(); JSONObject profile = new JSONObject(); @@ -220,25 +220,25 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte json.put("store", store); profile.put("dia", dia); - int offset = -(timeshift%24) + 24; + int offset = -(timeshift % 24) + 24; JSONArray icArray = new JSONArray(); - for (int i = 0; i<24; i++){ - icArray.put(new JSONObject().put("timeAsSeconds", i*60*60).put("value", baseic[(offset+i)%24]*100d/percentage)); + for (int i = 0; i < 24; i++) { + icArray.put(new JSONObject().put("timeAsSeconds", i * 60 * 60).put("value", baseic[(offset + i) % 24] * 100d / percentage)); } profile.put("carbratio", icArray); profile.put("carbs_hr", car); JSONArray isfArray = new JSONArray(); - for (int i = 0; i<24; i++){ - isfArray.put(new JSONObject().put("timeAsSeconds", i*60*60).put("value", baseisf[(offset+i)%24]*100d/percentage)); + for (int i = 0; i < 24; i++) { + isfArray.put(new JSONObject().put("timeAsSeconds", i * 60 * 60).put("value", baseisf[(offset + i) % 24] * 100d / percentage)); } profile.put("sens", isfArray); JSONArray basalArray = new JSONArray(); - for (int i = 0; i<24; i++){ - basalArray.put(new JSONObject().put("timeAsSeconds", i*60*60).put("value", basebasal[(offset+i)%24]*percentage/100d)); + for (int i = 0; i < 24; i++) { + basalArray.put(new JSONObject().put("timeAsSeconds", i * 60 * 60).put("value", basebasal[(offset + i) % 24] * percentage / 100d)); } profile.put("basal", basalArray); @@ -258,41 +258,47 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte return convertedProfile; } - public String basalString() { + String basalString() { return profileString(basebasal, timeshift, percentage, true); } - public String icString() { + String icString() { return profileString(baseic, timeshift, percentage, false); } - public String isfString() { + String isfString() { return profileString(baseisf, timeshift, percentage, false); } - public String baseIcString() { + String baseIcString() { return profileString(baseic, 0, 100, false); } - public String baseIsfString() { + String baseIsfString() { return profileString(baseisf, 0, 100, false); } - public String baseBasalString() { - return profileString(basebasal, 0, 100, true); - } + String baseBasalString() {return profileString(basebasal, 0, 100, true);} - private static String profileString(double[] values, int timeshift, int percentage, boolean inc){ - timeshift = -(timeshift%24) + 24; + + private static String profileString(double[] values, int timeshift, int percentage, boolean inc) { + timeshift = -(timeshift % 24) + 24; StringBuilder sb = new StringBuilder(); - sb.append(""); sb.append(0); sb.append("h: "); sb.append(""); - sb.append(DecimalFormatter.to2Decimal(values[(timeshift+0)%24]*(inc?percentage/100d:100d/percentage))); - double prevVal = values[(timeshift+0)%24]; + sb.append(""); + sb.append(0); + sb.append("h: "); + sb.append(""); + sb.append(DecimalFormatter.to2Decimal(values[(timeshift + 0) % 24] * (inc ? percentage / 100d : 100d / percentage))); + double prevVal = values[(timeshift + 0) % 24]; for (int i = 1; i < 24; i++) { - if(prevVal != values[(timeshift+i)%24]){ - sb.append(", ");sb.append(""); sb.append(i); sb.append("h: ");sb.append(""); - sb.append(DecimalFormatter.to2Decimal(values[(timeshift+i)%24]*(inc?percentage/100d:100d/percentage))); - prevVal = values[(timeshift+i)%24]; + if (prevVal != values[(timeshift + i) % 24]) { + sb.append(", "); + sb.append(""); + sb.append(i); + sb.append("h: "); + sb.append(""); + sb.append(DecimalFormatter.to2Decimal(values[(timeshift + i) % 24] * (inc ? percentage / 100d : 100d / percentage))); + prevVal = values[(timeshift + i) % 24]; } } return sb.toString(); diff --git a/app/src/main/res/layout/circadianpercentageprofile_editbasal_dialog.xml b/app/src/main/res/layout/circadianpercentageprofile_editbasal_dialog.xml index 90e2000aa8..ac703d6536 100644 --- a/app/src/main/res/layout/circadianpercentageprofile_editbasal_dialog.xml +++ b/app/src/main/res/layout/circadianpercentageprofile_editbasal_dialog.xml @@ -6,7 +6,6 @@ android:orientation="vertical" android:padding="10dp"> - - - + android:orientation="horizontal" + android:padding="10dp">