move onClick in SWRadioButton

This commit is contained in:
Roumen Georgiev 2018-04-27 13:30:45 +03:00
parent 11dc20faca
commit bb38d7644b
7 changed files with 77 additions and 75 deletions

View file

@ -32,7 +32,7 @@ public class SWDefinition {
// List all the screens here // List all the screens here
// todo: SWValidator ?!? // todo: SWValidator ?!?
add(new SWScreen(R.string.nsclientinternal_title) add(new SWScreen(R.string.nsclientinternal_title)
.skippable(false) .skippable(true)
.add(new SWUrl().preferenceId(R.string.key_nsclientinternal_url).label(R.string.nsclientinternal_url_title).comment(R.string.nsclientinternal_url_dialogmessage)) .add(new SWUrl().preferenceId(R.string.key_nsclientinternal_url).label(R.string.nsclientinternal_url_title).comment(R.string.nsclientinternal_url_dialogmessage))
.add(new SWString().preferenceId(R.string.key_nsclientinternal_api_secret).label(R.string.nsclientinternal_secret_dialogtitle).comment(R.string.nsclientinternal_secret_dialogmessage)) .add(new SWString().preferenceId(R.string.key_nsclientinternal_api_secret).label(R.string.nsclientinternal_secret_dialogtitle).comment(R.string.nsclientinternal_secret_dialogmessage))
.validator(() -> NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth) .validator(() -> NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth)

View file

@ -1,12 +1,20 @@
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 org.slf4j.Logger;
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.utils.SP; import info.nightscout.utils.SP;
public class SWItem { public class SWItem {
private static Logger log = LoggerFactory.getLogger(SWItem.class);
enum Type { enum Type {
NONE, NONE,
URL, URL,
@ -21,6 +29,8 @@ 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) {
@ -62,7 +72,17 @@ public class SWItem {
MainApp.bus().post(new EventPreferenceChange(preferenceId)); MainApp.bus().post(new EventPreferenceChange(preferenceId));
} }
public void generateDialog(View view){ public void setOptions(List<String> labels, List<String> values){
this.labels = labels;
this.values = values;
}
public static LinearLayout generateLayout(View view) {
LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
layout.removeAllViews();
return layout;
}
public void generateDialog(View view, LinearLayout layout){
} }
} }

View file

@ -41,10 +41,10 @@ public class SWRadioButton extends SWItem {
} }
@Override @Override
public void generateDialog(View view){ public void generateDialog(View view, LinearLayout layout){
Context context = view.getContext(); Context context = view.getContext();
LinearLayout layout = (LinearLayout) view.findViewById(view.getId()); // LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
layout.removeAllViews(); // layout.removeAllViews();
String[] labels = context.getResources().getStringArray(labelsArray); String[] labels = context.getResources().getStringArray(labelsArray);
String[] values = context.getResources().getStringArray(valuesArray); String[] values = context.getResources().getStringArray(valuesArray);
// Get if there is already value in SP // Get if there is already value in SP
@ -64,12 +64,17 @@ public class SWRadioButton extends SWItem {
rdbtn.setText(labels[i]); rdbtn.setText(labels[i]);
if(previousValue.equals(values[i])) if(previousValue.equals(values[i]))
rdbtn.setChecked(true); rdbtn.setChecked(true);
// log.debug("Button ["+labels[i]+"]="+rdbtn.getId()+" value is "+values[rdbtn.getId()]);
radioGroup.addView(rdbtn); radioGroup.addView(rdbtn);
} }
} }
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
save(getCheckedValue());
}
});
layout.addView(radioGroup); layout.addView(radioGroup);
} }

View file

@ -7,10 +7,14 @@ import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
public class SWString extends SWItem { public class SWString extends SWItem {
private static Logger log = LoggerFactory.getLogger(SWString.class);
private List<String> labels; private List<String> labels;
private List<String> values; private List<String> values;
private String groupName; private String groupName;
@ -23,28 +27,29 @@ public class SWString extends SWItem {
this.groupName = name; this.groupName = name;
} }
public void setOptions(List<String> labels, List<String> values){
this.labels = labels;
this.values = values;
}
@Override @Override
public void generateDialog(View view) { public void generateDialog(View view, LinearLayout layout) {
Context context = view.getContext(); Context context = view.getContext();
LinearLayout layout = (LinearLayout) view.findViewById(view.getId()); // LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
layout.removeAllViews(); // layout.removeAllViews();
TextView textlabel = new TextView(context); TextView textlabel = new TextView(context);
textlabel.setText(groupName); textlabel.setText(groupName);
layout.addView(textlabel); layout.addView(textlabel);
for (int row = 0; row < 1; row++) { if(values.get(values.size()-1) != "" && values.get(values.size()-1) != null) {
for (int i = 0; i < labels.size(); i++) { EditText editText = new EditText(context);
if(values.get(i) != "" && values.get(i) != null) { editText.setId(3);
EditText editText = new EditText(context); editText.setText(values.get(values.size()-1));
editText.setId((row * 2) + i); editText.setInputType(InputType.TYPE_CLASS_TEXT);
editText.setText(values.get(i)); editText.setMaxLines(1);
editText.setInputType(InputType.TYPE_CLASS_TEXT); layout.addView(editText);
editText.setMaxLines(1);
layout.addView(editText);
}
}
} }
} }

View file

@ -6,10 +6,13 @@ import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
public class SWUrl extends SWItem { public class SWUrl extends SWItem {
private static Logger log = LoggerFactory.getLogger(SWUrl.class);
private List<String> labels; private List<String> labels;
private List<String> values; private List<String> values;
private String groupName; private String groupName;
@ -18,6 +21,7 @@ public class SWUrl extends SWItem {
} }
public void setOptions(List<String> labels, List<String> values){ public void setOptions(List<String> labels, List<String> values){
// log.debug("Setting options - labels "+labels.size()+" values - "+values.size());
this.labels = labels; this.labels = labels;
this.values = values; this.values = values;
} }
@ -27,22 +31,18 @@ public class SWUrl extends SWItem {
} }
@Override @Override
public void generateDialog(View view) { public void generateDialog(View view, LinearLayout layout) {
Context context = view.getContext(); Context context = view.getContext();
LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
layout.removeAllViews();
for (int row = 0; row < 1; row++) {
for (int i = 0; i < labels.size(); i++) { if(values.get(values.size()-1) != "" && values.get(values.size()-1) != null) {
if(values.get(i) != "" && values.get(i) != null) { EditText editText = new EditText(context);
EditText editText = new EditText(context); editText.setId(1);
editText.setId((row * 2) + i); // get the last value in list
editText.setText(values.get(i)); editText.setText(values.get(values.size()-1));
editText.setInputType(InputType.TYPE_CLASS_TEXT); editText.setInputType(InputType.TYPE_CLASS_TEXT);
editText.setMaxLines(1); editText.setMaxLines(1);
layout.addView(editText); layout.addView(editText);
}
}
} }
} }

View file

@ -160,49 +160,20 @@ public class SetupWizardActivity extends AppCompatActivity {
skipButton = (Button) findViewById(R.id.skip_button); skipButton = (Button) findViewById(R.id.skip_button);
} }
//Generate layout first
LinearLayout layout = info.nightscout.androidaps.startupwizard.SWItem.generateLayout(this.findViewById(R.id.fullscreen_content_fields));
for(int i = 0; i < currentScreen.items.size(); i++){ for(int i = 0; i < currentScreen.items.size(); i++){
SWItem currentItem = currentScreen.items.get(i); SWItem currentItem = currentScreen.items.get(i);
if(currentItem.type == URL || currentItem.type == STRING){ labels.add(i,currentItem.getLabel());
labels.add(currentItem.getLabel()); comments.add(i,currentItem.getComment());
comments.add(currentItem.getComment()); currentItem.setOptions(labels, comments);
currentItem.generateDialog(this.findViewById(R.id.fullscreen_content_fields), layout);
} else if(currentItem.type == RADIOBUTTON){ }
// generate layout dynamically // Check if input isValid or screen is sckippable
SWRadioButton radioGroupItems = (SWRadioButton) currentItem; if(currentScreen.validator.isValid() || currentScreen.skippable) {
radioGroupItems.generateDialog(this.findViewById(R.id.fullscreen_content_fields)); showNextButton(showPage, screens.size() - 1);
//allow next button if we have something saved in preferences show();
if(!radioGroupItems.preferenceSet().equals("none")){
showNextButton(showPage, screens.size()-1);
}
radioGroupItems.getRadioGroup().setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
radioGroupItems.save(radioGroupItems.getCheckedValue());
if(currentScreen.validator.isValid()) {
showNextButton(showPage, screens.size() - 1);
show();
}
}
});
}
if(labels.size() > 0){
// we have some labels lets display them
SWUrl swUrl = new SWUrl();
swUrl.setOptions(labels, comments);
swUrl.generateDialog(this.findViewById(R.id.fullscreen_content_fields));
log.debug("Valid input:" +currentScreen.validator.isValid());
/* if(currentScreen.validator.isValid()) {
showNextButton(showPage, screens.size() - 1);
show();
}*/
showNextButton(showPage, screens.size()-1);
}
} }
} }

View file

@ -61,6 +61,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:onClick="showNextPage"
android:text="@string/setupwizard_skip" android:text="@string/setupwizard_skip"
android:visibility="invisible" /> android:visibility="invisible" />