more cleanup: remove obits and relay sync menuitem

This commit is contained in:
Eric House 2022-05-10 18:58:28 -07:00
parent 5834125058
commit f97623b489
15 changed files with 11 additions and 288 deletions

View file

@ -844,7 +844,6 @@ public class BoardDelegate extends DelegateBase
boolean netGame = null != m_gi
&& DeviceRole.SERVER_STANDALONE != m_gi.serverRole;
Utils.setItemVisible( menu, R.id.gamel_menu_checkmoves, netGame );
enable = netGame && null != m_gsi && 0 < m_gsi.nPendingMessages;
Utils.setItemVisible( menu, R.id.board_menu_game_resend, enable );
@ -974,13 +973,6 @@ public class BoardDelegate extends DelegateBase
handleViaThread( JNICmd.CMD_RESEND, true, false, true );
break;
case R.id.gamel_menu_checkmoves:
makeNotAgainBuilder( R.string.not_again_sync,
R.string.key_notagain_sync,
Action.SYNC_ACTION )
.show();
break;
case R.id.board_menu_file_prefs:
m_firingPrefs = true;
PrefsDelegate.launch( m_activity );
@ -1014,9 +1006,6 @@ public class BoardDelegate extends DelegateBase
case UNDO_LAST_ACTION:
cmd = JNICmd.CMD_UNDO_LAST;
break;
case SYNC_ACTION:
doSyncMenuitem();
break;
case SMS_CONFIG_ACTION:
PrefsDelegate.launch( m_activity );
break;

View file

