warn about duplicate games not just when there's exactly one, and

include the most recent create time in the warning.
This commit is contained in:
Eric House 2012-11-30 07:13:00 -08:00
parent 95062fb967
commit 32d7daf2b5
3 changed files with 30 additions and 22 deletions

View file

@ -1552,8 +1552,8 @@
the same room name over and over so they'll get this warning the same room name over and over so they'll get this warning
and it's harmless to ignore it. --> and it's harmless to ignore it. -->
<string name="dup_game_queryf">You already have a game that seems <string name="dup_game_queryf">You already have a game that seems
to have been created from the same invitation. Are you sure you to have been created (on %1$s) from the same invitation. Are you
want to open another?</string> sure you want to create another?</string>
<!-- Title of generic dialog used to display information --> <!-- Title of generic dialog used to display information -->
<string name="info_title">FYI...</string> <string name="info_title">FYI...</string>

View file

@ -535,13 +535,16 @@ public class DBUtils {
} }
} }
public static long getRowIDForOpen( Context context, NetLaunchInfo nli ) // Return creation time of newest game matching this nli, or null
// if none found.
public static Date getMostRecentCreate( Context context,
NetLaunchInfo nli )
{ {
long result = ROWID_NOTFOUND; Date result = null;
initDB( context ); initDB( context );
synchronized( s_dbHelper ) { synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getReadableDatabase(); SQLiteDatabase db = s_dbHelper.getReadableDatabase();
String[] columns = { ROW_ID }; String[] columns = { DBHelper.CREATE_TIME };
String selection = String selection =
String.format( "%s='%s' AND %s='%s' AND %s=%d AND %s=%d", String.format( "%s='%s' AND %s='%s' AND %s=%d AND %s=%d",
DBHelper.ROOMNAME, nli.room, DBHelper.ROOMNAME, nli.room,
@ -549,9 +552,12 @@ public class DBUtils {
DBHelper.DICTLANG, nli.lang, DBHelper.DICTLANG, nli.lang,
DBHelper.NUM_PLAYERS, nli.nPlayersT ); DBHelper.NUM_PLAYERS, nli.nPlayersT );
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns, Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
selection, null, null, null, null ); selection, null, null, null,
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) { DBHelper.CREATE_TIME + " DESC" ); // order by
result = cursor.getLong( cursor.getColumnIndex(ROW_ID) ); while ( cursor.moveToNext() ) {
int indx = cursor.getColumnIndex( DBHelper.CREATE_TIME );
result = new Date( cursor.getLong( indx ) );
break;
} }
cursor.close(); cursor.close();
db.close(); db.close();
@ -559,14 +565,14 @@ public class DBUtils {
return result; return result;
} }
public static long getRowIDForOpen( Context context, Uri data ) public static Date getMostRecentCreate( Context context, Uri data )
{ {
long rowid = ROWID_NOTFOUND; Date result = null;
NetLaunchInfo nli = new NetLaunchInfo( context, data ); NetLaunchInfo nli = new NetLaunchInfo( context, data );
if ( null != nli && nli.isValid() ) { if ( null != nli && nli.isValid() ) {
rowid = getRowIDForOpen( context, nli ); result = getMostRecentCreate( context, nli );
} }
return rowid; return result;
} }
public static String[] getRelayIDs( Context context, boolean noMsgs ) public static String[] getRelayIDs( Context context, boolean noMsgs )

View file

@ -20,30 +20,31 @@
package org.eehouse.android.xw4; package org.eehouse.android.xw4;
import android.app.ListActivity;
import android.app.Dialog;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.preference.PreferenceManager;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Button;
import android.view.MenuInflater;
import java.io.File; import java.io.File;
import android.preference.PreferenceManager; import java.util.Date;
// import android.telephony.PhoneStateListener; // import android.telephony.PhoneStateListener;
// import android.telephony.TelephonyManager; // import android.telephony.TelephonyManager;
import junit.framework.Assert; import junit.framework.Assert;
@ -779,14 +780,15 @@ public class GamesList extends XWListActivity
private void startNewNetGame( NetLaunchInfo nli ) private void startNewNetGame( NetLaunchInfo nli )
{ {
long rowid = DBUtils.getRowIDForOpen( this, nli ); Date create = DBUtils.getMostRecentCreate( this, nli );
if ( DBUtils.ROWID_NOTFOUND == rowid ) { if ( null == create ) {
if ( checkWarnNoDict( nli ) ) { if ( checkWarnNoDict( nli ) ) {
makeNewNetGame( nli ); makeNewNetGame( nli );
} }
} else { } else {
String msg = getString( R.string.dup_game_queryf, nli.room ); String msg = getString( R.string.dup_game_queryf,
create.toString() );
m_netLaunchInfo = nli; m_netLaunchInfo = nli;
showConfirmThen( msg, NEW_NET_GAME_ACTION ); showConfirmThen( msg, NEW_NET_GAME_ACTION );
} }