remove dead code around public rooms

This commit is contained in:
Eric House 2021-12-05 21:10:06 -08:00
parent cdbdf8a121
commit fd9e519eaa
8 changed files with 10 additions and 383 deletions

View file

@ -42,7 +42,6 @@ public enum DlgID {
, MOVE_DICT
, NAME_GAME
, NEW_GROUP
, NO_NAME_FOUND
, PLAYER_EDIT
, ENABLE_SMS
, QUERY_ENDGAME

View file

@ -60,9 +60,7 @@ import org.eehouse.android.xw4.jni.LocalPlayer;
import org.eehouse.android.xw4.jni.XwJNI;
public class GameConfigDelegate extends DelegateBase
implements View.OnClickListener
,XWListItem.DeleteCallback
,RefreshNamesTask.NoNameFound {
implements View.OnClickListener, XWListItem.DeleteCallback {
private static final String TAG = GameConfigDelegate.class.getSimpleName();
private static final String INTENT_FORRESULT_NEWGAME = "newgame";
@ -73,31 +71,22 @@ public class GameConfigDelegate extends DelegateBase
private static final String DIS_MAP = "DIS_MAP";
private Activity m_activity;
private CheckBox m_joinPublicCheck;
private CheckBox m_gameLockedCheck;
private boolean m_isLocked;
private boolean m_haveClosed;
private LinearLayout m_publicRoomsSet;
private LinearLayout m_privateRoomsSet;
private CommsConnTypeSet m_conTypes;
private Button m_addPlayerButton;
private Button m_changeConnButton;
private Button m_jugglePlayersButton;
private ImageButton m_refreshRoomsButton;
private View m_connectSetRelay;
private Spinner m_dictSpinner;
private Spinner m_playerDictSpinner;
private Spinner m_roomChoose;
// private Button m_configureButton;
private long m_rowid;
private boolean m_isNewGame;
private CurGameInfo m_gi;
private CurGameInfo m_giOrig;
private JNIThread m_jniThread;
private int m_whichPlayer;
// private Spinner m_roleSpinner;
// private Spinner m_connectSpinner;
private Spinner m_phoniesSpinner;
private Spinner m_boardsizeSpinner;
private Spinner m_traysizeSpinner;
@ -118,11 +107,6 @@ public class GameConfigDelegate extends DelegateBase
R.id.add_player,
R.id.lang_spinner,
R.id.dict_spinner,
R.id.join_public_room_check,
R.id.room_edit,
R.id.advertise_new_room_check,
R.id.room_spinner,
R.id.refresh_button,
R.id.hints_allowed,
R.id.duplicate_check,
R.id.pick_faceup,
@ -262,18 +246,6 @@ public class GameConfigDelegate extends DelegateBase
} );
}
break;
case NO_NAME_FOUND: {
String langName = DictLangCache.getLangName( m_activity,
m_gi.dictLang );
String msg = getString( R.string.no_name_found_fmt,
m_gi.nPlayers, xlateLang( langName ) );
dialog = makeAlertBuilder()
.setPositiveButton( android.R.string.ok, null )
// message added below since varies with language etc.
.setMessage( msg )
.create();
}
break;
case CHANGE_CONN: {
CommsConnTypeSet conTypes = (CommsConnTypeSet)params[0];
LinearLayout layout = (LinearLayout)inflate( R.layout.conn_types_display );
@ -331,8 +303,6 @@ public class GameConfigDelegate extends DelegateBase
m_car.populate( m_activity, m_conTypes );
setConnLabel();
setupRelayStuffIf();
showHideRelayStuff();
setDisableds();
}
};
@ -510,8 +480,6 @@ public class GameConfigDelegate extends DelegateBase
Assert.assertTrue( DBUtils.ROWID_NOTFOUND != m_rowid );
m_isNewGame = args.getBoolean( INTENT_FORRESULT_NEWGAME, false );
m_connectSetRelay = findViewById( R.id.connect_set_relay );
m_addPlayerButton = (Button)findViewById(R.id.add_player);
m_addPlayerButton.setOnClickListener( this );
m_changeConnButton = (Button)findViewById( R.id.change_connection );
@ -670,7 +638,6 @@ public class GameConfigDelegate extends DelegateBase
}
setConnLabel();
setupRelayStuffIf();
loadPlayersList();
configLangSpinner();
@ -783,6 +750,7 @@ public class GameConfigDelegate extends DelegateBase
}
// DeleteCallback interface
@Override
public void deleteCalled( XWListItem item )
{
if ( m_gi.delete( item.getPosition() ) ) {
@ -790,12 +758,6 @@ public class GameConfigDelegate extends DelegateBase
}
}
// NoNameFound interface
public void NoNameFound()
{
showDialogFragment( DlgID.NO_NAME_FOUND );
}
@Override
public boolean onPosButton( Action action, Object[] params )
{
@ -859,18 +821,12 @@ public class GameConfigDelegate extends DelegateBase
m_gi.juggle();
loadPlayersList();
break;
case R.id.join_public_room_check:
adjustConnectStuff();
break;
case R.id.game_locked_check:
makeNotAgainBuilder( R.string.not_again_unlock,
R.string.key_notagain_unlock,
Action.LOCKED_CHANGE_ACTION )
.show();
break;
case R.id.refresh_button:
refreshNames();
break;
case R.id.change_connection:
showConnAfterCheck();
break;
@ -1024,8 +980,6 @@ public class GameConfigDelegate extends DelegateBase
.setVisibility( names.length <= 1 ?
View.GONE : View.VISIBLE );
showHideRelayStuff();
if ( ! localOnlyGame()
&& ((0 == m_gi.remoteCount() )
|| (m_gi.nPlayers == m_gi.remoteCount()) ) ) {
@ -1243,20 +1197,6 @@ public class GameConfigDelegate extends DelegateBase
((TextView)findViewById( R.id.players_label )).setText( label );
}
private void adjustConnectStuff()
{
if ( XWPrefs.getPublicRoomsEnabled( m_activity ) ) {
if ( m_joinPublicCheck.isChecked() ) {
refreshNames();
m_privateRoomsSet.setVisibility( View.GONE );
m_publicRoomsSet.setVisibility( View.VISIBLE );
} else {
m_privateRoomsSet.setVisibility( View.VISIBLE );
m_publicRoomsSet.setVisibility( View.GONE );
}
}
}
// User's toggling whether everything's locked. That should mean
// we enable/disable a bunch of widgits. And if we're going from
// unlocked to locked we need to confirm that everything can be
@ -1329,23 +1269,6 @@ public class GameConfigDelegate extends DelegateBase
m_gi.boardSize = positionToSize( position );
m_gi.traySize = Integer.parseInt( m_traysizeSpinner.getSelectedItem().toString() );
if ( m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
m_car.ip_relay_seeksPublicRoom = m_joinPublicCheck.isChecked();
m_car.ip_relay_advertiseRoom =
getChecked( R.id.advertise_new_room_check );
if ( m_car.ip_relay_seeksPublicRoom ) {
SpinnerAdapter adapter = m_roomChoose.getAdapter();
if ( null != adapter ) {
int pos = m_roomChoose.getSelectedItemPosition();
if ( pos >= 0 && pos < adapter.getCount() ) {
m_car.ip_relay_invite = (String)adapter.getItem(pos);
}
}
} else {
m_car.ip_relay_invite = getText( R.id.room_edit ).trim();
}
}
m_car.conTypes = m_conTypes;
} // saveChanges
@ -1381,13 +1304,13 @@ public class GameConfigDelegate extends DelegateBase
}
}
private void refreshNames()
{
if ( !m_isLocked ) {
new RefreshNamesTask( m_activity, this, m_gi.dictLang,
m_gi.nPlayers, m_roomChoose ).execute();
}
}
// private void refreshNames()
// {
// if ( !m_isLocked ) {
// new RefreshNamesTask( m_activity, this, m_gi.dictLang,
// m_gi.nPlayers, m_roomChoose ).execute();
// }
// }
@Override
protected void setTitle()
@ -1432,48 +1355,4 @@ public class GameConfigDelegate extends DelegateBase
findViewById( R.id.pick_faceup ).setVisibility( View.GONE );
}
}
private void setupRelayStuffIf()
{
if ( m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
boolean publicEnabled = XWPrefs.getPublicRoomsEnabled( m_activity );
int vis = publicEnabled ? View.VISIBLE : View.GONE;
if ( null == m_joinPublicCheck ) {
m_joinPublicCheck =
(CheckBox)findViewById(R.id.join_public_room_check);
m_joinPublicCheck.setVisibility( vis );
CheckBox advertise = (CheckBox)
findViewById( R.id.advertise_new_room_check );
advertise.setVisibility( vis );
if ( publicEnabled ) {
m_joinPublicCheck.setOnClickListener( this );
m_joinPublicCheck.setChecked( m_car.ip_relay_seeksPublicRoom );
advertise.setChecked( m_car.ip_relay_advertiseRoom );
m_publicRoomsSet =
(LinearLayout)findViewById(R.id.public_rooms_set );
m_privateRoomsSet =
(LinearLayout)findViewById(R.id.private_rooms_set );
}
setText( R.id.room_edit, m_car.ip_relay_invite );
m_roomChoose = (Spinner)findViewById( R.id.room_spinner );
m_roomChoose.setVisibility( vis );
m_refreshRoomsButton =
(ImageButton)findViewById( R.id.refresh_button );
m_refreshRoomsButton.setVisibility( vis );
m_refreshRoomsButton.setOnClickListener( this );
adjustConnectStuff();
}
}
}
private void showHideRelayStuff()
{
boolean show = m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY );
m_connectSetRelay.setVisibility( show ? View.VISIBLE : View.GONE );
}
}

View file

@ -1,143 +0,0 @@
/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
/*
* Copyright 2009 - 2012 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
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import org.eehouse.android.xw4.loc.LocUtils;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import java.util.ArrayList;
public class RefreshNamesTask extends AsyncTask<Void, Void, String[]> {
private static final String TAG = RefreshNamesTask.class.getSimpleName();
public interface NoNameFound {
public void NoNameFound();
};
private Context m_context;
private Spinner m_resultSpinner;
private int m_lang;
private int m_nInGame;
private ProgressDialog m_progress;
private NoNameFound m_nnf;
public RefreshNamesTask( Context context, NoNameFound nnf,
int lang, int nInGame,
Spinner getsResults )
{
super();
m_context = context;
m_nnf = nnf;
m_resultSpinner = getsResults;
m_lang = lang;
m_nInGame = nInGame;
String langName = DictLangCache.getLangName( context, lang );
langName = LocUtils.xlateLang( context, langName );
String msg = LocUtils.getString( context, R.string.public_names_progress_fmt,
nInGame, langName );
m_progress = ProgressDialog.show( context, msg, null, true, true );
}
@Override
protected String[] doInBackground( Void...unused )
{
ArrayList<String> names = new ArrayList<>();
Log.i( TAG, "doInBackground()" );
try {
Socket socket = NetUtils.makeProxySocket( m_context, 15000 );
if ( null != socket ) {
DataOutputStream outStream =
new DataOutputStream( socket.getOutputStream() );
outStream.writeShort( 4 ); // total packet length
outStream.writeByte( NetUtils.PROTOCOL_VERSION );
outStream.writeByte( NetUtils.PRX_PUB_ROOMS );
outStream.writeByte( (byte)m_lang );
outStream.writeByte( (byte)m_nInGame );
outStream.flush();
// read result -- will block
DataInputStream dis =
new DataInputStream(socket.getInputStream());
short len = dis.readShort();
short nRooms = dis.readShort();
Log.i( TAG, "doInBackground(): got %d rooms", nRooms );
// Can't figure out how to read a null-terminated string
// from DataInputStream so parse it myself.
byte[] bytes = new byte[len];
dis.readFully( bytes );
int index = -1;
for ( int ii = 0; ii < nRooms; ++ii ) {
int lastIndex = ++index; // skip the null
while ( bytes[index] != '\n' ) {
++index;
}
String name = new String( bytes, lastIndex, index - lastIndex );
Log.i( TAG, "got public room name: %s", name );
int indx = name.lastIndexOf( "/" );
indx = name.lastIndexOf( "/", indx-1 );
names.add( name.substring(0, indx ) );
}
}
} catch ( java.io.IOException ioe ) {
Log.ex( TAG, ioe );
}
Log.i( TAG, "doInBackground() returning" );
return names.toArray( new String[names.size()] );
}
// protected void onProgressUpdate(Integer... progress) {
// setProgressPercent(progress[0]);
// }
@Override
protected void onPostExecute( String[] result )
{
Log.i( TAG, "onPostExecute()" );
ArrayAdapter<String> adapter =
new ArrayAdapter<>( m_context,
android.R.layout.simple_spinner_item,
result );
int resID = android.R.layout.simple_spinner_dropdown_item;
adapter.setDropDownViewResource( resID );
m_resultSpinner.setAdapter( adapter );
m_progress.cancel();
if ( result.length == 0 ) {
m_nnf.NoNameFound();
}
Log.i( TAG, "onPostExecute() done" );
}
}

View file

@ -103,11 +103,6 @@ public class XWPrefs {
false );
}
public static boolean getPublicRoomsEnabled( Context context )
{
return getPrefsBoolean( context, R.string.key_enable_pubroom, false );
}
public static void setHideNewgameButtons( Context context, boolean set )
{
setPrefsBoolean( context, R.string.key_hide_newgames, set );

View file

@ -105,81 +105,6 @@
android:layout_marginTop="15dp"
/>
<LinearLayout android:id="@+id/connect_set_relay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<!-- We'll use either the spinner or simple edit text
depending on whether user is naming room or picking from
a set one. -->
<CheckBox android:id="@+id/join_public_room_check"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/join_room"
/>
<LinearLayout android:id="@+id/private_rooms_set"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/new_room_hint"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<!-- maxLength derives from MAX_INVITE_LEN in xwrelay.h -->
<EditText android:id="@+id/room_edit"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollHorizontally="false"
android:maxLines="1"
android:inputType="text"
android:selectAllOnFocus="true"
android:windowSoftInputMode="stateHidden"
android:maxLength="31"
android:hint="@string/new_room_hint"
/>
</LinearLayout>
<CheckBox android:id="@+id/advertise_new_room_check"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/room_public"
/>
</LinearLayout>
<LinearLayout android:id="@+id/public_rooms_set"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Spinner android:id="@+id/room_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:gravity="left"
android:layout_weight="1"
android:prompt="@string/room_public_prompt"
/>
<ImageButton android:id="@+id/refresh_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/refresh"
android:gravity="right"
android:layout_weight="0"
/>
</LinearLayout>
</LinearLayout> <!--connect_set_relay-->
<Button android:id="@+id/change_connection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -19,7 +19,6 @@
<string name="key_hide_values">key_hide_values</string>
<string name="key_hide_title">key_hide_title</string>
<string name="key_hide_newgames">key_hide_newgames</string>
<string name="key_enable_pubroom">key_enable_pubroom</string>
<string name="key_player0">key_clr_player0</string>
<string name="key_player1">key_clr_player1</string>

View file

@ -295,27 +295,7 @@
<string name="langdict_label">Game language/wordlist</string>
<!-- text of separator marking out the connection area of the dialog -->
<string name="connect_label_fmt">Connection (via %1$s)</string>
<!-- text of checkbox asking if user wants to search for open
public rooms -->
<string name="join_room">Join public room</string>
<!-- hint (text shown when field is empty) for room name field -->
<string name="new_room_hint">Room name</string>
<!-- text of checkbox -->
<string name="room_public">Make new room public</string>
<!-- title for popup of public rooms found on server -->
<string name="room_public_prompt">Select public room</string>
<!-- If you check the join_room checkbox CrossWords queries the
relay. This is the text of the progress indicator displayed what
that's going on. (It's often visible for only a very short
time.)-->
<string name="public_names_progress_fmt">Fetching public rooms for
%1$d-player games in %2$s.</string>
<!-- If the query returns no rooms, this message is displayed,
with the number of players in the game and its language
substituted. -->
<string name="no_name_found_fmt">No public rooms found for
%1$d-player games in %2$s. Try refreshing or creating your
own.</string>
<!-- text of separator marking out other-setting area of the dialog -->
<string name="settings_label">Other settings</string>
<!-- text of checkbox. If this checkbox is checked, buttons will
@ -2278,8 +2258,6 @@
<string name="network_advanced_summary">For experienced players</string>
<string name="invite_multi_title">Invite multiple</string>
<string name="invite_multi_summary">Invite more than one player per remote device</string>
<string name="enable_pubroom_title">Enable public rooms</string>
<string name="enable_pubroom_summary">Rooms others can see and join</string>
<string name="connection_via_label">Change Communicate via</string>
<string name="set_pref">Hide buttons</string>
<string name="not_again_hidenewgamebuttons">The two buttons at the

View file

@ -6,11 +6,6 @@
<PreferenceCategory android:title="@string/network_advanced_title"
android:summary="@string/network_advanced_summary"
>
<CheckBoxPreference android:key="@string/key_enable_pubroom"
android:title="@string/enable_pubroom_title"
android:summary="@string/enable_pubroom_summary"
android:defaultValue="false"
/>
<CheckBoxPreference android:key="@string/key_invite_multi"
android:title="@string/invite_multi_title"
android:summary="@string/invite_multi_summary"