SW reuse save, cleanup
This commit is contained in:
parent
4539756455
commit
88d964f135
|
@ -1,20 +1,19 @@
|
|||
package info.nightscout.androidaps.startupwizard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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 SWItem {
|
||||
private static Logger log = LoggerFactory.getLogger(SWItem.class);
|
||||
|
||||
enum Type {
|
||||
NONE,
|
||||
URL,
|
||||
|
@ -30,8 +29,6 @@ public class SWItem {
|
|||
Integer label;
|
||||
Integer comment;
|
||||
int preferenceId;
|
||||
private List<String> labels;
|
||||
private List<String> values;
|
||||
|
||||
|
||||
public SWItem(Type type) {
|
||||
|
@ -71,11 +68,7 @@ public class SWItem {
|
|||
public void save(String value) {
|
||||
SP.putString(preferenceId, value);
|
||||
MainApp.bus().post(new EventPreferenceChange(preferenceId));
|
||||
}
|
||||
|
||||
public void setOptions(List<String> labels, List<String> values){
|
||||
this.labels = labels;
|
||||
this.values = values;
|
||||
MainApp.bus().post(new EventSWUpdate());
|
||||
}
|
||||
|
||||
public static LinearLayout generateLayout(View view) {
|
||||
|
@ -84,6 +77,6 @@ public class SWItem {
|
|||
return layout;
|
||||
}
|
||||
|
||||
public void generateDialog(View view, LinearLayout layout){
|
||||
public void generateDialog(View view, LinearLayout layout) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ import org.slf4j.Logger;
|
|||
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 SWRadioButton extends SWItem {
|
||||
|
@ -61,14 +59,8 @@ public class SWRadioButton extends SWItem {
|
|||
|
||||
radioGroup.setOnCheckedChangeListener((group, checkedId) -> {
|
||||
int i = (int) group.findViewById(checkedId).getTag();
|
||||
save(i);
|
||||
save(values()[i]);
|
||||
});
|
||||
layout.addView(radioGroup);
|
||||
}
|
||||
|
||||
public void save(int i) {
|
||||
SP.putString(preferenceId, values()[i]);
|
||||
MainApp.bus().post(new EventPreferenceChange(preferenceId));
|
||||
MainApp.bus().post(new EventSWUpdate());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,9 @@
|
|||
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.List;
|
||||
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
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 {
|
||||
|
||||
|
@ -44,11 +34,4 @@ public class SWScreen {
|
|||
this.validator = validator;
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean isValid() {
|
||||
if (validator != null)
|
||||
return validator.isValid();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,11 +12,6 @@ import android.widget.TextView;
|
|||
import org.slf4j.Logger;
|
||||
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 {
|
||||
private static Logger log = LoggerFactory.getLogger(SWString.class);
|
||||
|
@ -52,9 +47,7 @@ public class SWString extends SWItem {
|
|||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
SP.putString(preferenceId, s.toString());
|
||||
MainApp.bus().post(new EventPreferenceChange(preferenceId));
|
||||
MainApp.bus().post(new EventSWUpdate());
|
||||
save(s.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,11 +12,6 @@ import android.widget.TextView;
|
|||
import org.slf4j.Logger;
|
||||
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 {
|
||||
private static Logger log = LoggerFactory.getLogger(SWUrl.class);
|
||||
|
||||
|
@ -51,9 +46,7 @@ public class SWUrl extends SWItem {
|
|||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
SP.putString(preferenceId, s.toString());
|
||||
MainApp.bus().post(new EventPreferenceChange(preferenceId));
|
||||
MainApp.bus().post(new EventSWUpdate());
|
||||
save(s.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue