Local Profile
This commit is contained in:
parent
6b18336fa2
commit
38a9c94258
7 changed files with 283 additions and 97 deletions
|
@ -11,6 +11,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
@ -18,14 +19,16 @@ import com.squareup.otto.Subscribe;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.interfaces.FragmentBase;
|
import info.nightscout.androidaps.interfaces.FragmentBase;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.SimpleProfile.SimpleProfilePlugin;
|
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
import info.nightscout.utils.TimeListEdit;
|
||||||
|
|
||||||
public class LocalProfileFragment extends Fragment implements FragmentBase {
|
public class LocalProfileFragment extends Fragment implements FragmentBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(LocalProfileFragment.class);
|
private static Logger log = LoggerFactory.getLogger(LocalProfileFragment.class);
|
||||||
|
@ -39,40 +42,40 @@ public class LocalProfileFragment extends Fragment implements FragmentBase {
|
||||||
EditText diaView;
|
EditText diaView;
|
||||||
RadioButton mgdlView;
|
RadioButton mgdlView;
|
||||||
RadioButton mmolView;
|
RadioButton mmolView;
|
||||||
EditText icView;
|
TimeListEdit icView;
|
||||||
EditText isfView;
|
TimeListEdit isfView;
|
||||||
EditText carView;
|
EditText carView;
|
||||||
EditText basalView;
|
TimeListEdit basalView;
|
||||||
EditText targetlowView;
|
TimeListEdit targetView;
|
||||||
EditText targethighView;
|
|
||||||
Button profileswitchButton;
|
Button profileswitchButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View layout = inflater.inflate(R.layout.simpleprofile_fragment, container, false);
|
Runnable save = new Runnable() {
|
||||||
diaView = (EditText) layout.findViewById(R.id.simpleprofile_dia);
|
@Override
|
||||||
mgdlView = (RadioButton) layout.findViewById(R.id.simpleprofile_mgdl);
|
public void run() {
|
||||||
mmolView = (RadioButton) layout.findViewById(R.id.simpleprofile_mmol);
|
localProfilePlugin.storeSettings();
|
||||||
icView = (EditText) layout.findViewById(R.id.simpleprofile_ic);
|
}
|
||||||
isfView = (EditText) layout.findViewById(R.id.simpleprofile_isf);
|
};
|
||||||
carView = (EditText) layout.findViewById(R.id.simpleprofile_car);
|
|
||||||
basalView = (EditText) layout.findViewById(R.id.simpleprofile_basalrate);
|
View layout = inflater.inflate(R.layout.localprofile_fragment, container, false);
|
||||||
targetlowView = (EditText) layout.findViewById(R.id.simpleprofile_targetlow);
|
diaView = (EditText) layout.findViewById(R.id.localprofile_dia);
|
||||||
targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh);
|
mgdlView = (RadioButton) layout.findViewById(R.id.localprofile_mgdl);
|
||||||
profileswitchButton = (Button) layout.findViewById(R.id.simpleprofile_profileswitch);
|
mmolView = (RadioButton) layout.findViewById(R.id.localprofile_mmol);
|
||||||
|
icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.sResources.getString(R.string.nsprofileview_ic_label), getPlugin().ic, null, new DecimalFormat("0.0"), save);
|
||||||
|
isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.sResources.getString(R.string.nsprofileview_isf_label), getPlugin().isf, null, new DecimalFormat("0.0"), save);
|
||||||
|
carView = (EditText) layout.findViewById(R.id.localprofile_car);
|
||||||
|
basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label), getPlugin().basal, null, new DecimalFormat("0.00"), save);
|
||||||
|
targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label), getPlugin().targetLow, getPlugin().targetHigh, new DecimalFormat("0.0"), save);
|
||||||
|
profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch);
|
||||||
|
|
||||||
onStatusEvent(null);
|
onStatusEvent(null);
|
||||||
|
|
||||||
mgdlView.setChecked(localProfilePlugin.mgdl);
|
mgdlView.setChecked(localProfilePlugin.mgdl);
|
||||||
mmolView.setChecked(localProfilePlugin.mmol);
|
mmolView.setChecked(localProfilePlugin.mmol);
|
||||||
diaView.setText(localProfilePlugin.dia.toString());
|
diaView.setText(localProfilePlugin.dia.toString());
|
||||||
icView.setText(localProfilePlugin.ic.toString());
|
|
||||||
isfView.setText(localProfilePlugin.isf.toString());
|
|
||||||
carView.setText(localProfilePlugin.car.toString());
|
carView.setText(localProfilePlugin.car.toString());
|
||||||
basalView.setText(localProfilePlugin.basal.toString());
|
|
||||||
targetlowView.setText(localProfilePlugin.targetLow.toString());
|
|
||||||
targethighView.setText(localProfilePlugin.targetHigh.toString());
|
|
||||||
|
|
||||||
mgdlView.setOnClickListener(new View.OnClickListener() {
|
mgdlView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -119,23 +122,13 @@ public class LocalProfileFragment extends Fragment implements FragmentBase {
|
||||||
public void onTextChanged(CharSequence s, int start,
|
public void onTextChanged(CharSequence s, int start,
|
||||||
int before, int count) {
|
int before, int count) {
|
||||||
localProfilePlugin.dia = SafeParse.stringToDouble(diaView.getText().toString());
|
localProfilePlugin.dia = SafeParse.stringToDouble(diaView.getText().toString());
|
||||||
localProfilePlugin.ic = SafeParse.stringToDouble(icView.getText().toString());
|
|
||||||
localProfilePlugin.isf = SafeParse.stringToDouble(isfView.getText().toString());
|
|
||||||
localProfilePlugin.car = SafeParse.stringToDouble(carView.getText().toString());
|
localProfilePlugin.car = SafeParse.stringToDouble(carView.getText().toString());
|
||||||
localProfilePlugin.basal = SafeParse.stringToDouble(basalView.getText().toString());
|
|
||||||
localProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString());
|
|
||||||
localProfilePlugin.targetHigh = SafeParse.stringToDouble(targethighView.getText().toString());
|
|
||||||
localProfilePlugin.storeSettings();
|
localProfilePlugin.storeSettings();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
diaView.addTextChangedListener(textWatch);
|
diaView.addTextChangedListener(textWatch);
|
||||||
icView.addTextChangedListener(textWatch);
|
|
||||||
isfView.addTextChangedListener(textWatch);
|
|
||||||
carView.addTextChangedListener(textWatch);
|
carView.addTextChangedListener(textWatch);
|
||||||
basalView.addTextChangedListener(textWatch);
|
|
||||||
targetlowView.addTextChangedListener(textWatch);
|
|
||||||
targethighView.addTextChangedListener(textWatch);
|
|
||||||
|
|
||||||
onStatusEvent(null);
|
onStatusEvent(null);
|
||||||
|
|
||||||
|
|
|
@ -30,15 +30,17 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
|
||||||
|
|
||||||
private static NSProfile convertedProfile = null;
|
private static NSProfile convertedProfile = null;
|
||||||
|
|
||||||
|
final private String DEFAULTARRAY = "[{\"timeAsSeconds\":0,\"value\":0}]";
|
||||||
|
|
||||||
boolean mgdl;
|
boolean mgdl;
|
||||||
boolean mmol;
|
boolean mmol;
|
||||||
Double dia;
|
Double dia;
|
||||||
Double ic;
|
JSONArray ic;
|
||||||
Double isf;
|
JSONArray isf;
|
||||||
Double car;
|
Double car;
|
||||||
Double basal;
|
JSONArray basal;
|
||||||
Double targetLow;
|
JSONArray targetLow;
|
||||||
Double targetHigh;
|
JSONArray targetHigh;
|
||||||
|
|
||||||
public LocalProfilePlugin() {
|
public LocalProfilePlugin() {
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
@ -89,15 +91,15 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
|
||||||
log.debug("Storing settings");
|
log.debug("Storing settings");
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
editor.putBoolean("SimpleProfile" + "mmol", mmol);
|
editor.putBoolean("LocalProfile" + "mmol", mmol);
|
||||||
editor.putBoolean("SimpleProfile" + "mgdl", mgdl);
|
editor.putBoolean("LocalProfile" + "mgdl", mgdl);
|
||||||
editor.putString("SimpleProfile" + "dia", dia.toString());
|
editor.putString("LocalProfile" + "dia", dia.toString());
|
||||||
editor.putString("SimpleProfile" + "ic", ic.toString());
|
editor.putString("LocalProfile" + "ic", ic.toString());
|
||||||
editor.putString("SimpleProfile" + "isf", isf.toString());
|
editor.putString("LocalProfile" + "isf", isf.toString());
|
||||||
editor.putString("SimpleProfile" + "car", car.toString());
|
editor.putString("LocalProfile" + "car", car.toString());
|
||||||
editor.putString("SimpleProfile" + "basal", basal.toString());
|
editor.putString("LocalProfile" + "basal", basal.toString());
|
||||||
editor.putString("SimpleProfile" + "targetlow", targetLow.toString());
|
editor.putString("LocalProfile" + "targetlow", targetLow.toString());
|
||||||
editor.putString("SimpleProfile" + "targethigh", targetHigh.toString());
|
editor.putString("LocalProfile" + "targethigh", targetHigh.toString());
|
||||||
|
|
||||||
editor.commit();
|
editor.commit();
|
||||||
createConvertedProfile();
|
createConvertedProfile();
|
||||||
|
@ -108,69 +110,124 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
|
||||||
log.debug("Loading stored settings");
|
log.debug("Loading stored settings");
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||||
|
|
||||||
if (settings.contains("SimpleProfile" + "mgdl"))
|
if (settings.contains("LocalProfile" + "mgdl"))
|
||||||
try {
|
try {
|
||||||
mgdl = settings.getBoolean("SimpleProfile" + "mgdl", true);
|
mgdl = settings.getBoolean("LocalProfile" + "mgdl", false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
}
|
}
|
||||||
else mgdl = true;
|
else mgdl = false;
|
||||||
if (settings.contains("SimpleProfile" + "mmol"))
|
if (settings.contains("LocalProfile" + "mmol"))
|
||||||
try {
|
try {
|
||||||
mmol = settings.getBoolean("SimpleProfile" + "mmol", false);
|
mmol = settings.getBoolean("LocalProfile" + "mmol", true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
}
|
}
|
||||||
else mmol = false;
|
else mmol = true;
|
||||||
if (settings.contains("SimpleProfile" + "dia"))
|
if (settings.contains("LocalProfile" + "dia"))
|
||||||
try {
|
try {
|
||||||
dia = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "dia", "3"));
|
dia = SafeParse.stringToDouble(settings.getString("LocalProfile" + "dia", "3"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
}
|
}
|
||||||
else dia = 3d;
|
else dia = 3d;
|
||||||
if (settings.contains("SimpleProfile" + "ic"))
|
if (settings.contains("LocalProfile" + "ic"))
|
||||||
try {
|
try {
|
||||||
ic = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "ic", "20"));
|
ic = new JSONArray(settings.getString("LocalProfile" + "ic", DEFAULTARRAY));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
|
try {
|
||||||
|
ic = new JSONArray(DEFAULTARRAY);
|
||||||
|
} catch (JSONException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else ic = 20d;
|
else {
|
||||||
if (settings.contains("SimpleProfile" + "isf"))
|
|
||||||
try {
|
try {
|
||||||
isf = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "isf", "200"));
|
ic = new JSONArray(DEFAULTARRAY);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (settings.contains("LocalProfile" + "isf"))
|
||||||
|
try {
|
||||||
|
isf = new JSONArray(settings.getString("LocalProfile" + "isf", DEFAULTARRAY));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
|
try {
|
||||||
|
isf = new JSONArray(DEFAULTARRAY);
|
||||||
|
} catch (JSONException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else isf = 200d;
|
else {
|
||||||
if (settings.contains("SimpleProfile" + "car"))
|
|
||||||
try {
|
try {
|
||||||
car = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "car", "20"));
|
isf = new JSONArray(DEFAULTARRAY);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (settings.contains("LocalProfile" + "car"))
|
||||||
|
try {
|
||||||
|
car = SafeParse.stringToDouble(settings.getString("LocalProfile" + "car", "20"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
}
|
}
|
||||||
else car = 20d;
|
else car = 20d;
|
||||||
if (settings.contains("SimpleProfile" + "basal"))
|
if (settings.contains("LocalProfile" + "basal"))
|
||||||
try {
|
try {
|
||||||
basal = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "basal", "1"));
|
basal = new JSONArray(settings.getString("LocalProfile" + "basal", DEFAULTARRAY));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
|
try {
|
||||||
|
basal = new JSONArray(DEFAULTARRAY);
|
||||||
|
} catch (JSONException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else basal = 1d;
|
else {
|
||||||
if (settings.contains("SimpleProfile" + "targetlow"))
|
|
||||||
try {
|
try {
|
||||||
targetLow = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "targetlow", "80"));
|
basal = new JSONArray(DEFAULTARRAY);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (settings.contains("LocalProfile" + "targetlow"))
|
||||||
|
try {
|
||||||
|
targetLow = new JSONArray(settings.getString("LocalProfile" + "targetlow", DEFAULTARRAY));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
|
try {
|
||||||
|
targetLow = new JSONArray(DEFAULTARRAY);
|
||||||
|
} catch (JSONException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else targetLow = 80d;
|
else {
|
||||||
if (settings.contains("SimpleProfile" + "targethigh"))
|
|
||||||
try {
|
try {
|
||||||
targetHigh = SafeParse.stringToDouble(settings.getString("SimpleProfile" + "targethigh", "120"));
|
targetLow = new JSONArray(DEFAULTARRAY);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (settings.contains("LocalProfile" + "targethigh"))
|
||||||
|
try {
|
||||||
|
targetHigh = new JSONArray(settings.getString("LocalProfile" + "targethigh", DEFAULTARRAY));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug(e.getMessage());
|
log.debug(e.getMessage());
|
||||||
|
try {
|
||||||
|
targetHigh = new JSONArray(DEFAULTARRAY);
|
||||||
|
} catch (JSONException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else targetHigh = 120d;
|
else {
|
||||||
|
try {
|
||||||
|
targetHigh = new JSONArray(DEFAULTARRAY);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
createConvertedProfile();
|
createConvertedProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,21 +275,21 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
|
||||||
JSONObject profile = new JSONObject();
|
JSONObject profile = new JSONObject();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json.put("defaultProfile", "SimpleProfile");
|
json.put("defaultProfile", "LocalProfile");
|
||||||
json.put("store", store);
|
json.put("store", store);
|
||||||
profile.put("dia", dia);
|
profile.put("dia", dia);
|
||||||
profile.put("carbratio", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", ic)));
|
profile.put("carbratio", ic);
|
||||||
profile.put("carbs_hr", car);
|
profile.put("carbs_hr", car);
|
||||||
profile.put("sens", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", isf)));
|
profile.put("sens", isf);
|
||||||
profile.put("basal", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", basal)));
|
profile.put("basal", basal);
|
||||||
profile.put("target_low", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", targetLow)));
|
profile.put("target_low", targetLow);
|
||||||
profile.put("target_high", new JSONArray().put(new JSONObject().put("timeAsSeconds", 0).put("value", targetHigh)));
|
profile.put("target_high", targetHigh);
|
||||||
profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL);
|
profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL);
|
||||||
store.put("SimpleProfile", profile);
|
store.put("LocalProfile", profile);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
convertedProfile = new NSProfile(json, "SimpleProfile");
|
convertedProfile = new NSProfile(json, "LocalProfile");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package info.nightscout.utils;
|
package info.nightscout.utils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
import android.text.Layout;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
@ -46,8 +49,9 @@ public class TimeListEdit {
|
||||||
JSONArray data1;
|
JSONArray data1;
|
||||||
JSONArray data2;
|
JSONArray data2;
|
||||||
NumberFormat formatter;
|
NumberFormat formatter;
|
||||||
|
Runnable save;
|
||||||
|
|
||||||
public TimeListEdit(Context context, View view, int resLayoutId, String label, JSONArray data1, JSONArray data2, NumberFormat formatter) {
|
public TimeListEdit(Context context, View view, int resLayoutId, String label, JSONArray data1, JSONArray data2, NumberFormat formatter, Runnable save) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.resLayoutId = resLayoutId;
|
this.resLayoutId = resLayoutId;
|
||||||
|
@ -55,6 +59,7 @@ public class TimeListEdit {
|
||||||
this.data1 = data1;
|
this.data1 = data1;
|
||||||
this.data2 = data2;
|
this.data2 = data2;
|
||||||
this.formatter = formatter;
|
this.formatter = formatter;
|
||||||
|
this.save = save;
|
||||||
buildView();
|
buildView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,9 +72,14 @@ public class TimeListEdit {
|
||||||
TextView textlabel = new TextView(context);
|
TextView textlabel = new TextView(context);
|
||||||
textlabel.setText(label);
|
textlabel.setText(label);
|
||||||
textlabel.setGravity(Gravity.LEFT);
|
textlabel.setGravity(Gravity.LEFT);
|
||||||
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
llp.setMargins(10, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
|
llp.setMargins(10, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
|
||||||
textlabel.setLayoutParams(llp);
|
textlabel.setLayoutParams(llp);
|
||||||
|
textlabel.setBackgroundColor(MainApp.sResources.getColor(R.color.linearBlockBackground));
|
||||||
|
if (Build.VERSION.SDK_INT < 23)
|
||||||
|
textlabel.setTextAppearance(context, android.R.style.TextAppearance_Medium);
|
||||||
|
else
|
||||||
|
textlabel.setTextAppearance(android.R.style.TextAppearance_Medium);
|
||||||
layout.addView(textlabel);
|
layout.addView(textlabel);
|
||||||
|
|
||||||
for (int i = 0; i < itemsCount(); i++) {
|
for (int i = 0; i < itemsCount(); i++) {
|
||||||
|
@ -188,7 +198,11 @@ public class TimeListEdit {
|
||||||
if (!(itemsCount() > 0 && secondFromMidnight(itemsCount() - 1) == 23 * ONEHOURINSECONDS)) {
|
if (!(itemsCount() > 0 && secondFromMidnight(itemsCount() - 1) == 23 * ONEHOURINSECONDS)) {
|
||||||
ImageView imageView = new ImageView(context);
|
ImageView imageView = new ImageView(context);
|
||||||
imageView.setImageResource(R.drawable.add);
|
imageView.setImageResource(R.drawable.add);
|
||||||
|
LinearLayout.LayoutParams illp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||||
|
illp.setMargins(0, 25, 0, 25); // llp.setMargins(left, top, right, bottom);
|
||||||
|
illp.gravity = Gravity.CENTER;
|
||||||
layout.addView(imageView);
|
layout.addView(imageView);
|
||||||
|
imageView.setLayoutParams(illp);
|
||||||
imageView.setOnClickListener(new View.OnClickListener() {
|
imageView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
@ -255,13 +269,15 @@ public class TimeListEdit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public double value2(int index) {
|
public double value2(int index) {
|
||||||
try {
|
if (data2 != null) {
|
||||||
JSONObject item = (JSONObject) data2.get(index);
|
try {
|
||||||
if (item.has("value")) {
|
JSONObject item = (JSONObject) data2.get(index);
|
||||||
return item.getDouble("value");
|
if (item.has("value")) {
|
||||||
|
return item.getDouble("value");
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return 0d;
|
return 0d;
|
||||||
}
|
}
|
||||||
|
@ -278,6 +294,7 @@ public class TimeListEdit {
|
||||||
newObject2.put("value", value2);
|
newObject2.put("value", value2);
|
||||||
data2.put(index, newObject2);
|
data2.put(index, newObject2);
|
||||||
}
|
}
|
||||||
|
if (save != null) save.run();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -294,6 +311,7 @@ public class TimeListEdit {
|
||||||
}
|
}
|
||||||
// add new object
|
// add new object
|
||||||
editItem(index, timeAsSeconds, value1, value2);
|
editItem(index, timeAsSeconds, value1, value2);
|
||||||
|
if (save != null) save.run();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -304,6 +322,7 @@ public class TimeListEdit {
|
||||||
data1.remove(index);
|
data1.remove(index);
|
||||||
if (data2 != null)
|
if (data2 != null)
|
||||||
data2.remove(index);
|
data2.remove(index);
|
||||||
|
if (save != null) save.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void log() {
|
void log() {
|
||||||
|
|
118
app/src/main/res/layout/localprofile_fragment.xml
Normal file
118
app/src/main/res/layout/localprofile_fragment.xml
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".plugins.LocalProfile.LocalProfileFragment">
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/units"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:background="@color/linearBlockBackground" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/localprofile_mgdl"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/mgdl" />
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/localprofile_mmol"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/mmol" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/dia"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:background="@color/linearBlockBackground" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/localprofile_dia"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="numberDecimal"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_width="70dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/localprofile_ic"></LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/localprofile_isf"></LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/absorption_rate"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:background="@color/linearBlockBackground" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/localprofile_car"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="numberDecimal"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_width="70dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/localprofile_basal"></LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:id="@+id/localprofile_target">
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/localprofile_profileswitch"
|
||||||
|
style="?android:attr/buttonStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginBottom="3dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingRight="10dp"
|
||||||
|
android:text="@string/send_to_pump"
|
||||||
|
android:textColor="@color/colorProfileSwitchButton" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
|
||||||
|
</FrameLayout>
|
|
@ -41,7 +41,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/dia"
|
android:text="@string/dia"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
|
@ -139,12 +139,6 @@
|
||||||
android:text="@string/send_to_pump"
|
android:text="@string/send_to_pump"
|
||||||
android:textColor="@color/colorProfileSwitchButton" />
|
android:textColor="@color/colorProfileSwitchButton" />
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:id="@+id/simpleprofile_test"></LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
|
|
@ -11,21 +11,25 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/timelistedit_time"
|
android:id="@+id/timelistedit_time"
|
||||||
/>
|
android:layout_marginTop="10dp" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/timelistedit_edit1"
|
android:id="@+id/timelistedit_edit1"
|
||||||
android:layout_width="70dp"
|
android:layout_width="70dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="15dp"
|
android:layout_marginLeft="15dp"
|
||||||
android:inputType="numberDecimal"/>
|
android:inputType="numberDecimal"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/timelistedit_edit2"
|
android:id="@+id/timelistedit_edit2"
|
||||||
android:layout_width="70dp"
|
android:layout_width="70dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="15dp"
|
android:layout_marginLeft="15dp"
|
||||||
android:inputType="numberDecimal"/>
|
android:inputType="numberDecimal"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/timelistedit_add"
|
android:id="@+id/timelistedit_add"
|
||||||
|
|
|
@ -384,4 +384,5 @@
|
||||||
<string name="smscommunicator_bolusdelivered">Bolus %.2fU aplikován úspěšně</string>
|
<string name="smscommunicator_bolusdelivered">Bolus %.2fU aplikován úspěšně</string>
|
||||||
<string name="ongoingnotificaction">Průběžné oznámení</string>
|
<string name="ongoingnotificaction">Průběžné oznámení</string>
|
||||||
<string name="old_data">ZASTARALÉ</string>
|
<string name="old_data">ZASTARALÉ</string>
|
||||||
|
<string name="localprofile">Místní profil</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue