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
// todo: SWValidator ?!?
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 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)

View file

@ -1,12 +1,20 @@
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.utils.SP;
public class SWItem {
private static Logger log = LoggerFactory.getLogger(SWItem.class);
enum Type {
NONE,
URL,
@ -21,6 +29,8 @@ public class SWItem {
Integer label;
Integer comment;
int preferenceId;
private List<String> labels;
private List<String> values;
public SWItem(Type type) {
@ -62,7 +72,17 @@ public class SWItem {
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
public void generateDialog(View view){
public void generateDialog(View view, LinearLayout layout){
Context context = view.getContext();
LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
layout.removeAllViews();
// LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
// layout.removeAllViews();
String[] labels = context.getResources().getStringArray(labelsArray);
String[] values = context.getResources().getStringArray(valuesArray);
// Get if there is already value in SP
@ -64,12 +64,17 @@ public class SWRadioButton extends SWItem {
rdbtn.setText(labels[i]);
if(previousValue.equals(values[i]))
rdbtn.setChecked(true);
// log.debug("Button ["+labels[i]+"]="+rdbtn.getId()+" value is "+values[rdbtn.getId()]);
radioGroup.addView(rdbtn);
}
}
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
save(getCheckedValue());
}
});
layout.addView(radioGroup);
}

View file

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

View file

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

View file

@ -160,49 +160,20 @@ public class SetupWizardActivity extends AppCompatActivity {
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++){
SWItem currentItem = currentScreen.items.get(i);
if(currentItem.type == URL || currentItem.type == STRING){
labels.add(currentItem.getLabel());
comments.add(currentItem.getComment());
} else if(currentItem.type == RADIOBUTTON){
// generate layout dynamically
SWRadioButton radioGroupItems = (SWRadioButton) currentItem;
radioGroupItems.generateDialog(this.findViewById(R.id.fullscreen_content_fields));
//allow next button if we have something saved in preferences
if(!radioGroupItems.preferenceSet().equals("none")){
showNextButton(showPage, screens.size()-1);
labels.add(i,currentItem.getLabel());
comments.add(i,currentItem.getComment());
currentItem.setOptions(labels, comments);
currentItem.generateDialog(this.findViewById(R.id.fullscreen_content_fields), layout);
}
radioGroupItems.getRadioGroup().setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
radioGroupItems.save(radioGroupItems.getCheckedValue());
if(currentScreen.validator.isValid()) {
// Check if input isValid or screen is sckippable
if(currentScreen.validator.isValid() || currentScreen.skippable) {
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_height="wrap_content"
android:layout_weight="1"
android:onClick="showNextPage"
android:text="@string/setupwizard_skip"
android:visibility="invisible" />