diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index ef9bc32ba..fc520c98c 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -69,6 +69,7 @@ android { resValue "string", "nbs_port", "3344" resValue "string", "invite_prefix", "/and/" buildConfigField "boolean", "WIDIR_ENABLED", "false" + buildConfigField "boolean", "RELAYINVITE_SUPPORTED", "false" } xw4d { dimension "variant" @@ -79,6 +80,7 @@ android { resValue "string", "nbs_port", "3345" resValue "string", "invite_prefix", "/anddbg/" buildConfigField "boolean", "WIDIR_ENABLED", "true" + buildConfigField "boolean", "RELAYINVITE_SUPPORTED", "true" } // WARNING: "all" breaks things. Seems to be a keyword. Need diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java index 2302c2b10..a9ed0250e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java @@ -78,7 +78,7 @@ public class InviteChoicesAlert extends DlgDelegateAlert { items.add( getString( R.string.invite_choice_bt ) ); means.add( InviteMeans.BLUETOOTH ); } - if ( XWApp.RELAYINVITE_SUPPORTED ) { + if ( BuildConfig.RELAYINVITE_SUPPORTED ) { items.add( getString( R.string.invite_choice_relay ) ); means.add( InviteMeans.RELAY ); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java index 8627c469b..256cca49e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/RelayInviteDelegate.java @@ -20,20 +20,22 @@ package org.eehouse.android.xw4; -import android.content.DialogInterface; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; +import android.text.method.DigitsKeyListener; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CompoundButton; +import android.widget.EditText; import android.widget.FrameLayout; import android.widget.Spinner; @@ -122,21 +124,21 @@ public class RelayInviteDelegate extends InviteDelegate { @Override protected void onBarButtonClicked( int id ) { - // switch( id ) { - // case R.id.button_relay_add: - // Utils.notImpl( m_activity ); - // break; - // case R.id.manual_add_button: - // showDialog( DlgID.GET_NUMBER ); - // break; - // case R.id.button_clear: - // Utils.notImpl( m_activity ); - // // int count = getChecked().size(); - // // String msg = getQuantityString( R.plurals.confirm_clear_sms_fmt, - // // count, count ); - // // makeConfirmThenBuilder( msg, Action.CLEAR_ACTION ).show(); - // break; - // } + switch( id ) { + case R.id.button_relay_add: + Utils.notImpl( m_activity ); + break; + case R.id.manual_add_button: + showDialogFragment( DlgID.GET_NUMBER ); + break; + case R.id.button_clear: + Utils.notImpl( m_activity ); + // int count = getChecked().size(); + // String msg = getQuantityString( R.plurals.confirm_clear_sms_fmt, + // count, count ); + // makeConfirmThenBuilder( msg, Action.CLEAR_ACTION ).show(); + break; + } } // protected void onSaveInstanceState( Bundle outState ) @@ -166,6 +168,48 @@ public class RelayInviteDelegate extends InviteDelegate { // } // } + @Override + protected Dialog makeDialog( DBAlert alert, Object[] params ) + { + Dialog dialog; + DialogInterface.OnClickListener lstnr; + switch( alert.getDlgID() ) { + case GET_NUMBER: { + final View getNumView = inflate( R.layout.get_relay ); + ((EditText)getNumView.findViewById( R.id.num_field )) + .setKeyListener(DigitsKeyListener.getInstance()); + lstnr = new DialogInterface.OnClickListener() { + public void onClick( DialogInterface dlg, int item ) { + String number + = ((EditText)getNumView.findViewById(R.id.num_field)) + .getText().toString(); + if ( null != number && 0 < number.length() ) { + String name + = ((EditText)getNumView.findViewById(R.id.name_field)) + .getText().toString(); + DevIDRec rec = new DevIDRec( name, number ); + m_devIDRecs.add( rec ); + clearChecked(); + onItemChecked( rec, true ); + saveAndRebuild(); + } + } + }; + dialog = makeAlertBuilder() + .setTitle( R.string.get_sms_title ) + .setView( getNumView ) + .setPositiveButton( android.R.string.ok, lstnr ) + .setNegativeButton( android.R.string.cancel, null ) + .create(); + } + break; + default: + dialog = super.makeDialog( alert, params ); + break; + } + return dialog; + } + // protected Dialog onCreateDialog( int id ) // { // Dialog dialog = super.onCreateDialog( id ); @@ -203,7 +247,8 @@ public class RelayInviteDelegate extends InviteDelegate { @Override protected void onChildAdded( View child, InviterItem data ) { - Assert.fail(); + DevIDRec rec = (DevIDRec)data; + ((TwoStrsItem)child).setStrings( rec.m_opponent, rec.m_devID ); } // We want to present user with list of previous opponents and devices. We @@ -366,11 +411,12 @@ public class RelayInviteDelegate extends InviteDelegate { private void rebuildList( boolean checkIfAll ) { - // Collections.sort( m_devIDRecs, new Comparator() { - // public int compare( DevIDRec rec1, DevIDRec rec2 ) { - // return rec1.m_opponent.compareTo(rec2.m_opponent); - // } - // }); + Collections.sort( m_devIDRecs, new Comparator() { + public int compare( DevIDRec rec1, DevIDRec rec2 ) { + return rec1.m_opponent.compareTo(rec2.m_opponent); + } + }); + updateListAdapter( m_devIDRecs.toArray( new DevIDRec[m_devIDRecs.size()] ) ); // m_adapter = new RelayDevsAdapter(); // setListAdapter( m_adapter ); // if ( checkIfAll && m_devIDRecs.size() <= m_nMissing ) { @@ -379,7 +425,7 @@ public class RelayInviteDelegate extends InviteDelegate { // iter.next().m_isChecked = true; // } // } - // tryEnable(); + tryEnable(); } private void getSavedState() diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java index 1416f7a4d..f37658925 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java @@ -37,7 +37,6 @@ public class XWApp extends Application { public static final boolean BTSUPPORTED = true; public static final boolean GCMSUPPORTED = true; - public static final boolean RELAYINVITE_SUPPORTED = false; public static final boolean ATTACH_SUPPORTED = false; public static final boolean LOG_LIFECYLE = false; public static final boolean DEBUG_EXP_TIMERS = false; diff --git a/xwords4/android/app/src/main/res/layout/get_relay.xml b/xwords4/android/app/src/main/res/layout/get_relay.xml new file mode 100644 index 000000000..186f92600 --- /dev/null +++ b/xwords4/android/app/src/main/res/layout/get_relay.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index 135d70fc6..685ecb521 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -1922,7 +1922,9 @@ Manual entry Device phone number: Contact name (optional): + Device name (optional): Enter device ID: + Are you sure you want to delete the checked