This commit is contained in:
AdrianLxM 2018-04-03 14:34:15 +02:00
parent 1dca20550b
commit 75a91997b7
4 changed files with 66 additions and 33 deletions

View file

@ -4,6 +4,7 @@ package info.nightscout.androidaps.plugins.ProfileLocal;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
@ -48,45 +49,43 @@ public class LocalProfileFragment extends SubscriberFragment {
TimeListEdit basalView;
TimeListEdit targetView;
Button profileswitchButton;
Button resetButton;
TextView invalidProfile;
Runnable save = () -> {
doEdit();
if (basalView != null) {
basalView.updateLabel(MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel());
}
updateGUI();
};
TextWatcher textWatch = new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
LocalProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString());
doEdit();
updateGUI();
}
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
Runnable save = new Runnable() {
@Override
public void run() {
LocalProfilePlugin.getPlugin().storeSettings();
if (basalView != null) {
basalView.updateLabel(MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel());
}
updateGUI();
}
};
TextWatcher textWatch = new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
LocalProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString());
LocalProfilePlugin.getPlugin().storeSettings();
updateGUI();
}
};
PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription();
View layout = inflater.inflate(R.layout.localprofile_fragment, container, false);
diaView = (NumberPicker) layout.findViewById(R.id.localprofile_dia);
diaView.setParams(LocalProfilePlugin.getPlugin().dia, 2d, 48d, 0.1d, new DecimalFormat("0.0"), false, textWatch);
@ -97,6 +96,8 @@ public class LocalProfileFragment extends SubscriberFragment {
basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save);
targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save);
profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch);
resetButton = (Button) layout.findViewById(R.id.localprofile_reset);
invalidProfile = (TextView) layout.findViewById(R.id.invalidprofile);
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) {
@ -112,7 +113,7 @@ public class LocalProfileFragment extends SubscriberFragment {
LocalProfilePlugin.getPlugin().mgdl = mgdlView.isChecked();
LocalProfilePlugin.getPlugin().mmol = !LocalProfilePlugin.getPlugin().mgdl;
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
LocalProfilePlugin.getPlugin().storeSettings();
doEdit();
}
});
mmolView.setOnClickListener(new View.OnClickListener() {
@ -121,7 +122,7 @@ public class LocalProfileFragment extends SubscriberFragment {
LocalProfilePlugin.getPlugin().mmol = mmolView.isChecked();
LocalProfilePlugin.getPlugin().mgdl = !LocalProfilePlugin.getPlugin().mmol;
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
LocalProfilePlugin.getPlugin().storeSettings();
doEdit();
}
});
@ -136,6 +137,16 @@ public class LocalProfileFragment extends SubscriberFragment {
}
});
resetButton.setOnClickListener(view -> {
LocalProfilePlugin.getPlugin().loadSettings();
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
diaView.setParams(LocalProfilePlugin.getPlugin().dia, 2d, 48d, 0.1d, new DecimalFormat("0.0"), false, textWatch);
icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.sResources.getString(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save);
isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.sResources.getString(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save);
basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save);
targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save);
});
return layout;
} catch (Exception e) {
@ -146,6 +157,10 @@ public class LocalProfileFragment extends SubscriberFragment {
return null;
}
public void doEdit() {
LocalProfilePlugin.getPlugin().storeSettings();
}
@NonNull
public String getSumLabel() {
ProfileStore profile = LocalProfilePlugin.getPlugin().getProfile();

View file

@ -60,6 +60,7 @@ public class LocalProfilePlugin extends PluginBase implements ProfileInterface {
}
public void storeSettings() {
if (1==1) return;
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(LOCAL_PROFILE + "mmol", mmol);

View file

@ -78,6 +78,7 @@ public class TimeListEdit {
private void buildView() {
layout = (LinearLayout) view.findViewById(resLayoutId);
layout.removeAllViews();
textlabel = new TextView(context);
textlabel.setText(label);

View file

@ -153,6 +153,22 @@
android:text="@string/activate_profile"
android:textColor="@color/colorProfileSwitchButton" />
<Button
android:id="@+id/localprofile_reset"
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="reset"
android:textColor="@color/colorProfileSwitchButton" />
</LinearLayout>
</ScrollView>