From 02da56ce9cab88163651922e520ab05fdb3a36a4 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 1 Feb 2015 19:55:06 -0800 Subject: [PATCH] add populate() that can be called to add defaults when new type is added --- .../eehouse/android/xw4/jni/CommsAddrRec.java | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommsAddrRec.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommsAddrRec.java index 475fe4895..6ffbb4273 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommsAddrRec.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommsAddrRec.java @@ -187,31 +187,20 @@ public class CommsAddrRec { sms_port = 1; // so don't assert in comms.... } + public void populate( Context context, CommsConnTypeSet newTypes ) + { + for ( CommsConnType typ : newTypes.getTypes() ) { + if ( ! conTypes.contains( typ ) ) { + conTypes.add( typ ); + addTypeDefaults( context, typ ); + } + } + } + public void populate( Context context ) { for ( CommsConnType typ : conTypes.getTypes() ) { - switch ( typ ) { - case COMMS_CONN_RELAY: - String room = GameUtils.makeRandomID(); - String host = XWPrefs.getDefaultRelayHost( context ); - int port = XWPrefs.getDefaultRelayPort( context ); - setRelayParams( host, port, room ); - break; - case COMMS_CONN_BT: - String[] strs = BTService.getBTNameAndAddress(); - if ( null != strs ) { - bt_hostName = strs[0]; - bt_btAddr = strs[1]; - } - break; - case COMMS_CONN_SMS: - SMSService.SMSPhoneInfo pi = SMSService.getPhoneInfo( context ); - sms_phone = pi.number; - sms_port = 3; // fix comms already... - break; - default: - Assert.fail(); - } + addTypeDefaults( context, typ ); } } @@ -251,4 +240,30 @@ public class CommsAddrRec { sms_phone = src.sms_phone; sms_port = src.sms_port; } + + private void addTypeDefaults( Context context, CommsConnType typ ) + { + switch ( typ ) { + case COMMS_CONN_RELAY: + String room = GameUtils.makeRandomID(); + String host = XWPrefs.getDefaultRelayHost( context ); + int port = XWPrefs.getDefaultRelayPort( context ); + setRelayParams( host, port, room ); + break; + case COMMS_CONN_BT: + String[] strs = BTService.getBTNameAndAddress(); + if ( null != strs ) { + bt_hostName = strs[0]; + bt_btAddr = strs[1]; + } + break; + case COMMS_CONN_SMS: + SMSService.SMSPhoneInfo pi = SMSService.getPhoneInfo( context ); + sms_phone = pi.number; + sms_port = 3; // fix comms already... + break; + default: + Assert.fail(); + } + } }