SW reuse save, cleanup

This commit is contained in:
Milos Kozak 2018-05-04 09:35:57 +02:00
parent 4539756455
commit 88d964f135
5 changed files with 7 additions and 53 deletions

View file

@ -1,20 +1,19 @@
package info.nightscout.androidaps.startupwizard; package info.nightscout.androidaps.startupwizard;
import android.content.Context;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.startupwizard.events.EventSWUpdate;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
public class SWItem { public class SWItem {
private static Logger log = LoggerFactory.getLogger(SWItem.class); private static Logger log = LoggerFactory.getLogger(SWItem.class);
enum Type { enum Type {
NONE, NONE,
URL, URL,
@ -30,8 +29,6 @@ public class SWItem {
Integer label; Integer label;
Integer comment; Integer comment;
int preferenceId; int preferenceId;
private List<String> labels;
private List<String> values;
public SWItem(Type type) { public SWItem(Type type) {
@ -71,11 +68,7 @@ public class SWItem {
public void save(String value) { public void save(String value) {
SP.putString(preferenceId, value); SP.putString(preferenceId, value);
MainApp.bus().post(new EventPreferenceChange(preferenceId)); MainApp.bus().post(new EventPreferenceChange(preferenceId));
} MainApp.bus().post(new EventSWUpdate());
public void setOptions(List<String> labels, List<String> values){
this.labels = labels;
this.values = values;
} }
public static LinearLayout generateLayout(View view) { public static LinearLayout generateLayout(View view) {
@ -84,6 +77,6 @@ public class SWItem {
return layout; return layout;
} }
public void generateDialog(View view, LinearLayout layout){ public void generateDialog(View view, LinearLayout layout) {
} }
} }

View file

@ -10,8 +10,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.startupwizard.events.EventSWUpdate;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
public class SWRadioButton extends SWItem { public class SWRadioButton extends SWItem {
@ -61,14 +59,8 @@ public class SWRadioButton extends SWItem {
radioGroup.setOnCheckedChangeListener((group, checkedId) -> { radioGroup.setOnCheckedChangeListener((group, checkedId) -> {
int i = (int) group.findViewById(checkedId).getTag(); int i = (int) group.findViewById(checkedId).getTag();
save(i); save(values()[i]);
}); });
layout.addView(radioGroup); layout.addView(radioGroup);
} }
public void save(int i) {
SP.putString(preferenceId, values()[i]);
MainApp.bus().post(new EventPreferenceChange(preferenceId));
MainApp.bus().post(new EventSWUpdate());
}
} }

View file

@ -1,19 +1,9 @@
package info.nightscout.androidaps.startupwizard; package info.nightscout.androidaps.startupwizard;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.ActivityCompat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.utils.LocaleHelper;
import info.nightscout.utils.SP;
public class SWScreen { public class SWScreen {
@ -44,11 +34,4 @@ public class SWScreen {
this.validator = validator; this.validator = validator;
return this; return this;
} }
boolean isValid() {
if (validator != null)
return validator.isValid();
return true;
}
} }

View file

@ -12,11 +12,6 @@ import android.widget.TextView;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.startupwizard.events.EventSWUpdate;
import info.nightscout.utils.SP;
public class SWString extends SWItem { public class SWString extends SWItem {
private static Logger log = LoggerFactory.getLogger(SWString.class); private static Logger log = LoggerFactory.getLogger(SWString.class);
@ -52,9 +47,7 @@ public class SWString extends SWItem {
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
SP.putString(preferenceId, s.toString()); save(s.toString());
MainApp.bus().post(new EventPreferenceChange(preferenceId));
MainApp.bus().post(new EventSWUpdate());
} }
@Override @Override

View file

@ -12,11 +12,6 @@ import android.widget.TextView;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.startupwizard.events.EventSWUpdate;
import info.nightscout.utils.SP;
public class SWUrl extends SWItem { public class SWUrl extends SWItem {
private static Logger log = LoggerFactory.getLogger(SWUrl.class); private static Logger log = LoggerFactory.getLogger(SWUrl.class);
@ -51,9 +46,7 @@ public class SWUrl extends SWItem {
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
SP.putString(preferenceId, s.toString()); save(s.toString());
MainApp.bus().post(new EventPreferenceChange(preferenceId));
MainApp.bus().post(new EventSWUpdate());
} }
@Override @Override