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.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -13,6 +12,8 @@ import android.widget.Button;
|
|||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
@ -22,38 +23,37 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.data.ProfileStore;
|
||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||
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.Dialogs.NewNSTreatmentDialog;
|
||||
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.NumberPicker;
|
||||
import info.nightscout.androidaps.utils.SafeParse;
|
||||
import info.nightscout.androidaps.utils.TimeListEdit;
|
||||
|
||||
import static info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.MIN_DIA;
|
||||
|
||||
public class LocalProfileFragment extends SubscriberFragment {
|
||||
NumberPicker diaView;
|
||||
RadioButton mgdlView;
|
||||
RadioButton mmolView;
|
||||
TimeListEdit icView;
|
||||
TimeListEdit isfView;
|
||||
TimeListEdit basalView;
|
||||
TimeListEdit targetView;
|
||||
Button profileswitchButton;
|
||||
Button resetButton;
|
||||
Button saveButton;
|
||||
private NumberPicker diaView;
|
||||
private RadioButton mgdlView;
|
||||
private RadioButton mmolView;
|
||||
private TimeListEdit basalView;
|
||||
private Button profileswitchButton;
|
||||
private Button resetButton;
|
||||
private Button saveButton;
|
||||
|
||||
TextView invalidProfile;
|
||||
private TextView invalidProfile;
|
||||
|
||||
Runnable save = () -> {
|
||||
private Runnable save = () -> {
|
||||
doEdit();
|
||||
if (basalView != null) {
|
||||
basalView.updateLabel(MainApp.gs(R.string.nsprofileview_basal_label) + ": " + getSumLabel());
|
||||
}
|
||||
};
|
||||
|
||||
TextWatcher textWatch = new TextWatcher() {
|
||||
private TextWatcher textWatch = new TextWatcher() {
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
@ -77,20 +77,20 @@ public class LocalProfileFragment extends SubscriberFragment {
|
|||
Bundle savedInstanceState) {
|
||||
PumpDescription pumpDescription = ConfigBuilderPlugin.getPlugin().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, layout.findViewById(R.id.localprofile_save), textWatch);
|
||||
mgdlView = (RadioButton) layout.findViewById(R.id.localprofile_mgdl);
|
||||
mmolView = (RadioButton) 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);
|
||||
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);
|
||||
diaView = layout.findViewById(R.id.localprofile_dia);
|
||||
diaView.setParams(LocalProfilePlugin.getPlugin().dia, MIN_DIA, 12d, 0.1d, new DecimalFormat("0.0"), false, layout.findViewById(R.id.localprofile_save), textWatch);
|
||||
mgdlView = layout.findViewById(R.id.localprofile_mgdl);
|
||||
mmolView = layout.findViewById(R.id.localprofile_mmol);
|
||||
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_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);
|
||||
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);
|
||||
profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch);
|
||||
resetButton = (Button) layout.findViewById(R.id.localprofile_reset);
|
||||
saveButton = (Button) layout.findViewById(R.id.localprofile_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 = layout.findViewById(R.id.localprofile_profileswitch);
|
||||
resetButton = layout.findViewById(R.id.localprofile_reset);
|
||||
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) {
|
||||
layout.findViewById(R.id.localprofile_basal).setVisibility(View.GONE);
|
||||
|
@ -124,11 +124,11 @@ public class LocalProfileFragment extends SubscriberFragment {
|
|||
LocalProfilePlugin.getPlugin().loadSettings();
|
||||
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
diaView.setParams(LocalProfilePlugin.getPlugin().dia, MIN_DIA, 12d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.localprofile_save), textWatch);
|
||||
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_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);
|
||||
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();
|
||||
});
|
||||
|
||||
|
@ -166,36 +166,32 @@ public class LocalProfileFragment extends SubscriberFragment {
|
|||
protected void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean isValid = LocalProfilePlugin.getPlugin().isValidEditState();
|
||||
boolean isEdited = LocalProfilePlugin.getPlugin().isEdited();
|
||||
if (isValid) {
|
||||
invalidProfile.setVisibility(View.GONE); //show invalid profile
|
||||
activity.runOnUiThread(() -> {
|
||||
boolean isValid = LocalProfilePlugin.getPlugin().isValidEditState();
|
||||
boolean isEdited = LocalProfilePlugin.getPlugin().isEdited();
|
||||
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) {
|
||||
resetButton.setVisibility(View.VISIBLE);
|
||||
//edited profile -> save first
|
||||
profileswitchButton.setVisibility(View.GONE);
|
||||
saveButton.setVisibility(View.VISIBLE);
|
||||
} 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