Merge pull request #1937 from MilosKozak/cleanups/local-profile
Local Profile Plugin Cleanup
This commit is contained in:
commit
1ed89e99e5
|
@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.profile.local;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -13,6 +12,8 @@ import android.widget.Button;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
@ -22,38 +23,37 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
|
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
|
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||||
import info.nightscout.androidaps.utils.NumberPicker;
|
import info.nightscout.androidaps.utils.NumberPicker;
|
||||||
import info.nightscout.androidaps.utils.SafeParse;
|
import info.nightscout.androidaps.utils.SafeParse;
|
||||||
import info.nightscout.androidaps.utils.TimeListEdit;
|
import info.nightscout.androidaps.utils.TimeListEdit;
|
||||||
|
|
||||||
|
import static info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.MIN_DIA;
|
||||||
|
|
||||||
public class LocalProfileFragment extends SubscriberFragment {
|
public class LocalProfileFragment extends SubscriberFragment {
|
||||||
NumberPicker diaView;
|
private NumberPicker diaView;
|
||||||
RadioButton mgdlView;
|
private RadioButton mgdlView;
|
||||||
RadioButton mmolView;
|
private RadioButton mmolView;
|
||||||
TimeListEdit icView;
|
private TimeListEdit basalView;
|
||||||
TimeListEdit isfView;
|
private Button profileswitchButton;
|
||||||
TimeListEdit basalView;
|
private Button resetButton;
|
||||||
TimeListEdit targetView;
|
private Button saveButton;
|
||||||
Button profileswitchButton;
|
|
||||||
Button resetButton;
|
|
||||||
Button saveButton;
|
|
||||||
|
|
||||||
TextView invalidProfile;
|
private TextView invalidProfile;
|
||||||
|
|
||||||
Runnable save = () -> {
|
private Runnable save = () -> {
|
||||||
doEdit();
|
doEdit();
|
||||||
if (basalView != null) {
|
if (basalView != null) {
|
||||||
basalView.updateLabel(MainApp.gs(R.string.nsprofileview_basal_label) + ": " + getSumLabel());
|
basalView.updateLabel(MainApp.gs(R.string.nsprofileview_basal_label) + ": " + getSumLabel());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TextWatcher textWatch = new TextWatcher() {
|
private TextWatcher textWatch = new TextWatcher() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
|
@ -77,20 +77,20 @@ public class LocalProfileFragment extends SubscriberFragment {
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
PumpDescription pumpDescription = ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription();
|
PumpDescription pumpDescription = ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription();
|
||||||
View layout = inflater.inflate(R.layout.localprofile_fragment, container, false);
|
View layout = inflater.inflate(R.layout.localprofile_fragment, container, false);
|
||||||
diaView = (NumberPicker) layout.findViewById(R.id.localprofile_dia);
|
diaView = layout.findViewById(R.id.localprofile_dia);
|
||||||
diaView.setParams(LocalProfilePlugin.getPlugin().dia, 2d, 48d, 0.1d, new DecimalFormat("0.0"), false, layout.findViewById(R.id.localprofile_save), textWatch);
|
diaView.setParams(LocalProfilePlugin.getPlugin().dia, MIN_DIA, 12d, 0.1d, new DecimalFormat("0.0"), false, layout.findViewById(R.id.localprofile_save), textWatch);
|
||||||
mgdlView = (RadioButton) layout.findViewById(R.id.localprofile_mgdl);
|
mgdlView = layout.findViewById(R.id.localprofile_mgdl);
|
||||||
mmolView = (RadioButton) layout.findViewById(R.id.localprofile_mmol);
|
mmolView = layout.findViewById(R.id.localprofile_mmol);
|
||||||
icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save);
|
new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.gs(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.gs(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save);
|
new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.gs(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.gs(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save);
|
basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.gs(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.gs(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save);
|
new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.gs(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);
|
profileswitchButton = layout.findViewById(R.id.localprofile_profileswitch);
|
||||||
resetButton = (Button) layout.findViewById(R.id.localprofile_reset);
|
resetButton = layout.findViewById(R.id.localprofile_reset);
|
||||||
saveButton = (Button) layout.findViewById(R.id.localprofile_save);
|
saveButton = layout.findViewById(R.id.localprofile_save);
|
||||||
|
|
||||||
|
|
||||||
invalidProfile = (TextView) layout.findViewById(R.id.invalidprofile);
|
invalidProfile = layout.findViewById(R.id.invalidprofile);
|
||||||
|
|
||||||
if (!ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().isTempBasalCapable) {
|
if (!ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().isTempBasalCapable) {
|
||||||
layout.findViewById(R.id.localprofile_basal).setVisibility(View.GONE);
|
layout.findViewById(R.id.localprofile_basal).setVisibility(View.GONE);
|
||||||
|
@ -124,11 +124,11 @@ public class LocalProfileFragment extends SubscriberFragment {
|
||||||
LocalProfilePlugin.getPlugin().loadSettings();
|
LocalProfilePlugin.getPlugin().loadSettings();
|
||||||
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
|
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
|
||||||
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
|
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
|
||||||
diaView.setParams(LocalProfilePlugin.getPlugin().dia, 5d, 12d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.localprofile_save), textWatch);
|
diaView.setParams(LocalProfilePlugin.getPlugin().dia, MIN_DIA, 12d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.localprofile_save), textWatch);
|
||||||
icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save);
|
new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.gs(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.gs(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save);
|
new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.gs(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.gs(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save);
|
basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.gs(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.gs(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save);
|
new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save);
|
||||||
updateGUI();
|
updateGUI();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -166,36 +166,32 @@ public class LocalProfileFragment extends SubscriberFragment {
|
||||||
protected void updateGUI() {
|
protected void updateGUI() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null)
|
if (activity != null)
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(() -> {
|
||||||
@Override
|
boolean isValid = LocalProfilePlugin.getPlugin().isValidEditState();
|
||||||
public void run() {
|
boolean isEdited = LocalProfilePlugin.getPlugin().isEdited();
|
||||||
boolean isValid = LocalProfilePlugin.getPlugin().isValidEditState();
|
if (isValid) {
|
||||||
boolean isEdited = LocalProfilePlugin.getPlugin().isEdited();
|
invalidProfile.setVisibility(View.GONE); //show invalid profile
|
||||||
if (isValid) {
|
|
||||||
invalidProfile.setVisibility(View.GONE); //show invalid profile
|
|
||||||
|
|
||||||
if (isEdited) {
|
|
||||||
//edited profile -> save first
|
|
||||||
profileswitchButton.setVisibility(View.GONE);
|
|
||||||
saveButton.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
profileswitchButton.setVisibility(View.VISIBLE);
|
|
||||||
saveButton.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
invalidProfile.setVisibility(View.VISIBLE);
|
|
||||||
profileswitchButton.setVisibility(View.GONE);
|
|
||||||
saveButton.setVisibility(View.GONE); //don't save an invalid profile
|
|
||||||
}
|
|
||||||
|
|
||||||
//Show reset button iff data was edited
|
|
||||||
if (isEdited) {
|
if (isEdited) {
|
||||||
resetButton.setVisibility(View.VISIBLE);
|
//edited profile -> save first
|
||||||
|
profileswitchButton.setVisibility(View.GONE);
|
||||||
|
saveButton.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
resetButton.setVisibility(View.GONE);
|
profileswitchButton.setVisibility(View.VISIBLE);
|
||||||
|
saveButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
invalidProfile.setVisibility(View.VISIBLE);
|
||||||
|
profileswitchButton.setVisibility(View.GONE);
|
||||||
|
saveButton.setVisibility(View.GONE); //don't save an invalid profile
|
||||||
|
}
|
||||||
|
|
||||||
|
//Show reset button iff data was edited
|
||||||
|
if (isEdited) {
|
||||||
|
resetButton.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
resetButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue