remove simple profile

This commit is contained in:
Milos Kozak 2019-11-11 16:42:29 +01:00
parent 1f622e3517
commit 8fa4c49060
4 changed files with 0 additions and 487 deletions

View file

@ -59,7 +59,6 @@ import info.nightscout.androidaps.plugins.insulin.InsulinOrefUltraRapidActingPlu
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin;
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
import info.nightscout.androidaps.plugins.profile.simple.SimpleProfilePlugin;
import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
@ -188,7 +187,6 @@ public class MainApp extends Application {
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin());
pluginsList.add(NSProfilePlugin.getPlugin());
if (!Config.NSCLIENT) pluginsList.add(SimpleProfilePlugin.getPlugin());
if (!Config.NSCLIENT) pluginsList.add(LocalProfilePlugin.INSTANCE);
pluginsList.add(TreatmentsPlugin.getPlugin());
if (!Config.NSCLIENT) pluginsList.add(SafetyPlugin.getPlugin());

View file

@ -1,159 +0,0 @@
package info.nightscout.androidaps.plugins.profile.simple;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.plugins.bus.RxBus;
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.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.SafeParse;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
public class SimpleProfileFragment extends Fragment {
private CompositeDisposable disposable = new CompositeDisposable();
EditText diaView;
RadioButton mgdlView;
RadioButton mmolView;
EditText icView;
EditText isfView;
EditText basalView;
EditText targetlowView;
EditText targethighView;
Button profileswitchButton;
TextView invalidProfile;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.simpleprofile_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);
icView = (EditText) layout.findViewById(R.id.simpleprofile_ic);
isfView = (EditText) layout.findViewById(R.id.simpleprofile_isf);
basalView = (EditText) layout.findViewById(R.id.simpleprofile_basalrate);
targetlowView = (EditText) layout.findViewById(R.id.simpleprofile_targetlow);
targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh);
profileswitchButton = (Button) layout.findViewById(R.id.simpleprofile_profileswitch);
invalidProfile = (TextView) layout.findViewById(R.id.invalidprofile);
if (!ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().isTempBasalCapable) {
layout.findViewById(R.id.simpleprofile_basalrate).setVisibility(View.GONE);
layout.findViewById(R.id.simpleprofile_basalrate_label).setVisibility(View.GONE);
}
mgdlView.setChecked(SimpleProfilePlugin.getPlugin().mgdl);
mmolView.setChecked(SimpleProfilePlugin.getPlugin().mmol);
diaView.setText(SimpleProfilePlugin.getPlugin().dia.toString());
icView.setText(SimpleProfilePlugin.getPlugin().ic.toString());
isfView.setText(SimpleProfilePlugin.getPlugin().isf.toString());
basalView.setText(SimpleProfilePlugin.getPlugin().basal.toString());
targetlowView.setText(SimpleProfilePlugin.getPlugin().targetLow.toString());
targethighView.setText(SimpleProfilePlugin.getPlugin().targetHigh.toString());
mgdlView.setOnClickListener(v -> {
SimpleProfilePlugin.getPlugin().mgdl = mgdlView.isChecked();
SimpleProfilePlugin.getPlugin().mmol = !SimpleProfilePlugin.getPlugin().mgdl;
mmolView.setChecked(SimpleProfilePlugin.getPlugin().mmol);
SimpleProfilePlugin.getPlugin().storeSettings();
});
mmolView.setOnClickListener(v -> {
SimpleProfilePlugin.getPlugin().mmol = mmolView.isChecked();
SimpleProfilePlugin.getPlugin().mgdl = !SimpleProfilePlugin.getPlugin().mmol;
mgdlView.setChecked(SimpleProfilePlugin.getPlugin().mgdl);
SimpleProfilePlugin.getPlugin().storeSettings();
});
profileswitchButton.setOnClickListener(view -> {
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCH;
profileswitch.executeProfileSwitch = true;
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
newDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
});
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) {
SimpleProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString());
SimpleProfilePlugin.getPlugin().ic = SafeParse.stringToDouble(icView.getText().toString());
SimpleProfilePlugin.getPlugin().isf = SafeParse.stringToDouble(isfView.getText().toString());
SimpleProfilePlugin.getPlugin().basal = SafeParse.stringToDouble(basalView.getText().toString());
SimpleProfilePlugin.getPlugin().targetLow = SafeParse.stringToDouble(targetlowView.getText().toString());
SimpleProfilePlugin.getPlugin().targetHigh = SafeParse.stringToDouble(targethighView.getText().toString());
SimpleProfilePlugin.getPlugin().storeSettings();
updateGUI();
}
};
diaView.addTextChangedListener(textWatch);
icView.addTextChangedListener(textWatch);
isfView.addTextChangedListener(textWatch);
basalView.addTextChangedListener(textWatch);
targetlowView.addTextChangedListener(textWatch);
targethighView.addTextChangedListener(textWatch);
return layout;
}
@Override
public synchronized void onResume() {
super.onResume();
disposable.add(RxBus.INSTANCE
.toObservable(EventInitializationChanged.class)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(event -> updateGUI(), FabricPrivacy::logException)
);
updateGUI();
}
@Override
public synchronized void onPause() {
super.onPause();
disposable.clear();
}
protected void updateGUI() {
boolean isValid = SimpleProfilePlugin.getPlugin().getProfile() != null && SimpleProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid(MainApp.gs(R.string.simpleprofile));
if (!ConfigBuilderPlugin.getPlugin().getActivePump().isInitialized() || ConfigBuilderPlugin.getPlugin().getActivePump().isSuspended() || !isValid) {
profileswitchButton.setVisibility(View.GONE);
} else {
profileswitchButton.setVisibility(View.VISIBLE);
}
if (isValid)
invalidProfile.setVisibility(View.GONE);
else
invalidProfile.setVisibility(View.VISIBLE);
}
}

