return supported types as list, not set

I was seeing them displayed in different orders where I want to control
the order instead.
This commit is contained in:
Eric House 2019-03-03 14:07:40 -08:00
parent 8336a338f8
commit 1575d70ab9
3 changed files with 29 additions and 14 deletions

View file

@ -28,9 +28,9 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
@ -81,9 +81,9 @@ public class ConnViaViewLayout extends LinearLayout {
list.removeAllViews(); // in case being reused list.removeAllViews(); // in case being reused
Context context = getContext(); Context context = getContext();
CommsConnTypeSet supported = CommsConnTypeSet.getSupported( context ); List<CommsConnType> supported = CommsConnTypeSet.getSupported( context );
for ( CommsConnType typ : supported.getTypes() ) { for ( CommsConnType typ : supported ) {
CheckBox box = new CheckBox( context ); CheckBox box = new CheckBox( context );
box.setText( typ.longName( context ) ); box.setText( typ.longName( context ) );
box.setChecked( m_curSet.contains( typ ) ); box.setChecked( m_curSet.contains( typ ) );

View file

@ -35,6 +35,7 @@ import java.io.InputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -186,8 +187,8 @@ public class NetLaunchInfo implements Serializable {
m_addrs = new CommsConnTypeSet(); m_addrs = new CommsConnTypeSet();
} }
CommsConnTypeSet supported = CommsConnTypeSet.getSupported( context ); List<CommsConnType> supported = CommsConnTypeSet.getSupported( context );
for ( CommsConnType typ : supported.getTypes() ) { for ( CommsConnType typ : supported ) {
if ( hasAddrs && !m_addrs.contains( typ ) ) { if ( hasAddrs && !m_addrs.contains( typ ) ) {
continue; continue;
} }
@ -458,7 +459,7 @@ public class NetLaunchInfo implements Serializable {
private void init( Context context, String data ) throws JSONException private void init( Context context, String data ) throws JSONException
{ {
CommsConnTypeSet supported = CommsConnTypeSet.getSupported( context ); List<CommsConnType> supported = CommsConnTypeSet.getSupported( context );
JSONObject json = new JSONObject( data ); JSONObject json = new JSONObject( data );
int flags = json.optInt(ADDRS_KEY, -1); int flags = json.optInt(ADDRS_KEY, -1);
@ -476,7 +477,7 @@ public class NetLaunchInfo implements Serializable {
gameID = json.optInt( MultiService.GAMEID, 0 ); gameID = json.optInt( MultiService.GAMEID, 0 );
// Try each type // Try each type
for ( CommsConnType typ : supported.getTypes() ) { for ( CommsConnType typ : supported ) {
if ( hasAddrs && !m_addrs.contains( typ ) ) { if ( hasAddrs && !m_addrs.contains( typ ) ) {
continue; continue;
} }
@ -665,7 +666,7 @@ public class NetLaunchInfo implements Serializable {
&& 0 != gameID(); && 0 != gameID();
} }
private void removeUnsupported( CommsConnTypeSet supported ) private void removeUnsupported( List<CommsConnType> supported )
{ {
for ( Iterator<CommsConnType> iter = m_addrs.iterator(); for ( Iterator<CommsConnType> iter = m_addrs.iterator();
iter.hasNext(); ) { iter.hasNext(); ) {

View file

@ -25,6 +25,7 @@ import android.text.TextUtils;
import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.Assert;
import org.eehouse.android.xw4.BTService; import org.eehouse.android.xw4.BTService;
import org.eehouse.android.xw4.BuildConfig;
import org.eehouse.android.xw4.GameUtils; import org.eehouse.android.xw4.GameUtils;
import org.eehouse.android.xw4.Log; import org.eehouse.android.xw4.Log;
import org.eehouse.android.xw4.R; import org.eehouse.android.xw4.R;
@ -36,8 +37,10 @@ import org.eehouse.android.xw4.XWPrefs;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
public class CommsAddrRec { public class CommsAddrRec {
private static final String TAG = CommsAddrRec.class.getSimpleName(); private static final String TAG = CommsAddrRec.class.getSimpleName();
@ -63,6 +66,8 @@ public class CommsAddrRec {
id = R.string.invite_choice_data_sms; break; id = R.string.invite_choice_data_sms; break;
case COMMS_CONN_P2P: case COMMS_CONN_P2P:
id = R.string.invite_choice_p2p; break; id = R.string.invite_choice_p2p; break;
default:
Assert.assertFalse( BuildConfig.DEBUG );
} }
return ( 0 == id ) ? toString() : LocUtils.getString( context, id ); return ( 0 == id ) ? toString() : LocUtils.getString( context, id );
@ -113,19 +118,28 @@ public class CommsAddrRec {
return result; return result;
} }
public static CommsConnTypeSet getSupported( Context context ) /**
* Return supported types in display order, i.e. with the easiest to
* use or most broadly useful first. DATA_SMS comes last because it
* depends on permissions that are banned on PlayStore variants of the
* game.
*
* @return ordered list of types supported by this device as
* configured.
*/
public static List<CommsConnType> getSupported( Context context )
{ {
CommsConnTypeSet supported = new CommsConnTypeSet(); List<CommsConnType> supported = new ArrayList<>();
supported.add( CommsConnType.COMMS_CONN_RELAY ); supported.add( CommsConnType.COMMS_CONN_RELAY );
if ( BTService.BTAvailable() ) { if ( BTService.BTAvailable() ) {
supported.add( CommsConnType.COMMS_CONN_BT ); supported.add( CommsConnType.COMMS_CONN_BT );
} }
if ( Utils.isGSMPhone( context ) ) {
supported.add( CommsConnType.COMMS_CONN_SMS );
}
if ( WiDirWrapper.enabled() ) { if ( WiDirWrapper.enabled() ) {
supported.add( CommsConnType.COMMS_CONN_P2P ); supported.add( CommsConnType.COMMS_CONN_P2P );
} }
if ( Utils.isGSMPhone( context ) ) {
supported.add( CommsConnType.COMMS_CONN_SMS );
}
return supported; return supported;
} }
@ -134,7 +148,7 @@ public class CommsAddrRec {
{ {
// Remove anything no longer supported. This probably only // Remove anything no longer supported. This probably only
// happens when key_force_radio is being messed with // happens when key_force_radio is being messed with
CommsConnTypeSet supported = getSupported( context ); List<CommsConnType> supported = getSupported( context );
for ( CommsConnType typ : set.getTypes() ) { for ( CommsConnType typ : set.getTypes() ) {
if ( ! supported.contains( typ ) ) { if ( ! supported.contains( typ ) ) {
set.remove( typ ); set.remove( typ );