diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BackupConfigView.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BackupConfigView.java index 8d58cb943..2bf75254e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BackupConfigView.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BackupConfigView.java @@ -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 mCheckBoxes = new HashMap<>(); private List 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(); } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java index a0eafdaa1..88aa81be9 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ConnViaViewLayout.java @@ -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 ) { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index bdc6cd26b..f7e40f2f0 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -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,