mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
combine rematch-name and rematch-order alerts
This commit is contained in:
parent
1fa2b05b4c
commit
23533c6b0e
10 changed files with 101 additions and 128 deletions
|
@ -183,12 +183,12 @@ public class DBUtils {
|
|||
summary.modtime =
|
||||
cursor.getLong(cursor.
|
||||
getColumnIndex(DBHelper.LASTPLAY_TIME));
|
||||
int tmp = cursor.getInt(cursor.
|
||||
int tmpInt = cursor.getInt(cursor.
|
||||
getColumnIndex(DBHelper.GAME_OVER));
|
||||
summary.gameOver = tmp != 0;
|
||||
tmp = cursor.getInt(cursor.
|
||||
summary.gameOver = tmpInt != 0;
|
||||
tmpInt = cursor.getInt(cursor.
|
||||
getColumnIndex(DBHelper.QUASHED));
|
||||
summary.quashed = tmp != 0;
|
||||
summary.quashed = tmpInt != 0;
|
||||
|
||||
summary.lastMoveTime =
|
||||
cursor.getInt(cursor.getColumnIndex(DBHelper.LASTMOVE));
|
||||
|
@ -197,8 +197,9 @@ public class DBUtils {
|
|||
summary.created = cursor
|
||||
.getLong(cursor.getColumnIndex(DBHelper.CREATE_TIME));
|
||||
|
||||
tmp = cursor.getInt( cursor.getColumnIndex( DBHelper.CAN_REMATCH ));
|
||||
summary.canRematch = 0 != tmp;
|
||||
tmpInt = cursor.getInt( cursor.getColumnIndex( DBHelper.CAN_REMATCH ));
|
||||
summary.canRematch = 0 != (1 & tmpInt);
|
||||
summary.canOfferRO = 0 != (2 & tmpInt);
|
||||
|
||||
String str = cursor
|
||||
.getString(cursor.getColumnIndex(DBHelper.EXTRAS));
|
||||
|
@ -223,8 +224,8 @@ public class DBUtils {
|
|||
|
||||
int col = cursor.getColumnIndex( DBHelper.CONTYPE );
|
||||
if ( 0 <= col ) {
|
||||
tmp = cursor.getInt( col );
|
||||
summary.conTypes = new CommsConnTypeSet( tmp );
|
||||
tmpInt = cursor.getInt( col );
|
||||
summary.conTypes = new CommsConnTypeSet( tmpInt );
|
||||
col = cursor.getColumnIndex( DBHelper.SEED );
|
||||
if ( 0 < col ) {
|
||||
summary.seed = cursor.getInt( col );
|
||||
|
@ -264,8 +265,8 @@ public class DBUtils {
|
|||
}
|
||||
|
||||
col = cursor.getColumnIndex( DBHelper.SERVERROLE );
|
||||
tmp = cursor.getInt( col );
|
||||
summary.serverRole = DeviceRole.values()[tmp];
|
||||
tmpInt = cursor.getInt( col );
|
||||
summary.serverRole = DeviceRole.values()[tmpInt];
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
|
@ -310,7 +311,8 @@ public class DBUtils {
|
|||
values.put( DBHelper.QUASHED, summary.quashed? 1 : 0 );
|
||||
values.put( DBHelper.LASTMOVE, summary.lastMoveTime );
|
||||
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
|
||||
// JNIThread which has created the summary from common code that
|
||||
|
|
|
@ -65,7 +65,6 @@ public enum DlgID {
|
|||
GAMES_LIST_NEWGAME,
|
||||
CHANGE_CONN,
|
||||
GAMES_LIST_NAME_REMATCH,
|
||||
GAMES_LIST_GET_RO,
|
||||
ASK_DUP_PAUSE,
|
||||
CHOOSE_TILES,
|
||||
SHOW_TILES,
|
||||
|
|
|
@ -584,7 +584,7 @@ public class GameUtils {
|
|||
|
||||
public static long makeRematch( Context context, long srcRowid,
|
||||
long groupID, String gameName,
|
||||
NeedRematchOrder nro )
|
||||
RematchOrder ro )
|
||||
{
|
||||
long rowid = DBUtils.ROWID_NOTFOUND;
|
||||
try ( GameLock lock = GameLock.tryLockRO( srcRowid ) ) {
|
||||
|
@ -592,22 +592,13 @@ public class GameUtils {
|
|||
CurGameInfo gi = new CurGameInfo( context );
|
||||
try ( GamePtr gamePtr = loadMakeGame( context, gi, lock ) ) {
|
||||
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 );
|
||||
CommonPrefs cp = CommonPrefs.get( context );
|
||||
try ( GamePtr gamePtrNew = XwJNI
|
||||
.game_makeRematch( gamePtr, util, cp, gameName, ro ) ) {
|
||||
if ( null != gamePtrNew ) {
|
||||
rowid = saveNewGame1( context, gamePtrNew,
|
||||
groupID, gameName );
|
||||
}
|
||||
UtilCtxt util = new UtilCtxtImpl( context );
|
||||
CommonPrefs cp = CommonPrefs.get( context );
|
||||
try ( GamePtr gamePtrNew = XwJNI
|
||||
.game_makeRematch( gamePtr, util, cp, gameName, ro ) ) {
|
||||
if ( null != gamePtrNew ) {
|
||||
rowid = saveNewGame1( context, gamePtrNew,
|
||||
groupID, gameName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -875,24 +875,22 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
}
|
||||
break;
|
||||
|
||||
case GAMES_LIST_GET_RO: {
|
||||
NRO nro = (NRO)params[0];
|
||||
dialog = mkRematchConfigDlg( nro );
|
||||
}
|
||||
break;
|
||||
|
||||
case GAMES_LIST_NAME_REMATCH: {
|
||||
final LinearLayout view = (LinearLayout)
|
||||
LocUtils.inflate( m_activity, R.layout.msg_label_and_edit );
|
||||
final RematchConfigView view = (RematchConfigView)
|
||||
LocUtils.inflate( m_activity, R.layout.rematch_config );
|
||||
|
||||
int iconResID = R.drawable.ic_sologame;
|
||||
if ( null != m_rematchExtras ) {
|
||||
EditWClear edit = (EditWClear)view.findViewById( R.id.edit );
|
||||
edit.setText( m_rematchExtras.getString( REMATCH_NEWNAME_EXTRA ));
|
||||
long rowid = m_rematchExtras.getLong( REMATCH_ROWID_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 );
|
||||
if ( !solo ) {
|
||||
iconResID = R.drawable.ic_multigame;
|
||||
}
|
||||
view.findViewById( R.id.msg ).setVisibility( View.GONE );
|
||||
}
|
||||
|
||||
dialog = makeAlertBuilder()
|
||||
|
@ -902,12 +900,10 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
.setPositiveButton( android.R.string.ok, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
EditWClear edit = (EditWClear)((Dialog)dlg)
|
||||
.findViewById( R.id.edit );
|
||||
String gameName = edit.getText().toString();
|
||||
startRematchWithName( gameName, true );
|
||||
startRematchWithName( view.getName(), view.getRO(), true );
|
||||
}
|
||||
} )
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
.create();
|
||||
}
|
||||
break;
|
||||
|
@ -1584,30 +1580,6 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
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 )
|
||||
{
|
||||
final BackupConfigView view = (BackupConfigView)
|
||||
|
@ -2712,6 +2684,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
}
|
||||
|
||||
private void startRematchWithName( final String gameName,
|
||||
final RematchOrder ro,
|
||||
boolean showRationale )
|
||||
{
|
||||
if ( null != gameName && 0 < gameName.length() ) {
|
||||
|
@ -2721,7 +2694,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
final CommsConnTypeSet addrs = new CommsConnTypeSet( bits );
|
||||
boolean hasSMS = addrs.contains( CommsConnType.COMMS_CONN_SMS );
|
||||
if ( !hasSMS || null != SMSPhoneInfo.get( m_activity ) ) {
|
||||
rematchWithNameAndPerm( gameName, addrs );
|
||||
rematchWithNameAndPerm( gameName, ro, addrs );
|
||||
} else {
|
||||
int id = (1 == addrs.size())
|
||||
? R.string.phone_lookup_rationale_drop
|
||||
|
@ -2729,7 +2702,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
String msg = getString( R.string.phone_lookup_rationale )
|
||||
+ "\n\n" + getString( id );
|
||||
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 );
|
||||
}
|
||||
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 RematchOrder mChosenOrder = null;
|
||||
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 )
|
||||
private void rematchWithNameAndPerm( String gameName, RematchOrder ro,
|
||||
CommsConnTypeSet addrs )
|
||||
{
|
||||
if ( null != gameName && 0 < gameName.length() ) {
|
||||
Bundle extras = m_rematchExtras;
|
||||
|
@ -2800,7 +2729,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
DBUtils.GROUPID_UNSPEC );
|
||||
|
||||
long newid = GameUtils.makeRematch( m_activity, srcRowID,
|
||||
groupID, gameName, nro );
|
||||
groupID, gameName, ro );
|
||||
|
||||
if ( DBUtils.ROWID_NOTFOUND != newid ) {
|
||||
if ( extras.getBoolean( REMATCH_DELAFTER_EXTRA, false ) ) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* -*- 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
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
|
@ -50,6 +51,27 @@ public class RematchConfigView extends LinearLayout
|
|||
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
|
||||
protected void onFinishInflate()
|
||||
{
|
||||
|
@ -69,7 +91,7 @@ public class RematchConfigView extends LinearLayout
|
|||
}
|
||||
}
|
||||
|
||||
public RematchOrder onOkClicked()
|
||||
public RematchOrder getRO()
|
||||
{
|
||||
int id = mGroup.getCheckedRadioButtonId();
|
||||
RematchOrder ro = mRos.get(id);
|
||||
|
|
|
@ -85,6 +85,7 @@ public class GameSummary implements Serializable {
|
|||
public DeviceRole serverRole;
|
||||
public int nPacketsPending;
|
||||
public boolean canRematch;
|
||||
public boolean canOfferRO;
|
||||
|
||||
private Integer m_giFlags;
|
||||
private String m_playersSummary;
|
||||
|
|
|
@ -8,17 +8,44 @@
|
|||
android:padding="8dp"
|
||||
>
|
||||
|
||||
<TextView android:id="@+id/explanation"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
<!-- 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/expl_rematch_order"
|
||||
android:text="@string/game_name_label"
|
||||
/>
|
||||
|
||||
<RadioGroup android:id="@+id/group"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
<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"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/expl_rematch_order"
|
||||
/>
|
||||
|
||||
<RadioGroup android:id="@+id/group"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
</org.eehouse.android.xw4.RematchConfigView>
|
||||
|
|
|
@ -2319,6 +2319,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
|
|||
setInt( env, jsummary, "turn", summary.turn );
|
||||
setBool( env, jsummary, "turnIsLocal", summary.turnIsLocal );
|
||||
setBool( env, jsummary, "canRematch", summary.canRematch );
|
||||
setBool( env, jsummary, "canOfferRO", summary.canOfferRO );
|
||||
setInt( env, jsummary, "lastMoveTime", summary.lastMoveTime );
|
||||
setInt( env, jsummary, "dupTimerExpires", summary.dupTimerExpires );
|
||||
|
||||
|
|
|
@ -534,7 +534,7 @@ game_summarize( const XWGame* game, const CurGameInfo* gi, GameSummary* summary
|
|||
summary->gameOver = server_getGameIsOver( server );
|
||||
summary->nMoves = model_getNMoves( game->model );
|
||||
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 ) {
|
||||
const LocalPlayer* lp = &gi->players[ii];
|
||||
|
|
|
@ -56,6 +56,7 @@ typedef struct _GameSummary {
|
|||
XP_Bool gameOver;
|
||||
XP_Bool quashed;
|
||||
XP_Bool canRematch;
|
||||
XP_Bool canOfferRO;
|
||||
XP_S8 turn;
|
||||
XP_U32 lastMoveTime;
|
||||
XP_S32 dupTimerExpires;
|
||||
|
|
Loading…
Add table
Reference in a new issue