disable button when nothing checked

This commit is contained in:
Eric House 2022-06-12 10:06:38 -07:00
parent 3c1acf28ac
commit 7a0b38d5cf
3 changed files with 47 additions and 5 deletions

View file

@ -19,24 +19,28 @@
package org.eehouse.android.xw4;
import android.view.ViewGroup;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.ZipUtils.SaveWhat;
public class BackupConfigView extends LinearLayout
implements OnCheckedChangeListener
{
private static final String TAG = BackupConfigView.class.getSimpleName();
@ -44,6 +48,7 @@ public class BackupConfigView extends LinearLayout
private Uri mLoadFile;
private Map<SaveWhat, CheckBox> mCheckBoxes = new HashMap<>();
private List<SaveWhat> mShowWhats;
private AlertDialog mDialog;
public BackupConfigView( Context cx, AttributeSet as )
{
@ -60,6 +65,18 @@ public class BackupConfigView extends LinearLayout
initOnce();
}
AlertDialog setDialog( AlertDialog dialog )
{
mDialog = dialog;
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow( DialogInterface dialog ) {
countChecks();
}
});
return dialog;
}
// Usually called before init(), but IIRC wasn't on older Android versions
@Override
protected void onFinishInflate()
@ -67,6 +84,28 @@ public class BackupConfigView extends LinearLayout
initOnce();
}
@Override
public void onCheckedChanged( CompoundButton buttonView,
boolean isChecked )
{
countChecks();
}
private void countChecks()
{
if ( null != mDialog ) {
boolean haveCheck = false;
for ( CheckBox box : mCheckBoxes.values() ) {
if ( box.isChecked() ) {
haveCheck = true;
break;
}
}
Utils.enableAlertButton( mDialog, AlertDialog.BUTTON_POSITIVE,
haveCheck );
}
}
private void initOnce()
{
if ( null != mIsStore ) {
@ -87,11 +126,13 @@ public class BackupConfigView extends LinearLayout
box.setText( what.titleID() );
mCheckBoxes.put( what, box );
box.setChecked( !mIsStore );
box.setOnCheckedChangeListener( this );
((TextView)(item.findViewById(R.id.expl)))
.setText( what.explID() );
}
}
}
countChecks();
}
}

View file

@ -97,6 +97,7 @@ public class ConnViaViewLayout extends LinearLayout {
final CommsConnType typf = typ;
box.setOnCheckedChangeListener( new OnCheckedChangeListener() {
@Override
public void onCheckedChanged( CompoundButton buttonView,
boolean isChecked ) {
if ( isChecked ) {

View file

@ -1576,7 +1576,7 @@ public class GamesListDelegate extends ListDelegateBase
} )
.setNegativeButton( android.R.string.cancel, null )
;
return ab.create();
return view.setDialog( ab.create() );
}
// This is in liu of passing through the startActivityForResult call,