show "NEXT" only when isValid() == true

This commit is contained in:
Roumen Georgiev 2018-04-26 15:18:01 +03:00
parent dc91e3a544
commit d75de2f645
5 changed files with 86 additions and 33 deletions

View file

@ -2,19 +2,24 @@ package info.nightscout.androidaps.startupwizard;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
public class SWRadioButton extends SWItem {
private static Logger log = LoggerFactory.getLogger(SWRadioButton.class);
int labelsArray;
int valuesArray;
private RadioGroup radioGroup;
public boolean somethingChecked = false;
public SWRadioButton() {
super(Type.RADIOBUTTON);
@ -42,29 +47,58 @@ public class SWRadioButton extends SWItem {
String[] labels = context.getResources().getStringArray(labelsArray);
String[] values = context.getResources().getStringArray(valuesArray);
/* textlabel.setGravity(Gravity.START);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
llp.setMargins(10, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
textlabel.setLayoutParams(llp);
textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);*/
RadioGroup rg = new RadioGroup(context);
radioGroup = new RadioGroup(context);
radioGroup.clearCheck();
for (int row = 0; row < 1; row++) {
rg.setOrientation(LinearLayout.VERTICAL);
rg.setVisibility(View.VISIBLE);
radioGroup.setOrientation(LinearLayout.VERTICAL);
radioGroup.setVisibility(View.VISIBLE);
for (int i = 0; i < labels.length; i++) {
RadioButton rdbtn = new RadioButton(context);
rdbtn.setId((row * 2) + i);
rdbtn.setText(labels[i]);
rg.addView(rdbtn);
// log.debug("Button ["+labels[i]+"]="+rdbtn.getId()+" value is "+values[rdbtn.getId()]);
radioGroup.addView(rdbtn);
}
}
layout.addView(rg);
}
layout.addView(radioGroup);
}
public RadioGroup getRadioGroup(){
return this.radioGroup;
}
// returns the id of the group
public int getGroupId(){
return radioGroup.getId();
}
public String getCheckedValue(){
if(radioGroup != null && radioGroup.getCheckedRadioButtonId() > -1){
Context context = radioGroup.getRootView().getContext();
String[] values = context.getResources().getStringArray(valuesArray);
return values[radioGroup.getCheckedRadioButtonId()];
} else {
return "none";
}
}
public boolean isSomethingChecked(){
return this.somethingChecked;
}
// return true if we have something checked
public boolean isValid(){
if(getCheckedValue().equals("none"))
return false;
else
return true;
}
}

View file

@ -4,7 +4,6 @@ import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.TextViewCompat;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
@ -12,8 +11,6 @@ import android.widget.TextView;
import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
public class SWString extends SWItem {
private List<String> labels;
@ -40,12 +37,6 @@ public class SWString extends SWItem {
TextView textlabel = new TextView(context);
textlabel.setText(groupName);
/* textlabel.setGravity(Gravity.START);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
llp.setMargins(10, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
textlabel.setLayoutParams(llp);
textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);*/
layout.addView(textlabel);
@ -62,4 +53,9 @@ public class SWString extends SWItem {
}
}
}
public boolean isValid(){
return true;
}
}

View file

@ -39,13 +39,6 @@ public class SWUrl extends SWItem {
LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
layout.removeAllViews();
/*textlabel.setGravity(Gravity.START);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
llp.setMargins(10, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
textlabel.setLayoutParams(llp);
textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);*/
for (int row = 0; row < 1; row++) {
for (int i = 0; i < labels.size(); i++) {
if(values.get(i) != "" && values.get(i) != null) {
@ -59,4 +52,10 @@ public class SWUrl extends SWItem {
}
}
}
public boolean isValid(){
// checks for URL validation
return true;
}
}

View file

@ -10,6 +10,8 @@ import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import org.slf4j.Logger;
@ -59,6 +61,7 @@ public class SetupWizardActivity extends AppCompatActivity {
private TextView textlabel;
private TextView screenName;
private Button skipButton;
private boolean nextAllowed = false;
//logiing
private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class);
@ -139,13 +142,15 @@ public class SetupWizardActivity extends AppCompatActivity {
int showPage = intent.getIntExtra(SetupWizardActivity.INTENT_MESSAGE,0);
SWDefinition swDefinition = SWDefinition.getInstance();
List<SWScreen> screens = swDefinition.getScreens();
if(screens.size() > 0){
if(screens.size() > 0 && showPage < screens.size()){
SWScreen currentScreen = screens.get(showPage);
currentWizardPage = showPage;
// show/hide prev/next buttons if we are at the beninning/end
if(showPage == screens.size() - 1) {
((Button) findViewById(R.id.next_button)).setVisibility(View.GONE);
if(nextAllowed && showPage == screens.size() - 1) {
((Button) findViewById(R.id.finish_button)).setVisibility(View.VISIBLE);
((Button) findViewById(R.id.next_button)).setVisibility(View.GONE);
} else if(nextAllowed && showPage != screens.size() - 1) {
((Button) findViewById(R.id.next_button)).setVisibility(View.VISIBLE);
}else if(showPage == 0)
((Button) findViewById(R.id.previous_button)).setVisibility(View.GONE);
//Set screen name
@ -164,16 +169,35 @@ public class SetupWizardActivity extends AppCompatActivity {
if(currentItem.type == URL || currentItem.type == STRING){
labels.add(currentItem.getLabel());
comments.add(currentItem.getComment());
} else if(currentItem.type == RADIOBUTTON){
//disable next before creating layout
nextAllowed = false;
// generate layout dynamically
SWRadioButton radioGroupItems = (SWRadioButton) currentItem;
radioGroupItems.generateDialog(this.findViewById(R.id.fullscreen_content_fields));
radioGroupItems.getRadioGroup().setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
nextAllowed = radioGroupItems.isValid();
if(showPage == screens.size() - 1 && nextAllowed) {
((Button) findViewById(R.id.finish_button)).setVisibility(View.VISIBLE);
((Button) findViewById(R.id.next_button)).setVisibility(View.GONE);
} else if(nextAllowed)
((Button) findViewById(R.id.next_button)).setVisibility(View.VISIBLE);
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));
nextAllowed = swUrl.isValid();
((Button) findViewById(R.id.next_button)).setVisibility(View.VISIBLE);
}
}

View file

@ -72,7 +72,7 @@
android:layout_weight="1"
android:onClick="showNextPage"
android:text="@string/setupwizard_next"
android:visibility="visible" />
android:visibility="gone" />
<Button
android:id="@+id/finish_button"