get invite-by-relayid working again

In Dbg version only (with enabling boolean moved to BuildConfig.)
Currently crashes when first used, and recipient can't always connect to
relay until app rebooted. And of course there are still open questions
like how to populate the list -- how user learns the deviceID of an
opponent.
This commit is contained in:
Eric House 2017-07-23 16:45:14 -07:00
parent bd250cfe1e
commit 7eb9458a78
6 changed files with 119 additions and 25 deletions

View file

@ -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

View file

@ -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 );
}

View file

@ -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<DevIDRec>() {
// public int compare( DevIDRec rec1, DevIDRec rec2 ) {
// return rec1.m_opponent.compareTo(rec2.m_opponent);
// }
// });
Collections.sort( m_devIDRecs, new Comparator<DevIDRec>() {
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()

View file

@ -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;

View file

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:text="@string/get_relay_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText android:id="@+id/name_field"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:autoText="false"
android:singleLine="true"
android:selectAllOnFocus="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView android:text="@string/get_relay_number"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText android:id="@+id/num_field"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:autoText="false"
android:singleLine="true"
android:selectAllOnFocus="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>

View file

@ -1922,7 +1922,9 @@
<string name="get_sms_title">Manual entry</string>
<string name="get_sms_number">Device phone number:</string>
<string name="get_sms_name">Contact name (optional):</string>
<string name="get_relay_name">Device name (optional):</string>
<string name="get_relay_number">Enter device ID:</string>
<!-- -->
<plurals name="confirm_clear_sms_fmt">
<item quantity="one">Are you sure you want to delete the checked