@ -37,7 +37,7 @@ public class DBHelper extends SQLiteOpenHelper {
public enum TABLE_NAMES {
SUM( "summaries", 0 ),
OBITS( "obits", 5 ),
_OBITS( "obits", 5 ),
DICTBROWSE( "dictbrowse", 12 ),
DICTINFO( "dictinfo", 12 ),
GROUPS( "groups", 14 ),
@ -174,11 +174,6 @@ public class DBHelper extends SQLiteOpenHelper {
,{ THUMBNAIL, "BLOB" }
};
private static final String[][] s_obitsColsAndTypes = {
{ RELAYID, "TEXT" }
,{ SEED, "INTEGER" }
};
private static final String[][] s_dictInfoColsAndTypes = {
{ DICTNAME, "TEXT" },
{ LOC, "UNSIGNED INTEGER(1)" },
@ -259,7 +254,6 @@ public class DBHelper extends SQLiteOpenHelper {
public void onCreate( SQLiteDatabase db )
{
createTable( db, TABLE_NAMES.SUM, s_summaryColsAndTypes );
createTable( db, TABLE_NAMES.OBITS, s_obitsColsAndTypes );
createTable( db, TABLE_NAMES.DICTINFO, s_dictInfoColsAndTypes );
createTable( db, TABLE_NAMES.DICTBROWSE, s_dictBrowseColsAndTypes );
forceRowidHigh( db, TABLE_NAMES.SUM );
@ -282,8 +276,6 @@ public class DBHelper extends SQLiteOpenHelper {
boolean madeChatTable = false;
boolean madeDITable = false;
switch( oldVersion ) {
case 5:
createTable( db, TABLE_NAMES.OBITS, s_obitsColsAndTypes );
case 6:
addSumColumn( db, TURN );
addSumColumn( db, GIFLAGS );

View file

@ -105,14 +105,6 @@ public class DBUtils {
private static SQLiteOpenHelper s_dbHelper = null;
private static SQLiteDatabase s_db = null;
public static class Obit {
public Obit( String relayID, int seed ) {
m_relayID = relayID; m_seed = seed;
}
String m_relayID;
int m_seed;
}
public static class HistoryPair {
private HistoryPair( String p_msg, int p_playerIndx, int p_ts )
{
@ -236,6 +228,7 @@ public class DBUtils {
CommsConnType typ = iter.next();
switch ( typ ) {
case COMMS_CONN_RELAY:
Assert.failDbg();
col = cursor.getColumnIndex( DBHelper.ROOMNAME );
if ( col >= 0 ) {
summary.roomName = cursor.getString( col );
@ -335,6 +328,7 @@ public class DBUtils {
iter.hasNext(); ) {
switch ( iter.next() ) {
case COMMS_CONN_RELAY:
Assert.failDbg();
values.put( DBHelper.ROOMNAME, summary.roomName );
String relayID = summary.relayID;
values.put( DBHelper.RELAYID, relayID );
@ -479,13 +473,6 @@ public class DBUtils {
return result;
}
public static int countOpenGamesUsingRelay( Context context )
{
int result = countOpenGamesUsing( context, CommsConnType.COMMS_CONN_RELAY,
CommsConnType.COMMS_CONN_MQTT );
return result;
}
public static int countOpenGamesUsingNBS( Context context )
{
int result = countOpenGamesUsing( context, CommsConnType.COMMS_CONN_SMS );
@ -616,6 +603,7 @@ public class DBUtils {
devName, timestamp );
break;
case RELAY:
Assert.failDbg();
msg = LocUtils.getString( context, R.string.invit_expl_relay_fmt,
timestamp );
break;
@ -803,23 +791,6 @@ public class DBUtils {
}
}
public static String getRelayID( Context context, long rowid )
{
String result = null;
String[] columns = { DBHelper.RELAYID };
String selection = String.format( ROW_ID_FMT, rowid );
initDB( context );
synchronized( s_dbHelper ) {
Cursor cursor = query( TABLE_NAMES.SUM, columns, selection );
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
result =
cursor.getString( cursor.getColumnIndex(DBHelper.RELAYID) );
}
cursor.close();
}
return result;
}
public static HashMap<Long,CommsConnTypeSet>
getGamesWithSendsPending( Context context )
{
@ -978,109 +949,6 @@ public class DBUtils {
}
}
public static String[] getRelayIDs( Context context, long[][] rowIDs )
{
String[] result = null;
String[] columns = { ROW_ID, DBHelper.RELAYID };
String selection = DBHelper.RELAYID + " NOT null";
ArrayList<String> ids = new ArrayList<>();
initDB( context );
synchronized( s_dbHelper ) {
Cursor cursor = query( TABLE_NAMES.SUM, columns, selection );
int count = cursor.getCount();
if ( 0 < count ) {
result = new String[count];
if ( null != rowIDs ) {
rowIDs[0] = new long[count];
}
int idIndex = cursor.getColumnIndex(DBHelper.RELAYID);
int rowIndex = cursor.getColumnIndex(ROW_ID);
for ( int ii = 0; cursor.moveToNext(); ++ii ) {
result[ii] = cursor.getString( idIndex );
if ( null != rowIDs ) {
rowIDs[0][ii] = cursor.getLong( rowIndex );
}
}
}
cursor.close();
}
return result;
}
public static boolean haveRelayIDs( Context context )
{
long[][] rowIDss = new long[1][];
String[] relayIDs = getRelayIDs( context, rowIDss );
boolean result = null != relayIDs && 0 < relayIDs.length;
return result;
}
public static void addDeceased( Context context, String relayID,
int seed )
{
ContentValues values = new ContentValues();
values.put( DBHelper.RELAYID, relayID );
values.put( DBHelper.SEED, seed );
initDB( context );
synchronized( s_dbHelper ) {
try {
long result = s_db.replaceOrThrow( TABLE_NAMES.OBITS.toString(),
"", values );
} catch ( Exception ex ) {
Log.ex( TAG, ex );
}
}
}
public static Obit[] listObits( Context context )
{
Obit[] result = null;
ArrayList<Obit> al = new ArrayList<>();
String[] columns = { DBHelper.RELAYID, DBHelper.SEED };
initDB( context );
synchronized( s_dbHelper ) {
Cursor cursor = query( TABLE_NAMES.OBITS, columns, null );
if ( 0 < cursor.getCount() ) {
int idIndex = cursor.getColumnIndex( DBHelper.RELAYID );
int seedIndex = cursor.getColumnIndex( DBHelper.SEED );
while ( cursor.moveToNext() ) {
String relayID = cursor.getString( idIndex );
int seed = cursor.getInt( seedIndex );
al.add( new Obit( relayID, seed ) );
}
}
cursor.close();
}
int siz = al.size();
if ( siz > 0 ) {
result = al.toArray( new Obit[siz] );
}
return result;
}
public static void clearObits( Context context, Obit[] obits )
{
String fmt = DBHelper.RELAYID + "= \"%s\" AND + "
+ DBHelper.SEED + " = %d";
initDB( context );
synchronized( s_dbHelper ) {
for ( Obit obit: obits ) {
String selection = String.format( fmt, obit.m_relayID,
obit.m_seed );
delete( TABLE_NAMES.OBITS, selection );
}
}
}
public static GameLock saveNewGame( Context context, byte[] bytes,
long groupID, String name )
{

View file

@ -599,11 +599,6 @@ public abstract class DelegateBase implements DlgClickNotify,
return m_dlgDelegate.post( runnable );
}
protected void doSyncMenuitem()
{
m_dlgDelegate.doSyncMenuitem();
}
protected void launchLookup( String[] words, int lang, boolean noStudy )
{
m_dlgDelegate.launchLookup( words, lang, noStudy );

View file

@ -39,7 +39,6 @@ public class DlgDelegate {
// GameListDelegate
RESET_GAMES,
SYNC_MENU,
NEW_FROM,
DELETE_GAMES,
DELETE_GROUPS,
@ -63,7 +62,6 @@ public class DlgDelegate {
// BoardDelegate
UNDO_LAST_ACTION,
LAUNCH_INVITE_ACTION,
SYNC_ACTION,
COMMIT_ACTION,
SHOW_EXPL_ACTION,
PREV_HINT_ACTION,
@ -416,18 +414,6 @@ public class DlgDelegate {
m_dlgt.show( state );
}
// Get rid of this?
public void doSyncMenuitem()
{
Log.d( TAG, "doSyncMenuitem()" );
if ( null == DBUtils.getRelayIDs( m_activity, null ) ) {
makeOkOnlyBuilder( R.string.no_games_to_refresh ).show();
} else {
TimerReceiver.allTimersFired( m_activity );
Utils.showToast( m_activity, R.string.msgs_progress );
}
}
public void launchLookup( String[] words, int lang, boolean noStudy )
{
m_dlgt.show( LookupAlert.newInstance( words, lang, noStudy ) );

View file

@ -1295,24 +1295,13 @@ public class GameUtils {
// deleting on relay half-games that we created but nobody
// joined, special-case this one.
if ( summary.inRelayGame() ) {
tellRelayDied( context, summary, informNow );
Assert.failDbg();
}
}
}
}
}
private static void tellRelayDied( Context context, GameSummary summary,
boolean informNow )
{
if ( null != summary.relayID ) {
DBUtils.addDeceased( context, summary.relayID, summary.seed );
if ( informNow ) {
NetUtils.informOfDeaths( context );
}
}
}
private static File makeJsonFor( File dir, NetLaunchInfo nli )
{
File result = null;

View file

@ -556,7 +556,6 @@ public class GamesListDelegate extends ListDelegateBase
R.id.games_menu_dicts,
R.id.games_menu_about,
R.id.games_menu_email,
R.id.games_menu_checkmoves,
};
private static final int[] ONEGAME_ITEMS = {
R.id.games_game_config,
@ -1041,8 +1040,6 @@ public class GamesListDelegate extends ListDelegateBase
}
} );
NetUtils.informOfDeaths( m_activity );
post( new Runnable() {
@Override
public void run() {
@ -1438,9 +1435,6 @@ public class GamesListDelegate extends ListDelegateBase
mkListAdapter(); // required because position may change
}
break;
case SYNC_MENU:
doSyncMenuitem();
break;
case NEW_FROM:
long curID = (Long)params[0];
long newid = GameUtils.dupeGame( m_activity, curID );
@ -1782,14 +1776,6 @@ public class GamesListDelegate extends ListDelegateBase
DictsDelegate.start( getDelegator() );
break;
// Get rid of this???
case R.id.games_menu_checkmoves:
makeNotAgainBuilder( R.string.not_again_sync,
R.string.key_notagain_sync,
Action.SYNC_MENU )
.show();
break;
case R.id.games_menu_checkupdates:
UpdateCheckReceiver.checkVersions( m_activity, true );
break;
@ -2747,8 +2733,6 @@ public class GamesListDelegate extends ListDelegateBase
}
invalidateOptionsMenuIf();
setTitle();
NetUtils.informOfDeaths( m_activity );
}
private boolean makeNewNetGameIf()

View file

@ -1,6 +1,6 @@
/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
/*
* Copyright 2009 - 2012 by Eric House (xwords@eehouse.org). All
* Copyright 2009 - 2022 by Eric House (xwords@eehouse.org). All
* rights reserved.
*
* This program is free software; you can redistribute it and/or

View file

@ -54,13 +54,6 @@ public class NetUtils {
private static final String TAG = NetUtils.class.getSimpleName();
public static final String k_PARAMS = "params";
public static final byte PROTOCOL_VERSION = 0;
// from xwrelay.h
public static byte PRX_PUB_ROOMS = 1;
public static byte PRX_HAS_MSGS = 2;
public static byte PRX_DEVICE_GONE = 3;
public static byte PRX_GET_MSGS = 4;
public static byte PRX_PUT_MSGS = 5;
public static Socket makeProxySocket( Context context,
int timeoutMillis )
@ -83,50 +76,6 @@ public class NetUtils {
return socket;
}
private static class InformThread extends Thread {
Context m_context;
DBUtils.Obit[] m_obits;
public InformThread( Context context, DBUtils.Obit[] obits )
{
m_context = context;
m_obits = obits;
}
@Override
public void run()
{
try {
JSONArray params = new JSONArray();
for ( int ii = 0; ii < m_obits.length; ++ii ) {
JSONObject one = new JSONObject();
one.put( "relayID", m_obits[ii].m_relayID );
one.put( "seed", m_obits[ii].m_seed );
params.put( one );
}
HttpsURLConnection conn = makeHttpsRelayConn( m_context, "kill" );
String resStr = runConn( conn, params );
Log.d( TAG, "runViaWeb(): kill(%s) => %s", params, resStr );
if ( null != resStr ) {
JSONObject result = new JSONObject( resStr );
if ( 0 == result.optInt( "err", -1 ) ) {
DBUtils.clearObits( m_context, m_obits );
}
}
} catch ( JSONException ex ) {
Assert.failDbg();
}
}
}
public static void informOfDeaths( Context context )
{
DBUtils.Obit[] obits = DBUtils.listObits( context );
if ( null != obits && 0 < obits.length ) {
new InformThread( context, obits ).start();
}
}
private static String urlForGameID( Context context, int gameID )
{
String host = XWPrefs.getPrefsString( context, R.string.key_mqtt_host );
@ -153,12 +102,13 @@ public class NetUtils {
}
}
private static final String FORCE_RELAY_HOST = null;
// private static final String FORCE_RELAY_HOST = "eehouse.org";
private static final String FORCE_HOST = null
// "eehouse.org"
;
public static String forceHost( String host )
{
if ( null != FORCE_RELAY_HOST ) {
host = FORCE_RELAY_HOST;
if ( null != FORCE_HOST ) {
host = FORCE_HOST;
}
return host;
}
@ -184,13 +134,6 @@ public class NetUtils {
context.startActivity( intent );
}
protected static HttpsURLConnection makeHttpsRelayConn( Context context,
String proc )
{
String url = XWPrefs.getDefaultRelayUrl( context );
return makeHttpsConn( context, url, proc );
}
public static HttpsURLConnection makeHttpsMQTTConn( Context context,
String proc )
{

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

View file

@ -86,10 +86,6 @@
android:title="@string/gamel_menu_study"
/>
<item android:id="@+id/gamel_menu_checkmoves"
android:title="@string/gamel_menu_checkmoves"
/>
<item android:id="@+id/board_menu_file_prefs"
android:title="@string/menu_prefs"
android:alphabeticShortcut="P"

View file

@ -68,10 +68,6 @@
android:title="@string/gamel_menu_study"
/>
<item android:id="@+id/gamel_menu_checkmoves"
android:title="@string/gamel_menu_checkmoves"
/>
<item android:id="@+id/board_menu_file_prefs"
android:title="@string/menu_prefs"
android:alphabeticShortcut="P"

View file

@ -51,11 +51,6 @@
<item android:id="@+id/games_menu_resend"
android:title="@string/board_menu_game_resend"
/>
<item android:id="@+id/games_menu_checkmoves"
android:title="@string/gamel_menu_checkmoves"
android:icon="@drawable/stat_notify_sync"
/>
<!-- Game items -->
<item android:id="@+id/games_game_delete"
android:title="@string/list_item_delete"

View file

@ -118,7 +118,6 @@
<string name="key_last_packet">key_last_packet</string>
<string name="key_udp_interval">key_udp_interval</string>
<string name="key_notagain_sync">key_notagain_sync</string>
<string name="key_notagain_newselect">key_notagain_newselect</string>
<string name="key_notagain_emptybtscan">key_notagain_emptybtscan</string>
<string name="key_notagain_backclears">key_notagain_backclears</string>

View file

@ -87,11 +87,6 @@
<string name="gamel_menu_dicts">Wordlists…</string>
<!-- text of menu that brings up the Settings (preferences) dialog -->
<string name="menu_prefs">App Settings…</string>
<!-- Regardless of the setting of the connect_frequency
preference, checks the relay immediately for any moves for
networked games on this device and posts a notification if
any is downloaded. -->
<string name="gamel_menu_checkmoves">Check for moves</string>
<!-- Text of progress indicator shown while check is being conducted -->
<string name="msgs_progress">Checking relay for moves
etc…</string>
@ -1350,10 +1345,6 @@
<!-- The following strings (all whose names start with
"not_again") appear in the New user info dialog.
-->
<!-- shown when user chooses the gamel_menu_checkmoves ("check for
moves") menu -->
<string name="not_again_sync">This action checks the relay for
pending moves/messages for all networked games.</string>
<!-- Shown when the user chooses the "board_menu_trade" menu -->
<string name="not_again_trading">You are entering tile-exchange
mode.\n\nTap tiles to add/remove them from the set to be