mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
fix handling bt invitations when the wordlist specified is missing
This commit is contained in:
parent
9031885eb0
commit
bd55ed025e
3 changed files with 87 additions and 99 deletions
|
@ -45,6 +45,7 @@ import java.util.Set;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.eehouse.android.xw4.MultiService.DictFetchOwner;
|
||||||
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
||||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
||||||
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
||||||
|
@ -1056,8 +1057,9 @@ public class BTService extends XWService {
|
||||||
if ( DictLangCache.haveDict( context, nli.lang, nli.dict ) ) {
|
if ( DictLangCache.haveDict( context, nli.lang, nli.dict ) ) {
|
||||||
result = makeGame( context, nli, btName, btAddr );
|
result = makeGame( context, nli, btName, btAddr );
|
||||||
} else {
|
} else {
|
||||||
Intent intent = MultiService.makeMissingDictIntent( context, nli );
|
Intent intent = MultiService
|
||||||
Assert.fail();
|
.makeMissingDictIntent( context, nli,
|
||||||
|
DictFetchOwner.OWNER_BT );
|
||||||
// NetLaunchInfo.putExtras( intent, gameID, btName, btAddr );
|
// NetLaunchInfo.putExtras( intent, gameID, btName, btAddr );
|
||||||
MultiService.postMissingDictNotification( context, intent,
|
MultiService.postMissingDictNotification( context, intent,
|
||||||
nli.gameID );
|
nli.gameID );
|
||||||
|
|
|
@ -43,10 +43,15 @@ public class MultiService {
|
||||||
public static final String OWNER = "OWNER";
|
public static final String OWNER = "OWNER";
|
||||||
public static final String BT_NAME = "BT_NAME";
|
public static final String BT_NAME = "BT_NAME";
|
||||||
public static final String BT_ADDRESS = "BT_ADDRESS";
|
public static final String BT_ADDRESS = "BT_ADDRESS";
|
||||||
|
public static final String NLI_DATA = "nli";
|
||||||
|
|
||||||
public static final int OWNER_SMS = 1;
|
public enum DictFetchOwner { _NONE,
|
||||||
public static final int OWNER_RELAY = 2;
|
OWNER_SMS,
|
||||||
public static final int OWNER_BT = 3;
|
OWNER_RELAY,
|
||||||
|
OWNER_BT,
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final String ACTION_FETCH_DICT = "_afd";
|
||||||
|
|
||||||
private MultiEventListener m_li;
|
private MultiEventListener m_li;
|
||||||
|
|
||||||
|
@ -102,42 +107,23 @@ public class MultiService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fillInviteIntent( Intent intent, String gameName,
|
public static Intent makeMissingDictIntent( Context context, NetLaunchInfo nli,
|
||||||
int lang, String dict,
|
DictFetchOwner owner )
|
||||||
int nPlayersT, int nPlayersH )
|
|
||||||
{
|
|
||||||
intent.putExtra( GAMENAME, gameName );
|
|
||||||
intent.putExtra( LANG, lang );
|
|
||||||
intent.putExtra( DICT, dict );
|
|
||||||
intent.putExtra( NPLAYERST, nPlayersT ); // both of these used
|
|
||||||
intent.putExtra( NPLAYERSH, nPlayersH );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Intent makeMissingDictIntent( Context context, String gameName,
|
|
||||||
int lang, String dict,
|
|
||||||
int nPlayersT, int nPlayersH )
|
|
||||||
{
|
{
|
||||||
Intent intent = new Intent( context, DictsActivity.class );
|
Intent intent = new Intent( context, DictsActivity.class );
|
||||||
fillInviteIntent( intent, gameName, lang, dict, nPlayersT, nPlayersH );
|
intent.setAction( ACTION_FETCH_DICT );
|
||||||
return intent;
|
intent.putExtra( LANG, nli.lang );
|
||||||
}
|
intent.putExtra( DICT, nli.dict );
|
||||||
|
intent.putExtra( OWNER, owner.ordinal() );
|
||||||
public static Intent makeMissingDictIntent( Context context, NetLaunchInfo nli )
|
intent.putExtra( NLI_DATA, nli.toString() );
|
||||||
{
|
|
||||||
Intent intent = makeMissingDictIntent( context, null, nli.lang, nli.dict,
|
|
||||||
nli.nPlayersT, 1 );
|
|
||||||
intent.putExtra( ROOM, nli.room );
|
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMissingDictIntent( Intent intent )
|
public static boolean isMissingDictIntent( Intent intent )
|
||||||
{
|
{
|
||||||
boolean result = intent.hasExtra( LANG )
|
String action = intent.getAction();
|
||||||
// && intent.hasExtra( DICT )
|
boolean result = null != action && action.equals( ACTION_FETCH_DICT );
|
||||||
&& (intent.hasExtra( GAMEID ) || intent.hasExtra( ROOM ))
|
// DbgUtils.logf( "isMissingDictIntent() => %b", result );
|
||||||
&& intent.hasExtra( GAMENAME )
|
|
||||||
&& intent.hasExtra( NPLAYERST )
|
|
||||||
&& intent.hasExtra( NPLAYERSH );
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,16 +165,20 @@ public class MultiService {
|
||||||
String dict = intent.getStringExtra( DICT );
|
String dict = intent.getStringExtra( DICT );
|
||||||
downloaded = DictLangCache.haveDict( context, lang, dict );
|
downloaded = DictLangCache.haveDict( context, lang, dict );
|
||||||
if ( downloaded ) {
|
if ( downloaded ) {
|
||||||
switch ( intent.getIntExtra( OWNER, -1 ) ) {
|
int ordinal = intent.getIntExtra( OWNER, -1 );
|
||||||
case OWNER_SMS:
|
if ( -1 == ordinal ) {
|
||||||
SMSService.onGameDictDownload( context, intent );
|
|
||||||
break;
|
|
||||||
case OWNER_RELAY:
|
|
||||||
case OWNER_BT:
|
|
||||||
GamesListDelegate.onGameDictDownload( context, intent );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
DbgUtils.logf( "unexpected OWNER" );
|
DbgUtils.logf( "unexpected OWNER" );
|
||||||
|
} else {
|
||||||
|
DictFetchOwner owner = DictFetchOwner.values()[ordinal];
|
||||||
|
switch ( owner ) {
|
||||||
|
case OWNER_SMS:
|
||||||
|
SMSService.onGameDictDownload( context, intent );
|
||||||
|
break;
|
||||||
|
case OWNER_RELAY:
|
||||||
|
case OWNER_BT:
|
||||||
|
GamesListDelegate.onGameDictDownload( context, intent );
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,45 +82,14 @@ public class NetLaunchInfo {
|
||||||
|
|
||||||
public NetLaunchInfo( String data )
|
public NetLaunchInfo( String data )
|
||||||
{
|
{
|
||||||
try {
|
init( data );
|
||||||
JSONObject json = new JSONObject( data );
|
}
|
||||||
|
|
||||||
int flags = json.getInt(ADDRS_KEY);
|
public NetLaunchInfo( Intent intent )
|
||||||
m_addrs = DBUtils.intToConnTypeSet( flags );
|
{
|
||||||
|
String data = intent.getStringExtra( MultiService.NLI_DATA );
|
||||||
lang = json.optInt( MultiService.LANG, -1 );
|
Assert.assertNotNull( data );
|
||||||
forceChannel = json.optInt( MultiService.FORCECHANNEL, 0 );
|
init( data );
|
||||||
dict = json.optString( MultiService.DICT );
|
|
||||||
gameName = json.optString( MultiService.GAMENAME );
|
|
||||||
nPlayersT = json.optInt( MultiService.NPLAYERST, -1 );
|
|
||||||
nPlayersH = json.optInt( MultiService.NPLAYERSH, -1 );
|
|
||||||
gameID = json.optInt( MultiService.GAMEID, -1 );
|
|
||||||
|
|
||||||
for ( CommsConnType typ : m_addrs.getTypes() ) {
|
|
||||||
switch ( typ ) {
|
|
||||||
case COMMS_CONN_BT:
|
|
||||||
btAddress = json.getString( MultiService.BT_ADDRESS );
|
|
||||||
btName = json.getString( MultiService.BT_NAME );
|
|
||||||
break;
|
|
||||||
case COMMS_CONN_RELAY:
|
|
||||||
room = json.getString( MultiService.ROOM );
|
|
||||||
m_inviteID = json.optString( MultiService.INVITEID );
|
|
||||||
break;
|
|
||||||
case COMMS_CONN_SMS:
|
|
||||||
phone = json.getString( PHONE_KEY );
|
|
||||||
isGSM = json.getBoolean( GSM_KEY );
|
|
||||||
osVers = json.getInt( OSVERS_KEY );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
DbgUtils.logf( "Unexpected typ %s", typ.toString() );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
calcValid();
|
|
||||||
} catch ( JSONException jse ) {
|
|
||||||
DbgUtils.loge( jse );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetLaunchInfo( Bundle bundle )
|
public NetLaunchInfo( Bundle bundle )
|
||||||
|
@ -195,24 +164,6 @@ public class NetLaunchInfo {
|
||||||
calcValid();
|
calcValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetLaunchInfo( Intent intent )
|
|
||||||
{
|
|
||||||
room = intent.getStringExtra( MultiService.ROOM );
|
|
||||||
m_inviteID = intent.getStringExtra( MultiService.INVITEID );
|
|
||||||
lang = intent.getIntExtra( MultiService.LANG, -1 );
|
|
||||||
forceChannel = intent.getIntExtra( MultiService.FORCECHANNEL, -1 );
|
|
||||||
dict = intent.getStringExtra( MultiService.DICT );
|
|
||||||
gameName = intent.getStringExtra( MultiService.GAMENAME );
|
|
||||||
nPlayersT = intent.getIntExtra( MultiService.NPLAYERST, -1 );
|
|
||||||
nPlayersH = intent.getIntExtra( MultiService.NPLAYERSH, -1 );
|
|
||||||
gameID = intent.getIntExtra( MultiService.GAMEID, -1 );
|
|
||||||
btName = intent.getStringExtra( MultiService.BT_NAME );
|
|
||||||
btAddress = intent.getStringExtra( MultiService.BT_ADDRESS );
|
|
||||||
m_addrs = DBUtils.intToConnTypeSet( intent.getIntExtra( ADDRS_KEY, -1 ) );
|
|
||||||
|
|
||||||
calcValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
public NetLaunchInfo( int gamID, int dictLang, String dictName, int nPlayers )
|
public NetLaunchInfo( int gamID, int dictLang, String dictName, int nPlayers )
|
||||||
{
|
{
|
||||||
this();
|
this();
|
||||||
|
@ -349,6 +300,51 @@ public class NetLaunchInfo {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void init( String data )
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
JSONObject json = new JSONObject( data );
|
||||||
|
|
||||||
|
int flags = json.getInt(ADDRS_KEY);
|
||||||
|
m_addrs = DBUtils.intToConnTypeSet( flags );
|
||||||
|
|
||||||
|
lang = json.optInt( MultiService.LANG, -1 );
|
||||||
|
forceChannel = json.optInt( MultiService.FORCECHANNEL, 0 );
|
||||||
|
dict = json.optString( MultiService.DICT );
|
||||||
|
gameName = json.optString( MultiService.GAMENAME );
|
||||||
|
nPlayersT = json.optInt( MultiService.NPLAYERST, -1 );
|
||||||
|
nPlayersH = json.optInt( MultiService.NPLAYERSH, -1 );
|
||||||
|
gameID = json.optInt( MultiService.GAMEID, -1 );
|
||||||
|
|
||||||
|
for ( CommsConnType typ : m_addrs.getTypes() ) {
|
||||||
|
switch ( typ ) {
|
||||||
|
case COMMS_CONN_BT:
|
||||||
|
btAddress = json.getString( MultiService.BT_ADDRESS );
|
||||||
|
btName = json.getString( MultiService.BT_NAME );
|
||||||
|
break;
|
||||||
|
case COMMS_CONN_RELAY:
|
||||||
|
room = json.getString( MultiService.ROOM );
|
||||||
|
m_inviteID = json.optString( MultiService.INVITEID );
|
||||||
|
break;
|
||||||
|
case COMMS_CONN_SMS:
|
||||||
|
phone = json.getString( PHONE_KEY );
|
||||||
|
isGSM = json.getBoolean( GSM_KEY );
|
||||||
|
osVers = json.getInt( OSVERS_KEY );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
DbgUtils.logf( "Unexpected typ %s", typ.toString() );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
calcValid();
|
||||||
|
} catch ( JSONException jse ) {
|
||||||
|
DbgUtils.loge( jse );
|
||||||
|
}
|
||||||
|
|
||||||
|
calcValid();
|
||||||
|
}
|
||||||
|
|
||||||
private void appendInt( Uri.Builder ub, String key, int value )
|
private void appendInt( Uri.Builder ub, String key, int value )
|
||||||
{
|
{
|
||||||
ub.appendQueryParameter( key, String.format("%d", value ) );
|
ub.appendQueryParameter( key, String.format("%d", value ) );
|
||||||
|
|
Loading…
Reference in a new issue