convert some more callbacks to ints passed back: GamesList done.

This commit is contained in:
Andy2 2011-08-23 20:25:59 -07:00
parent 05607a15b9
commit fbb467af80
3 changed files with 82 additions and 37 deletions

View file

@ -63,6 +63,11 @@ public class GamesList extends XWListActivity
private static final String SAVE_ROWID = "SAVE_ROWID";
private static final int NEW_NET_GAME_ACTION = 1;
private static final int RESET_GAME_ACTION = 2;
private static final int DELETE_GAME_ACTION = 3;
private static final int DELETE_ALL_ACTION = 4;
private GameListAdapter m_adapter;
private String m_missingDict;
private Handler m_handler;
@ -72,6 +77,7 @@ public class GamesList extends XWListActivity
private int m_missingDictLang;
private long m_rowid;
private String m_nameField;
private NetLaunchInfo m_netLaunchInfo;
@Override
protected Dialog onCreateDialog( int id )
@ -334,12 +340,16 @@ public class GamesList extends XWListActivity
{
super.onSaveInstanceState( outState );
outState.putLong( SAVE_ROWID, m_rowid );
if ( null != m_netLaunchInfo ) {
m_netLaunchInfo.putSelf( outState );
}
}
private void getBundledData( Bundle bundle )
{
if ( null != bundle ) {
m_rowid = bundle.getLong( SAVE_ROWID );
m_netLaunchInfo = new NetLaunchInfo( bundle );
}
}
@ -393,6 +403,32 @@ public class GamesList extends XWListActivity
onContentChanged();
}
// DlgDelegate.DlgClickNotify interface
public void buttonClicked( int id )
{
switch( id ) {
case NEW_NET_GAME_ACTION:
long rowid = GameUtils.makeNewNetGame( this, m_netLaunchInfo );
GameUtils.launchGame( this, rowid, true );
break;
case RESET_GAME_ACTION:
GameUtils.resetGame( this, m_rowid );
break;
case DELETE_GAME_ACTION:
GameUtils.deleteGame( this, m_rowid, true );
break;
case DELETE_ALL_ACTION:
long[] games = DBUtils.gamesList( this );
for ( int ii = games.length - 1; ii >= 0; --ii ) {
GameUtils.deleteGame( this, games[ii], ii == 0 );
m_adapter.inval( games[ii] );
}
break;
default:
Assert.fail();
}
}
public void itemClicked( long rowid )
{
// We need a way to let the user get back to the basic-config
@ -466,19 +502,9 @@ public class GamesList extends XWListActivity
break;
case R.id.gamel_menu_delete_all:
final long[] games = DBUtils.gamesList( this );
if ( games.length > 0 ) {
DialogInterface.OnClickListener lstnr =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
for ( int ii = games.length - 1; ii >= 0; --ii ) {
GameUtils.deleteGame( GamesList.this, games[ii],
ii == 0 );
m_adapter.inval( games[ii] );
}
}
};
showConfirmThen( R.string.confirm_delete_all, lstnr );
if ( DBUtils.gamesList( this ).length > 0 ) {
showConfirmThen( R.string.confirm_delete_all,
DELETE_ALL_ACTION );
}
handled = true;
break;
@ -525,22 +551,14 @@ public class GamesList extends XWListActivity
final long rowid = DBUtils.gamesList( this )[position];
if ( R.id.list_item_delete == menuID ) {
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int ii ) {
GameUtils.deleteGame( GamesList.this, rowid, true );
}
};
showConfirmThen( R.string.confirm_delete, lstnr );
m_rowid = rowid;
showConfirmThen( R.string.confirm_delete, DELETE_GAME_ACTION );
} else {
if ( checkWarnNoDict( rowid ) ) {
switch ( menuID ) {
case R.id.list_item_reset:
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int ii ) {
GameUtils.resetGame( GamesList.this, rowid );
}
};
showConfirmThen( R.string.confirm_reset, lstnr );
m_rowid = rowid;
showConfirmThen( R.string.confirm_reset, RESET_GAME_ACTION );
break;
case R.id.list_item_config:
GameUtils.doConfig( this, rowid, GameConfig.class );
@ -656,7 +674,7 @@ public class GamesList extends XWListActivity
startActivity( new Intent( this, NewGameActivity.class ) );
}
private void startNewNetGame( final NetLaunchInfo info )
private void startNewNetGame( NetLaunchInfo info )
{
long rowid = DBUtils.getRowIDForOpen( this, info.room, info.lang,
info.nPlayers );
@ -665,19 +683,10 @@ public class GamesList extends XWListActivity
rowid = GameUtils.makeNewNetGame( this, info );
GameUtils.launchGame( this, rowid, true );
} else {
DialogInterface.OnClickListener then =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg,
int ii ) {
long rowid = GameUtils.
makeNewNetGame( GamesList.this, info );
GameUtils.launchGame( GamesList.this,
rowid, true );
}
};
String fmt = getString( R.string.dup_game_queryf );
String msg = String.format( fmt, info.room );
showConfirmThen( msg, then );
m_netLaunchInfo = info;
showConfirmThen( msg, NEW_NET_GAME_ACTION );
}
} // startNewNetGame

View file

@ -23,6 +23,7 @@ package org.eehouse.android.xw4;
import android.content.Context;
import android.net.Uri;
import android.net.Uri.Builder;
import android.os.Bundle;
import java.net.URLEncoder;
import org.eehouse.android.xw4.jni.CommonPrefs;
@ -33,8 +34,33 @@ public class NetLaunchInfo {
public int lang;
public int nPlayers;
private static final String LANG = "netlaunchinfo_lang";
private static final String ROOM = "netlaunchinfo_room";
private static final String NPLAYERS = "netlaunchinfo_nplayers";
private static final String VALID = "netlaunchinfo_valid";
private boolean m_valid;
public void putSelf( Bundle bundle )
{
bundle.putInt( LANG, lang );
bundle.putString( ROOM, room );
bundle.putInt( NPLAYERS, nPlayers );
bundle.putBoolean( VALID, m_valid );
Utils.logf( "bundling NetLaunchInfo: %d, %s, %d, %b",
lang, room, nPlayers, m_valid );
}
public NetLaunchInfo( Bundle bundle )
{
lang = bundle.getInt( LANG );
room = bundle.getString( ROOM );
nPlayers = bundle.getInt( NPLAYERS );
m_valid = bundle.getBoolean( VALID );
Utils.logf( "unbundled NetLaunchInfo: %d, %s, %d, %b",
lang, room, nPlayers, m_valid );
}
public static Uri makeLaunchUri( Context context, String room,
int lang, int nPlayers )
{

View file

@ -144,6 +144,16 @@ public class XWListActivity extends ListActivity
m_delegate.showConfirmThen( msg, action );
}
protected void showConfirmThen( String msg, int action )
{
m_delegate.showConfirmThen( msg, action );
}
protected void showConfirmThen( int msg, int action )
{
m_delegate.showConfirmThen( getString(msg), action );
}
protected void showConfirmThen( int msgID,
DialogInterface.OnClickListener action )
{