lp isValid

This commit is contained in:
AdrianLxM 2018-04-03 17:54:29 +02:00
parent b4c3c3f216
commit f17deaedfb
2 changed files with 38 additions and 18 deletions

View file

@ -57,7 +57,6 @@ public class LocalProfileFragment extends SubscriberFragment {
if (basalView != null) { if (basalView != null) {
basalView.updateLabel(MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel()); basalView.updateLabel(MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel());
} }
updateGUI();
}; };
TextWatcher textWatch = new TextWatcher() { TextWatcher textWatch = new TextWatcher() {
@ -76,7 +75,6 @@ public class LocalProfileFragment extends SubscriberFragment {
int before, int count) { int before, int count) {
LocalProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString()); LocalProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString());
doEdit(); doEdit();
updateGUI();
} }
}; };
@ -146,6 +144,7 @@ public class LocalProfileFragment extends SubscriberFragment {
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); 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); 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); 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);
updateGUI();
}); });
return layout; return layout;
@ -158,12 +157,14 @@ public class LocalProfileFragment extends SubscriberFragment {
} }
public void doEdit() { public void doEdit() {
LocalProfilePlugin.getPlugin().storeSettings(); //LocalProfilePlugin.getPlugin().storeSettings();
LocalProfilePlugin.getPlugin().setEdited(true);
updateGUI();
} }
@NonNull @NonNull
public String getSumLabel() { public String getSumLabel() {
ProfileStore profile = LocalProfilePlugin.getPlugin().getProfile(); ProfileStore profile = LocalProfilePlugin.getPlugin().createProfileStore();
if (profile != null) if (profile != null)
return "" + DecimalFormatter.to2Decimal(profile.getDefaultProfile().baseBasalSum()) + "U"; return "" + DecimalFormatter.to2Decimal(profile.getDefaultProfile().baseBasalSum()) + "U";
else else
@ -182,16 +183,23 @@ public class LocalProfileFragment extends SubscriberFragment {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
boolean isValid = LocalProfilePlugin.getPlugin().getProfile() != null && LocalProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid(MainApp.gs(R.string.localprofile)); boolean isValid = LocalProfilePlugin.getPlugin().isValidEditState();
if (!ConfigBuilderPlugin.getActivePump().isInitialized() || ConfigBuilderPlugin.getActivePump().isSuspended() || !isValid) { if (isValid) {
invalidProfile.setVisibility(View.GONE);
if (!ConfigBuilderPlugin.getActivePump().isInitialized() || ConfigBuilderPlugin.getActivePump().isSuspended()) {
profileswitchButton.setVisibility(View.GONE); profileswitchButton.setVisibility(View.GONE);
} else { } else {
profileswitchButton.setVisibility(View.VISIBLE); profileswitchButton.setVisibility(View.VISIBLE);
} }
if (isValid)
invalidProfile.setVisibility(View.GONE);
else }
else {
invalidProfile.setVisibility(View.VISIBLE); invalidProfile.setVisibility(View.VISIBLE);
profileswitchButton.setVisibility(View.GONE);
}
} }
}); });
} }

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.ProfileLocal;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -69,7 +70,7 @@ public class LocalProfilePlugin extends PluginBase implements ProfileInterface {
loadSettings(); loadSettings();
} }
public void storeSettings() { public synchronized void storeSettings() {
if (1==1) return; if (1==1) return;
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
@ -83,12 +84,13 @@ public class LocalProfilePlugin extends PluginBase implements ProfileInterface {
editor.putString(LOCAL_PROFILE + "targethigh", targetHigh.toString()); editor.putString(LOCAL_PROFILE + "targethigh", targetHigh.toString());
editor.apply(); editor.apply();
createConvertedProfile(); createAndStoreConvertedProfile();
edited = false;
if (Config.logPrefsChange) if (Config.logPrefsChange)
log.debug("Storing settings: " + getRawProfile().getData().toString()); log.debug("Storing settings: " + getRawProfile().getData().toString());
} }
public void loadSettings() { public synchronized void loadSettings() {
if (Config.logPrefsChange) if (Config.logPrefsChange)
log.debug("Loading stored settings"); log.debug("Loading stored settings");
@ -135,7 +137,8 @@ public class LocalProfilePlugin extends PluginBase implements ProfileInterface {
} catch (JSONException ignored) { } catch (JSONException ignored) {
} }
} }
createConvertedProfile(); edited = false;
createAndStoreConvertedProfile();
} }
/* /*
@ -176,7 +179,16 @@ public class LocalProfilePlugin extends PluginBase implements ProfileInterface {
"created_at": "2016-06-16T08:34:41.256Z" "created_at": "2016-06-16T08:34:41.256Z"
} }
*/ */
private void createConvertedProfile() { private void createAndStoreConvertedProfile() {
convertedProfile = createProfileStore();
}
public boolean isValidEditState() {
return createProfileStore().getDefaultProfile().isValid(MainApp.gs(R.string.localprofile));
}
@NonNull
public ProfileStore createProfileStore() {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
JSONObject store = new JSONObject(); JSONObject store = new JSONObject();
JSONObject profile = new JSONObject(); JSONObject profile = new JSONObject();
@ -195,7 +207,7 @@ public class LocalProfilePlugin extends PluginBase implements ProfileInterface {
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
convertedProfile = new ProfileStore(json); return new ProfileStore(json);
} }
@Override @Override