LangCode->ISOCode replacement, Android side

Now we use only ISOCode string internally to identify languages, and
since that's universal it can be built into an wordlist and used
without the build of CrossWords knowing about that language
specifically (though it'll have to know about it to have the language
name be localizable.) For legacy support, though, the old int codes
are transmitted in invitations and URLs IFF available, otherwise the
string's used. If a newer build invites and older build to play in a
too-new language there will be trouble.
This commit is contained in:
Eric House 2022-06-04 14:05:54 -07:00
parent ba132bb23d
commit 20908284f5
38 changed files with 619 additions and 505 deletions

View file

@ -254,7 +254,7 @@ public class BoardDelegate extends DelegateBase
setGotGameDict( m_mySIS.getDict ); setGotGameDict( m_mySIS.getDict );
} else { } else {
DwnldDelegate DwnldDelegate
.downloadDictInBack( m_activity, m_gi.dictLang, .downloadDictInBack( m_activity, m_gi.isoCode,
m_mySIS.getDict, m_mySIS.getDict,
BoardDelegate.this ); BoardDelegate.this );
} }
@ -925,7 +925,7 @@ public class BoardDelegate extends DelegateBase
cmd = JNICmd.CMD_TOGGLE_TRAY; cmd = JNICmd.CMD_TOGGLE_TRAY;
break; break;
case R.id.board_menu_study: case R.id.board_menu_study:
StudyListDelegate.launchOrAlert( getDelegator(), m_gi.dictLang, this ); StudyListDelegate.launchOrAlert( getDelegator(), m_gi.isoCode, this );
break; break;
case R.id.board_menu_game_netstats: case R.id.board_menu_game_netstats:
handleViaThread( JNICmd.CMD_NETSTATS, R.string.netstats_title ); handleViaThread( JNICmd.CMD_NETSTATS, R.string.netstats_title );
@ -1021,12 +1021,13 @@ public class BoardDelegate extends DelegateBase
case BUTTON_BROWSE_ACTION: case BUTTON_BROWSE_ACTION:
String curDict = m_gi.dictName( m_view.getCurPlayer() ); String curDict = m_gi.dictName( m_view.getCurPlayer() );
View button = m_toolbar.getButtonFor( Buttons.BUTTON_BROWSE_DICT ); View button = m_toolbar.getButtonFor( Buttons.BUTTON_BROWSE_DICT );
Assert.assertTrueNR( null != m_gi.isoCode );
if ( Action.BUTTON_BROWSEALL_ACTION == action && if ( Action.BUTTON_BROWSEALL_ACTION == action &&
DictsDelegate.handleDictsPopup( getDelegator(), button, DictsDelegate.handleDictsPopup( getDelegator(), button,
curDict, m_gi.dictLang ) ) { curDict, m_gi.isoCode ) ) {
// do nothing // do nothing
} else { } else {
String selDict = DictsDelegate.prevSelFor( m_activity, m_gi.dictLang ); String selDict = DictsDelegate.prevSelFor( m_activity, m_gi.isoCode );
if ( null == selDict ) { if ( null == selDict ) {
selDict = curDict; selDict = curDict;
} }
@ -1059,7 +1060,7 @@ public class BoardDelegate extends DelegateBase
cmd = JNICmd.CMD_TRADE; cmd = JNICmd.CMD_TRADE;
break; break;
case LOOKUP_ACTION: case LOOKUP_ACTION:
launchLookup( m_mySIS.words, m_gi.dictLang ); launchLookup( m_mySIS.words, m_gi.isoCode );
break; break;
case DROP_MQTT_ACTION: case DROP_MQTT_ACTION:
dropConViaAndRestart( CommsConnType.COMMS_CONN_MQTT ); dropConViaAndRestart( CommsConnType.COMMS_CONN_MQTT );
@ -1761,7 +1762,7 @@ public class BoardDelegate extends DelegateBase
post( new Runnable() { post( new Runnable() {
@Override @Override
public void run() { public void run() {
launchLookup( wordsToArray( words ), m_gi.dictLang ); launchLookup( wordsToArray( words ), m_gi.isoCode );
} }
} ); } );
} }
@ -2023,7 +2024,7 @@ public class BoardDelegate extends DelegateBase
} }
@Override @Override
public void informNetDict( int code, String oldName, public void informNetDict( String isoCode, String oldName,
String newName, String newSum, String newName, String newSum,
CurGameInfo.XWPhoniesChoice phonies ) CurGameInfo.XWPhoniesChoice phonies )
{ {
@ -2046,7 +2047,7 @@ public class BoardDelegate extends DelegateBase
DlgID dlgID; DlgID dlgID;
msg = getString( R.string.inform_dict_diffdict_fmt, msg = getString( R.string.inform_dict_diffdict_fmt,
oldName, newName, newName ); oldName, newName, newName );
if ( DictLangCache.haveDict( m_activity, code, if ( DictLangCache.haveDict( m_activity, isoCode,
newName ) ) { newName ) ) {
dlgID = DlgID.DLG_USEDICT; dlgID = DlgID.DLG_USEDICT;
} else { } else {

View file

@ -26,11 +26,15 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils; import android.text.TextUtils;
import android.database.sqlite.SQLiteException;
import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class DBHelper extends SQLiteOpenHelper { public class DBHelper extends SQLiteOpenHelper {
private static final String TAG = DBHelper.class.getSimpleName(); private static final String TAG = DBHelper.class.getSimpleName();
@ -56,7 +60,7 @@ public class DBHelper extends SQLiteOpenHelper {
private int addedVersion() { return mAddedVersion; } private int addedVersion() { return mAddedVersion; }
} }
private static final String DB_NAME = BuildConfig.DB_NAME; private static final String DB_NAME = BuildConfig.DB_NAME;
private static final int DB_VERSION = 31; private static final int DB_VERSION = 32;
public static final String GAME_NAME = "GAME_NAME"; public static final String GAME_NAME = "GAME_NAME";
public static final String VISID = "VISID"; public static final String VISID = "VISID";
@ -75,7 +79,9 @@ public class DBHelper extends SQLiteOpenHelper {
public static final String GAMEID = "GAMEID"; public static final String GAMEID = "GAMEID";
public static final String REMOTEDEVS = "REMOTEDEVS"; public static final String REMOTEDEVS = "REMOTEDEVS";
public static final String EXTRAS = "EXTRAS"; public static final String EXTRAS = "EXTRAS";
public static final String DICTLANG = "DICTLANG"; private static final String DICTLANG = "DICTLANG";
public static final String ISOCODE = "ISOCODE";
public static final String LANGNAME = "LANGNAME";
public static final String DICTLIST = "DICTLIST"; public static final String DICTLIST = "DICTLIST";
public static final String HASMSGS = "HASMSGS"; public static final String HASMSGS = "HASMSGS";
public static final String CONTRACTED = "CONTRACTED"; public static final String CONTRACTED = "CONTRACTED";
@ -100,7 +106,7 @@ public class DBHelper extends SQLiteOpenHelper {
public static final String FULLSUM = "FULLSUM"; public static final String FULLSUM = "FULLSUM";
public static final String WORDCOUNT = "WORDCOUNT"; public static final String WORDCOUNT = "WORDCOUNT";
public static final String WORDCOUNTS = "WORDCOUNTS"; public static final String WORDCOUNTS = "WORDCOUNTS";
public static final String LANGCODE = "LANGCODE"; private static final String LANGCODE = "LANGCODE";
public static final String LOC = "LOC"; public static final String LOC = "LOC";
public static final String ITERMIN = "ITERMIN"; public static final String ITERMIN = "ITERMIN";
public static final String ITERMAX = "ITERMAX"; public static final String ITERMAX = "ITERMAX";
@ -115,7 +121,7 @@ public class DBHelper extends SQLiteOpenHelper {
public static final String EXPANDED = "EXPANDED"; public static final String EXPANDED = "EXPANDED";
public static final String WORD = "WORD"; public static final String WORD = "WORD";
public static final String LANGUAGE = "LANGUAGE"; private static final String LANGUAGE = "LANGUAGE";
public static final String KEY = "KEY"; public static final String KEY = "KEY";
public static final String VALUE = "VALUE"; public static final String VALUE = "VALUE";
@ -275,6 +281,7 @@ public class DBHelper extends SQLiteOpenHelper {
boolean madeSumTable = false; boolean madeSumTable = false;
boolean madeChatTable = false; boolean madeChatTable = false;
boolean madeDITable = false; boolean madeDITable = false;
boolean madeStudyTable = false;
switch( oldVersion ) { switch( oldVersion ) {
case 6: case 6:
addSumColumn( db, TURN ); addSumColumn( db, TURN );
@ -313,6 +320,7 @@ public class DBHelper extends SQLiteOpenHelper {
} }
case 18: case 18:
createStudyTable( db ); createStudyTable( db );
madeStudyTable = true;
case 19: case 19:
if ( !madeSumTable ) { if ( !madeSumTable ) {
// NPACKETSPENDING also added by makeAutoincrement above // NPACKETSPENDING also added by makeAutoincrement above
@ -354,9 +362,25 @@ public class DBHelper extends SQLiteOpenHelper {
addColumn( db, TABLE_NAMES.DICTINFO, s_dictInfoColsAndTypes, FULLSUM ); addColumn( db, TABLE_NAMES.DICTINFO, s_dictInfoColsAndTypes, FULLSUM );
} }
// case 31: case 31:
// drop table obits if ( !madeSumTable ) {
addSumColumn( db, ISOCODE );
}
langCodeToISOCode( db, TABLE_NAMES.SUM, DICTLANG, ISOCODE );
if ( !madeStudyTable ) {
addColumn( db, TABLE_NAMES.STUDYLIST, s_studySchema, ISOCODE );
}
langCodeToISOCode( db, TABLE_NAMES.STUDYLIST, LANGUAGE, ISOCODE );
if ( !madeDITable ) {
addColumn( db, TABLE_NAMES.DICTINFO, s_dictInfoColsAndTypes, ISOCODE );
addColumn( db, TABLE_NAMES.DICTINFO, s_dictInfoColsAndTypes, LANGNAME );
}
langCodeToISOCode( db, TABLE_NAMES.DICTINFO, LANGCODE, ISOCODE );
try {
db.execSQL( "DROP TABLE " + TABLE_NAMES._OBITS + ";" );
} catch ( SQLiteException ex ) {
Log.ex( TAG, ex );
}
break; break;
default: default:
for ( TABLE_NAMES table : TABLE_NAMES.values() ) { for ( TABLE_NAMES table : TABLE_NAMES.values() ) {
@ -368,6 +392,37 @@ public class DBHelper extends SQLiteOpenHelper {
} }
} }
private void langCodeToISOCode( SQLiteDatabase db, TABLE_NAMES table,
String oldIntCol, String newIsoStringCol )
{
String[] columns = { oldIntCol };
String groupBy = columns[0];
// First gather all the lang codes
Map<Integer, String> map = new HashMap<>();
Cursor cursor = db.query( table.toString(),
columns, null, null, groupBy, null, null );
int colIndex = cursor.getColumnIndex( columns[0] );
while ( cursor.moveToNext() ) {
int code = cursor.getInt( colIndex );
String isoCode = XwJNI.lcToLocale( code );
map.put( code, isoCode );
Log.d( TAG, "added %d => %s", code, isoCode );
}
// Then update the DB
for ( Integer code : map.keySet() ) {
StringBuffer sb = new StringBuffer()
.append("Update ").append(table)
.append(" SET ").append(newIsoStringCol).append(" = '").append(map.get(code)).append("'")
.append( " WHERE ").append(oldIntCol).append(" = ").append(code)
.append(";");
String query = sb.toString();
// Log.d( TAG, "langCodeToISOCode() query: %s", query );
db.execSQL( query );
}
}
private void addSumColumn( SQLiteDatabase db, String colName ) private void addSumColumn( SQLiteDatabase db, String colName )
{ {
addColumn( db, TABLE_NAMES.SUM, s_summaryColsAndTypes, colName ); addColumn( db, TABLE_NAMES.SUM, s_summaryColsAndTypes, colName );

View file

@ -97,7 +97,7 @@ public class DBUtils {
new HashSet<>(); new HashSet<>();
public static interface StudyListListener { public static interface StudyListListener {
void onWordAdded( String word, int langCode ); void onWordAdded( String word, String isoCode );
} }
private static Set<StudyListListener> s_slListeners private static Set<StudyListListener> s_slListeners
= new HashSet<>(); = new HashSet<>();
@ -131,7 +131,7 @@ public class DBUtils {
DBHelper.CONTYPE, DBHelper.SERVERROLE, DBHelper.CONTYPE, DBHelper.SERVERROLE,
DBHelper.ROOMNAME, DBHelper.RELAYID, DBHelper.ROOMNAME, DBHelper.RELAYID,
/*DBHelper.SMSPHONE,*/ DBHelper.SEED, /*DBHelper.SMSPHONE,*/ DBHelper.SEED,
DBHelper.DICTLANG, DBHelper.GAMEID, DBHelper.ISOCODE, DBHelper.GAMEID,
DBHelper.SCORES, DBHelper.SCORES,
DBHelper.LASTPLAY_TIME, DBHelper.REMOTEDEVS, DBHelper.LASTPLAY_TIME, DBHelper.REMOTEDEVS,
DBHelper.LASTMOVE, DBHelper.NPACKETSPENDING, DBHelper.LASTMOVE, DBHelper.NPACKETSPENDING,
@ -173,9 +173,11 @@ public class DBUtils {
getString(cursor.getColumnIndex( DBHelper.PLAYERS )); getString(cursor.getColumnIndex( DBHelper.PLAYERS ));
summary.readPlayers( context, players ); summary.readPlayers( context, players );
summary.dictLang = summary.isoCode = cursor
cursor.getInt(cursor. .getString(cursor.getColumnIndex(DBHelper.ISOCODE));
getColumnIndex(DBHelper.DICTLANG)); // isoCode will be null when game first created
// Assert.assertTrueNR( null != summary.isoCode ); // fired!
summary.modtime = summary.modtime =
cursor.getLong(cursor. cursor.getLong(cursor.
getColumnIndex(DBHelper.LASTPLAY_TIME)); getColumnIndex(DBHelper.LASTPLAY_TIME));
@ -292,7 +294,8 @@ public class DBUtils {
values.put( DBHelper.GIFLAGS, summary.giflags() ); values.put( DBHelper.GIFLAGS, summary.giflags() );
values.put( DBHelper.PLAYERS, values.put( DBHelper.PLAYERS,
summary.summarizePlayers() ); summary.summarizePlayers() );
values.put( DBHelper.DICTLANG, summary.dictLang ); Assert.assertTrueNR( null != summary.isoCode );
values.put( DBHelper.ISOCODE, summary.isoCode );
values.put( DBHelper.GAMEID, summary.gameID ); values.put( DBHelper.GAMEID, summary.gameID );
values.put( DBHelper.GAME_OVER, summary.gameOver? 1 : 0 ); values.put( DBHelper.GAME_OVER, summary.gameOver? 1 : 0 );
values.put( DBHelper.LASTMOVE, summary.lastMoveTime ); values.put( DBHelper.LASTMOVE, summary.lastMoveTime );
@ -402,13 +405,13 @@ public class DBUtils {
} }
} }
public static int countGamesUsingLang( Context context, int lang ) public static int countGamesUsingISOCode( Context context, String isoCode )
{ {
int result = 0; int result = 0;
String selection = String.format( "%s = %d", DBHelper.DICTLANG, String[] columns = { DBHelper.ISOCODE };
lang ); String selection = String.format( "%s = '%s'", columns[0],
isoCode );
// null for columns will return whole rows: bad // null for columns will return whole rows: bad
String[] columns = { DBHelper.DICTLANG };
initDB( context ); initDB( context );
synchronized( s_dbHelper ) { synchronized( s_dbHelper ) {
Cursor cursor = query( TABLE_NAMES.SUM, columns, selection ); Cursor cursor = query( TABLE_NAMES.SUM, columns, selection );
@ -428,7 +431,7 @@ public class DBUtils {
DBHelper.DICTLIST, pattern ); DBHelper.DICTLIST, pattern );
// null for columns will return whole rows: bad. But // null for columns will return whole rows: bad. But
// might as well make it an int for speed // might as well make it an int for speed
String[] columns = { DBHelper.DICTLANG }; String[] columns = { DBHelper.ISOCODE };
initDB( context ); initDB( context );
synchronized( s_dbHelper ) { synchronized( s_dbHelper ) {
Cursor cursor = query( TABLE_NAMES.SUM, columns, selection ); Cursor cursor = query( TABLE_NAMES.SUM, columns, selection );
@ -1910,7 +1913,8 @@ public class DBUtils {
public static DictInfo dictsGetInfo( Context context, String name ) public static DictInfo dictsGetInfo( Context context, String name )
{ {
DictInfo result = null; DictInfo result = null;
String[] columns = { DBHelper.LANGCODE, String[] columns = { DBHelper.ISOCODE,
DBHelper.LANGNAME,
DBHelper.WORDCOUNT, DBHelper.WORDCOUNT,
DBHelper.MD5SUM, DBHelper.MD5SUM,
DBHelper.FULLSUM, DBHelper.FULLSUM,
@ -1922,14 +1926,16 @@ public class DBUtils {
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) { if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
result = new DictInfo(); result = new DictInfo();
result.name = name; result.name = name;
result.langCode = result.isoCode =
cursor.getInt( cursor.getColumnIndex(DBHelper.LANGCODE)); cursor.getString( cursor.getColumnIndex(DBHelper.ISOCODE));
result.wordCount = result.wordCount =
cursor.getInt( cursor.getColumnIndex(DBHelper.WORDCOUNT)); cursor.getInt( cursor.getColumnIndex(DBHelper.WORDCOUNT));
result.md5Sum = result.md5Sum =
cursor.getString( cursor.getColumnIndex(DBHelper.MD5SUM)); cursor.getString( cursor.getColumnIndex(DBHelper.MD5SUM));
result.fullSum = result.fullSum =
cursor.getString( cursor.getColumnIndex(DBHelper.FULLSUM)); cursor.getString( cursor.getColumnIndex(DBHelper.FULLSUM));
result.langName =
cursor.getString( cursor.getColumnIndex(DBHelper.LANGNAME));
// int loc = cursor.getInt(cursor.getColumnIndex(DBHelper.LOC)); // int loc = cursor.getInt(cursor.getColumnIndex(DBHelper.LOC));
// Log.d( TAG, "dictsGetInfo(): read sum %s/loc %d for %s", result.md5Sum, // Log.d( TAG, "dictsGetInfo(): read sum %s/loc %d for %s", result.md5Sum,
// loc, name ); // loc, name );
@ -1951,7 +1957,8 @@ public class DBUtils {
String.format( NAME_FMT, DBHelper.DICTNAME, dal.name ); String.format( NAME_FMT, DBHelper.DICTNAME, dal.name );
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put( DBHelper.LANGCODE, info.langCode ); values.put( DBHelper.ISOCODE, info.isoCode );
values.put( DBHelper.LANGNAME, info.langName );
values.put( DBHelper.WORDCOUNT, info.wordCount ); values.put( DBHelper.WORDCOUNT, info.wordCount );
values.put( DBHelper.MD5SUM, info.md5Sum ); values.put( DBHelper.MD5SUM, info.md5Sum );
values.put( DBHelper.FULLSUM, info.fullSum ); values.put( DBHelper.FULLSUM, info.fullSum );
@ -2012,37 +2019,37 @@ public class DBUtils {
} }
public static void addToStudyList( Context context, String word, public static void addToStudyList( Context context, String word,
int lang ) String isoCode )
{ {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put( DBHelper.WORD, word ); values.put( DBHelper.WORD, word );
values.put( DBHelper.LANGUAGE, lang ); values.put( DBHelper.ISOCODE, isoCode );
initDB( context ); initDB( context );
synchronized( s_dbHelper ) { synchronized( s_dbHelper ) {
insert( TABLE_NAMES.STUDYLIST, values ); insert( TABLE_NAMES.STUDYLIST, values );
} }
notifyStudyListListeners( word, lang ); notifyStudyListListeners( word, isoCode );
} }
public static int[] studyListLangs( Context context ) public static String[] studyListLangs( Context context )
{ {
int[] result = null; String[] result = null;
String groupBy = DBHelper.LANGUAGE;
String selection = null;//DBHelper.LANGUAGE; String selection = null;//DBHelper.LANGUAGE;
String[] columns = { DBHelper.LANGUAGE }; String[] columns = { DBHelper.ISOCODE };
String groupBy = columns[0];
initDB( context ); initDB( context );
synchronized( s_dbHelper ) { synchronized( s_dbHelper ) {
Cursor cursor = s_db.query( TABLE_NAMES.STUDYLIST.toString(), columns, Cursor cursor = s_db.query( TABLE_NAMES.STUDYLIST.toString(), columns,
null, null, groupBy, null, null ); null, null, groupBy, null, null );
int count = cursor.getCount(); int count = cursor.getCount();
result = new int[count]; result = new String[count];
if ( 0 < count ) { if ( 0 < count ) {
int index = 0; int index = 0;
int colIndex = cursor.getColumnIndex( DBHelper.LANGUAGE ); int colIndex = cursor.getColumnIndex( columns[0] );
while ( cursor.moveToNext() ) { while ( cursor.moveToNext() ) {
result[index++] = cursor.getInt(colIndex); result[index++] = cursor.getString(colIndex);
} }
} }
cursor.close(); cursor.close();
@ -2050,12 +2057,12 @@ public class DBUtils {
return result; return result;
} }
public static String[] studyListWords( Context context, int lang ) public static String[] studyListWords( Context context, String isoCode )
{ {
String[] result = null; String[] result = null;
String selection = String.format( "%s = %d", DBHelper.LANGUAGE, lang ); String selection = String.format( "%s = '%s'", DBHelper.ISOCODE, isoCode );
String[] columns = { DBHelper.WORD }; String[] columns = { DBHelper.WORD };
String orderBy = DBHelper.WORD; String orderBy = columns[0];
initDB( context ); initDB( context );
synchronized( s_dbHelper ) { synchronized( s_dbHelper ) {
@ -2075,9 +2082,9 @@ public class DBUtils {
return result; return result;
} }
public static void studyListClear( Context context, int lang, String[] words ) public static void studyListClear( Context context, String isoCode, String[] words )
{ {
String selection = String.format( "%s = %d", DBHelper.LANGUAGE, lang ); String selection = String.format( "%s = '%s'", DBHelper.ISOCODE, isoCode );
if ( null != words ) { if ( null != words ) {
selection += String.format( " AND %s in ('%s')", DBHelper.WORD, selection += String.format( " AND %s in ('%s')", DBHelper.WORD,
TextUtils.join("','", words) ); TextUtils.join("','", words) );
@ -2089,9 +2096,9 @@ public class DBUtils {
} }
} }
public static void studyListClear( Context context, int lang ) public static void studyListClear( Context context, String isoCode )
{ {
studyListClear( context, lang, null ); studyListClear( context, isoCode, null );
} }
public static void saveXlations( Context context, String locale, public static void saveXlations( Context context, String locale,
@ -2598,11 +2605,11 @@ public class DBUtils {
return result; return result;
} }
private static void notifyStudyListListeners( String word, int lang ) private static void notifyStudyListListeners( String word, String isoCode )
{ {
synchronized( s_slListeners ) { synchronized( s_slListeners ) {
for ( StudyListListener listener : s_slListeners ) { for ( StudyListListener listener : s_slListeners ) {
listener.onWordAdded( word, lang ); listener.onWordAdded( word, isoCode );
} }
} }
} }

View file

@ -599,15 +599,15 @@ public abstract class DelegateBase implements DlgClickNotify,
return m_dlgDelegate.post( runnable ); return m_dlgDelegate.post( runnable );
} }
protected void launchLookup( String[] words, int lang, boolean noStudy ) protected void launchLookup( String[] words, String isoCode, boolean noStudy )
{ {
m_dlgDelegate.launchLookup( words, lang, noStudy ); m_dlgDelegate.launchLookup( words, isoCode, noStudy );
} }
protected void launchLookup( String[] words, int lang ) protected void launchLookup( String[] words, String isoCode )
{ {
boolean studyOn = XWPrefs.getStudyEnabled( m_activity ); boolean studyOn = XWPrefs.getStudyEnabled( m_activity );
m_dlgDelegate.launchLookup( words, lang, !studyOn ); m_dlgDelegate.launchLookup( words, isoCode, !studyOn );
} }
protected void showInviteChoicesThen( Action action, NetLaunchInfo nli, protected void showInviteChoicesThen( Action action, NetLaunchInfo nli,

View file

@ -127,7 +127,7 @@ public class DictBrowseDelegate extends DelegateBase
} }
private Activity m_activity; private Activity m_activity;
private int m_lang; private String m_lang;
private String m_name; private String m_name;
private String mAboutStr; private String mAboutStr;
private DictUtils.DictLoc m_loc; private DictUtils.DictLoc m_loc;
@ -242,7 +242,7 @@ public class DictBrowseDelegate extends DelegateBase
m_name = name; m_name = name;
m_loc = m_loc =
DictUtils.DictLoc.values()[args.getInt( DICT_LOC, 0 )]; DictUtils.DictLoc.values()[args.getInt( DICT_LOC, 0 )];
m_lang = DictLangCache.getDictLangCode( m_activity, name ); m_lang = DictLangCache.getDictISOCode( m_activity, name );
findTableRows(); findTableRows();
m_spinnerMin = ((LabeledSpinner)findViewById( R.id.spinner_min )) m_spinnerMin = ((LabeledSpinner)findViewById( R.id.spinner_min ))
@ -345,7 +345,7 @@ public class DictBrowseDelegate extends DelegateBase
View tilesView = inflate( R.layout.tiles_table ); View tilesView = inflate( R.layout.tiles_table );
addTileRows( tilesView, info ); addTileRows( tilesView, info );
String langName = DictLangCache.getLangName( m_activity, m_lang ); String langName = DictLangCache.getLangNameForISOCode( m_activity, m_lang );
title = getString( R.string.show_tiles_title_fmt, langName ); title = getString( R.string.show_tiles_title_fmt, langName );
dialog = makeAlertBuilder() dialog = makeAlertBuilder()
.setView( tilesView ) .setView( tilesView )
@ -615,7 +615,7 @@ public class DictBrowseDelegate extends DelegateBase
if ( null != strPat && 0 < strPat.length() ) { if ( null != strPat && 0 < strPat.length() ) {
byte[][] choices = XwJNI.dict_strToTiles( m_dict, strPat ); byte[][] choices = XwJNI.dict_strToTiles( m_dict, strPat );
if ( null == choices || 0 == choices.length ) { if ( null == choices || 0 == choices.length ) {
String langName = DictLangCache.getLangName( m_activity, m_lang ); String langName = DictLangCache.getLangNameForISOCode( m_activity, m_lang );
String msg = getString( R.string.no_tiles_exist, strPat, langName ); String msg = getString( R.string.no_tiles_exist, strPat, langName );
makeOkOnlyBuilder( msg ) makeOkOnlyBuilder( msg )
.setActionPair( Action.SHOW_TILES, R.string.show_tiles_button ) .setActionPair( Action.SHOW_TILES, R.string.show_tiles_button )

View file

@ -41,22 +41,21 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
public class DictLangCache { public class DictLangCache {
private static final String TAG = DictLangCache.class.getSimpleName(); private static final String TAG = DictLangCache.class.getSimpleName();
private static Map<Integer, String> s_langNames; private static Map<String, String> s_langNames;
private static Map<String, Integer> s_langCodes; private static Map<String, String> s_langCodes;
private static Map<Integer, String> s_langCodeStrs;
private static int s_adaptedLang = -1; private static String s_adaptedLang = null;
private static LangsArrayAdapter s_langsAdapter; private static LangsArrayAdapter s_langsAdapter;
private static ArrayAdapter<String> s_dictsAdapter; private static ArrayAdapter<String> s_dictsAdapter;
private static String s_last; private static String s_last;
private static Handler s_handler; private static Handler s_handler;
public static class LangsArrayAdapter extends ArrayAdapter<String> { public static class LangsArrayAdapter extends ArrayAdapter<String> {
private Context m_context; private Context m_context;
private Map<String, String> m_map; private Map<String, String> m_map;
@ -145,43 +144,27 @@ public class DictLangCache {
return result; return result;
} }
public static String annotatedDictName( Context context, String name, // This populates the cache and will take significant time if it's mostly
int lang ) // empty and there are a lot of dicts.
{ public static int getLangCount( Context context, String isoCode )
return name + " (" + getLangName( context, lang ) + ")";
}
public static String getLangName( Context context, int code )
{
makeMaps( context );
String name = s_langNames.get( code );
if ( null == name ) {
name = s_langNames.get( 0 );
}
return name;
}
// This populates the cache and will take significant time if it's
// mostly empty and there are a lot of dicts.
public static int getLangCount( Context context, int code )
{ {
int count = 0; int count = 0;
DictAndLoc[] dals = DictUtils.dictList( context ); DictAndLoc[] dals = DictUtils.dictList( context );
for ( DictAndLoc dal : dals ) { for ( DictAndLoc dal : dals ) {
if ( code == getDictLangCode( context, dal ) ) { if ( isoCode.equals( getDictISOCode( context, dal ) ) ) {
++count; ++count;
} }
} }
return count; return count;
} }
private static DictInfo[] getInfosHaveLang( Context context, int code ) private static DictInfo[] getInfosHaveLang( Context context, String isoCode )
{ {
ArrayList<DictInfo> al = new ArrayList<>(); List<DictInfo> al = new ArrayList<>();
DictAndLoc[] dals = DictUtils.dictList( context ); DictAndLoc[] dals = DictUtils.dictList( context );
for ( DictAndLoc dal : dals ) { for ( DictAndLoc dal : dals ) {
DictInfo info = getInfo( context, dal ); DictInfo info = getInfo( context, dal );
if ( null != info && code == info.langCode ) { if ( null != info && isoCode.equals( info.isoCode ) ) {
al.add( info ); al.add( info );
} }
} }
@ -189,21 +172,10 @@ public class DictLangCache {
return result; return result;
} }
public static boolean haveDict( Context context, String lang, String name ) public static boolean haveDict( Context context, String isoCode, String name )
{
boolean result = false;
makeMaps( context );
Integer code = s_langCodes.get( lang );
if ( null != code ) {
result = haveDict( context, code, name );
}
return result;
}
public static boolean haveDict( Context context, int code, String name )
{ {
boolean found = false; boolean found = false;
DictInfo[] infos = getInfosHaveLang( context, code ); DictInfo[] infos = getInfosHaveLang( context, isoCode );
for ( DictInfo info : infos ) { for ( DictInfo info : infos ) {
if ( info.name.equals( name ) ) { if ( info.name.equals( name ) ) {
found = true; found = true;
@ -213,17 +185,17 @@ public class DictLangCache {
return found; return found;
} }
private static String[] getHaveLang( Context context, int code, private static String[] getHaveLang( Context context, String isoCode,
Comparator<DictInfo> comp, Comparator<DictInfo> comp,
boolean withCounts ) boolean withCounts )
{ {
DictInfo[] infos = getInfosHaveLang( context, code ); DictInfo[] infos = getInfosHaveLang( context, isoCode );
if ( null != comp ) { if ( null != comp ) {
Arrays.sort( infos, comp ); Arrays.sort( infos, comp );
} }
ArrayList<String> al = new ArrayList<>(); List<String> al = new ArrayList<>();
String fmt = "%s (%d)"; // must match stripCount below String fmt = "%s (%d)"; // must match stripCount below
for ( DictInfo info : infos ) { for ( DictInfo info : infos ) {
String name = info.name; String name = info.name;
@ -239,29 +211,30 @@ public class DictLangCache {
return result; return result;
} }
public static String[] getHaveLang( Context context, int code ) public static String[] getHaveLang( Context context, String isoCode )
{ {
return getHaveLang( context, code, null, false ); return getHaveLang( context, isoCode, null, false );
} }
public static DictAndLoc[] getDALsHaveLang( Context context, int code ) public static DictAndLoc[] getDALsHaveLang( Context context, String isoCode )
{ {
ArrayList<DictAndLoc> al = new ArrayList<>(); Assert.assertNotNull( isoCode );
List<DictAndLoc> al = new ArrayList<>();
DictAndLoc[] dals = DictUtils.dictList( context ); DictAndLoc[] dals = DictUtils.dictList( context );
makeMaps( context ); makeMaps( context );
for ( DictAndLoc dal : dals ) { for ( DictAndLoc dal : dals ) {
DictInfo info = getInfo( context, dal ); DictInfo info = getInfo( context, dal );
int langCode = info.langCode; if ( null != info ) {
if ( !s_langNames.containsKey( langCode ) ) { Assert.assertTrueNR( s_langNames.containsKey( info.isoCode ) );
langCode = 0; if ( isoCode.equals( info.isoCode ) ) {
}
if ( null != info && code == langCode ) {
al.add( dal ); al.add( dal );
} }
} }
}
DictAndLoc[] result = al.toArray( new DictAndLoc[al.size()] ); DictAndLoc[] result = al.toArray( new DictAndLoc[al.size()] );
Log.d( TAG, "getDALsHaveLang(%s) => %s", isoCode, result );
return result; return result;
} }
@ -273,14 +246,14 @@ public class DictLangCache {
} }
}; };
public static String[] getHaveLangByCount( Context context, int code ) public static String[] getHaveLangByCount( Context context, String isoCode )
{ {
return getHaveLang( context, code, s_ByCount, false ); return getHaveLang( context, isoCode, s_ByCount, false );
} }
public static String[] getHaveLangCounts( Context context, int code ) public static String[] getHaveLangCounts( Context context, String isoCode )
{ {
return getHaveLang( context, code, null, true ); return getHaveLang( context, isoCode, null, true );
} }
public static String stripCount( String nameWithCount ) public static String stripCount( String nameWithCount )
@ -289,15 +262,42 @@ public class DictLangCache {
return nameWithCount.substring( 0, indx ); return nameWithCount.substring( 0, indx );
} }
public static int getDictLangCode( Context context, DictAndLoc dal ) public static String getDictISOCode( Context context, DictAndLoc dal )
{ {
return getInfo( context, dal ).langCode; return getInfo( context, dal ).isoCode;
} }
public static String getLangCodeStr( Context context, int code ) public static String getDictISOCode( Context context, String dictName )
{
DictInfo info = getInfo( context, dictName );
return info.isoCode;
}
public static String getLangNameForISOCode( Context context, String isoCode )
{ {
makeMaps( context ); makeMaps( context );
return s_langCodeStrs.get( code ); return s_langNames.get( isoCode );
}
public static void setLangNameForISOCode( Context context, String isoCode,
String langName )
{
makeMaps( context );
putTwo( isoCode, langName );
}
public static String getLangIsoCode( Context context, String langName )
{
makeMaps( context );
String result = s_langCodes.get( langName );
Log.d( TAG, "getLangIsoCode(%s) => %s", langName, result );
return result;
}
public static String getDictLangName( Context context, String dictName )
{
String isoCode = getDictISOCode( context, dictName );
return getLangNameForISOCode( context, isoCode );
} }
public static String[] getDictMD5Sums( Context context, String dict ) public static String[] getDictMD5Sums( Context context, String dict )
@ -317,41 +317,10 @@ public class DictLangCache {
return path.length(); return path.length();
} }
public static int getDictLangCode( Context context, String dict ) public static String getLangName( Context context, String dictName )
{ {
return getInfo( context, dict ).langCode; String isoCode = getDictISOCode( context, dictName );
} return getLangNameForISOCode( context, isoCode );
public static int getLangLangCode( Context context, String lang )
{
makeMaps( context );
Integer code = s_langCodes.get( lang );
if ( null == code ) {
code = 0;
}
return code;
}
public static String userLangForLc( Context context, String lc )
{
makeMaps( context );
String result = null;
for ( Integer code : s_langCodeStrs.keySet() ) {
if ( s_langCodeStrs.get(code).equals(lc) ) {
result = s_langNames.get(code);
break;
}
}
return result;
}
public static String getLangName( Context context, String dict )
{
int code = getDictLangCode( context, dict );
return getLangName( context, code );
} }
// May be called from background thread // May be called from background thread
@ -402,21 +371,21 @@ public class DictLangCache {
return langs.toArray( result ); return langs.toArray( result );
} }
public static String getBestDefault( Context context, int lang, public static String getBestDefault( Context context, String isoCode,
boolean human ) boolean human )
{ {
String dict = human? CommonPrefs.getDefaultHumanDict( context ) String dictName = human? CommonPrefs.getDefaultHumanDict( context )
: CommonPrefs.getDefaultRobotDict( context ); : CommonPrefs.getDefaultRobotDict( context );
if ( lang != DictLangCache.getDictLangCode( context, dict ) ) { if ( ! isoCode.equals( getDictISOCode( context, dictName ) ) ) {
String dicts[] = getHaveLangByCount( context, lang ); String dicts[] = getHaveLangByCount( context, isoCode );
if ( dicts.length > 0 ) { if ( dicts.length > 0 ) {
// Human gets biggest; robot gets smallest // Human gets biggest; robot gets smallest
dict = dicts[ human ? 0 : dicts.length-1 ]; dictName = dicts[ human ? 0 : dicts.length-1 ];
} else { } else {
dict = null; dictName = null;
} }
} }
return dict; return dictName;
} }
private static void rebuildAdapter( ArrayAdapter<String> adapter, private static void rebuildAdapter( ArrayAdapter<String> adapter,
@ -451,47 +420,53 @@ public class DictLangCache {
} }
public static ArrayAdapter<String> getDictsAdapter( Context context, public static ArrayAdapter<String> getDictsAdapter( Context context,
int lang ) String isoCode )
{ {
if ( lang != s_adaptedLang ) { if ( ! isoCode.equals( s_adaptedLang ) ) {
s_dictsAdapter = s_dictsAdapter =
new ArrayAdapter<>(context, android.R.layout.simple_spinner_item); new ArrayAdapter<>(context, android.R.layout.simple_spinner_item);
rebuildAdapter( s_dictsAdapter, getHaveLang( context, lang ) ); rebuildAdapter( s_dictsAdapter, getHaveLang( context, isoCode ) );
s_adaptedLang = lang; s_adaptedLang = isoCode;
} }
return s_dictsAdapter; return s_dictsAdapter;
} }
private static void putTwo( String isoCode, String langName )
{
Log.d( TAG, "putTwo(): adding %s => %s", langName, isoCode );
s_langCodes.put( langName, isoCode );
s_langNames.put( isoCode, langName );
}
private static void makeMaps( Context context ) private static void makeMaps( Context context )
{ {
if ( null == s_langNames ) { if ( null == s_langNames ) {
s_langCodes = new HashMap<>(); s_langCodes = new HashMap<>();
s_langNames = new HashMap<>(); s_langNames = new HashMap<>();
s_langCodeStrs = new HashMap<>();
Resources res = context.getResources(); Resources res = context.getResources();
String[] entries = res.getStringArray( R.array.languages_map ); String[] entries = res.getStringArray( R.array.language_names );
for ( int ii = 0; ii < entries.length; ii += 3 ) { for ( int ii = 0; ii < entries.length; ii += 2 ) {
Integer code = Integer.parseInt(entries[ii]); String isoCode = entries[ii];
String name = entries[ii+1]; String langName = entries[ii+1];
String lc = entries[ii+2]; putTwo( isoCode, langName );
s_langCodes.put( name, code );
s_langNames.put( code, name );
s_langCodeStrs.put( code, lc );
}
}
} }
public static int getDictCount( Context context, String name ) // Now deal with any dicts too new for their isoCodes to be in
{ // language_names
int result = 0; DictAndLoc[] dals = DictUtils.dictList( context ) ;
for ( DictAndLoc dal : DictUtils.dictList( context ) ) { for ( DictAndLoc dal : dals ) {
if ( name.equals( dal.name ) ) { DictInfo info = getInfo( context, dal );
++result; String isoCode = info.isoCode;
if ( !s_langNames.containsKey( isoCode ) ) {
Log.d( TAG, "looking at info %s", info );
Assert.assertTrueNR( null != info.langName );
Log.d( TAG, "makeMaps(2): adding %s => %s", info.langName, isoCode );
putTwo( isoCode, info.langName );
} }
} }
Assert.assertTrue( result > 0 ); Log.d( TAG, "makeMaps() DONE" );
return result; }
} }
private static DictInfo getInfo( Context context, String name ) private static DictInfo getInfo( Context context, String name )
@ -509,7 +484,7 @@ public class DictLangCache {
DictInfo info = DBUtils.dictsGetInfo( context, dal.name ); DictInfo info = DBUtils.dictsGetInfo( context, dal.name );
// Tmp test that recovers from problem with new background download code // Tmp test that recovers from problem with new background download code
if ( null != info && 0 == info.langCode ) { if ( null != info && null == info.isoCode ) {
Log.w( TAG, "getInfo: dropping info for %s b/c lang code wrong", Log.w( TAG, "getInfo: dropping info for %s b/c lang code wrong",
dal.name ); dal.name );
info = null; info = null;

View file

@ -25,6 +25,8 @@ import android.util.AttributeSet;
import java.util.ArrayList; import java.util.ArrayList;
import org.eehouse.android.xw4.loc.LocUtils;
public class DictListPreference extends XWListPreference { public class DictListPreference extends XWListPreference {
public DictListPreference( Context context, AttributeSet attrs ) public DictListPreference( Context context, AttributeSet attrs )
@ -43,18 +45,20 @@ public class DictListPreference extends XWListPreference {
private String[] setEntriesForLang() private String[] setEntriesForLang()
{ {
Context context = getContext(); Context context = getContext();
String curLang = XWPrefs.getPrefsString( context, R.string.key_default_language ); String curLang = XWPrefs
int langCode = DictLangCache.getLangLangCode( context, curLang ); .getPrefsString( context, R.string.key_default_language, null );
if ( null == curLang ) {
curLang = LocUtils.getString( context, R.string.lang_name_english );
}
String isoCode = DictLangCache.getLangIsoCode( context, curLang );
DictUtils.DictAndLoc[] dals = DictUtils.dictList( context ); DictUtils.DictAndLoc[] dals = DictUtils.dictList( context );
ArrayList<String> dictEntries = new ArrayList<>(); ArrayList<String> dictEntries = new ArrayList<>();
ArrayList<String> values = new ArrayList<>(); ArrayList<String> values = new ArrayList<>();
for ( int ii = 0; ii < dals.length; ++ii ) { for ( DictUtils.DictAndLoc dal : dals ) {
String name = dals[ii].name; if ( isoCode.equals( DictLangCache.getDictISOCode( context, dal ) ) ) {
if ( langCode == DictLangCache.getDictLangCode( context, name ) ) { values.add( dal.name );
values.add( name ); dictEntries.add( DictLangCache.annotatedDictName( context, dal ) );
dictEntries.add( DictLangCache.annotatedDictName( context,
dals[ii] ) );
} }
} }
setEntries( dictEntries.toArray( new String[dictEntries.size()] ) ); setEntries( dictEntries.toArray( new String[dictEntries.size()] ) );

View file

@ -114,16 +114,16 @@ public class DictsDelegate extends ListDelegateBase
private static class DictInfo implements Comparable, Serializable { private static class DictInfo implements Comparable, Serializable {
public String m_name; public String m_name;
public String m_localLang; // what we display to user, i.e. translated public String m_localLang; // what we display to user, i.e. translated
public String m_urlLang; // what needs to be in URL public String mISOCode; // what needs to be in URL
public int m_nWords; public int m_nWords;
public long m_nBytes; public long m_nBytes;
public String m_note; public String m_note;
public DictInfo( String name, String urlLang, String localLang, public DictInfo( String name, String isoCode, String localLang,
int nWords, long nBytes, String note ) int nWords, long nBytes, String note )
{ {
m_name = name; m_name = name;
m_localLang = localLang; m_localLang = localLang;
m_urlLang = urlLang; mISOCode = isoCode;
m_nWords = nWords; m_nWords = nWords;
m_nBytes = nBytes; m_nBytes = nBytes;
m_note = note; m_note = note;
@ -292,8 +292,8 @@ public class DictsDelegate extends ListDelegateBase
ArrayList<Object> result = new ArrayList<>(); ArrayList<Object> result = new ArrayList<>();
HashSet<String> locals = new HashSet<>(); HashSet<String> locals = new HashSet<>();
int lang = DictLangCache.getLangLangCode( m_context, langName ); String isoCode = DictLangCache.getLangIsoCode( m_context, langName );
DictAndLoc[] dals = DictLangCache.getDALsHaveLang( m_context, lang ); DictAndLoc[] dals = DictLangCache.getDALsHaveLang( m_context, isoCode );
if ( null != dals ) { if ( null != dals ) {
for ( DictAndLoc dal : dals ) { for ( DictAndLoc dal : dals ) {
locals.add( dal.name ); locals.add( dal.name );
@ -381,25 +381,27 @@ public class DictsDelegate extends ListDelegateBase
break; break;
case SET_DEFAULT: { case SET_DEFAULT: {
final String name = m_selDicts.keySet().iterator().next(); final String dictName = m_selDicts.keySet().iterator().next();
lstnr = new OnClickListener() { lstnr = new OnClickListener() {
@Override @Override
public void onClick( DialogInterface dlg, int item ) { public void onClick( DialogInterface dlg, int item ) {
if ( DialogInterface.BUTTON_NEGATIVE == item if ( DialogInterface.BUTTON_NEGATIVE == item
|| DialogInterface.BUTTON_POSITIVE == item ) { || DialogInterface.BUTTON_POSITIVE == item ) {
setDefault( name, R.string.key_default_dict, setDefault( dictName, R.string.key_default_dict,
R.string.key_default_robodict ); R.string.key_default_robodict );
} }
if ( DialogInterface.BUTTON_NEGATIVE == item if ( DialogInterface.BUTTON_NEGATIVE == item
|| DialogInterface.BUTTON_NEUTRAL == item ) { || DialogInterface.BUTTON_NEUTRAL == item ) {
setDefault( name, R.string.key_default_robodict, setDefault( dictName, R.string.key_default_robodict,
R.string.key_default_dict ); R.string.key_default_dict );
} }
} }
}; };
String lang = DictLangCache.getLangName( m_activity, name); String lang = DictLangCache.getDictLangName( m_activity,
dictName );
lang = xlateLang( lang ); lang = xlateLang( lang );
message = getString( R.string.set_default_message_fmt, name, lang ); message = getString( R.string.set_default_message_fmt,
dictName, lang );
dialog = makeAlertBuilder() dialog = makeAlertBuilder()
.setTitle( R.string.query_title ) .setTitle( R.string.query_title )
.setMessage( message ) .setMessage( message )
@ -415,11 +417,11 @@ public class DictsDelegate extends ListDelegateBase
@Override @Override
public void onClick( DialogInterface dlg, int item ) { public void onClick( DialogInterface dlg, int item ) {
Intent intent = getIntent(); Intent intent = getIntent();
int lang = intent.getIntExtra( MultiService.LANG, -1 ); String isoCode = intent.getStringExtra( MultiService.ISO );
String name = intent.getStringExtra( MultiService.DICT ); String name = intent.getStringExtra( MultiService.DICT );
m_launchedForMissing = true; m_launchedForMissing = true;
DwnldDelegate DwnldDelegate
.downloadDictInBack( m_activity, lang, name, .downloadDictInBack( m_activity, isoCode, name,
DictsDelegate.this ); DictsDelegate.this );
} }
}; };
@ -476,9 +478,9 @@ public class DictsDelegate extends ListDelegateBase
m_showRemote = true; m_showRemote = true;
m_checkbox.setVisibility( View.GONE ); m_checkbox.setVisibility( View.GONE );
int lang = args.getInt( DICT_LANG_EXTRA, 0 ); String isoCode = args.getString( DICT_LANG_EXTRA );
if ( 0 < lang ) { if ( null != isoCode ) {
m_filterLang = DictLangCache.getLangName( m_activity, lang ); m_filterLang = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
m_closedLangs.remove( m_filterLang ); m_closedLangs.remove( m_filterLang );
} }
String name = args.getString( DICT_NAME_EXTRA ); String name = args.getString( DICT_NAME_EXTRA );
@ -486,7 +488,7 @@ public class DictsDelegate extends ListDelegateBase
new FetchListTask( m_activity ).execute(); new FetchListTask( m_activity ).execute();
} else { } else {
m_finishOnName = name; m_finishOnName = name;
startDownload( lang, name ); startDownload( isoCode, name );
} }
} }
@ -620,8 +622,8 @@ public class DictsDelegate extends ListDelegateBase
if ( cached instanceof DictInfo ) { if ( cached instanceof DictInfo ) {
DictInfo info = (DictInfo)cached; DictInfo info = (DictInfo)cached;
String name = entry.getKey(); String name = entry.getKey();
Uri uri = Utils.makeDictUri( m_activity, info.m_urlLang, Uri uri = Utils.makeDictUriFromCode( m_activity,
name ); info.mISOCode, name );
uris[count] = uri; uris[count] = uri;
names[count] = name; names[count] = name;
++count; ++count;
@ -721,10 +723,10 @@ public class DictsDelegate extends ListDelegateBase
private void setDefault( String name, int keyId, int otherKey ) private void setDefault( String name, int keyId, int otherKey )
{ {
int langCode = DictLangCache.getDictLangCode( m_activity, name ); String isoCode = DictLangCache.getDictISOCode( m_activity, name );
String curLangName = XWPrefs.getPrefsString( m_activity, R.string.key_default_language ); String curLangName = XWPrefs.getPrefsString( m_activity, R.string.key_default_language );
int curLangCode = DictLangCache.getLangLangCode( m_activity, curLangName ); String curISOCode = DictLangCache.getLangIsoCode( m_activity, curLangName );
boolean changeLang = langCode != curLangCode; boolean changeLang = !isoCode.equals( curISOCode );
SharedPreferences sp SharedPreferences sp
= PreferenceManager.getDefaultSharedPreferences( m_activity ); = PreferenceManager.getDefaultSharedPreferences( m_activity );
@ -738,7 +740,7 @@ public class DictsDelegate extends ListDelegateBase
editor.putString( key, name ); editor.putString( key, name );
// and change language // and change language
String langName = DictLangCache.getLangName( m_activity, langCode ); String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
key = getString( R.string.key_default_language ); key = getString( R.string.key_default_language );
editor.putString( key, langName ); editor.putString( key, langName );
} }
@ -807,10 +809,10 @@ public class DictsDelegate extends ListDelegateBase
// a different same-lang wordlist to open a game. // a different same-lang wordlist to open a game.
class LangDelData { class LangDelData {
public LangDelData( int langCode ) { public LangDelData( String isoCode ) {
delDicts = new HashSet<>(); delDicts = new HashSet<>();
langName = DictLangCache.getLangName( m_activity, langCode ); langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
nDicts = DictLangCache.getDALsHaveLang( m_activity, langCode ).length; nDicts = DictLangCache.getDALsHaveLang( m_activity, isoCode ).length;
} }
public String dictsStr() public String dictsStr()
{ {
@ -826,22 +828,22 @@ public class DictsDelegate extends ListDelegateBase
int nDicts; int nDicts;
} }
Map<Integer, LangDelData> dels = new HashMap<>(); Map<String, LangDelData> dels = new HashMap<>();
Set<Integer> skipLangs = new HashSet<>(); Set<String> skipLangs = new HashSet<>();
for ( String dict : m_selDicts.keySet() ) { for ( String dict : m_selDicts.keySet() ) {
int langCode = DictLangCache.getDictLangCode( m_activity, dict ); String isoCode = DictLangCache.getDictISOCode( m_activity, dict );
if ( skipLangs.contains( langCode ) ) { if ( skipLangs.contains( isoCode ) ) {
continue; continue;
} }
int nUsingLang = DBUtils.countGamesUsingLang( m_activity, langCode ); int nUsingLang = DBUtils.countGamesUsingISOCode( m_activity, isoCode );
if ( 0 == nUsingLang ) { if ( 0 == nUsingLang ) {
// remember, since countGamesUsingLang is expensive // remember, since countGamesUsingLang is expensive
skipLangs.add( langCode ); skipLangs.add( isoCode );
} else { } else {
LangDelData data = dels.get( langCode ); LangDelData data = dels.get( isoCode );
if ( null == data ) { if ( null == data ) {
data = new LangDelData( langCode ); data = new LangDelData( isoCode );
dels.put( langCode, data ); dels.put( isoCode, data );
} }
data.delDicts.add( dict ); data.delDicts.add( dict );
} }
@ -950,9 +952,9 @@ public class DictsDelegate extends ListDelegateBase
DictLangCache.inval( m_activity, dict, loc, false ); DictLangCache.inval( m_activity, dict, loc, false );
} }
private void startDownload( int lang, String name ) private void startDownload( String isoCode, String name )
{ {
DwnldDelegate.downloadDictInBack( m_activity, lang, name, this ); DwnldDelegate.downloadDictInBack( m_activity, isoCode, name, this );
} }
private void resetLangs() private void resetLangs()
@ -1058,20 +1060,20 @@ public class DictsDelegate extends ListDelegateBase
} }
public static void downloadForResult( Delegator delegator, RequestCode requestCode, public static void downloadForResult( Delegator delegator, RequestCode requestCode,
int lang ) String isoCode )
{ {
downloadForResult( delegator, requestCode, lang, null ); downloadForResult( delegator, requestCode, isoCode, null );
} }
public static void downloadForResult( Delegator delegator, RequestCode requestCode ) public static void downloadForResult( Delegator delegator, RequestCode requestCode )
{ {
downloadForResult( delegator, requestCode, 0, null ); downloadForResult( delegator, requestCode, null, null );
} }
public static void downloadDefaultDict( Context context, String lc, public static void downloadDefaultDict( Context context, String isoCode,
OnGotLcDictListener lstnr ) OnGotLcDictListener lstnr )
{ {
new GetDefaultDictTask( context, lc, lstnr ).execute(); new GetDefaultDictTask( context, isoCode, lstnr ).execute();
} }
private static final int FAKE_GROUP = 101; private static final int FAKE_GROUP = 101;
@ -1081,7 +1083,7 @@ public class DictsDelegate extends ListDelegateBase
} }
private static void doPopup( final Delegator dlgtor, View button, private static void doPopup( final Delegator dlgtor, View button,
String curDict, final int lang ) { String curDict, final String isoCode ) {
final HashMap<MenuItem, DictAndLoc> itemData final HashMap<MenuItem, DictAndLoc> itemData
= new HashMap<>(); = new HashMap<>();
@ -1093,7 +1095,7 @@ public class DictsDelegate extends ListDelegateBase
public boolean onMenuItemClick( MenuItem item ) public boolean onMenuItemClick( MenuItem item )
{ {
DictAndLoc dal = itemData.get( item ); DictAndLoc dal = itemData.get( item );
String prevKey = keyForLang( lang ); String prevKey = keyForLang( isoCode );
DBUtils.setStringFor( context, prevKey, dal.name ); DBUtils.setStringFor( context, prevKey, dal.name );
DictBrowseDelegate.launch( dlgtor, dal.name, DictBrowseDelegate.launch( dlgtor, dal.name,
dal.loc ); dal.loc );
@ -1101,7 +1103,7 @@ public class DictsDelegate extends ListDelegateBase
} }
}; };
String prevSel = prevSelFor( context, lang ); String prevSel = prevSelFor( context, isoCode );
if ( null == prevSel ) { if ( null == prevSel ) {
prevSel = curDict; prevSel = curDict;
} }
@ -1113,7 +1115,7 @@ public class DictsDelegate extends ListDelegateBase
LocUtils.getString( context, LocUtils.getString( context,
R.string.cur_menu_marker_fmt, R.string.cur_menu_marker_fmt,
curDict ) ); curDict ) );
DictAndLoc[] dals = DictLangCache.getDALsHaveLang( context, lang ); DictAndLoc[] dals = DictLangCache.getDALsHaveLang( context, isoCode );
for ( DictAndLoc dal : dals ) { for ( DictAndLoc dal : dals ) {
boolean isCur = dal.name.equals(curDict); boolean isCur = dal.name.equals(curDict);
MenuItem item = isCur ? curItem : addItem( menu, dal.name ); MenuItem item = isCur ? curItem : addItem( menu, dal.name );
@ -1127,24 +1129,24 @@ public class DictsDelegate extends ListDelegateBase
} }
public static boolean handleDictsPopup( Delegator delegator, View button, public static boolean handleDictsPopup( Delegator delegator, View button,
String curDict, int lang ) String curDict, String isoCode )
{ {
int nDicts = DictLangCache.getLangCount( delegator.getActivity(), lang ); int nDicts = DictLangCache.getLangCount( delegator.getActivity(), isoCode );
boolean canHandle = 1 < nDicts; boolean canHandle = 1 < nDicts;
if ( canHandle ) { if ( canHandle ) {
doPopup( delegator, button, curDict, lang ); doPopup( delegator, button, curDict, isoCode );
} }
return canHandle; return canHandle;
} }
private static String keyForLang(int lang) private static String keyForLang( String isoCode )
{ {
return String.format( "%s:lang=%d", TAG, lang ); return String.format( "%s:lang=%s", TAG, isoCode );
} }
static String prevSelFor( Context context, int lang ) static String prevSelFor( Context context, String isoCode )
{ {
String key = keyForLang( lang ); String key = keyForLang( isoCode );
return DBUtils.getStringFor( context, key ); return DBUtils.getStringFor( context, key );
} }
@ -1169,7 +1171,7 @@ public class DictsDelegate extends ListDelegateBase
@Override @Override
public void onClick( View view ) { public void onClick( View view ) {
DwnldDelegate. DwnldDelegate.
downloadDictInBack( m_activity, info.m_urlLang, downloadDictInBack( m_activity, info.mISOCode,
info.m_name, info.m_name,
DictsDelegate.this ); DictsDelegate.this );
} }
@ -1440,14 +1442,17 @@ public class DictsDelegate extends ListDelegateBase
m_remoteInfo = new HashMap<>(); m_remoteInfo = new HashMap<>();
for ( int ii = 0; !isCancelled() && ii < nLangs; ++ii ) { for ( int ii = 0; !isCancelled() && ii < nLangs; ++ii ) {
JSONObject langObj = langs.getJSONObject( ii ); JSONObject langObj = langs.getJSONObject( ii );
String lc = langObj.optString( "lc", null ); String isoCode = langObj.optString( "lc", null );
String urlLangName = langObj.getString( "lang" ); String urlLangName = langObj.getString( "lang" );
String localLangName = null; String localLangName = null;
if ( null != lc ) { if ( null != isoCode ) {
localLangName = DictLangCache.userLangForLc( m_activity, lc ); localLangName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
} }
if ( null == localLangName ) { if ( null == localLangName ) {
localLangName = urlLangName; localLangName = urlLangName;
DictLangCache.setLangNameForISOCode( m_context,
isoCode,
urlLangName );
} }
if ( null != m_filterLang && if ( null != m_filterLang &&
@ -1473,7 +1478,7 @@ public class DictsDelegate extends ListDelegateBase
if ( 0 == note.length() ) { if ( 0 == note.length() ) {
note = null; note = null;
} }
DictInfo info = new DictInfo( name, urlLangName, localLangName, DictInfo info = new DictInfo( name, isoCode, localLangName,
nWords, nBytes, note ); nWords, nBytes, note );
if ( !m_quickFetchMode ) { if ( !m_quickFetchMode ) {
@ -1495,7 +1500,7 @@ public class DictsDelegate extends ListDelegateBase
} }
if ( !matches ) { if ( !matches ) {
Uri uri = Uri uri =
Utils.makeDictUri( m_activity, Utils.makeDictUriFromName( m_activity,
urlLangName, name ); urlLangName, name );
m_needUpdates.put( name, uri ); m_needUpdates.put( name, uri );
} }
@ -1550,15 +1555,15 @@ public class DictsDelegate extends ListDelegateBase
public static void downloadForResult( Delegator delegator, public static void downloadForResult( Delegator delegator,
RequestCode requestCode, RequestCode requestCode,
int lang, String name ) String isoCode, String name )
{ {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putBoolean( DICT_SHOWREMOTE, true ); bundle.putBoolean( DICT_SHOWREMOTE, true );
if ( lang > 0 ) { if ( null != isoCode ) {
bundle.putInt( DICT_LANG_EXTRA, lang ); bundle.putString( DICT_LANG_EXTRA, isoCode );
} }
if ( null != name ) { if ( null != name ) {
Assert.assertTrue( lang != 0 ); Assert.assertTrue( null != isoCode );
bundle.putString( DICT_NAME_EXTRA, name ); bundle.putString( DICT_NAME_EXTRA, name );
} }
delegator.addFragmentForResult( DictsFrag.newInstance( delegator ), delegator.addFragmentForResult( DictsFrag.newInstance( delegator ),

View file

@ -414,9 +414,9 @@ public class DlgDelegate {
m_dlgt.show( state ); m_dlgt.show( state );
} }
public void launchLookup( String[] words, int lang, boolean noStudy ) public void launchLookup( String[] words, String isoCode, boolean noStudy )
{ {
m_dlgt.show( LookupAlert.newInstance( words, lang, noStudy ) ); m_dlgt.show( LookupAlert.newInstance( words, isoCode, noStudy ) );
} }
public void startProgress( int titleID, int msgID, OnCancelListener lstnr ) public void startProgress( int titleID, int msgID, OnCancelListener lstnr )

View file

@ -64,11 +64,11 @@ public class DwnldDelegate extends ListDelegateBase {
private ArrayList<DownloadFilesTask> m_dfts; private ArrayList<DownloadFilesTask> m_dfts;
public interface DownloadFinishedListener { public interface DownloadFinishedListener {
void downloadFinished( String lang, String name, boolean success ); void downloadFinished( String isoCode, String name, boolean success );
} }
public interface OnGotLcDictListener { public interface OnGotLcDictListener {
void gotDictInfo( boolean success, String lc, String name ); void gotDictInfo( boolean success, String isoCode, String name );
} }
public DwnldDelegate( Delegator delegator, Bundle savedInstanceState ) public DwnldDelegate( Delegator delegator, Bundle savedInstanceState )
@ -478,28 +478,20 @@ public class DwnldDelegate extends ListDelegateBase {
} }
} }
public static void downloadDictInBack( Context context, String langName, public static void downloadDictInBack( Context context, String isoCode,
String name, String dictName,
DownloadFinishedListener lstnr ) DownloadFinishedListener lstnr )
{ {
Uri uri = Utils.makeDictUri( context, langName, name ); Uri uri = Utils.makeDictUriFromCode( context, isoCode, dictName );
downloadDictInBack( context, uri, name, lstnr ); downloadDictInBack( context, uri, dictName, lstnr );
}
public static void downloadDictInBack( Context context, int lang,
String name,
DownloadFinishedListener lstnr )
{
Uri uri = Utils.makeDictUri( context, lang, name );
downloadDictInBack( context, uri, name, lstnr );
} }
public static void downloadDictInBack( Context context, Uri uri, public static void downloadDictInBack( Context context, Uri uri,
String name, String dictName,
DownloadFinishedListener lstnr ) DownloadFinishedListener lstnr )
{ {
Uri[] uris = { uri }; Uri[] uris = { uri };
String[] names = { name }; String[] names = { dictName };
downloadDictsInBack( context, uris, names, lstnr ); downloadDictsInBack( context, uris, names, lstnr );
} }

View file

@ -353,7 +353,7 @@ public class GameConfigDelegate extends DelegateBase
TextView dictLabel = (TextView)playerView TextView dictLabel = (TextView)playerView
.findViewById( R.id.dict_label ); .findViewById( R.id.dict_label );
if ( localOnlyGame() ) { if ( localOnlyGame() ) {
String langName = DictLangCache.getLangName( m_activity, m_gi.dictLang ); String langName = DictLangCache.getLangNameForISOCode( m_activity, m_gi.isoCode );
String label = getString( R.string.dict_lang_label_fmt, langName ); String label = getString( R.string.dict_lang_label_fmt, langName );
dictLabel.setText( label ); dictLabel.setText( label );
} else { } else {
@ -363,7 +363,7 @@ public class GameConfigDelegate extends DelegateBase
.findViewById( R.id.player_dict_spinner )) .findViewById( R.id.player_dict_spinner ))
.getSpinner(); .getSpinner();
if ( localOnlyGame() ) { if ( localOnlyGame() ) {
configDictSpinner( m_playerDictSpinner, m_gi.dictLang, m_gi.dictName(lp) ); configDictSpinner( m_playerDictSpinner, m_gi.isoCode, m_gi.dictName(lp) );
} else { } else {
m_playerDictSpinner.setVisibility( View.GONE ); m_playerDictSpinner.setVisibility( View.GONE );
m_playerDictSpinner = null; m_playerDictSpinner = null;
@ -544,12 +544,12 @@ public class GameConfigDelegate extends DelegateBase
case REQUEST_DICT: case REQUEST_DICT:
String dictName = cancelled ? m_gi.dictName String dictName = cancelled ? m_gi.dictName
: data.getStringExtra( DictsDelegate.RESULT_LAST_DICT ); : data.getStringExtra( DictsDelegate.RESULT_LAST_DICT );
configDictSpinner( m_dictSpinner, m_gi.dictLang, dictName ); configDictSpinner( m_dictSpinner, m_gi.isoCode, dictName );
configDictSpinner( m_playerDictSpinner, m_gi.dictLang, dictName ); configDictSpinner( m_playerDictSpinner, m_gi.isoCode, dictName );
break; break;
case REQUEST_LANG_GC: case REQUEST_LANG_GC:
String langName = cancelled String langName = cancelled
? DictLangCache.getLangName( m_activity, m_gi.dictLang ) ? DictLangCache.getLangNameForISOCode( m_activity, m_gi.isoCode )
: data.getStringExtra( DictsDelegate.RESULT_LAST_LANG ); : data.getStringExtra( DictsDelegate.RESULT_LAST_LANG );
selLangChanged( langName ); selLangChanged( langName );
setLangSpinnerSelection( langName ); setLangSpinnerSelection( langName );
@ -990,11 +990,11 @@ public class GameConfigDelegate extends DelegateBase
} }
} // loadPlayersList } // loadPlayersList
private void configDictSpinner( Spinner dictsSpinner, int lang, private void configDictSpinner( Spinner dictsSpinner, final String isoCode,
String curDict ) String curDict )
{ {
if ( null != dictsSpinner ) { if ( null != dictsSpinner ) {
String langName = DictLangCache.getLangName( m_activity, lang ); String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
dictsSpinner.setPrompt( getString( R.string.dicts_list_prompt_fmt, dictsSpinner.setPrompt( getString( R.string.dicts_list_prompt_fmt,
langName ) ); langName ) );
@ -1009,13 +1009,14 @@ public class GameConfigDelegate extends DelegateBase
if ( chosen.equals( m_browseText ) ) { if ( chosen.equals( m_browseText ) ) {
DictsDelegate.downloadForResult( getDelegator(), DictsDelegate.downloadForResult( getDelegator(),
RequestCode.REQUEST_DICT, RequestCode.REQUEST_DICT,
m_gi.dictLang ); m_gi.isoCode );
Assert.assertTrueNR( isoCode.equals(m_gi.isoCode) );
} }
} }
}; };
ArrayAdapter<String> adapter = ArrayAdapter<String> adapter =
DictLangCache.getDictsAdapter( m_activity, lang ); DictLangCache.getDictsAdapter( m_activity, isoCode );
configSpinnerWDownload( dictsSpinner, adapter, onSel, curDict ); configSpinnerWDownload( dictsSpinner, adapter, onSel, curDict );
} }
@ -1048,17 +1049,17 @@ public class GameConfigDelegate extends DelegateBase
} }
}; };
String lang = DictLangCache.getLangName( m_activity, m_gi.dictLang ); String lang = DictLangCache.getLangNameForISOCode( m_activity, m_gi.isoCode );
configSpinnerWDownload( m_langSpinner, adapter, onSel, lang ); configSpinnerWDownload( m_langSpinner, adapter, onSel, lang );
} }
} }
private void selLangChanged( String chosen ) private void selLangChanged( String chosen )
{ {
m_gi.setLang( m_activity, DictLangCache String isoCode = DictLangCache.getLangIsoCode( m_activity, chosen );
.getLangLangCode( m_activity, chosen ) ); m_gi.setLang( m_activity, isoCode );
loadPlayersList(); loadPlayersList();
configDictSpinner( m_dictSpinner, m_gi.dictLang, m_gi.dictName ); configDictSpinner( m_dictSpinner, m_gi.isoCode, m_gi.dictName );
} }
private void configSpinnerWDownload( Spinner spinner, private void configSpinnerWDownload( Spinner spinner,

View file

@ -275,8 +275,7 @@ public class GameListItem extends LinearLayout
break; break;
case R.string.game_summary_field_language: case R.string.game_summary_field_language:
value = value =
DictLangCache.getLangName( m_context, DictLangCache.getLangNameForISOCode( m_context, m_summary.isoCode );
m_summary.dictLang );
value = LocUtils.xlateLang( m_context, value, true ); value = LocUtils.xlateLang( m_context, value, true );
break; break;
case R.string.game_summary_field_opponents: case R.string.game_summary_field_opponents:

View file

@ -406,7 +406,7 @@ public class GameUtils {
DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames ); DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames );
if ( pairs.anyMissing( dictNames ) ) { if ( pairs.anyMissing( dictNames ) ) {
postMoveDroppedForDictNotification( context, rowid, gi.gameID, postMoveDroppedForDictNotification( context, rowid, gi.gameID,
gi.dictLang ); gi.isoCode );
} else { } else {
String langName = gi.langName( context ); String langName = gi.langName( context );
gamePtr = XwJNI.initFromStream( rowid, stream, gi, util, null, gamePtr = XwJNI.initFromStream( rowid, stream, gi, util, null,
@ -598,7 +598,7 @@ public class GameUtils {
CommsAddrRec addr = nli.makeAddrRec( context ); CommsAddrRec addr = nli.makeAddrRec( context );
return makeNewMultiGame( context, sink, util, DBUtils.GROUPID_UNSPEC, return makeNewMultiGame( context, sink, util, DBUtils.GROUPID_UNSPEC,
addr, new int[] {nli.lang}, addr, new String[] {nli.isoCode},
new String[] { nli.dict }, null, nli.nPlayersT, new String[] { nli.dict }, null, nli.nPlayersT,
nli.nPlayersH, nli.forceChannel, nli.nPlayersH, nli.forceChannel,
nli.inviteID(), nli.gameID(), nli.inviteID(), nli.gameID(),
@ -608,27 +608,28 @@ public class GameUtils {
public static long makeNewMultiGame( Context context, long groupID, public static long makeNewMultiGame( Context context, long groupID,
String gameName ) String gameName )
{ {
return makeNewMultiGame( context, groupID, null, 0, null, return makeNewMultiGame( context, groupID, null, null, null,
(CommsConnTypeSet)null, gameName ); (CommsConnTypeSet)null, gameName );
} }
public static long makeNewMultiGame( Context context, long groupID, public static long makeNewMultiGame( Context context, long groupID,
String dict, int lang, String jsonData, String dict, String isoCode,
String jsonData,
CommsConnTypeSet addrSet, CommsConnTypeSet addrSet,
String gameName ) String gameName )
{ {
String inviteID = makeRandomID(); String inviteID = makeRandomID();
return makeNewMultiGame( context, groupID, inviteID, dict, lang, return makeNewMultiGame( context, groupID, inviteID, dict, isoCode,
jsonData, addrSet, gameName ); jsonData, addrSet, gameName );
} }
private static long makeNewMultiGame( Context context, long groupID, private static long makeNewMultiGame( Context context, long groupID,
String inviteID, String dict, String inviteID, String dict,
int lang, String jsonData, String isoCode, String jsonData,
CommsConnTypeSet addrSet, CommsConnTypeSet addrSet,
String gameName ) String gameName )
{ {
int[] langArray = {lang}; String[] langArray = {isoCode};
String[] dictArray = {dict}; String[] dictArray = {dict};
if ( null == addrSet ) { if ( null == addrSet ) {
addrSet = XWPrefs.getAddrTypes( context ); addrSet = XWPrefs.getAddrTypes( context );
@ -653,7 +654,7 @@ public class GameUtils {
private static long makeNewMultiGame( Context context, MultiMsgSink sink, private static long makeNewMultiGame( Context context, MultiMsgSink sink,
UtilCtxt util, long groupID, UtilCtxt util, long groupID,
CommsAddrRec addr, CommsAddrRec addr,
int[] lang, String[] dict, String[] isoCode, String[] dict,
String jsonData, String jsonData,
int nPlayersT, int nPlayersH, int nPlayersT, int nPlayersH,
int forceChannel, String inviteID, int forceChannel, String inviteID,
@ -665,9 +666,9 @@ public class GameUtils {
Assert.assertNotNull( inviteID ); Assert.assertNotNull( inviteID );
CurGameInfo gi = new CurGameInfo( context, inviteID ); CurGameInfo gi = new CurGameInfo( context, inviteID );
gi.setFrom( jsonData ); gi.setFrom( jsonData );
gi.setLang( context, lang[0], dict[0] ); gi.setLang( context, isoCode[0], dict[0] );
gi.forceChannel = forceChannel; gi.forceChannel = forceChannel;
lang[0] = gi.dictLang; isoCode[0] = gi.isoCode;
dict[0] = gi.dictName; dict[0] = gi.dictName;
gi.setNPlayers( nPlayersT, nPlayersH, localsRobots ); gi.setNPlayers( nPlayersT, nPlayersH, localsRobots );
gi.juggle(); gi.juggle();
@ -829,14 +830,14 @@ public class GameUtils {
} }
public static String[] dictNames( Context context, long rowid, public static String[] dictNames( Context context, long rowid,
int[] missingLang ) String[] missingLang )
{ {
String[] result = null; String[] result = null;
byte[] stream = savedGame( context, rowid ); byte[] stream = savedGame( context, rowid );
CurGameInfo gi = giFromStream( context, stream ); CurGameInfo gi = giFromStream( context, stream );
if ( null != gi ) { if ( null != gi ) {
if ( null != missingLang ) { if ( null != missingLang ) {
missingLang[0] = gi.dictLang; missingLang[0] = gi.isoCode;
} }
result = gi.dictNames(); result = gi.dictNames();
} }
@ -863,7 +864,7 @@ public class GameUtils {
// are not. // are not.
public static boolean gameDictsHere( Context context, long rowid, public static boolean gameDictsHere( Context context, long rowid,
String[][] missingNames, String[][] missingNames,
int[] missingLang ) String[] missingLang )
{ {
String[] gameDicts = dictNames( context, rowid, missingLang ); String[] gameDicts = dictNames( context, rowid, missingLang );
return null != gameDicts return null != gameDicts
@ -1234,11 +1235,11 @@ public class GameUtils {
} }
private static void postMoveDroppedForDictNotification( Context context, long rowid, private static void postMoveDroppedForDictNotification( Context context, long rowid,
int gameID, int lang ) int gameID, String isoCode )
{ {
Intent intent = GamesListDelegate.makeGameIDIntent( context, gameID ); Intent intent = GamesListDelegate.makeGameIDIntent( context, gameID );
String langName = DictLangCache.getLangName( context, lang ); String langName = DictLangCache.getLangNameForISOCode( context, isoCode );
String body = LocUtils.getString( context, R.string.no_dict_for_move_fmt, String body = LocUtils.getString( context, R.string.no_dict_for_move_fmt,
langName ); langName );
Utils.postNotification( context, intent, R.string.no_dict_for_move_title, Utils.postNotification( context, intent, R.string.no_dict_for_move_title,

View file

@ -607,7 +607,7 @@ public class GamesListDelegate extends ListDelegateBase
case WARN_NODICT_SUBST: { case WARN_NODICT_SUBST: {
final long rowid = (Long)params[0]; final long rowid = (Long)params[0];
final String missingDictName = (String)params[1]; final String missingDictName = (String)params[1];
final int missingDictLang = (Integer)params[2]; final String missingDictLang = (String)params[2];
lstnr = new OnClickListener() { lstnr = new OnClickListener() {
@Override @Override
@ -629,7 +629,7 @@ public class GamesListDelegate extends ListDelegateBase
}; };
String message; String message;
String langName = String langName =
DictLangCache.getLangName( m_activity, missingDictLang ); DictLangCache.getLangNameForISOCode( m_activity, missingDictLang );
String locLang = xlateLang( langName ); String locLang = xlateLang( langName );
String gameName = GameUtils.getName( m_activity, rowid ); String gameName = GameUtils.getName( m_activity, rowid );
if ( DlgID.WARN_NODICT_GENERIC == dlgID ) { if ( DlgID.WARN_NODICT_GENERIC == dlgID ) {
@ -674,11 +674,12 @@ public class GamesListDelegate extends ListDelegateBase
case SHOW_SUBST: { case SHOW_SUBST: {
final long rowid = (Long)params[0]; final long rowid = (Long)params[0];
final String missingDict = (String)params[1]; final String missingDict = (String)params[1];
final int lang = (Integer)params[2]; final String isoCode = (String)params[2];
final String[] sameLangDicts = final String[] sameLangDicts =
DictLangCache.getHaveLangCounts( m_activity, lang ); DictLangCache.getHaveLangCounts( m_activity, isoCode );
lstnr = new OnClickListener() { lstnr = new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, public void onClick( DialogInterface dlg,
int which ) { int which ) {
int pos = ((AlertDialog)dlg).getListView(). int pos = ((AlertDialog)dlg).getListView().
@ -1792,7 +1793,7 @@ public class GamesListDelegate extends ListDelegateBase
break; break;
case R.id.games_menu_study: case R.id.games_menu_study:
StudyListDelegate.launchOrAlert( getDelegator(), StudyListDelegate.NO_LANG, this ); StudyListDelegate.launchOrAlert( getDelegator(), this );
break; break;
case R.id.games_menu_knownplyrs: case R.id.games_menu_knownplyrs:
@ -2250,7 +2251,8 @@ public class GamesListDelegate extends ListDelegateBase
// check that we have the dict required // check that we have the dict required
boolean haveDict; boolean haveDict;
if ( null == nli.dict ) { // can only test for language support if ( null == nli.dict ) { // can only test for language support
String[] dicts = DictLangCache.getHaveLang( m_activity, nli.lang );
String[] dicts = DictLangCache.getHaveLang( m_activity, nli.isoCode );
haveDict = 0 < dicts.length; haveDict = 0 < dicts.length;
if ( haveDict ) { if ( haveDict ) {
// Just pick one -- good enough for the period when // Just pick one -- good enough for the period when
@ -2260,11 +2262,11 @@ public class GamesListDelegate extends ListDelegateBase
} }
} else { } else {
haveDict = haveDict =
DictLangCache.haveDict( m_activity, nli.lang, nli.dict ); DictLangCache.haveDict( m_activity, nli.isoCode, nli.dict );
} }
if ( !haveDict ) { if ( !haveDict ) {
m_netLaunchInfo = nli; m_netLaunchInfo = nli;
showDialogFragment( DlgID.WARN_NODICT_INVITED, 0L, nli.dict, nli.lang ); showDialogFragment( DlgID.WARN_NODICT_INVITED, 0L, nli.dict, nli.isoCode );
} }
return haveDict; return haveDict;
} }
@ -2277,7 +2279,7 @@ public class GamesListDelegate extends ListDelegateBase
private boolean checkWarnNoDict( long rowid, int forMenu ) private boolean checkWarnNoDict( long rowid, int forMenu )
{ {
String[][] missingNames = new String[1][]; String[][] missingNames = new String[1][];
int[] missingLang = new int[1]; String[] missingLang = { "en" };
boolean hasDicts; boolean hasDicts;
try { try {
hasDicts = GameUtils.gameDictsHere( m_activity, rowid, missingNames, hasDicts = GameUtils.gameDictsHere( m_activity, rowid, missingNames,
@ -2288,7 +2290,7 @@ public class GamesListDelegate extends ListDelegateBase
if ( !hasDicts ) { if ( !hasDicts ) {
String missingDictName = null; String missingDictName = null;
int missingDictLang = missingLang[0]; String missingDictLang = missingLang[0];
if ( 0 < missingNames[0].length ) { if ( 0 < missingNames[0].length ) {
missingDictName = missingNames[0][0]; missingDictName = missingNames[0][0];
} }
@ -2573,12 +2575,12 @@ public class GamesListDelegate extends ListDelegateBase
String phone = extras.getString( REMATCH_PHONE_EXTRA ); String phone = extras.getString( REMATCH_PHONE_EXTRA );
String p2pMacAddress = extras.getString( REMATCH_P2PADDR_EXTRA ); String p2pMacAddress = extras.getString( REMATCH_P2PADDR_EXTRA );
String dict = extras.getString( REMATCH_DICT_EXTRA ); String dict = extras.getString( REMATCH_DICT_EXTRA );
int lang = extras.getInt( REMATCH_LANG_EXTRA, -1 ); String isoCode = extras.getString( REMATCH_LANG_EXTRA );
String mqttDevID = extras.getString( GameSummary.EXTRA_REMATCH_MQTT ); String mqttDevID = extras.getString( GameSummary.EXTRA_REMATCH_MQTT );
String json = extras.getString( REMATCH_PREFS_EXTRA ); String json = extras.getString( REMATCH_PREFS_EXTRA );
newid = GameUtils.makeNewMultiGame( m_activity, groupID, dict, newid = GameUtils.makeNewMultiGame( m_activity, groupID, dict,
lang, json, addrs, gameName ); isoCode, json, addrs, gameName );
DBUtils.addRematchInfo( m_activity, newid, btAddr, phone, DBUtils.addRematchInfo( m_activity, newid, btAddr, phone,
p2pMacAddress, mqttDevID ); p2pMacAddress, mqttDevID );
} }
@ -2634,14 +2636,13 @@ public class GamesListDelegate extends ListDelegateBase
false ) ) { false ) ) {
m_haveShownGetDict = true; m_haveShownGetDict = true;
String lc = LocUtils.getCurLangCode( m_activity ); String isoCode = LocUtils.getCurLangCode( m_activity );
if ( !lc.equals("en") ) { if ( !isoCode.equals("en") ) {
int code = DictLangCache.getLangLangCode( m_activity, lc ); String[] names = DictLangCache.getHaveLang( m_activity, isoCode );
if ( 0 < code ) {
String[] names = DictLangCache.getHaveLang( m_activity, code );
if ( 0 == names.length ) { if ( 0 == names.length ) {
OnGotLcDictListener lstnr = new OnGotLcDictListener() { OnGotLcDictListener lstnr = new OnGotLcDictListener() {
@Override
public void gotDictInfo( boolean success, String lang, public void gotDictInfo( boolean success, String lang,
String name ) { String name ) {
stopProgress(); stopProgress();
@ -2659,12 +2660,11 @@ public class GamesListDelegate extends ListDelegateBase
} }
}; };
String langName = DictLangCache.getLangName( m_activity, code ); String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
String locLang = xlateLang( langName ); String locLang = xlateLang( langName );
String msg = getString( R.string.checking_for_fmt, locLang ); String msg = getString( R.string.checking_for_fmt, locLang );
startProgress( R.string.checking_title, msg ); startProgress( R.string.checking_title, msg );
DictsDelegate.downloadDefaultDict( m_activity, lc, lstnr ); DictsDelegate.downloadDefaultDict( m_activity, isoCode, lstnr );
}
} }
} }
} }
@ -3084,7 +3084,7 @@ public class GamesListDelegate extends ListDelegateBase
.putExtra( REMATCH_GROUPID_EXTRA, groupID ) .putExtra( REMATCH_GROUPID_EXTRA, groupID )
.putExtra( REMATCH_DICT_EXTRA, gi.dictName ) .putExtra( REMATCH_DICT_EXTRA, gi.dictName )
.putExtra( REMATCH_IS_SOLO, isSolo ) .putExtra( REMATCH_IS_SOLO, isSolo )
.putExtra( REMATCH_LANG_EXTRA, gi.dictLang ) .putExtra( REMATCH_LANG_EXTRA, gi.isoCode )
.putExtra( REMATCH_PREFS_EXTRA, gi.getJSONData() ) .putExtra( REMATCH_PREFS_EXTRA, gi.getJSONData() )
.putExtra( REMATCH_NEWNAME_EXTRA, newName ); .putExtra( REMATCH_NEWNAME_EXTRA, newName );

View file

@ -84,7 +84,7 @@ public class LangListPreference extends XWListPreference
} }
if ( !haveDictForLang ) { if ( !haveDictForLang ) {
curLang = DictLangCache.getLangName( mContext, 1 ); // English, unlocalized curLang = DictLangCache.getLangNameForISOCode( mContext, "en" ); // English, unlocalized
setValue( curLang ); setValue( curLang );
} }
forceDictsMatch( curLang ); forceDictsMatch( curLang );
@ -97,7 +97,7 @@ public class LangListPreference extends XWListPreference
private void forceDictsMatch( String newLang ) private void forceDictsMatch( String newLang )
{ {
if ( null != newLang ) { if ( null != newLang ) {
int code = DictLangCache.getLangLangCode( mContext, newLang ); String isoCode = DictLangCache.getLangIsoCode( mContext, newLang );
int[] keyIds = { R.string.key_default_dict, int[] keyIds = { R.string.key_default_dict,
R.string.key_default_robodict }; R.string.key_default_robodict };
for ( int id : keyIds ) { for ( int id : keyIds ) {
@ -111,8 +111,8 @@ public class LangListPreference extends XWListPreference
String curDict = pref.getValue().toString(); String curDict = pref.getValue().toString();
if ( ! DictUtils.dictExists( mContext, curDict ) if ( ! DictUtils.dictExists( mContext, curDict )
|| code != DictLangCache.getDictLangCode( mContext, || ! isoCode.equals( DictLangCache.getDictISOCode( mContext,
curDict ) ) { curDict ) ) ) {
pref.invalidate(); pref.invalidate();
} }
} }

View file

@ -30,10 +30,10 @@ public class LookupAlert extends XWDialogFragment {
private static final String TAG = LookupAlert.class.getSimpleName(); private static final String TAG = LookupAlert.class.getSimpleName();
private LookupAlertView m_view; private LookupAlertView m_view;
public static LookupAlert newInstance( String[] words, int lang, boolean noStudy ) public static LookupAlert newInstance( String[] words, String isoCode, boolean noStudy )
{ {
LookupAlert result = new LookupAlert(); LookupAlert result = new LookupAlert();
Bundle bundle = LookupAlertView.makeParams( words, lang, noStudy ); Bundle bundle = LookupAlertView.makeParams( words, isoCode, noStudy );
result.setArguments( bundle ); result.setArguments( bundle );
return result; return result;
} }

View file

@ -67,7 +67,7 @@ public class LookupAlertView extends LinearLayout
private static ArrayAdapter<String> s_urlsAdapter; private static ArrayAdapter<String> s_urlsAdapter;
private static final int LIST_LAYOUT = android.R.layout.simple_list_item_1; private static final int LIST_LAYOUT = android.R.layout.simple_list_item_1;
private static int s_lang = -1; private static String s_lang = null;
private static String s_langName; private static String s_langName;
// These two are probably always the same object // These two are probably always the same object
@ -93,8 +93,8 @@ public class LookupAlertView extends LinearLayout
{ {
m_onDone = lstn; m_onDone = lstn;
m_words = bundle.getStringArray( WORDS ); m_words = bundle.getStringArray( WORDS );
int lang = bundle.getInt( LANG, 0 ); String isoCode = bundle.getString( LANG );
setLang( m_context, lang ); setLang( m_context, isoCode );
m_studyOn = XWPrefs.getStudyEnabled( m_context ) m_studyOn = XWPrefs.getStudyEnabled( m_context )
&& bundle.getBoolean( STUDY_ON, true ); && bundle.getBoolean( STUDY_ON, true );
@ -234,8 +234,7 @@ public class LookupAlertView extends LinearLayout
private void lookupWord( Context context, String word, String fmt ) private void lookupWord( Context context, String word, String fmt )
{ {
String langCode = DictLangCache.getLangCodeStr( context, s_lang ); String dict_url = String.format( fmt, s_lang, word );
String dict_url = String.format( fmt, langCode, word );
Uri uri = Uri.parse( dict_url ); Uri uri = Uri.parse( dict_url );
Intent intent = new Intent( Intent.ACTION_VIEW, uri ); Intent intent = new Intent( Intent.ACTION_VIEW, uri );
intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK ); intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
@ -247,14 +246,13 @@ public class LookupAlertView extends LinearLayout
} }
} // lookupWord } // lookupWord
private void setLang( Context context, int lang ) private void setLang( Context context, String isoCode )
{ {
if ( s_lang != lang ) { if ( ! isoCode.equals( s_lang ) ) {
String[] urls = context.getResources().getStringArray( R.array.lookup_urls ); String[] urls = context.getResources().getStringArray( R.array.lookup_urls );
ArrayList<String> tmpUrls = new ArrayList<>(); ArrayList<String> tmpUrls = new ArrayList<>();
ArrayList<String> tmpNames = new ArrayList<>(); ArrayList<String> tmpNames = new ArrayList<>();
String langCode = String String langCode = String.format( ":%s:", isoCode );
.format( ":%s:", DictLangCache.getLangCodeStr( context, lang ) );
for ( int ii = 0; ii < urls.length; ii += 3 ) { for ( int ii = 0; ii < urls.length; ii += 3 ) {
String codes = urls[ii+1]; String codes = urls[ii+1];
if ( 0 == codes.length() || codes.contains( langCode ) ) { if ( 0 == codes.length() || codes.contains( langCode ) ) {
@ -269,8 +267,8 @@ public class LookupAlertView extends LinearLayout
s_lookupUrls = tmpUrls.toArray( new String[tmpUrls.size()] ); s_lookupUrls = tmpUrls.toArray( new String[tmpUrls.size()] );
s_urlsAdapter = new ArrayAdapter<>( context, LIST_LAYOUT, s_urlsAdapter = new ArrayAdapter<>( context, LIST_LAYOUT,
s_lookupNames ); s_lookupNames );
s_lang = lang; s_lang = isoCode;
String langName = DictLangCache.getLangName( context, lang ); String langName = DictLangCache.getLangNameForISOCode( context, isoCode );
s_langName = LocUtils.xlateLang( context, langName ); s_langName = LocUtils.xlateLang( context, langName );
} }
} }
@ -300,19 +298,19 @@ public class LookupAlertView extends LinearLayout
return handled; return handled;
} }
private static void addParams( Bundle bundle, String[] words, int lang, private static void addParams( Bundle bundle, String[] words, String isoCode,
boolean studyOn ) boolean studyOn )
{ {
bundle.putStringArray( WORDS, words ); bundle.putStringArray( WORDS, words );
bundle.putInt( LANG, lang ); bundle.putString( LANG, isoCode );
bundle.putBoolean( STUDY_ON, studyOn ); bundle.putBoolean( STUDY_ON, studyOn );
} }
protected static Bundle makeParams( String[] words, int lang, protected static Bundle makeParams( String[] words, String isoCode,
boolean noStudyOption ) boolean noStudyOption )
{ {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
addParams( bundle, words, lang, !noStudyOption ); addParams( bundle, words, isoCode, !noStudyOption );
return bundle; return bundle;
} }
} }

View file

@ -37,6 +37,7 @@ public class MultiService {
public static final String FORCECHANNEL = "FC"; public static final String FORCECHANNEL = "FC";
public static final String LANG = "LANG"; public static final String LANG = "LANG";
public static final String ISO = "ISO";
public static final String DICT = "DICT"; public static final String DICT = "DICT";
public static final String GAMEID = "GAMEID"; public static final String GAMEID = "GAMEID";
public static final String INVITEID = "INVITEID"; // relay only public static final String INVITEID = "INVITEID"; // relay only
@ -131,7 +132,7 @@ public class MultiService {
{ {
Intent intent = new Intent( context, MainActivity.class ); // PENDING TEST THIS!!! Intent intent = new Intent( context, MainActivity.class ); // PENDING TEST THIS!!!
intent.setAction( ACTION_FETCH_DICT ); intent.setAction( ACTION_FETCH_DICT );
intent.putExtra( LANG, nli.lang ); intent.putExtra( ISO, nli.isoCode );
intent.putExtra( DICT, nli.dict ); intent.putExtra( DICT, nli.dict );
intent.putExtra( OWNER, owner.ordinal() ); intent.putExtra( OWNER, owner.ordinal() );
intent.putExtra( NLI_DATA, nli.toString() ); intent.putExtra( NLI_DATA, nli.toString() );
@ -169,7 +170,8 @@ public class MultiService {
OnClickListener onDecline ) OnClickListener onDecline )
{ {
int lang = intent.getIntExtra( LANG, -1 ); int lang = intent.getIntExtra( LANG, -1 );
String langStr = DictLangCache.getLangName( context, lang ); String isoCode = intent.getStringExtra( ISO );
String langStr = DictLangCache.getLangNameForISOCode( context, isoCode );
String dict = intent.getStringExtra( DICT ); String dict = intent.getStringExtra( DICT );
String inviter = intent.getStringExtra( INVITER ); String inviter = intent.getStringExtra( INVITER );
int msgID = (null == inviter) ? R.string.invite_dict_missing_body_noname_fmt int msgID = (null == inviter) ? R.string.invite_dict_missing_body_noname_fmt
@ -199,9 +201,9 @@ public class MultiService {
{ {
boolean downloaded = isMissingDictIntent( intent ); boolean downloaded = isMissingDictIntent( intent );
if ( downloaded ) { if ( downloaded ) {
int lang = intent.getIntExtra( LANG, -1 ); String isoCode = intent.getStringExtra( ISO );
String dict = intent.getStringExtra( DICT ); String dict = intent.getStringExtra( DICT );
downloaded = DictLangCache.haveDict( context, lang, dict ); downloaded = DictLangCache.haveDict( context, isoCode, dict );
if ( downloaded ) { if ( downloaded ) {
int ordinal = intent.getIntExtra( OWNER, -1 ); int ordinal = intent.getIntExtra( OWNER, -1 );
if ( -1 == ordinal ) { if ( -1 == ordinal ) {

View file

@ -60,6 +60,7 @@ public class NetLaunchInfo implements Serializable {
private static final String ID_KEY = "id"; private static final String ID_KEY = "id";
private static final String WORDLIST_KEY = "wl"; private static final String WORDLIST_KEY = "wl";
private static final String LANG_KEY = "lang"; private static final String LANG_KEY = "lang";
private static final String ISO_KEY = "iso";
private static final String TOTPLAYERS_KEY = "np"; private static final String TOTPLAYERS_KEY = "np";
private static final String HEREPLAYERS_KEY = "nh"; private static final String HEREPLAYERS_KEY = "nh";
private static final String GID_KEY = "gid"; private static final String GID_KEY = "gid";
@ -73,7 +74,7 @@ public class NetLaunchInfo implements Serializable {
protected String gameName; protected String gameName;
protected String dict; protected String dict;
protected int lang; protected String isoCode; // added in version 2
protected int forceChannel; protected int forceChannel;
protected int nPlayersT; protected int nPlayersT;
protected int nPlayersH; protected int nPlayersH;
@ -109,7 +110,14 @@ public class NetLaunchInfo implements Serializable {
private NetLaunchInfo( Bundle bundle ) private NetLaunchInfo( Bundle bundle )
{ {
lang = bundle.getInt( MultiService.LANG ); isoCode = bundle.getString( MultiService.ISO );
if ( null == isoCode ) {
int lang = bundle.getInt( MultiService.LANG, 0 );
if ( 0 != lang ) {
isoCode = XwJNI.lcToLocale( lang );
}
}
Assert.assertTrueNR( null != isoCode );
room = bundle.getString( MultiService.ROOM ); room = bundle.getString( MultiService.ROOM );
inviteID = bundle.getString( MultiService.INVITEID ); inviteID = bundle.getString( MultiService.INVITEID );
forceChannel = bundle.getInt( MultiService.FORCECHANNEL ); forceChannel = bundle.getInt( MultiService.FORCECHANNEL );
@ -132,7 +140,8 @@ public class NetLaunchInfo implements Serializable {
public static NetLaunchInfo makeFrom( Bundle bundle ) public static NetLaunchInfo makeFrom( Bundle bundle )
{ {
NetLaunchInfo nli = null; NetLaunchInfo nli = null;
if ( 0 != bundle.getInt( MultiService.LANG ) ) { // quick test: valid? if ( 0 != bundle.getInt( MultiService.LANG )
|| null != bundle.getString( MultiService.ISO ) ) { // quick test: valid?
nli = new NetLaunchInfo( bundle ); nli = new NetLaunchInfo( bundle );
nli.calcValid(); nli.calcValid();
if ( !nli.isValid() ) { if ( !nli.isValid() ) {
@ -161,6 +170,7 @@ public class NetLaunchInfo implements Serializable {
DataInputStream dis = new DataInputStream( bais ); DataInputStream dis = new DataInputStream( bais );
String nliData = dis.readUTF(); String nliData = dis.readUTF();
nli = NetLaunchInfo.makeFrom( context, nliData ); nli = NetLaunchInfo.makeFrom( context, nliData );
Assert.assertTrueNR( null != nli.isoCode );
} catch ( java.io.IOException ex ) { } catch ( java.io.IOException ex ) {
Log.d( TAG, "not an nli" ); Log.d( TAG, "not an nli" );
} }
@ -247,8 +257,16 @@ public class NetLaunchInfo implements Serializable {
removeUnsupported( supported ); removeUnsupported( supported );
dict = data.getQueryParameter( WORDLIST_KEY ); dict = data.getQueryParameter( WORDLIST_KEY );
isoCode = data.getQueryParameter( ISO_KEY );
if ( null == isoCode ) {
String langStr = data.getQueryParameter( LANG_KEY ); String langStr = data.getQueryParameter( LANG_KEY );
lang = Integer.decode( langStr ); if ( null != langStr && !langStr.equals("0") ) {
int lang = Integer.decode( langStr );
isoCode = XwJNI.lcToLocale( lang );
}
}
Assert.assertTrueNR( null != isoCode );
String np = data.getQueryParameter( TOTPLAYERS_KEY ); String np = data.getQueryParameter( TOTPLAYERS_KEY );
nPlayersT = Integer.decode( np ); nPlayersT = Integer.decode( np );
String nh = data.getQueryParameter( HEREPLAYERS_KEY ); String nh = data.getQueryParameter( HEREPLAYERS_KEY );
@ -270,13 +288,14 @@ public class NetLaunchInfo implements Serializable {
calcValid(); calcValid();
} }
private NetLaunchInfo( int gamID, String gamNam, int dictLang, private NetLaunchInfo( int gamID, String gamNam, String isoCodeIn,
String dictName, int nPlayers, boolean dupMode ) String dictName, int nPlayers, boolean dupMode )
{ {
this(); this();
Assert.assertTrueNR( null != isoCodeIn );
gameName = gamNam; gameName = gamNam;
dict = dictName; dict = dictName;
lang = dictLang; isoCode = isoCodeIn;
nPlayersT = nPlayers; nPlayersT = nPlayers;
nPlayersH = 1; nPlayersH = 1;
gameID = gamID; gameID = gamID;
@ -293,8 +312,8 @@ public class NetLaunchInfo implements Serializable {
public NetLaunchInfo( CurGameInfo gi ) public NetLaunchInfo( CurGameInfo gi )
{ {
this( gi.gameID, gi.getName(), gi.dictLang, gi.dictName, gi.nPlayers, this( gi.gameID, gi.getName(), gi.isoCode,
gi.inDuplicateMode ); gi.dictName, gi.nPlayers, gi.inDuplicateMode );
} }
public NetLaunchInfo( Context context, GameSummary summary, CurGameInfo gi ) public NetLaunchInfo( Context context, GameSummary summary, CurGameInfo gi )
@ -369,7 +388,12 @@ public class NetLaunchInfo implements Serializable {
{ {
bundle.putString( MultiService.ROOM, room ); bundle.putString( MultiService.ROOM, room );
bundle.putString( MultiService.INVITEID, inviteID ); bundle.putString( MultiService.INVITEID, inviteID );
bundle.putInt( MultiService.LANG, lang ); int[] lang = {0};
if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) {
bundle.putInt( MultiService.LANG, lang[0] );
} else {
bundle.putString( MultiService.ISO, isoCode );
}
bundle.putString( MultiService.DICT, dict ); bundle.putString( MultiService.DICT, dict );
bundle.putString( MultiService.GAMENAME, gameName ); bundle.putString( MultiService.GAMENAME, gameName );
bundle.putInt( MultiService.NPLAYERST, nPlayersT ); bundle.putInt( MultiService.NPLAYERST, nPlayersT );
@ -399,7 +423,7 @@ public class NetLaunchInfo implements Serializable {
other = (NetLaunchInfo)obj; other = (NetLaunchInfo)obj;
result = TextUtils.equals( gameName, other.gameName ) result = TextUtils.equals( gameName, other.gameName )
&& TextUtils.equals( dict, other.dict ) && TextUtils.equals( dict, other.dict )
&& lang == other.lang && TextUtils.equals( isoCode, other.isoCode )
&& forceChannel == other.forceChannel && forceChannel == other.forceChannel
&& nPlayersT == other.nPlayersT && nPlayersT == other.nPlayersT
&& nPlayersH == other.nPlayersH && nPlayersH == other.nPlayersH
@ -429,7 +453,6 @@ public class NetLaunchInfo implements Serializable {
try { try {
JSONObject obj = new JSONObject() JSONObject obj = new JSONObject()
.put( ADDRS_KEY, _conTypes ) .put( ADDRS_KEY, _conTypes )
.put( MultiService.LANG, lang )
.put( MultiService.DICT, dict ) .put( MultiService.DICT, dict )
.put( MultiService.GAMENAME, gameName ) .put( MultiService.GAMENAME, gameName )
.put( MultiService.NPLAYERST, nPlayersT ) .put( MultiService.NPLAYERST, nPlayersT )
@ -438,6 +461,12 @@ public class NetLaunchInfo implements Serializable {
.put( MultiService.GAMEID, gameID() ) .put( MultiService.GAMEID, gameID() )
.put( MultiService.FORCECHANNEL, forceChannel ) .put( MultiService.FORCECHANNEL, forceChannel )
; ;
int[] lang = {0};
if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) {
obj.put( MultiService.LANG, lang[0] );
} else {
obj.put( MultiService.ISO, isoCode );
}
if ( dupeMode ) { if ( dupeMode ) {
obj.put( MultiService.DUPEMODE, dupeMode ); obj.put( MultiService.DUPEMODE, dupeMode );
@ -518,7 +547,15 @@ public class NetLaunchInfo implements Serializable {
boolean hasAddrs = -1 != flags; boolean hasAddrs = -1 != flags;
_conTypes = hasAddrs ? flags : EMPTY_SET; _conTypes = hasAddrs ? flags : EMPTY_SET;
lang = json.optInt( MultiService.LANG, -1 ); isoCode = json.optString( MultiService.ISO );
if ( null == isoCode ) {
int lang = json.optInt( MultiService.LANG, 0 );
if ( 0 != lang ) {
isoCode = XwJNI.lcToLocale( lang );
}
}
Assert.assertTrueNR( null != isoCode );
forceChannel = json.optInt( MultiService.FORCECHANNEL, 0 ); forceChannel = json.optInt( MultiService.FORCECHANNEL, 0 );
dupeMode = json.optBoolean( MultiService.DUPEMODE, false ); dupeMode = json.optBoolean( MultiService.DUPEMODE, false );
dict = json.optString( MultiService.DICT ); dict = json.optString( MultiService.DICT );
@ -590,8 +627,17 @@ public class NetLaunchInfo implements Serializable {
Uri.Builder ub = new Uri.Builder() Uri.Builder ub = new Uri.Builder()
.scheme( "http" ) // PENDING: should be https soon .scheme( "http" ) // PENDING: should be https soon
.path( String.format( "//%s%s", host, .path( String.format( "//%s%s", host,
LocUtils.getString(context, R.string.invite_prefix) ) ); LocUtils.getString(context,
appendInt( ub, LANG_KEY, lang ); R.string.invite_prefix) ) );
// We'll use lang rather than ISO IFF we have it.
int[] lang = {0};
Assert.assertTrueNR( null != isoCode );
if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) {
appendInt( ub, LANG_KEY, lang[0] );
} else {
ub.appendQueryParameter( ISO_KEY, isoCode );
}
appendInt( ub, TOTPLAYERS_KEY, nPlayersT ); appendInt( ub, TOTPLAYERS_KEY, nPlayersT );
appendInt( ub, HEREPLAYERS_KEY, nPlayersH ); appendInt( ub, HEREPLAYERS_KEY, nPlayersH );
appendInt( ub, GID_KEY, gameID() ); appendInt( ub, GID_KEY, gameID() );
@ -737,10 +783,12 @@ public class NetLaunchInfo implements Serializable {
private boolean hasCommon() private boolean hasCommon()
{ {
return null != dict boolean good = null != dict
&& 0 < lang && null != isoCode
&& 0 < nPlayersT && 0 < nPlayersT
&& 0 != gameID(); && 0 != gameID();
// Log.d( TAG, "hasCommon() => %b", good );
return good;
} }
private void removeUnsupported( List<CommsConnType> supported ) private void removeUnsupported( List<CommsConnType> supported )

View file

@ -51,8 +51,6 @@ public class StudyListDelegate extends ListDelegateBase
DBUtils.StudyListListener { DBUtils.StudyListListener {
private static final String TAG = StudyListDelegate.class.getSimpleName(); private static final String TAG = StudyListDelegate.class.getSimpleName();
protected static final int NO_LANG = -1;
protected static final String START_LANG = "START_LANG"; protected static final String START_LANG = "START_LANG";
private static final String CHECKED_KEY = "CHECKED_KEY"; private static final String CHECKED_KEY = "CHECKED_KEY";
@ -60,7 +58,7 @@ public class StudyListDelegate extends ListDelegateBase
private Activity m_activity; private Activity m_activity;
private Spinner m_spinner; private Spinner m_spinner;
private LabeledSpinner m_pickView; private LabeledSpinner m_pickView;
private int[] m_langCodes; private String[] m_langCodes;
private String[] m_words; private String[] m_words;
private Set<String> m_checkeds; private Set<String> m_checkeds;
private int m_langPosition; private int m_langPosition;
@ -183,9 +181,9 @@ public class StudyListDelegate extends ListDelegateBase
// DBUtils.StudyListListener // DBUtils.StudyListListener
////////////////////////////////////////////////// //////////////////////////////////////////////////
@Override @Override
public void onWordAdded( String word, int langCode ) public void onWordAdded( String word, String isoCode )
{ {
if ( langCode == m_langCodes[m_langPosition] ) { if ( isoCode.equals( m_langCodes[m_langPosition] ) ) {
loadList(); loadList();
} }
} }
@ -295,12 +293,12 @@ public class StudyListDelegate extends ListDelegateBase
private void loadList() private void loadList()
{ {
int lang = m_langCodes[m_langPosition]; String isoCode = m_langCodes[m_langPosition];
m_words = DBUtils.studyListWords( m_activity, lang ); m_words = DBUtils.studyListWords( m_activity, isoCode );
makeAdapter(); makeAdapter();
String langName = DictLangCache.getLangName( m_activity, lang ); String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
m_origTitle = getString( R.string.studylist_title_fmt, m_origTitle = getString( R.string.studylist_title_fmt,
xlateLang( langName ) ); xlateLang( langName ) );
setTitleBar(); setTitleBar();
@ -322,18 +320,18 @@ public class StudyListDelegate extends ListDelegateBase
m_langPosition = 0; m_langPosition = 0;
loadList(); loadList();
} else { } else {
int startLang = NO_LANG; String startLang = null;
int startIndex = -1; int startIndex = -1;
if ( null != args ) { if ( null != args ) {
startLang = args.getInt( START_LANG, NO_LANG ); startLang = args.getString( START_LANG );
} }
String[] myNames = new String[m_langCodes.length]; String[] myNames = new String[m_langCodes.length];
for ( int ii = 0; ii < m_langCodes.length; ++ii ) { for ( int ii = 0; ii < m_langCodes.length; ++ii ) {
int lang = m_langCodes[ii]; String isoCode = m_langCodes[ii];
String name = DictLangCache.getLangName( m_activity, lang ); String name = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
myNames[ii] = xlateLang( name, true ); myNames[ii] = xlateLang( name, true );
if ( lang == startLang ) { if ( isoCode.equals( startLang ) ) {
startIndex = ii; startIndex = ii;
} }
} }
@ -385,22 +383,27 @@ public class StudyListDelegate extends ListDelegateBase
setTitleBar(); setTitleBar();
} }
public static void launchOrAlert( Delegator delegator, int lang, public static void launchOrAlert( Delegator delegator, DlgDelegate.HasDlgDelegate dlg )
{
launchOrAlert( delegator, null, dlg );
}
public static void launchOrAlert( Delegator delegator, String isoCode,
DlgDelegate.HasDlgDelegate dlg ) DlgDelegate.HasDlgDelegate dlg )
{ {
String msg = null; String msg = null;
Activity activity = delegator.getActivity(); Activity activity = delegator.getActivity();
if ( 0 == DBUtils.studyListLangs( activity ).length ) { if ( 0 == DBUtils.studyListLangs( activity ).length ) {
msg = LocUtils.getString( activity, R.string.study_no_lists ); msg = LocUtils.getString( activity, R.string.study_no_lists );
} else if ( NO_LANG != lang && } else if ( null != isoCode &&
0 == DBUtils.studyListWords( activity, lang ).length ) { 0 == DBUtils.studyListWords( activity, isoCode ).length ) {
String langname = DictLangCache.getLangName( activity, lang ); String langname = DictLangCache.getLangNameForISOCode( activity, isoCode );
msg = LocUtils.getString( activity, R.string.study_no_lang_fmt, msg = LocUtils.getString( activity, R.string.study_no_lang_fmt,
langname ); langname );
} else { } else {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
if ( NO_LANG != lang ) { if ( null != isoCode ) {
bundle.putInt( START_LANG, lang ); bundle.putString( START_LANG, isoCode );
} }
delegator.addFragment( StudyListFrag.newInstance( delegator ), delegator.addFragment( StudyListFrag.newInstance( delegator ),

View file

@ -215,16 +215,15 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
int index ) int index )
{ {
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
int lang = DictLangCache.getDictLangCode( context, dal ); String isoCode = DictLangCache.getDictISOCode( context, dal );
String langCode = DictLangCache.getLangCodeStr( context, lang ); String langStr = DictLangCache.getLangNameForISOCode( context, isoCode );
String langStr = DictLangCache.getLangName( context, lang );
String[] sums = DictLangCache.getDictMD5Sums( context, dal.name ); String[] sums = DictLangCache.getDictMD5Sums( context, dal.name );
Assert.assertTrueNR( null != sums[1] ); Assert.assertTrueNR( null != sums[1] );
long len = DictLangCache.getFileLen( context, dal ); long len = DictLangCache.getFileLen( context, dal );
try { try {
params.put( k_NAME, dal.name ); params.put( k_NAME, dal.name );
params.put( k_LANG, langStr ); params.put( k_LANG, langStr );
params.put( k_LANGCODE, langCode ); params.put( k_LANGCODE, isoCode );
params.put( k_MD5SUM, sums[0] ); params.put( k_MD5SUM, sums[0] );
params.put( k_FULLSUM, sums[1] ); params.put( k_FULLSUM, sums[1] );
params.put( k_INDEX, index ); params.put( k_INDEX, index );

View file

@ -636,30 +636,27 @@ public class Utils {
return result; return result;
} }
public static Uri makeDictUri( Context context, String langName, String name ) public static Uri makeDictUriFromName( Context context,
String langName, String dictName )
{
String isoCode = DictLangCache.getLangIsoCode( context, langName );
return makeDictUriFromCode( context, isoCode, dictName );
}
public static Uri makeDictUriFromCode( Context context, String isoCode, String name )
{ {
String dictUrl = CommonPrefs.getDefaultDictURL( context ); String dictUrl = CommonPrefs.getDefaultDictURL( context );
Uri.Builder builder = Uri.parse( dictUrl ).buildUpon(); Uri.Builder builder = Uri.parse( dictUrl ).buildUpon();
if ( null != langName ) { if ( null != isoCode ) {
builder.appendPath( langName ); builder.appendPath( isoCode );
} }
if ( null != name ) { if ( null != name ) {
Assert.assertNotNull( langName ); Assert.assertNotNull( isoCode );
builder.appendPath( DictUtils.addDictExtn( name ) ); builder.appendPath( DictUtils.addDictExtn( name ) );
} }
Uri result = builder.build(); Uri result = builder.build();
// Log.d( TAG, "makeDictUri(langName=%s, name=%s) => %s", langName, name, result ); DbgUtils.printStack( TAG );
return result; Log.d( TAG, "makeDictUriFromCode(isoCode=%s, name=%s) => %s", isoCode, name, result );
}
public static Uri makeDictUri( Context context, int lang, String name )
{
String langName = null;
if ( 0 < lang ) {
langName = DictLangCache.getLangName( context, lang );
}
Uri result = makeDictUri( context, langName, name );
// Log.d( TAG, "makeDictUri(lang=%d, name=%s) => %s", lang, name, result );
return result; return result;
} }

View file

@ -362,12 +362,17 @@ public class XWPrefs {
return getPrefsBoolean( context, R.string.key_studyon, true ); return getPrefsBoolean( context, R.string.key_studyon, true );
} }
protected static String getPrefsString( Context context, int keyID ) protected static String getPrefsString( Context context, int keyID, String dflt )
{ {
String key = context.getString( keyID ); String key = context.getString( keyID );
SharedPreferences sp = PreferenceManager SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences( context ); .getDefaultSharedPreferences( context );
return sp.getString( key, "" ); return sp.getString( key, dflt );
}
protected static String getPrefsString( Context context, int keyID )
{
return getPrefsString( context, keyID, "" );
} }
protected static void setPrefsString( Context context, int keyID, protected static void setPrefsString( Context context, int keyID,

View file

@ -156,7 +156,7 @@ abstract class XWServiceHelper {
} }
if ( success ) { if ( success ) {
if ( DictLangCache.haveDict( mContext, nli.lang, nli.dict ) ) { if ( DictLangCache.haveDict( mContext, nli.isoCode, nli.dict ) ) {
long rowid = GameUtils.makeNewMultiGame( mContext, nli, long rowid = GameUtils.makeNewMultiGame( mContext, nli,
getSink( 0 ), getSink( 0 ),
getUtilCtxt() ); getUtilCtxt() );

View file

@ -60,7 +60,7 @@ public class CurGameInfo implements Serializable {
public String dictName; public String dictName;
public LocalPlayer[] players; public LocalPlayer[] players;
public int dictLang; public String isoCode;
public int gameID; public int gameID;
public int gameSeconds; public int gameSeconds;
public int nPlayers; public int nPlayers;
@ -138,7 +138,7 @@ public class CurGameInfo implements Serializable {
juggle(); juggle();
} }
setLang( context, 0 ); setLang( context, null );
} }
public CurGameInfo( CurGameInfo src ) public CurGameInfo( CurGameInfo src )
@ -153,7 +153,7 @@ public class CurGameInfo implements Serializable {
players = new LocalPlayer[MAX_NUM_PLAYERS]; players = new LocalPlayer[MAX_NUM_PLAYERS];
serverRole = src.serverRole; serverRole = src.serverRole;
dictName = src.dictName; dictName = src.dictName;
dictLang = src.dictLang; isoCode = src.isoCode;
hintsNotAllowed = src.hintsNotAllowed; hintsNotAllowed = src.hintsNotAllowed;
inDuplicateMode = src.inDuplicateMode; inDuplicateMode = src.inDuplicateMode;
phoniesAction = src.phoniesAction; phoniesAction = src.phoniesAction;
@ -246,22 +246,24 @@ public class CurGameInfo implements Serializable {
} }
} }
public void setLang( Context context, int lang, String dict ) public void setLang( Context context, String isoCode, String dict )
{ {
if ( null != dict ) { if ( null != dict ) {
dictName = dict; dictName = dict;
} }
setLang( context, lang ); setLang( context, isoCode );
} }
public void setLang( Context context, int lang ) public void setLang( Context context, String isoCodeNew )
{ {
if ( 0 == lang ) { if ( null == isoCodeNew ) {
String dictName = CommonPrefs.getDefaultHumanDict( context ); String dictName = CommonPrefs.getDefaultHumanDict( context );
lang = DictLangCache.getDictLangCode( context, dictName ); isoCodeNew = DictLangCache.getDictISOCode( context, dictName );
} }
if ( dictLang != lang ) { Assert.assertTrueNR( null != isoCodeNew );
dictLang = lang;
if ( ! TextUtils.equals( isoCodeNew, this.isoCode ) ) {
isoCode = isoCodeNew;
assignDicts( context ); assignDicts( context );
} }
} }
@ -299,7 +301,7 @@ public class CurGameInfo implements Serializable {
{ {
boolean matter = nPlayers != other.nPlayers boolean matter = nPlayers != other.nPlayers
|| serverRole != other.serverRole || serverRole != other.serverRole
|| dictLang != other.dictLang || ! TextUtils.equals(isoCode, other.isoCode)
|| boardSize != other.boardSize || boardSize != other.boardSize
|| traySize != other.traySize || traySize != other.traySize
|| bingoMin != other.bingoMin || bingoMin != other.bingoMin
@ -331,7 +333,7 @@ public class CurGameInfo implements Serializable {
result = null != obj && obj instanceof CurGameInfo; result = null != obj && obj instanceof CurGameInfo;
if ( result ) { if ( result ) {
other = (CurGameInfo)obj; other = (CurGameInfo)obj;
result = dictLang == other.dictLang result = TextUtils.equals( isoCode, other.isoCode)
&& gameID == other.gameID && gameID == other.gameID
&& gameSeconds == other.gameSeconds && gameSeconds == other.gameSeconds
&& nPlayers == other.nPlayers && nPlayers == other.nPlayers
@ -442,7 +444,7 @@ public class CurGameInfo implements Serializable {
public void replaceDicts( Context context, String newDict ) public void replaceDicts( Context context, String newDict )
{ {
String[] dicts = String[] dicts =
DictLangCache.getHaveLang( context, dictLang ); DictLangCache.getHaveLang( context, isoCode );
HashSet<String> installed = new HashSet<>( Arrays.asList(dicts) ); HashSet<String> installed = new HashSet<>( Arrays.asList(dicts) );
if ( !installed.contains( dictName ) ) { if ( !installed.contains( dictName ) ) {
@ -461,7 +463,7 @@ public class CurGameInfo implements Serializable {
public String langName( Context context ) public String langName( Context context )
{ {
return DictLangCache.getLangName( context, dictLang ); return DictLangCache.getLangNameForISOCode( context, isoCode );
} }
public String dictName( final LocalPlayer lp ) public String dictName( final LocalPlayer lp )
@ -586,14 +588,14 @@ public class CurGameInfo implements Serializable {
// right language. // right language.
String humanDict = String humanDict =
DictLangCache.getBestDefault( context, dictLang, true ); DictLangCache.getBestDefault( context, isoCode, true );
String robotDict = String robotDict =
DictLangCache.getBestDefault( context, dictLang, false ); DictLangCache.getBestDefault( context, isoCode, false );
if ( null == dictName if ( null == dictName
|| ! DictUtils.dictExists( context, dictName ) || ! DictUtils.dictExists( context, dictName )
|| dictLang != DictLangCache.getDictLangCode( context, || ! isoCode.equals( DictLangCache.getDictISOCode( context,
dictName ) ) { dictName ) ) ) {
dictName = humanDict; dictName = humanDict;
} }
@ -601,8 +603,8 @@ public class CurGameInfo implements Serializable {
LocalPlayer lp = players[ii]; LocalPlayer lp = players[ii];
if ( null != lp.dictName && if ( null != lp.dictName &&
dictLang != DictLangCache.getDictLangCode( context, !isoCode.equals( DictLangCache.getDictISOCode( context,
lp.dictName ) ) { lp.dictName ) ) ) {
lp.dictName = null; lp.dictName = null;
} }

View file

@ -295,9 +295,9 @@ public class DUtilCtxt {
return msg; return msg;
} }
public void getDictPath( int lang, String name, String[] path, byte[][] bytes ) public void getDictPath( String isoCode, String name, String[] path, byte[][] bytes )
{ {
// Log.d( TAG, "getDictPath(%d, %s)", lang, name ); // Log.d( TAG, "getDictPath(%s, %s)", isoCode, name );
String[] names = { name }; String[] names = { name };
DictUtils.DictPairs pairs = DictUtils.openDicts( m_context, names ); DictUtils.DictPairs pairs = DictUtils.openDicts( m_context, names );
// Log.d( TAG, "openDicts() => %s", pairs ); // Log.d( TAG, "openDicts() => %s", pairs );

View file

@ -28,9 +28,9 @@ public class DictInfo {
public String fullSum; // md5sum of the whole file public String fullSum; // md5sum of the whole file
// set in jni code // set in jni code
public int langCode;
public int wordCount; public int wordCount;
public String isoCode; public String isoCode;
public String langName;
public String md5Sum; // internal (skipping header?) public String md5Sum; // internal (skipping header?)
@Override @Override

View file

@ -81,7 +81,7 @@ public class GameSummary implements Serializable {
public int gameID; public int gameID;
public String[] remoteDevs; // BTAddrs and phone numbers public String[] remoteDevs; // BTAddrs and phone numbers
public int dictLang; public String isoCode;
public DeviceRole serverRole; public DeviceRole serverRole;
public int nPacketsPending; public int nPacketsPending;
@ -96,7 +96,7 @@ public class GameSummary implements Serializable {
public GameSummary( CurGameInfo gi ) public GameSummary( CurGameInfo gi )
{ {
nPlayers = gi.nPlayers; nPlayers = gi.nPlayers;
dictLang = gi.dictLang; isoCode = gi.isoCode;
serverRole = gi.serverRole; serverRole = gi.serverRole;
gameID = gi.gameID; gameID = gi.gameID;
m_gi = gi; m_gi = gi;
@ -127,7 +127,7 @@ public class GameSummary implements Serializable {
&& modtime == other.modtime && modtime == other.modtime
&& created == other.created && created == other.created
&& gameID == other.gameID && gameID == other.gameID
&& dictLang == other.dictLang && TextUtils.equals( isoCode, other.isoCode)
&& nPacketsPending == other.nPacketsPending && nPacketsPending == other.nPacketsPending
&& Arrays.equals( scores, other.scores ) && Arrays.equals( scores, other.scores )
&& Arrays.equals( m_players, other.m_players ) && Arrays.equals( m_players, other.m_players )

View file

@ -104,7 +104,7 @@ public interface UtilCtxt {
void informMove( int turn, String expl, String words ); void informMove( int turn, String expl, String words );
void informUndo(); void informUndo();
void informNetDict( int lang, String oldName, String newName, void informNetDict( String isoCode, String oldName, String newName,
String newSum, CurGameInfo.XWPhoniesChoice phonies ); String newSum, CurGameInfo.XWPhoniesChoice phonies );
void informMissing( boolean isServer, CommsConnTypeSet connTypes, void informMissing( boolean isServer, CommsConnTypeSet connTypes,

View file

@ -217,7 +217,7 @@ public class UtilCtxtImpl implements UtilCtxt {
} }
@Override @Override
public void informNetDict( int lang, String oldName, public void informNetDict( String isoCode, String oldName,
String newName, String newSum, String newName, String newSum,
CurGameInfo.XWPhoniesChoice phonies ) CurGameInfo.XWPhoniesChoice phonies )
{ {

View file

@ -277,6 +277,7 @@ public class XwJNI {
public static native CommsAddrRec comms_getInitialAddr(); public static native CommsAddrRec comms_getInitialAddr();
public static native String comms_getUUID(); public static native String comms_getUUID();
public static native String lcToLocale( int lc ); public static native String lcToLocale( int lc );
public static native boolean haveLocaleToLc( String isoCode, int[] lc );
// Game methods // Game methods
private static GamePtr initGameJNI( long rowid ) private static GamePtr initGameJNI( long rowid )

View file

@ -202,6 +202,7 @@ public class LocUtils {
if ( lang.contains( "-" ) ) { if ( lang.contains( "-" ) ) {
lang = TextUtils.split(lang, "-")[0]; lang = TextUtils.split(lang, "-")[0];
} }
Assert.assertTrueNR( 2 == lang.length() );
s_curLang = lang; s_curLang = lang;
} }
return s_curLang; return s_curLang;

View file

@ -237,30 +237,31 @@
<item>@string/loc_downloads</item> <item>@string/loc_downloads</item>
</string-array> </string-array>
<string-array name="languages_map"> <!-- We can function without an entry here for a new language, but
<item>0</item><item>@string/lang_unknown</item><item>--</item> only the unlocalized name from the wordlist itself will be
<item>1</item><item>@string/lang_name_english</item><item>en</item> displayed. -->
<item>2</item><item>@string/lang_name_french</item><item>fr</item> <string-array name="language_names">
<item>3</item><item>@string/lang_name_german</item><item>de</item> <item>en</item><item>@string/lang_name_english</item>
<item>4</item><item>@string/lang_name_turkish</item><item>tr</item> <item>fr</item><item>@string/lang_name_french</item>
<item>5</item><item>@string/lang_name_arabic</item><item>ar</item> <item>de</item><item>@string/lang_name_german</item>
<item>6</item><item>@string/lang_name_spanish</item><item>es</item> <item>tr</item><item>@string/lang_name_turkish</item>
<item>7</item><item>@string/lang_name_swedish</item><item>sv</item> <item>ar</item><item>@string/lang_name_arabic</item>
<item>8</item><item>@string/lang_name_polish</item><item>pl</item> <item>es</item><item>@string/lang_name_spanish</item>
<item>9</item><item>@string/lang_name_danish</item><item>da</item> <item>sv</item><item>@string/lang_name_swedish</item>
<item>10</item><item>@string/lang_name_italian</item><item>it</item> <item>pl</item><item>@string/lang_name_polish</item>
<item>11</item><item>@string/lang_name_dutch</item><item>nl</item> <item>da</item><item>@string/lang_name_danish</item>
<item>12</item><item>@string/lang_name_catalan</item><item>ca</item> <item>it</item><item>@string/lang_name_italian</item>
<item>13</item><item>@string/lang_name_portuguese</item><item>pt</item> <item>nl</item><item>@string/lang_name_dutch</item>
<item>15</item><item>@string/lang_name_russian</item><item>ru</item> <item>ca</item><item>@string/lang_name_catalan</item>
<item>17</item><item>@string/lang_name_czech</item><item>cs</item> <item>pt</item><item>@string/lang_name_portuguese</item>
<item>18</item><item>@string/lang_name_greek</item><item>el</item> <item>ru</item><item>@string/lang_name_russian</item>
<item>19</item><item>@string/lang_name_slovak</item><item>sk</item> <item>cs</item><item>@string/lang_name_czech</item>
<item>20</item><item>@string/lang_name_hungarian</item><item>hu</item> <item>el</item><item>@string/lang_name_greek</item>
<item>21</item><item>@string/lang_name_romanian</item><item>ro</item> <item>sk</item><item>@string/lang_name_slovak</item>
<item>25</item><item>@string/lang_name_finnish</item><item>fi</item> <item>hu</item><item>@string/lang_name_hungarian</item>
<item>ro</item><item>@string/lang_name_romanian</item>
<item>127</item><item>Hex</item><item>--</item> <item>fi</item><item>@string/lang_name_finnish</item>
<item>hex</item><item>Hex</item>
</string-array> </string-array>
<!-- Triples of Name, supported codes, and URL format string --> <!-- Triples of Name, supported codes, and URL format string -->

View file

@ -11,7 +11,7 @@ LOCAL_C_INCLUDES+= \
LOCAL_LDLIBS += -llog LOCAL_LDLIBS += -llog
ifeq ($(BUILD_TARGET),debug) ifeq ($(BUILD_TARGET),debug)
LOCAL_DEBUG = -DMEM_DEBUG -DDEBUG -DENABLE_LOGGING -DCOMMS_CHECKSUM -DNLI_VERSION=1 -Wno-unused-variable LOCAL_DEBUG = -DMEM_DEBUG -DDEBUG -DENABLE_LOGGING -DCOMMS_CHECKSUM -Wno-unused-variable
endif endif
LOCAL_DEFINES += \ LOCAL_DEFINES += \
$(LOCAL_DEBUG) \ $(LOCAL_DEBUG) \

View file

@ -762,7 +762,6 @@ jEnumToInt( JNIEnv* env, jobject jenum )
static const SetInfo nli_ints[] = { static const SetInfo nli_ints[] = {
ARR_MEMBER( NetLaunchInfo, _conTypes ), ARR_MEMBER( NetLaunchInfo, _conTypes ),
ARR_MEMBER( NetLaunchInfo, lang ),
ARR_MEMBER( NetLaunchInfo, forceChannel ), ARR_MEMBER( NetLaunchInfo, forceChannel ),
ARR_MEMBER( NetLaunchInfo, nPlayersT ), ARR_MEMBER( NetLaunchInfo, nPlayersT ),
ARR_MEMBER( NetLaunchInfo, nPlayersH ), ARR_MEMBER( NetLaunchInfo, nPlayersH ),
@ -777,6 +776,7 @@ static const SetInfo nli_bools[] = {
static const SetInfo nli_strs[] = { static const SetInfo nli_strs[] = {
ARR_MEMBER( NetLaunchInfo, dict ), ARR_MEMBER( NetLaunchInfo, dict ),
ARR_MEMBER( NetLaunchInfo, isoCode ),
ARR_MEMBER( NetLaunchInfo, gameName ), ARR_MEMBER( NetLaunchInfo, gameName ),
ARR_MEMBER( NetLaunchInfo, room ), ARR_MEMBER( NetLaunchInfo, room ),
ARR_MEMBER( NetLaunchInfo, btName ), ARR_MEMBER( NetLaunchInfo, btName ),

View file

@ -41,7 +41,7 @@ typedef struct _AndDraw {
EnvThreadInfo* ti; EnvThreadInfo* ti;
#endif #endif
jobject jdraw; /* global ref; free it! */ jobject jdraw; /* global ref; free it! */
XP_LangCode curLang; XP_UCHAR curISOCode[MAX_ISO_CODE_LEN+1];
jobject jCache[JCACHE_COUNT]; jobject jCache[JCACHE_COUNT];
jobject jTvType; jobject jTvType;
XP_UCHAR miniTextBuf[128]; XP_UCHAR miniTextBuf[128];
@ -600,13 +600,13 @@ and_draw_dictChanged( DrawCtx* dctx, XWEnv xwe, XP_S16 playerNum,
AndDraw* draw = (AndDraw*)dctx; AndDraw* draw = (AndDraw*)dctx;
if ( !!dict && !!draw->jdraw ) { if ( !!dict && !!draw->jdraw ) {
XP_LOGFF( "(dict=%p/%s); code=%x", dict, dict_getName(dict), andDictID(dict) ); XP_LOGFF( "(dict=%p/%s); code=%x", dict, dict_getName(dict), andDictID(dict) );
XP_LangCode code = 0; /* A null dict means no-lang */ const XP_UCHAR* isoCode = NULL; /* A null dict means no-lang */
if ( NULL != dict ) { if ( NULL != dict ) {
code = dict_getLangCode( dict ); isoCode = dict_getISOCode( dict );
} }
/* Don't bother sending repeats. */ /* Don't bother sending repeats. */
if ( code != draw->curLang ) { if ( 0 != XP_STRCMP( isoCode, draw->curISOCode ) ) {
draw->curLang = code; XP_STRNCPY( draw->curISOCode, isoCode, VSIZE(draw->curISOCode) );
DRAW_CBK_HEADER( "dictChanged", "(J)V" ); DRAW_CBK_HEADER( "dictChanged", "(J)V" );

View file

@ -245,33 +245,34 @@ and_util_informUndo( XW_UtilCtxt* uc, XWEnv xwe )
} }
static void static void
and_util_informNetDict( XW_UtilCtxt* uc, XWEnv xwe, XP_LangCode lang, and_util_informNetDict( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR* isoCode,
const XP_UCHAR* oldName, const XP_UCHAR* oldName, const XP_UCHAR* newName,
const XP_UCHAR* newName, const XP_UCHAR* newSum, const XP_UCHAR* newSum, XWPhoniesChoice phoniesAction )
XWPhoniesChoice phoniesAction )
{ {
LOG_FUNC(); LOG_FUNC();
UTIL_CBK_HEADER( "informNetDict", UTIL_CBK_HEADER( "informNetDict",
"(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;L" "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
"Ljava/lang/String;L"
PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") ";)V" ); PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") ";)V" );
jstring jIsoCode = (*env)->NewStringUTF( env, isoCode );
jstring jnew = (*env)->NewStringUTF( env, newName ); jstring jnew = (*env)->NewStringUTF( env, newName );
jstring jsum = (*env)->NewStringUTF( env, newSum ); jstring jsum = (*env)->NewStringUTF( env, newSum );
jstring jold = (*env)->NewStringUTF( env, oldName ); jstring jold = (*env)->NewStringUTF( env, oldName );
jobject jphon = intToJEnum( env, phoniesAction, jobject jphon = intToJEnum( env, phoniesAction,
PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") ); PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") );
(*env)->CallVoidMethod( env, util->jutil, mid, lang, jold, jnew, jsum, (*env)->CallVoidMethod( env, util->jutil, mid, jIsoCode, jold, jnew, jsum,
jphon ); jphon );
deleteLocalRefs( env, jnew, jold, jsum, jphon, DELETE_NO_REF ); deleteLocalRefs( env, jnew, jold, jsum, jphon, jIsoCode, DELETE_NO_REF );
UTIL_CBK_TAIL(); UTIL_CBK_TAIL();
} }
const DictionaryCtxt* const DictionaryCtxt*
and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe, and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
XP_LangCode lang, const XP_UCHAR* dictName ) const XP_UCHAR* isoCode, const XP_UCHAR* dictName )
{ {
XP_LOGFF( "(lang: %d, name: %s)", lang, dictName ); XP_LOGFF( "(isoCode: %s, name: %s)", isoCode, dictName );
JNIEnv* env = xwe; JNIEnv* env = xwe;
XW_DUtilCtxt* duc = util_getDevUtilCtxt( uc, xwe ); XW_DUtilCtxt* duc = util_getDevUtilCtxt( uc, xwe );
@ -280,12 +281,14 @@ and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
dmgr_get( dictMgr, xwe, dictName ); dmgr_get( dictMgr, xwe, dictName );
if ( !dict ) { if ( !dict ) {
jstring jname = (*env)->NewStringUTF( env, dictName ); jstring jname = (*env)->NewStringUTF( env, dictName );
jstring jISOCode = (*env)->NewStringUTF( env, isoCode );
jobjectArray jstrs = makeStringArray( env, 1, NULL ); jobjectArray jstrs = makeStringArray( env, 1, NULL );
jobjectArray jbytes = makeByteArrayArray( env, 1 ); jobjectArray jbytes = makeByteArrayArray( env, 1 );
DUTIL_CBK_HEADER( "getDictPath", "(ILjava/lang/String;[Ljava/lang/String;[[B)V" ); DUTIL_CBK_HEADER( "getDictPath",
(*env)->CallVoidMethod( env, dutil->jdutil, mid, lang, jname, jstrs, jbytes ); "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[[B)V" );
(*env)->CallVoidMethod( env, dutil->jdutil, mid, jISOCode, jname, jstrs, jbytes );
DUTIL_CBK_TAIL(); DUTIL_CBK_TAIL();
jstring jpath = (*env)->GetObjectArrayElement( env, jstrs, 0 ); jstring jpath = (*env)->GetObjectArrayElement( env, jstrs, 0 );
@ -295,7 +298,7 @@ and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
TI_IF(&globalState->ti) TI_IF(&globalState->ti)
dictMgr, ((AndDUtil*)duc)->jniutil, dictMgr, ((AndDUtil*)duc)->jniutil,
jname, jdata, jpath, NULL, false ); jname, jdata, jpath, NULL, false );
deleteLocalRefs( env, jname, jstrs, jbytes, jdata, jpath, DELETE_NO_REF ); deleteLocalRefs( env, jname, jstrs, jbytes, jdata, jpath, jISOCode, DELETE_NO_REF );
} }
LOG_RETURNF( "%p", dict ); LOG_RETURNF( "%p", dict );
return dict; return dict;

View file

@ -424,7 +424,6 @@ static const SetInfo gi_ints[] = {
,ARR_MEMBER( CurGameInfo, traySize ) ,ARR_MEMBER( CurGameInfo, traySize )
,ARR_MEMBER( CurGameInfo, bingoMin ) ,ARR_MEMBER( CurGameInfo, bingoMin )
,ARR_MEMBER( CurGameInfo, gameID ) ,ARR_MEMBER( CurGameInfo, gameID )
,ARR_MEMBER( CurGameInfo, dictLang )
,ARR_MEMBER( CurGameInfo, forceChannel ) ,ARR_MEMBER( CurGameInfo, forceChannel )
}; };
@ -469,6 +468,8 @@ makeGI( MPFORMAL JNIEnv* env, jobject jgi )
getString( env, jgi, "dictName", AANDS(buf) ); getString( env, jgi, "dictName", AANDS(buf) );
gi->dictName = copyString( mpool, buf ); gi->dictName = copyString( mpool, buf );
getString( env, jgi, "isoCode", AANDS(buf) );
XP_STRNCPY( gi->isoCode, buf, VSIZE(gi->isoCode) );
XP_ASSERT( gi->nPlayers <= MAX_NUM_PLAYERS ); XP_ASSERT( gi->nPlayers <= MAX_NUM_PLAYERS );
@ -511,6 +512,7 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
setBools( env, jgi, (void*)gi, AANDS(gi_bools) ); setBools( env, jgi, (void*)gi, AANDS(gi_bools) );
setString( env, jgi, "dictName", gi->dictName ); setString( env, jgi, "dictName", gi->dictName );
setString( env, jgi, "isoCode", gi->isoCode );
intToJenumField( env, jgi, gi->phoniesAction, "phoniesAction", intToJenumField( env, jgi, gi->phoniesAction, "phoniesAction",
PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") ); PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") );
@ -995,12 +997,25 @@ Java_org_eehouse_android_xw4_jni_XwJNI_lcToLocale
const XP_UCHAR* locale = lcToLocale( lc ); const XP_UCHAR* locale = lcToLocale( lc );
if ( !!locale ) { if ( !!locale ) {
result = (*env)->NewStringUTF( env, locale ); result = (*env)->NewStringUTF( env, locale );
} else {
XP_LOGFF( "(%d) => NULL", lc );
} }
return result; return result;
} }
JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_haveLocaleToLc
( JNIEnv* env, jclass C, jstring jIsoCode, jintArray jOutArray )
{
XP_ASSERT( !!jIsoCode );
XP_LangCode lc;
const char* isoCode = (*env)->GetStringUTFChars( env, jIsoCode, NULL );
jboolean result = haveLocaleToLc( isoCode, &lc );
if ( result ) {
setIntInArray( env, jOutArray, 0, lc );
}
(*env)->ReleaseStringUTFChars( env, jIsoCode, isoCode );
return result;
}
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1make Java_org_eehouse_android_xw4_jni_XwJNI_dict_1make
( JNIEnv* env, jclass C, jlong jniGlobalPtr, jbyteArray jDictBytes, ( JNIEnv* env, jclass C, jlong jniGlobalPtr, jbyteArray jDictBytes,
@ -1151,11 +1166,10 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getInfo
DictionaryCtxt* dict = (DictionaryCtxt*)dictPtr; DictionaryCtxt* dict = (DictionaryCtxt*)dictPtr;
if ( NULL != dict ) { if ( NULL != dict ) {
jinfo = makeObjectEmptyConst( env, PKG_PATH("jni/DictInfo") ); jinfo = makeObjectEmptyConst( env, PKG_PATH("jni/DictInfo") );
XP_LangCode code = dict_getLangCode( dict );
setInt( env, jinfo, "langCode", code );
setInt( env, jinfo, "wordCount", dict_getWordCount( dict, env ) ); setInt( env, jinfo, "wordCount", dict_getWordCount( dict, env ) );
setString( env, jinfo, "md5Sum", dict_getMd5Sum( dict ) ); setString( env, jinfo, "md5Sum", dict_getMd5Sum( dict ) );
setString( env, jinfo, "isoCode", dict_getISOCode( dict ) ); setString( env, jinfo, "isoCode", dict_getISOCode( dict ) );
setString( env, jinfo, "langName", dict_getLangName( dict ) );
} }
return jinfo; return jinfo;