View file

@ -1,181 +0,0 @@
package info.nightscout.androidaps.plugins.profile.simple;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.events.EventProfileStoreChanged;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 05.08.2016.
*/
public class SimpleProfilePlugin extends PluginBase implements ProfileInterface {
private static Logger log = LoggerFactory.getLogger(L.PROFILE);
private static SimpleProfilePlugin simpleProfilePlugin;
public static SimpleProfilePlugin getPlugin() {
if (simpleProfilePlugin == null)
simpleProfilePlugin = new SimpleProfilePlugin();
return simpleProfilePlugin;
}
private static ProfileStore convertedProfile = null;
boolean mgdl;
boolean mmol;
Double dia;
Double ic;
Double isf;
Double basal;
Double targetLow;
Double targetHigh;
private SimpleProfilePlugin() {
super(new PluginDescription()
.mainType(PluginType.PROFILE)
.fragmentClass(SimpleProfileFragment.class.getName())
.pluginName(R.string.simpleprofile)
.shortName(R.string.simpleprofile_shortname)
.description(R.string.description_profile_simple)
);
loadSettings();
}
public void storeSettings() {
if (L.isEnabled(L.PROFILE))
log.debug("Storing settings");
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("SimpleProfile" + "mmol", mmol);
editor.putBoolean("SimpleProfile" + "mgdl", mgdl);
editor.putString("SimpleProfile" + "dia", dia.toString());
editor.putString("SimpleProfile" + "ic", ic.toString());
editor.putString("SimpleProfile" + "isf", isf.toString());
editor.putString("SimpleProfile" + "basal", basal.toString());
editor.putString("SimpleProfile" + "targetlow", targetLow.toString());
editor.putString("SimpleProfile" + "targethigh", targetHigh.toString());
editor.apply();
createConvertedProfile();
if (L.isEnabled(L.PROFILE))
log.debug("Storing settings: " + getRawProfile().getData().toString());
RxBus.INSTANCE.send(new EventProfileStoreChanged());
}
private void loadSettings() {
if (L.isEnabled(L.PROFILE))
log.debug("Loading stored settings");
mgdl = SP.getBoolean("SimpleProfile" + "mgdl", true);
mmol = SP.getBoolean("SimpleProfile" + "mmol", false);
dia = SP.getDouble("SimpleProfile" + "dia", Constants.defaultDIA);
ic = SP.getDouble("SimpleProfile" + "ic", 0d);
isf = SP.getDouble("SimpleProfile" + "isf", 0d);
basal = SP.getDouble("SimpleProfile" + "basal", 0d);
targetLow = SP.getDouble("SimpleProfile" + "targetlow", 0d);
targetHigh = SP.getDouble("SimpleProfile" + "targethigh", 0d);
}
/*
{
"_id": "576264a12771b7500d7ad184",
"startDate": "2016-06-16T08:35:00.000Z",
"defaultProfile": "Default",
"store": {
"Default": {
"dia": "3",
"carbratio": [{
"time": "00:00",
"value": "30"
}],
"carbs_hr": "20",
"delay": "20",
"sens": [{
"time": "00:00",
"value": "100"
}],
"timezone": "UTC",
"basal": [{
"time": "00:00",
"value": "0.1"
}],
"target_low": [{
"time": "00:00",
"value": "0"
}],
"target_high": [{
"time": "00:00",
"value": "0"
}],
"startDate": "1970-01-01T00:00:00.000Z",
"units": "mmol"
}
},
"created_at": "2016-06-16T08:34:41.256Z"
}
*/
private void createConvertedProfile() {
JSONObject json = new JSONObject();
JSONObject store = new JSONObject();
JSONObject profile = new JSONObject();
try {
json.put("defaultProfile", "SimpleProfile");
json.put("store", store);
profile.put("dia", dia);
profile.put("carbratio", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", ic)));
profile.put("sens", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", isf)));
profile.put("basal", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", basal)));
profile.put("target_low", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", targetLow)));
profile.put("target_high", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", targetHigh)));
profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL);
store.put("SimpleProfile", profile);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
convertedProfile = new ProfileStore(json);
}
@Override
public ProfileStore getProfile() {
if (convertedProfile == null)
createConvertedProfile();
if (!convertedProfile.getDefaultProfile().isValid(MainApp.gs(R.string.simpleprofile)))
return null;
return convertedProfile;
}
public ProfileStore getRawProfile() {
if (convertedProfile == null)
createConvertedProfile();
return convertedProfile;
}
@Override
public String getUnits() {
return mgdl ? Constants.MGDL : Constants.MMOL;
}
@Override
public String getProfileName() {
return "SimpleProfile";
}
}

View file

@ -1,145 +0,0 @@
<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.profile.simple.SimpleProfileFragment">
<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:id="@+id/invalidprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/invalidprofile"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_light"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/units"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RadioButton
android:id="@+id/simpleprofile_mgdl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mgdl" />
<RadioButton
android:id="@+id/simpleprofile_mmol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mmol" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dia"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/simpleprofile_dia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/nsprofileview_ic_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/simpleprofile_ic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/nsprofileview_isf_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/simpleprofile_isf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal" />
<TextView
android:id="@+id/simpleprofile_basalrate_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/basal_rate"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/simpleprofile_basalrate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/target_range"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="@+id/simpleprofile_targetlow"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal" />
<EditText
android:id="@+id/simpleprofile_targethigh"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal" />
</LinearLayout>
<Button
android:id="@+id/simpleprofile_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/activate_profile"
android:textColor="@color/colorProfileSwitchButton" />
</LinearLayout>
</ScrollView>
</FrameLayout>