combine rematch-name and rematch-order alerts

This commit is contained in:
Eric House 2024-01-13 09:04:57 -08:00
parent 1fa2b05b4c
commit 23533c6b0e
10 changed files with 101 additions and 128 deletions

View file

@ -183,12 +183,12 @@ public class DBUtils {
summary.modtime = summary.modtime =
cursor.getLong(cursor. cursor.getLong(cursor.
getColumnIndex(DBHelper.LASTPLAY_TIME)); getColumnIndex(DBHelper.LASTPLAY_TIME));
int tmp = cursor.getInt(cursor. int tmpInt = cursor.getInt(cursor.
getColumnIndex(DBHelper.GAME_OVER)); getColumnIndex(DBHelper.GAME_OVER));
summary.gameOver = tmp != 0; summary.gameOver = tmpInt != 0;
tmp = cursor.getInt(cursor. tmpInt = cursor.getInt(cursor.
getColumnIndex(DBHelper.QUASHED)); getColumnIndex(DBHelper.QUASHED));
summary.quashed = tmp != 0; summary.quashed = tmpInt != 0;
summary.lastMoveTime = summary.lastMoveTime =
cursor.getInt(cursor.getColumnIndex(DBHelper.LASTMOVE)); cursor.getInt(cursor.getColumnIndex(DBHelper.LASTMOVE));
@ -197,8 +197,9 @@ public class DBUtils {
summary.created = cursor summary.created = cursor
.getLong(cursor.getColumnIndex(DBHelper.CREATE_TIME)); .getLong(cursor.getColumnIndex(DBHelper.CREATE_TIME));
tmp = cursor.getInt( cursor.getColumnIndex( DBHelper.CAN_REMATCH )); tmpInt = cursor.getInt( cursor.getColumnIndex( DBHelper.CAN_REMATCH ));
summary.canRematch = 0 != tmp; summary.canRematch = 0 != (1 & tmpInt);
summary.canOfferRO = 0 != (2 & tmpInt);
String str = cursor String str = cursor
.getString(cursor.getColumnIndex(DBHelper.EXTRAS)); .getString(cursor.getColumnIndex(DBHelper.EXTRAS));
@ -223,8 +224,8 @@ public class DBUtils {
int col = cursor.getColumnIndex( DBHelper.CONTYPE ); int col = cursor.getColumnIndex( DBHelper.CONTYPE );
if ( 0 <= col ) { if ( 0 <= col ) {
tmp = cursor.getInt( col ); tmpInt = cursor.getInt( col );
summary.conTypes = new CommsConnTypeSet( tmp ); summary.conTypes = new CommsConnTypeSet( tmpInt );
col = cursor.getColumnIndex( DBHelper.SEED ); col = cursor.getColumnIndex( DBHelper.SEED );
if ( 0 < col ) { if ( 0 < col ) {
summary.seed = cursor.getInt( col ); summary.seed = cursor.getInt( col );
@ -264,8 +265,8 @@ public class DBUtils {
} }
col = cursor.getColumnIndex( DBHelper.SERVERROLE ); col = cursor.getColumnIndex( DBHelper.SERVERROLE );
tmp = cursor.getInt( col ); tmpInt = cursor.getInt( col );
summary.serverRole = DeviceRole.values()[tmp]; summary.serverRole = DeviceRole.values()[tmpInt];
} }
cursor.close(); cursor.close();
} }
@ -310,7 +311,8 @@ public class DBUtils {
values.put( DBHelper.QUASHED, summary.quashed? 1 : 0 ); values.put( DBHelper.QUASHED, summary.quashed? 1 : 0 );
values.put( DBHelper.LASTMOVE, summary.lastMoveTime ); values.put( DBHelper.LASTMOVE, summary.lastMoveTime );
values.put( DBHelper.NEXTDUPTIMER, summary.dupTimerExpires ); values.put( DBHelper.NEXTDUPTIMER, summary.dupTimerExpires );
values.put( DBHelper.CAN_REMATCH, summary.canRematch?1:0 ); int tmpInt = (summary.canRematch? 1 : 0) | (summary.canOfferRO? 2 : 0);
values.put( DBHelper.CAN_REMATCH, tmpInt );
// Don't overwrite extras! Sometimes this method is called from // Don't overwrite extras! Sometimes this method is called from
// JNIThread which has created the summary from common code that // JNIThread which has created the summary from common code that

View file

@ -65,7 +65,6 @@ public enum DlgID {
GAMES_LIST_NEWGAME, GAMES_LIST_NEWGAME,
CHANGE_CONN, CHANGE_CONN,
GAMES_LIST_NAME_REMATCH, GAMES_LIST_NAME_REMATCH,
GAMES_LIST_GET_RO,
ASK_DUP_PAUSE, ASK_DUP_PAUSE,
CHOOSE_TILES, CHOOSE_TILES,
SHOW_TILES, SHOW_TILES,

View file

@ -584,7 +584,7 @@ public class GameUtils {
public static long makeRematch( Context context, long srcRowid, public static long makeRematch( Context context, long srcRowid,
long groupID, String gameName, long groupID, String gameName,
NeedRematchOrder nro ) RematchOrder ro )
{ {
long rowid = DBUtils.ROWID_NOTFOUND; long rowid = DBUtils.ROWID_NOTFOUND;
try ( GameLock lock = GameLock.tryLockRO( srcRowid ) ) { try ( GameLock lock = GameLock.tryLockRO( srcRowid ) ) {
@ -592,14 +592,6 @@ public class GameUtils {
CurGameInfo gi = new CurGameInfo( context ); CurGameInfo gi = new CurGameInfo( context );
try ( GamePtr gamePtr = loadMakeGame( context, gi, lock ) ) { try ( GamePtr gamePtr = loadMakeGame( context, gi, lock ) ) {
if ( null != gamePtr ) { if ( null != gamePtr ) {
RematchOrder ro = RematchOrder.RO_SAME;
if ( XwJNI.server_canOfferRematch( gamePtr ) ) {
ro = XWPrefs.getDefaultRematchOrder( context );
if ( null == ro ) {
ro = nro.getRematchOrder();
}
}
if ( null != ro ) {
UtilCtxt util = new UtilCtxtImpl( context ); UtilCtxt util = new UtilCtxtImpl( context );
CommonPrefs cp = CommonPrefs.get( context ); CommonPrefs cp = CommonPrefs.get( context );
try ( GamePtr gamePtrNew = XwJNI try ( GamePtr gamePtrNew = XwJNI
@ -613,7 +605,6 @@ public class GameUtils {
} }
} }
} }
}
Log.d( TAG, "makeRematch() => %d", rowid ); Log.d( TAG, "makeRematch() => %d", rowid );
return rowid; return rowid;

View file

@ -875,24 +875,22 @@ public class GamesListDelegate extends ListDelegateBase
} }
break; break;
case GAMES_LIST_GET_RO: {
NRO nro = (NRO)params[0];
dialog = mkRematchConfigDlg( nro );
}
break;
case GAMES_LIST_NAME_REMATCH: { case GAMES_LIST_NAME_REMATCH: {
final LinearLayout view = (LinearLayout) final RematchConfigView view = (RematchConfigView)
LocUtils.inflate( m_activity, R.layout.msg_label_and_edit ); LocUtils.inflate( m_activity, R.layout.rematch_config );
int iconResID = R.drawable.ic_sologame; int iconResID = R.drawable.ic_sologame;
if ( null != m_rematchExtras ) { if ( null != m_rematchExtras ) {
EditWClear edit = (EditWClear)view.findViewById( R.id.edit ); long rowid = m_rematchExtras.getLong( REMATCH_ROWID_EXTRA,
edit.setText( m_rematchExtras.getString( REMATCH_NEWNAME_EXTRA )); ROWID_NOTFOUND );
GameSummary summary = GameUtils.getSummary( m_activity, rowid );
view.setName( m_rematchExtras.getString( REMATCH_NEWNAME_EXTRA ) )
.setCanOfferRO( summary.canOfferRO );
solo = m_rematchExtras.getBoolean( REMATCH_IS_SOLO, true ); solo = m_rematchExtras.getBoolean( REMATCH_IS_SOLO, true );
if ( !solo ) { if ( !solo ) {
iconResID = R.drawable.ic_multigame; iconResID = R.drawable.ic_multigame;
} }
view.findViewById( R.id.msg ).setVisibility( View.GONE );
} }
dialog = makeAlertBuilder() dialog = makeAlertBuilder()
@ -902,12 +900,10 @@ public class GamesListDelegate extends ListDelegateBase
.setPositiveButton( android.R.string.ok, new OnClickListener() { .setPositiveButton( android.R.string.ok, new OnClickListener() {
@Override @Override
public void onClick( DialogInterface dlg, int item ) { public void onClick( DialogInterface dlg, int item ) {
EditWClear edit = (EditWClear)((Dialog)dlg) startRematchWithName( view.getName(), view.getRO(), true );
.findViewById( R.id.edit );
String gameName = edit.getText().toString();
startRematchWithName( gameName, true );
} }
} ) } )
.setNegativeButton( android.R.string.cancel, null )
.create(); .create();
} }
break; break;
@ -1584,30 +1580,6 @@ public class GamesListDelegate extends ListDelegateBase
return handled || super.onDismissed( action, params ); return handled || super.onDismissed( action, params );
} }
private Dialog mkRematchConfigDlg( NRO nro )
{
final RematchConfigView view = (RematchConfigView)
LocUtils.inflate( m_activity, R.layout.rematch_config );
int iconResID = nro.isSolo()
? R.drawable.ic_sologame : R.drawable.ic_multigame;
AlertDialog.Builder ab = makeAlertBuilder()
.setView( view )
.setIcon( iconResID )
.setTitle( R.string.button_rematch )
.setNegativeButton( android.R.string.cancel, null )
.setPositiveButton( android.R.string.ok,
new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, int ii ) {
RematchOrder ro = view.onOkClicked();
nro.rerun( ro );
}
} )
;
return ab.create();
}
private Dialog mkLoadStoreDlg( final Uri uri ) private Dialog mkLoadStoreDlg( final Uri uri )
{ {
final BackupConfigView view = (BackupConfigView) final BackupConfigView view = (BackupConfigView)
@ -2712,6 +2684,7 @@ public class GamesListDelegate extends ListDelegateBase
} }
private void startRematchWithName( final String gameName, private void startRematchWithName( final String gameName,
final RematchOrder ro,
boolean showRationale ) boolean showRationale )
{ {
if ( null != gameName && 0 < gameName.length() ) { if ( null != gameName && 0 < gameName.length() ) {
@ -2721,7 +2694,7 @@ public class GamesListDelegate extends ListDelegateBase
final CommsConnTypeSet addrs = new CommsConnTypeSet( bits ); final CommsConnTypeSet addrs = new CommsConnTypeSet( bits );
boolean hasSMS = addrs.contains( CommsConnType.COMMS_CONN_SMS ); boolean hasSMS = addrs.contains( CommsConnType.COMMS_CONN_SMS );
if ( !hasSMS || null != SMSPhoneInfo.get( m_activity ) ) { if ( !hasSMS || null != SMSPhoneInfo.get( m_activity ) ) {
rematchWithNameAndPerm( gameName, addrs ); rematchWithNameAndPerm( gameName, ro, addrs );
} else { } else {
int id = (1 == addrs.size()) int id = (1 == addrs.size())
? R.string.phone_lookup_rationale_drop ? R.string.phone_lookup_rationale_drop
@ -2729,7 +2702,7 @@ public class GamesListDelegate extends ListDelegateBase
String msg = getString( R.string.phone_lookup_rationale ) String msg = getString( R.string.phone_lookup_rationale )
+ "\n\n" + getString( id ); + "\n\n" + getString( id );
Perms23.tryGetPerms( this, Perms23.NBS_PERMS, msg, Perms23.tryGetPerms( this, Perms23.NBS_PERMS, msg,
Action.ASKED_PHONE_STATE, gameName, addrs ); Action.ASKED_PHONE_STATE, gameName, ro, addrs );
} }
} }
} }
@ -2741,56 +2714,12 @@ public class GamesListDelegate extends ListDelegateBase
addrs.remove( CommsConnType.COMMS_CONN_SMS ); addrs.remove( CommsConnType.COMMS_CONN_SMS );
} }
if ( 0 < addrs.size() ) { if ( 0 < addrs.size() ) {
rematchWithNameAndPerm( (String)params[0], addrs ); rematchWithNameAndPerm( (String)params[0], (RematchOrder)params[1], addrs );
} }
} }
private class NRO implements Serializable, GameUtils.NeedRematchOrder { private void rematchWithNameAndPerm( String gameName, RematchOrder ro,
private RematchOrder mChosenOrder = null; CommsConnTypeSet addrs )
private Bundle mExtras;
private String mGameName;
private CommsConnTypeSet mAddrs;
NRO( Bundle extras, String gameName, CommsConnTypeSet addrs )
{
mExtras = extras;
mGameName = gameName;
mAddrs = addrs;
}
@Override
public RematchOrder getRematchOrder()
{
RematchOrder result = mChosenOrder;
if ( null == result ) {
showDialogFragment( DlgID.GAMES_LIST_GET_RO, this );
}
return result;
}
boolean isSolo() { return mExtras.getBoolean( REMATCH_IS_SOLO, true ); }
void rerun( RematchOrder ro )
{
mChosenOrder = ro;
m_rematchExtras = mExtras;
runOnUiThread( new Runnable() {
@Override
public void run() {
rematchWithNameAndPerm( mGameName, mAddrs, NRO.this );
}
} );
}
} // class NRO
private void rematchWithNameAndPerm( String gameName, CommsConnTypeSet addrs )
{
NRO nro = new NRO( m_rematchExtras, gameName, addrs );
rematchWithNameAndPerm( gameName, addrs, nro );
}
private void rematchWithNameAndPerm( String gameName, CommsConnTypeSet addrs,
NRO nro )
{ {
if ( null != gameName && 0 < gameName.length() ) { if ( null != gameName && 0 < gameName.length() ) {
Bundle extras = m_rematchExtras; Bundle extras = m_rematchExtras;
@ -2800,7 +2729,7 @@ public class GamesListDelegate extends ListDelegateBase
DBUtils.GROUPID_UNSPEC ); DBUtils.GROUPID_UNSPEC );
long newid = GameUtils.makeRematch( m_activity, srcRowID, long newid = GameUtils.makeRematch( m_activity, srcRowID,
groupID, gameName, nro ); groupID, gameName, ro );
if ( DBUtils.ROWID_NOTFOUND != newid ) { if ( DBUtils.ROWID_NOTFOUND != newid ) {
if ( extras.getBoolean( REMATCH_DELAFTER_EXTRA, false ) ) { if ( extras.getBoolean( REMATCH_DELAFTER_EXTRA, false ) ) {

View file

@ -1,6 +1,7 @@
/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */ /* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
/* /*
* Copyright 2023 by Eric House (xwords@eehouse.org). All rights reserved. * Copyright 2023 - 2024 by Eric House (xwords@eehouse.org). All rights
* reserved.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
@ -50,6 +51,27 @@ public class RematchConfigView extends LinearLayout
mContext = cx; mContext = cx;
} }
public RematchConfigView setName( String name )
{
EditWClear ewc = (EditWClear)findViewById( R.id.name );
ewc.setText( name );
return this;
}
public String getName()
{
EditWClear ewc = (EditWClear)findViewById( R.id.name );
return ewc.getText().toString();
}
public RematchConfigView setCanOfferRO( boolean canOfferRO )
{
if ( !canOfferRO ) {
findViewById( R.id.ro_stuff ).setVisibility( View.GONE );
}
return this;
}
@Override @Override
protected void onFinishInflate() protected void onFinishInflate()
{ {
@ -69,7 +91,7 @@ public class RematchConfigView extends LinearLayout
} }
} }
public RematchOrder onOkClicked() public RematchOrder getRO()
{ {
int id = mGroup.getCheckedRadioButtonId(); int id = mGroup.getCheckedRadioButtonId();
RematchOrder ro = mRos.get(id); RematchOrder ro = mRos.get(id);

View file

@ -85,6 +85,7 @@ public class GameSummary implements Serializable {
public DeviceRole serverRole; public DeviceRole serverRole;
public int nPacketsPending; public int nPacketsPending;
public boolean canRematch; public boolean canRematch;
public boolean canOfferRO;
private Integer m_giFlags; private Integer m_giFlags;
private String m_playersSummary; private String m_playersSummary;

View file

@ -8,6 +8,32 @@
android:padding="8dp" android:padding="8dp"
> >
<!-- copied from msg_label_and_edit -->
<TextView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/game_name_label"
/>
<org.eehouse.android.xw4.EditWClear android:id="@+id/name"
style="@style/edit_w_clear"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollHorizontally="true"
android:maxLines="1"
android:inputType="textCapWords"
android:maxLength="32"
android:textAppearance="?android:attr/textAppearanceMedium"
android:selectAllOnFocus="true"
android:focusable="false"
/>
<LinearLayout android:id="@+id/ro_stuff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView android:id="@+id/explanation" <TextView android:id="@+id/explanation"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -20,5 +46,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
/> />
</LinearLayout>
</org.eehouse.android.xw4.RematchConfigView> </org.eehouse.android.xw4.RematchConfigView>

View file

@ -2319,6 +2319,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
setInt( env, jsummary, "turn", summary.turn ); setInt( env, jsummary, "turn", summary.turn );
setBool( env, jsummary, "turnIsLocal", summary.turnIsLocal ); setBool( env, jsummary, "turnIsLocal", summary.turnIsLocal );
setBool( env, jsummary, "canRematch", summary.canRematch ); setBool( env, jsummary, "canRematch", summary.canRematch );
setBool( env, jsummary, "canOfferRO", summary.canOfferRO );
setInt( env, jsummary, "lastMoveTime", summary.lastMoveTime ); setInt( env, jsummary, "lastMoveTime", summary.lastMoveTime );
setInt( env, jsummary, "dupTimerExpires", summary.dupTimerExpires ); setInt( env, jsummary, "dupTimerExpires", summary.dupTimerExpires );

View file

@ -534,7 +534,7 @@ game_summarize( const XWGame* game, const CurGameInfo* gi, GameSummary* summary
summary->gameOver = server_getGameIsOver( server ); summary->gameOver = server_getGameIsOver( server );
summary->nMoves = model_getNMoves( game->model ); summary->nMoves = model_getNMoves( game->model );
summary->dupTimerExpires = server_getDupTimerExpires( server ); summary->dupTimerExpires = server_getDupTimerExpires( server );
summary->canRematch = server_canRematch( server, NULL ); summary->canRematch = server_canRematch( server, &summary->canOfferRO );
for ( int ii = 0; ii < gi->nPlayers; ++ii ) { for ( int ii = 0; ii < gi->nPlayers; ++ii ) {
const LocalPlayer* lp = &gi->players[ii]; const LocalPlayer* lp = &gi->players[ii];

View file

@ -56,6 +56,7 @@ typedef struct _GameSummary {
XP_Bool gameOver; XP_Bool gameOver;
XP_Bool quashed; XP_Bool quashed;
XP_Bool canRematch; XP_Bool canRematch;
XP_Bool canOfferRO;
XP_S8 turn; XP_S8 turn;
XP_U32 lastMoveTime; XP_U32 lastMoveTime;
XP_S32 dupTimerExpires; XP_S32 dupTimerExpires;