add ISOCode class

I was getting language name and iso code confused so adding a new type
to keep them separate. Keep string type for crossing JNI boundary and
passing as param e.g. in URLs and Bundles.
This commit is contained in:
Eric House 2022-07-07 08:01:23 -07:00
parent 882c717add
commit a393a99c19
32 changed files with 353 additions and 326 deletions

View file

@ -60,6 +60,7 @@ import org.eehouse.android.xw4.NFCUtils.Wrapper;
import org.eehouse.android.xw4.Perms23.Perm; import org.eehouse.android.xw4.Perms23.Perm;
import org.eehouse.android.xw4.TilePickAlert.TilePickState; import org.eehouse.android.xw4.TilePickAlert.TilePickState;
import org.eehouse.android.xw4.Toolbar.Buttons; import org.eehouse.android.xw4.Toolbar.Buttons;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.gen.PrefsWrappers; import org.eehouse.android.xw4.gen.PrefsWrappers;
import org.eehouse.android.xw4.jni.CommonPrefs.TileValueType; import org.eehouse.android.xw4.jni.CommonPrefs.TileValueType;
import org.eehouse.android.xw4.jni.CommonPrefs; import org.eehouse.android.xw4.jni.CommonPrefs;
@ -254,7 +255,7 @@ public class BoardDelegate extends DelegateBase
setGotGameDict( m_mySIS.getDict ); setGotGameDict( m_mySIS.getDict );
} else { } else {
DwnldDelegate DwnldDelegate
.downloadDictInBack( m_activity, m_gi.isoCode, .downloadDictInBack( m_activity, m_gi.isoCode(),
m_mySIS.getDict, m_mySIS.getDict,
BoardDelegate.this ); BoardDelegate.this );
} }
@ -925,7 +926,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.isoCode, 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,13 +1022,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 ); 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.isoCode ) ) { curDict, m_gi.isoCode() ) ) {
// do nothing // do nothing
} else { } else {
String selDict = DictsDelegate.prevSelFor( m_activity, m_gi.isoCode ); String selDict = DictsDelegate.prevSelFor( m_activity, m_gi.isoCode() );
if ( null == selDict ) { if ( null == selDict ) {
selDict = curDict; selDict = curDict;
} }
@ -1060,7 +1061,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.isoCode ); 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 );
@ -1432,7 +1433,7 @@ public class BoardDelegate extends DelegateBase
// DwnldActivity.DownloadFinishedListener interface // DwnldActivity.DownloadFinishedListener interface
////////////////////////////////////////////////// //////////////////////////////////////////////////
@Override @Override
public void downloadFinished( String lang, final String name, public void downloadFinished( ISOCode isoCode, final String name,
boolean success ) boolean success )
{ {
if ( success ) { if ( success ) {
@ -1762,7 +1763,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.isoCode ); launchLookup( wordsToArray( words ), m_gi.isoCode() );
} }
} ); } );
} }
@ -2024,7 +2025,7 @@ public class BoardDelegate extends DelegateBase
} }
@Override @Override
public void informNetDict( String isoCode, String oldName, public void informNetDict( ISOCode isoCode, String oldName,
String newName, String newSum, String newName, String newSum,
CurGameInfo.XWPhoniesChoice phonies ) CurGameInfo.XWPhoniesChoice phonies )
{ {

View file

@ -30,6 +30,7 @@ import android.database.sqlite.SQLiteException;
import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -391,13 +392,13 @@ public class DBHelper extends SQLiteOpenHelper {
String groupBy = columns[0]; String groupBy = columns[0];
// First gather all the lang codes // First gather all the lang codes
Map<Integer, String> map = new HashMap<>(); Map<Integer, ISOCode> map = new HashMap<>();
Cursor cursor = db.query( table.toString(), Cursor cursor = db.query( table.toString(),
columns, null, null, groupBy, null, null ); columns, null, null, groupBy, null, null );
int colIndex = cursor.getColumnIndex( columns[0] ); int colIndex = cursor.getColumnIndex( columns[0] );
while ( cursor.moveToNext() ) { while ( cursor.moveToNext() ) {
int code = cursor.getInt( colIndex ); int code = cursor.getInt( colIndex );
String isoCode = XwJNI.lcToLocale( code ); ISOCode isoCode = XwJNI.lcToLocaleJ( code );
map.put( code, isoCode ); map.put( code, isoCode );
Log.d( TAG, "added %d => %s", code, isoCode ); Log.d( TAG, "added %d => %s", code, isoCode );
} }

View file

@ -39,11 +39,12 @@ import android.text.TextUtils;
import org.eehouse.android.xw4.DBHelper.TABLE_NAMES; import org.eehouse.android.xw4.DBHelper.TABLE_NAMES;
import org.eehouse.android.xw4.DictUtils.DictLoc; import org.eehouse.android.xw4.DictUtils.DictLoc;
import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify.InviteMeans; import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify.InviteMeans;
import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
import org.eehouse.android.xw4.jni.CurGameInfo; import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole; import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
import org.eehouse.android.xw4.jni.CurGameInfo;
import org.eehouse.android.xw4.jni.DictInfo; import org.eehouse.android.xw4.jni.DictInfo;
import org.eehouse.android.xw4.jni.GameSummary; import org.eehouse.android.xw4.jni.GameSummary;
import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.jni.XwJNI;
@ -99,7 +100,7 @@ public class DBUtils {
new HashSet<>(); new HashSet<>();
public static interface StudyListListener { public static interface StudyListListener {
void onWordAdded( String word, String isoCode ); void onWordAdded( String word, ISOCode isoCode );
} }
private static Set<StudyListListener> s_slListeners private static Set<StudyListListener> s_slListeners
= new HashSet<>(); = new HashSet<>();
@ -176,8 +177,8 @@ public class DBUtils {
summary.readPlayers( context, players ); summary.readPlayers( context, players );
// isoCode will be null when game first created // isoCode will be null when game first created
summary.isoCode = cursor summary.isoCode =
.getString(cursor.getColumnIndex(DBHelper.ISOCODE)); ISOCode.newIf( cursor.getString(cursor.getColumnIndex(DBHelper.ISOCODE)) );
summary.modtime = summary.modtime =
cursor.getLong(cursor. cursor.getLong(cursor.
@ -296,7 +297,7 @@ public class DBUtils {
values.put( DBHelper.PLAYERS, values.put( DBHelper.PLAYERS,
summary.summarizePlayers() ); summary.summarizePlayers() );
Assert.assertTrueNR( null != summary.isoCode ); Assert.assertTrueNR( null != summary.isoCode );
values.put( DBHelper.ISOCODE, summary.isoCode ); values.put( DBHelper.ISOCODE, summary.isoCode.toString() );
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 );
@ -405,7 +406,7 @@ public class DBUtils {
} }
} }
public static int countGamesUsingISOCode( Context context, String isoCode ) public static int countGamesUsingISOCode( Context context, ISOCode isoCode )
{ {
int result = 0; int result = 0;
String[] columns = { DBHelper.ISOCODE }; String[] columns = { DBHelper.ISOCODE };
@ -1912,8 +1913,8 @@ 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.isoCode = result.isoCodeStr
cursor.getString( cursor.getColumnIndex(DBHelper.ISOCODE)); = 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 =
@ -1930,25 +1931,25 @@ public class DBUtils {
} }
if ( null != result ) { if ( null != result ) {
Assert.assertTrueNR( !TextUtils.isEmpty(result.isoCode ) );
if ( null == result.fullSum ) { // force generation if ( null == result.fullSum ) { // force generation
result = null; result = null;
} }
} }
Log.d( TAG, "dictsGetInfo(%s) => %s", name, result );
return result; return result;
} }
public static void dictsSetInfo( Context context, DictUtils.DictAndLoc dal, public static void dictsSetInfo( Context context, DictUtils.DictAndLoc dal,
DictInfo info ) DictInfo info )
{ {
Assert.assertTrueNR( ! TextUtils.isEmpty( info.isoCode ) ); Assert.assertTrueNR( null != info.isoCode() );
String selection = String selection =
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.ISOCODE, info.isoCode ); values.put( DBHelper.ISOCODE, info.isoCode().toString() );
values.put( DBHelper.LANGNAME, info.langName ); 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 );
@ -1997,11 +1998,11 @@ public class DBUtils {
} }
public static void addToStudyList( Context context, String word, public static void addToStudyList( Context context, String word,
String isoCode ) ISOCode isoCode )
{ {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put( DBHelper.WORD, word ); values.put( DBHelper.WORD, word );
values.put( DBHelper.ISOCODE, isoCode ); values.put( DBHelper.ISOCODE, isoCode.toString() );
initDB( context ); initDB( context );
synchronized( s_dbHelper ) { synchronized( s_dbHelper ) {
@ -2010,9 +2011,9 @@ public class DBUtils {
notifyStudyListListeners( word, isoCode ); notifyStudyListListeners( word, isoCode );
} }
public static String[] studyListLangs( Context context ) public static ISOCode[] studyListLangs( Context context )
{ {
String[] result = null; ISOCode[] result = null;
String[] columns = { DBHelper.ISOCODE }; String[] columns = { DBHelper.ISOCODE };
String groupBy = columns[0]; String groupBy = columns[0];
@ -2021,12 +2022,12 @@ public class DBUtils {
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 String[count]; result = new ISOCode[count];
if ( 0 < count ) { if ( 0 < count ) {
int index = 0; int index = 0;
int colIndex = cursor.getColumnIndex( columns[0] ); int colIndex = cursor.getColumnIndex( columns[0] );
while ( cursor.moveToNext() ) { while ( cursor.moveToNext() ) {
result[index++] = cursor.getString(colIndex); result[index++] = new ISOCode(cursor.getString(colIndex));
} }
} }
cursor.close(); cursor.close();
@ -2034,7 +2035,7 @@ public class DBUtils {
return result; return result;
} }
public static String[] studyListWords( Context context, String isoCode ) public static String[] studyListWords( Context context, ISOCode isoCode )
{ {
String[] result = null; String[] result = null;
String selection = String.format( "%s = '%s'", DBHelper.ISOCODE, isoCode ); String selection = String.format( "%s = '%s'", DBHelper.ISOCODE, isoCode );
@ -2059,7 +2060,7 @@ public class DBUtils {
return result; return result;
} }
public static void studyListClear( Context context, String isoCode, String[] words ) public static void studyListClear( Context context, ISOCode isoCode, String[] words )
{ {
String selection = String.format( "%s = '%s'", DBHelper.ISOCODE, isoCode ); String selection = String.format( "%s = '%s'", DBHelper.ISOCODE, isoCode );
if ( null != words ) { if ( null != words ) {
@ -2073,7 +2074,7 @@ public class DBUtils {
} }
} }
public static void studyListClear( Context context, String isoCode ) public static void studyListClear( Context context, ISOCode isoCode )
{ {
studyListClear( context, isoCode, null ); studyListClear( context, isoCode, null );
} }
@ -2554,7 +2555,7 @@ public class DBUtils {
return result; return result;
} }
private static void notifyStudyListListeners( String word, String isoCode ) private static void notifyStudyListListeners( String word, ISOCode isoCode )
{ {
synchronized( s_slListeners ) { synchronized( s_slListeners ) {
for ( StudyListListener listener : s_slListeners ) { for ( StudyListListener listener : s_slListeners ) {

View file

@ -51,6 +51,7 @@ import org.eehouse.android.xw4.jni.GameSummary;
import org.eehouse.android.xw4.jni.XwJNI.GamePtr; import org.eehouse.android.xw4.jni.XwJNI.GamePtr;
import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
@ -331,16 +332,6 @@ public abstract class DelegateBase implements DlgClickNotify,
return LocUtils.getString( m_activity, resID, params ); return LocUtils.getString( m_activity, resID, params );
} }
protected String xlateLang( String langCode )
{
return LocUtils.xlateLang( m_activity, langCode );
}
protected String xlateLang( String langCode, boolean caps )
{
return LocUtils.xlateLang( m_activity, langCode, caps );
}
protected String getQuantityString( int resID, int quantity, protected String getQuantityString( int resID, int quantity,
Object... params ) Object... params )
{ {
@ -593,12 +584,12 @@ public abstract class DelegateBase implements DlgClickNotify,
return m_dlgDelegate.post( runnable ); return m_dlgDelegate.post( runnable );
} }
protected void launchLookup( String[] words, String isoCode, boolean noStudy ) protected void launchLookup( String[] words, ISOCode isoCode, boolean noStudy )
{ {
m_dlgDelegate.launchLookup( words, isoCode, noStudy ); m_dlgDelegate.launchLookup( words, isoCode, noStudy );
} }
protected void launchLookup( String[] words, String isoCode ) protected void launchLookup( String[] words, ISOCode isoCode )
{ {
boolean studyOn = XWPrefs.getStudyEnabled( m_activity ); boolean studyOn = XWPrefs.getStudyEnabled( m_activity );
m_dlgDelegate.launchLookup( words, isoCode, !studyOn ); m_dlgDelegate.launchLookup( words, isoCode, !studyOn );

View file

@ -55,6 +55,7 @@ import org.eehouse.android.xw4.jni.XwJNI.IterWrapper;
import org.eehouse.android.xw4.jni.XwJNI.PatDesc; import org.eehouse.android.xw4.jni.XwJNI.PatDesc;
import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import java.util.Arrays; import java.util.Arrays;
import java.io.Serializable; import java.io.Serializable;
@ -127,7 +128,7 @@ public class DictBrowseDelegate extends DelegateBase
} }
private Activity m_activity; private Activity m_activity;
private String m_lang; private ISOCode 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;

View file

@ -33,6 +33,7 @@ import org.eehouse.android.xw4.jni.DictInfo;
import org.eehouse.android.xw4.jni.JNIUtilsImpl; import org.eehouse.android.xw4.jni.JNIUtilsImpl;
import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -47,10 +48,10 @@ 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<String, String> s_langNames; private static Map<ISOCode, String> s_langNames;
private static Map<String, String> s_langCodes; private static Map<String, ISOCode> s_langCodes;
private static String s_adaptedLang = null; private static ISOCode 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;
@ -58,7 +59,6 @@ public class DictLangCache {
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;
public LangsArrayAdapter( Context context, int itemLayout ) { public LangsArrayAdapter( Context context, int itemLayout ) {
super( context, itemLayout ); super( context, itemLayout );
@ -67,25 +67,20 @@ public class DictLangCache {
public void rebuild() public void rebuild()
{ {
m_map = new HashMap<>(); Set<String> langsSet = new HashSet<>();
DictAndLoc[] dals = DictUtils.dictList( m_context ); DictAndLoc[] dals = DictUtils.dictList( m_context );
for ( DictAndLoc dal : dals ) { for ( DictAndLoc dal : dals ) {
String lang = getLangName( m_context, dal.name ); String lang = getLangName( m_context, dal.name );
if ( null != lang && 0 != lang.length() ) { if ( null != lang && 0 != lang.length() ) {
if ( ! m_map.containsValue( lang ) ) { langsSet.add( lang );
String locName = LocUtils.xlateLang( m_context, lang,
true );
m_map.put( locName, lang );
}
} }
} }
// Now build the array data // Now build the array data
clear(); clear();
for ( Iterator<String> iter = m_map.keySet().iterator(); for ( Iterator<String> iter = langsSet.iterator();
iter.hasNext(); ) { iter.hasNext(); ) {
String locName = iter.next(); add( iter.next() );
add( locName );
} }
if ( null != s_last ) { if ( null != s_last ) {
add( s_last ); add( s_last );
@ -93,11 +88,11 @@ public class DictLangCache {
sort( KeepLast ); sort( KeepLast );
} }
public int getPosForLang( String lang ) public int getPosForLang( String langName )
{ {
int result = -1; int result = -1;
for ( int ii = 0; ii < getCount(); ++ii ) { for ( int ii = 0; ii < getCount(); ++ii ) {
if ( lang.equals( getLangAtPosition( ii ) ) ) { if ( langName.equals( getLangAtPosition( ii ) ) ) {
result = ii; result = ii;
break; break;
} }
@ -107,9 +102,7 @@ public class DictLangCache {
public String getLangAtPosition( int position ) public String getLangAtPosition( int position )
{ {
String locName = getItem( position ); return getItem( position );
String result = m_map.get( locName );
return result;
} }
} }
@ -135,9 +128,8 @@ public class DictLangCache {
int wordCount = info.wordCount; int wordCount = info.wordCount;
String langName = getLangName( context, dal.name ); String langName = getLangName( context, dal.name );
String locName = LocUtils.xlateLang( context, langName );
result = LocUtils.getString( context, R.string.dict_desc_fmt, result = LocUtils.getString( context, R.string.dict_desc_fmt,
dal.name, locName, dal.name, langName,
wordCount ); wordCount );
} }
return result; return result;
@ -145,7 +137,7 @@ public class DictLangCache {
// This populates the cache and will take significant time if it's mostly // This populates the cache and will take significant time if it's mostly
// empty and there are a lot of dicts. // empty and there are a lot of dicts.
public static int getLangCount( Context context, String isoCode ) public static int getLangCount( Context context, ISOCode isoCode )
{ {
int count = 0; int count = 0;
DictAndLoc[] dals = DictUtils.dictList( context ); DictAndLoc[] dals = DictUtils.dictList( context );
@ -157,13 +149,13 @@ public class DictLangCache {
return count; return count;
} }
private static DictInfo[] getInfosHaveLang( Context context, String isoCode ) private static DictInfo[] getInfosHaveLang( Context context, ISOCode isoCode )
{ {
List<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 && isoCode.equals( info.isoCode ) ) { if ( null != info && isoCode.equals( info.isoCode() ) ) {
al.add( info ); al.add( info );
} }
} }
@ -171,12 +163,12 @@ public class DictLangCache {
return result; return result;
} }
public static boolean haveDict( Context context, String isoCode, String name ) public static boolean haveDict( Context context, ISOCode isoCode, String dictName )
{ {
boolean found = false; boolean found = false;
DictInfo[] infos = getInfosHaveLang( context, isoCode ); DictInfo[] infos = getInfosHaveLang( context, isoCode );
for ( DictInfo info : infos ) { for ( DictInfo info : infos ) {
if ( name.equals( info.name ) ) { if ( dictName.equals( info.name ) ) {
found = true; found = true;
break; break;
} }
@ -184,7 +176,7 @@ public class DictLangCache {
return found; return found;
} }
private static String[] getHaveLang( Context context, String isoCode, private static String[] getHaveLang( Context context, ISOCode isoCode,
Comparator<DictInfo> comp, Comparator<DictInfo> comp,
boolean withCounts ) boolean withCounts )
{ {
@ -210,12 +202,12 @@ public class DictLangCache {
return result; return result;
} }
public static String[] getHaveLang( Context context, String isoCode ) public static String[] getHaveLang( Context context, ISOCode isoCode )
{ {
return getHaveLang( context, isoCode, null, false ); return getHaveLang( context, isoCode, null, false );
} }
public static DictAndLoc[] getDALsHaveLang( Context context, String isoCode ) public static DictAndLoc[] getDALsHaveLang( Context context, ISOCode isoCode )
{ {
Assert.assertNotNull( isoCode ); Assert.assertNotNull( isoCode );
List<DictAndLoc> al = new ArrayList<>(); List<DictAndLoc> al = new ArrayList<>();
@ -226,8 +218,8 @@ public class DictLangCache {
for ( DictAndLoc dal : dals ) { for ( DictAndLoc dal : dals ) {
DictInfo info = getInfo( context, dal ); DictInfo info = getInfo( context, dal );
if ( null != info ) { if ( null != info ) {
Assert.assertTrueNR( s_langNames.containsKey( info.isoCode ) ); Assert.assertTrueNR( s_langNames.containsKey( info.isoCode() ) );
if ( isoCode.equals( info.isoCode ) ) { if ( isoCode.equals( info.isoCode() ) ) {
al.add( dal ); al.add( dal );
} }
} }
@ -245,12 +237,12 @@ public class DictLangCache {
} }
}; };
public static String[] getHaveLangByCount( Context context, String isoCode ) public static String[] getHaveLangByCount( Context context, ISOCode isoCode )
{ {
return getHaveLang( context, isoCode, s_ByCount, false ); return getHaveLang( context, isoCode, s_ByCount, false );
} }
public static String[] getHaveLangCounts( Context context, String isoCode ) public static String[] getHaveLangCounts( Context context, ISOCode isoCode )
{ {
return getHaveLang( context, isoCode, null, true ); return getHaveLang( context, isoCode, null, true );
} }
@ -261,41 +253,41 @@ public class DictLangCache {
return nameWithCount.substring( 0, indx ); return nameWithCount.substring( 0, indx );
} }
public static String getDictISOCode( Context context, DictAndLoc dal ) public static ISOCode getDictISOCode( Context context, DictAndLoc dal )
{ {
return getInfo( context, dal ).isoCode; return getInfo( context, dal ).isoCode();
} }
public static String getDictISOCode( Context context, String dictName ) public static ISOCode getDictISOCode( Context context, String dictName )
{ {
DictInfo info = getInfo( context, dictName ); DictInfo info = getInfo( context, dictName );
return info.isoCode; return info.isoCode();
} }
public static String getLangNameForISOCode( Context context, String isoCode ) public static String getLangNameForISOCode( Context context, ISOCode isoCode )
{ {
makeMaps( context ); makeMaps( context );
return s_langNames.get( isoCode ); return s_langNames.get( isoCode );
} }
public static void setLangNameForISOCode( Context context, String isoCode, public static void setLangNameForISOCode( Context context, ISOCode isoCode,
String langName ) String langName )
{ {
makeMaps( context ); makeMaps( context );
putTwo( isoCode, langName ); putTwo( isoCode, langName );
} }
public static String getLangIsoCode( Context context, String langName ) public static ISOCode getLangIsoCode( Context context, String langName )
{ {
makeMaps( context ); makeMaps( context );
String result = s_langCodes.get( langName ); ISOCode result = s_langCodes.get( langName );
// Log.d( TAG, "getLangIsoCode(%s) => %s", langName, result ); // Log.d( TAG, "getLangIsoCode(%s) => %s", langName, result );
return result; return result;
} }
public static String getDictLangName( Context context, String dictName ) public static String getDictLangName( Context context, String dictName )
{ {
String isoCode = getDictISOCode( context, dictName ); ISOCode isoCode = getDictISOCode( context, dictName );
return getLangNameForISOCode( context, isoCode ); return getLangNameForISOCode( context, isoCode );
} }
@ -318,7 +310,7 @@ public class DictLangCache {
public static String getLangName( Context context, String dictName ) public static String getLangName( Context context, String dictName )
{ {
String isoCode = getDictISOCode( context, dictName ); ISOCode isoCode = getDictISOCode( context, dictName );
return getLangNameForISOCode( context, isoCode ); return getLangNameForISOCode( context, isoCode );
} }
@ -370,7 +362,7 @@ public class DictLangCache {
return langs.toArray( result ); return langs.toArray( result );
} }
public static String getBestDefault( Context context, String isoCode, public static String getBestDefault( Context context, ISOCode isoCode,
boolean human ) boolean human )
{ {
String dictName = human? CommonPrefs.getDefaultHumanDict( context ) String dictName = human? CommonPrefs.getDefaultHumanDict( context )
@ -419,21 +411,21 @@ public class DictLangCache {
} }
public static ArrayAdapter<String> getDictsAdapter( Context context, public static ArrayAdapter<String> getDictsAdapter( Context context,
String isoCode ) ISOCode isoCode )
{ {
if ( ! isoCode.equals( 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, isoCode ) ); rebuildAdapter( s_dictsAdapter, getHaveLang( context, isoCode ) );
s_adaptedLang = isoCode; s_adaptedLang = isoCode;
} }
return s_dictsAdapter; return s_dictsAdapter;
} }
private static void putTwo( String isoCode, String langName ) private static void putTwo( ISOCode isoCode, String langName )
{ {
// Log.d( TAG, "putTwo(): adding %s => %s", langName, isoCode ); // Log.d( TAG, "putTwo(): adding %s => %s", langName, isoCode );
Assert.assertTrueNR( !TextUtils.isEmpty(isoCode) Assert.assertTrueNR( null != isoCode
&& !TextUtils.isEmpty(langName) ); && !TextUtils.isEmpty(langName) );
s_langCodes.put( langName, isoCode ); s_langCodes.put( langName, isoCode );
s_langNames.put( isoCode, langName ); s_langNames.put( isoCode, langName );
@ -448,7 +440,7 @@ public class DictLangCache {
Resources res = context.getResources(); Resources res = context.getResources();
String[] entries = res.getStringArray( R.array.language_names ); String[] entries = res.getStringArray( R.array.language_names );
for ( int ii = 0; ii < entries.length; ii += 2 ) { for ( int ii = 0; ii < entries.length; ii += 2 ) {
String isoCode = entries[ii]; ISOCode isoCode = new ISOCode(entries[ii]);
String langName = entries[ii+1]; String langName = entries[ii+1];
putTwo( isoCode, langName ); putTwo( isoCode, langName );
} }
@ -458,7 +450,7 @@ public class DictLangCache {
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 );
String isoCode = info.isoCode; ISOCode isoCode = info.isoCode();
Assert.assertTrueNR( null != isoCode ); Assert.assertTrueNR( null != isoCode );
if ( !s_langNames.containsKey( isoCode ) ) { if ( !s_langNames.containsKey( isoCode ) ) {
// Log.d( TAG, "looking at info %s", info ); // Log.d( TAG, "looking at info %s", info );
@ -484,7 +476,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 && null == info.isoCode ) { 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

@ -26,6 +26,7 @@ import android.util.AttributeSet;
import java.util.ArrayList; import java.util.ArrayList;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
public class DictListPreference extends XWListPreference { public class DictListPreference extends XWListPreference {
@ -50,7 +51,7 @@ public class DictListPreference extends XWListPreference {
if ( null == curLang ) { if ( null == curLang ) {
curLang = LocUtils.getString( context, R.string.lang_name_english ); curLang = LocUtils.getString( context, R.string.lang_name_english );
} }
String isoCode = DictLangCache.getLangIsoCode( context, curLang ); ISOCode 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<>();

View file

@ -54,6 +54,7 @@ import org.eehouse.android.xw4.DwnldDelegate.OnGotLcDictListener;
import org.eehouse.android.xw4.Perms23.Perm; import org.eehouse.android.xw4.Perms23.Perm;
import org.eehouse.android.xw4.jni.GameSummary; import org.eehouse.android.xw4.jni.GameSummary;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -82,9 +83,9 @@ public class DictsDelegate extends ListDelegateBase
private static final String REMOTE_INFO_KEY = "REMOTE_INFO_KEY"; private static final String REMOTE_INFO_KEY = "REMOTE_INFO_KEY";
private static final String SEL_DICTS_KEY = "SEL_DICTS_KEY"; private static final String SEL_DICTS_KEY = "SEL_DICTS_KEY";
protected static final String DICT_SHOWREMOTE = "do_launch"; private static final String DICT_SHOWREMOTE = "do_launch";
protected static final String DICT_LANG_EXTRA = "use_lang"; private static final String DICT_LANG_EXTRA = "use_lang";
protected static final String DICT_NAME_EXTRA = "use_dict"; private static final String DICT_NAME_EXTRA = "use_dict";
protected static final String RESULT_LAST_LANG = "last_lang"; protected static final String RESULT_LAST_LANG = "last_lang";
protected static final String RESULT_LAST_DICT = "last_dict"; protected static final String RESULT_LAST_DICT = "last_dict";
@ -108,17 +109,17 @@ public class DictsDelegate extends ListDelegateBase
private String m_filterLang; private String m_filterLang;
private Map<String, Uri> m_needUpdates; private Map<String, Uri> m_needUpdates;
private String m_onServerStr; private String m_onServerStr;
private String m_lastLang; private ISOCode m_lastLang;
private String m_lastDict; private String m_lastDict;
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 mISOCode; // what needs to be in URL public ISOCode 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 isoCode, String localLang, public DictInfo( String name, ISOCode isoCode, String localLang,
int nWords, long nBytes, String note ) int nWords, long nBytes, String note )
{ {
m_name = name; m_name = name;
@ -201,7 +202,6 @@ public class DictsDelegate extends ListDelegateBase
int groupPos = info.m_posn; int groupPos = info.m_posn;
String langName = m_langs[groupPos]; String langName = m_langs[groupPos];
boolean expanded = ! m_closedLangs.contains( langName ); boolean expanded = ! m_closedLangs.contains( langName );
String locLangName = xlateLang( langName );
String details = null; String details = null;
if ( 0 < info.m_numDictsInst && 0 < info.m_numDictsAvail ) { if ( 0 < info.m_numDictsInst && 0 < info.m_numDictsAvail ) {
details = getString( R.string.dict_lang_inst_and_avail, details = getString( R.string.dict_lang_inst_and_avail,
@ -214,7 +214,7 @@ public class DictsDelegate extends ListDelegateBase
} else { } else {
Assert.failDbg(); Assert.failDbg();
} }
String title = Utils.capitalize( locLangName ) + " " + details; String title = Utils.capitalize( langName ) + " " + details;
result = ListGroup.make( m_context, convertView, result = ListGroup.make( m_context, convertView,
DictsDelegate.this, groupPos, title, DictsDelegate.this, groupPos, title,
expanded ); expanded );
@ -292,7 +292,7 @@ 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<>();
String isoCode = DictLangCache.getLangIsoCode( m_context, langName ); ISOCode isoCode = DictLangCache.getLangIsoCode( m_context, langName );
DictAndLoc[] dals = DictLangCache.getDALsHaveLang( m_context, isoCode ); DictAndLoc[] dals = DictLangCache.getDALsHaveLang( m_context, isoCode );
if ( null != dals ) { if ( null != dals ) {
for ( DictAndLoc dal : dals ) { for ( DictAndLoc dal : dals ) {
@ -399,7 +399,6 @@ public class DictsDelegate extends ListDelegateBase
}; };
String lang = DictLangCache.getDictLangName( m_activity, String lang = DictLangCache.getDictLangName( m_activity,
dictName ); dictName );
lang = xlateLang( lang );
message = getString( R.string.set_default_message_fmt, message = getString( R.string.set_default_message_fmt,
dictName, lang ); dictName, lang );
dialog = makeAlertBuilder() dialog = makeAlertBuilder()
@ -417,7 +416,8 @@ 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();
String isoCode = intent.getStringExtra( MultiService.ISO ); ISOCode isoCode = ISOCode
.newIf( intent.getStringExtra( MultiService.ISO ) );
String name = intent.getStringExtra( MultiService.DICT ); String name = intent.getStringExtra( MultiService.DICT );
m_launchedForMissing = true; m_launchedForMissing = true;
DwnldDelegate DwnldDelegate
@ -478,7 +478,7 @@ public class DictsDelegate extends ListDelegateBase
m_showRemote = true; m_showRemote = true;
m_checkbox.setVisibility( View.GONE ); m_checkbox.setVisibility( View.GONE );
String isoCode = args.getString( DICT_LANG_EXTRA ); ISOCode isoCode = ISOCode.newIf( args.getString( DICT_LANG_EXTRA ) );
if ( null != isoCode ) { if ( null != isoCode ) {
m_filterLang = DictLangCache.getLangNameForISOCode( m_activity, isoCode ); m_filterLang = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
m_closedLangs.remove( m_filterLang ); m_closedLangs.remove( m_filterLang );
@ -561,7 +561,7 @@ public class DictsDelegate extends ListDelegateBase
} else { } else {
if ( null != m_lastLang && null != m_lastDict ) { if ( null != m_lastLang && null != m_lastDict ) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra( RESULT_LAST_LANG, m_lastLang ); intent.putExtra( RESULT_LAST_LANG, m_lastLang.toString() );
intent.putExtra( RESULT_LAST_DICT, m_lastDict ); intent.putExtra( RESULT_LAST_DICT, m_lastDict );
setResult( Activity.RESULT_OK, intent ); setResult( Activity.RESULT_OK, intent );
} else { } else {
@ -723,9 +723,9 @@ public class DictsDelegate extends ListDelegateBase
private void setDefault( String name, int keyId, int otherKey ) private void setDefault( String name, int keyId, int otherKey )
{ {
String isoCode = DictLangCache.getDictISOCode( m_activity, name ); ISOCode 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 );
String curISOCode = DictLangCache.getLangIsoCode( m_activity, curLangName ); ISOCode curISOCode = DictLangCache.getLangIsoCode( m_activity, curLangName );
boolean changeLang = !isoCode.equals( curISOCode ); boolean changeLang = !isoCode.equals( curISOCode );
SharedPreferences sp SharedPreferences sp
@ -809,7 +809,7 @@ 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( String isoCode ) { public LangDelData( ISOCode isoCode ) {
delDicts = new HashSet<>(); delDicts = new HashSet<>();
langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode ); langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
nDicts = DictLangCache.getDALsHaveLang( m_activity, isoCode ).length; nDicts = DictLangCache.getDALsHaveLang( m_activity, isoCode ).length;
@ -828,10 +828,10 @@ public class DictsDelegate extends ListDelegateBase
int nDicts; int nDicts;
} }
Map<String, LangDelData> dels = new HashMap<>(); Map<ISOCode, LangDelData> dels = new HashMap<>();
Set<String> skipLangs = new HashSet<>(); Set<ISOCode> skipLangs = new HashSet<>();
for ( String dict : m_selDicts.keySet() ) { for ( String dict : m_selDicts.keySet() ) {
String isoCode = DictLangCache.getDictISOCode( m_activity, dict ); ISOCode isoCode = DictLangCache.getDictISOCode( m_activity, dict );
if ( skipLangs.contains( isoCode ) ) { if ( skipLangs.contains( isoCode ) ) {
continue; continue;
} }
@ -854,9 +854,8 @@ public class DictsDelegate extends ListDelegateBase
int nLeftAfter = data.nDicts - data.delDicts.size(); int nLeftAfter = data.nDicts - data.delDicts.size();
if ( 0 == nLeftAfter ) { // last in this language? if ( 0 == nLeftAfter ) { // last in this language?
String locName = xlateLang( data.langName );
String newMsg = getString( R.string.confirm_deleteonly_dicts_fmt, String newMsg = getString( R.string.confirm_deleteonly_dicts_fmt,
data.dictsStr(), locName ); data.dictsStr(), data.langName );
msg += "\n\n" + newMsg; msg += "\n\n" + newMsg;
} }
} }
@ -952,7 +951,7 @@ public class DictsDelegate extends ListDelegateBase
DictLangCache.inval( m_activity, dict, loc, false ); DictLangCache.inval( m_activity, dict, loc, false );
} }
private void startDownload( String isoCode, String name ) private void startDownload( ISOCode isoCode, String name )
{ {
DwnldDelegate.downloadDictInBack( m_activity, isoCode, name, this ); DwnldDelegate.downloadDictInBack( m_activity, isoCode, name, this );
} }
@ -1060,7 +1059,7 @@ public class DictsDelegate extends ListDelegateBase
} }
public static void downloadForResult( Delegator delegator, RequestCode requestCode, public static void downloadForResult( Delegator delegator, RequestCode requestCode,
String isoCode ) ISOCode isoCode )
{ {
downloadForResult( delegator, requestCode, isoCode, null ); downloadForResult( delegator, requestCode, isoCode, null );
} }
@ -1070,7 +1069,7 @@ public class DictsDelegate extends ListDelegateBase
downloadForResult( delegator, requestCode, null, null ); downloadForResult( delegator, requestCode, null, null );
} }
public static void downloadDefaultDict( Context context, String isoCode, public static void downloadDefaultDict( Context context, ISOCode isoCode,
OnGotLcDictListener lstnr ) OnGotLcDictListener lstnr )
{ {
new GetDefaultDictTask( context, isoCode, lstnr ).execute(); new GetDefaultDictTask( context, isoCode, lstnr ).execute();
@ -1083,7 +1082,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 String isoCode ) { String curDict, final ISOCode isoCode ) {
final HashMap<MenuItem, DictAndLoc> itemData final HashMap<MenuItem, DictAndLoc> itemData
= new HashMap<>(); = new HashMap<>();
@ -1129,7 +1128,7 @@ public class DictsDelegate extends ListDelegateBase
} }
public static boolean handleDictsPopup( Delegator delegator, View button, public static boolean handleDictsPopup( Delegator delegator, View button,
String curDict, String isoCode ) String curDict, ISOCode isoCode )
{ {
int nDicts = DictLangCache.getLangCount( delegator.getActivity(), isoCode ); int nDicts = DictLangCache.getLangCount( delegator.getActivity(), isoCode );
boolean canHandle = 1 < nDicts; boolean canHandle = 1 < nDicts;
@ -1139,12 +1138,12 @@ public class DictsDelegate extends ListDelegateBase
return canHandle; return canHandle;
} }
private static String keyForLang( String isoCode ) private static String keyForLang( ISOCode isoCode )
{ {
return String.format( "%s:lang=%s", TAG, isoCode ); return String.format( "%s:lang=%s", TAG, isoCode );
} }
static String prevSelFor( Context context, String isoCode ) static String prevSelFor( Context context, ISOCode isoCode )
{ {
String key = keyForLang( isoCode ); String key = keyForLang( isoCode );
return DBUtils.getStringFor( context, key ); return DBUtils.getStringFor( context, key );
@ -1197,11 +1196,11 @@ public class DictsDelegate extends ListDelegateBase
// DwnldActivity.DownloadFinishedListener interface // DwnldActivity.DownloadFinishedListener interface
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@Override @Override
public void downloadFinished( String lang, final String name, public void downloadFinished( ISOCode isoCode, final String name,
final boolean success ) final boolean success )
{ {
if ( success && m_showRemote ) { if ( success && m_showRemote ) {
m_lastLang = lang; m_lastLang = isoCode;
m_lastDict = name; m_lastDict = name;
} }
@ -1261,14 +1260,14 @@ public class DictsDelegate extends ListDelegateBase
private static class GetDefaultDictTask extends AsyncTask<Void, Void, String> { private static class GetDefaultDictTask extends AsyncTask<Void, Void, String> {
private Context m_context; private Context m_context;
private String m_lc; private ISOCode m_lc;
private String m_langName; private String m_langName;
private OnGotLcDictListener m_lstnr; private OnGotLcDictListener m_lstnr;
public GetDefaultDictTask( Context context, String lc, public GetDefaultDictTask( Context context, ISOCode isoCode,
OnGotLcDictListener lnr ) { OnGotLcDictListener lnr ) {
m_context = context; m_context = context;
m_lc = lc; m_lc = isoCode;
m_lstnr = lnr; m_lstnr = lnr;
} }
@ -1292,7 +1291,7 @@ public class DictsDelegate extends ListDelegateBase
int nLangs = langs.length(); int nLangs = langs.length();
for ( int ii = 0; ii < nLangs; ++ii ) { for ( int ii = 0; ii < nLangs; ++ii ) {
JSONObject langObj = langs.getJSONObject( ii ); JSONObject langObj = langs.getJSONObject( ii );
String langCode = langObj.getString( "lc" ); ISOCode langCode = ISOCode.newIf( langObj.getString( "lc" ) );
if ( ! langCode.equals( m_lc ) ) { if ( ! langCode.equals( m_lc ) ) {
continue; continue;
} }
@ -1344,7 +1343,7 @@ public class DictsDelegate extends ListDelegateBase
@Override @Override
protected void onPostExecute( String name ) protected void onPostExecute( String name )
{ {
m_lstnr.gotDictInfo( null != name, m_langName, name ); m_lstnr.gotDictInfo( null != name, m_lc, name );
} }
} }
@ -1442,7 +1441,7 @@ 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 isoCode = langObj.optString( "lc", null ); ISOCode isoCode = ISOCode.newIf( langObj.optString( "lc", null ) );
String urlLangName = langObj.getString( "lang" ); String urlLangName = langObj.getString( "lang" );
String localLangName = null; String localLangName = null;
if ( null != isoCode ) { if ( null != isoCode ) {
@ -1483,8 +1482,7 @@ public class DictsDelegate extends ListDelegateBase
if ( !m_quickFetchMode ) { if ( !m_quickFetchMode ) {
// Check if we have it and it needs an update // Check if we have it and it needs an update
if ( DictLangCache.haveDict( m_activity, if ( DictLangCache.haveDict( m_activity, isoCode, name )){
localLangName, name )){
boolean matches = true; boolean matches = true;
JSONArray sums = dict.optJSONArray("md5sums"); JSONArray sums = dict.optJSONArray("md5sums");
if ( null != sums ) { if ( null != sums ) {
@ -1538,7 +1536,7 @@ public class DictsDelegate extends ListDelegateBase
} }
} // class FetchListTask } // class FetchListTask
private static String listDictsProc( String lc ) private static String listDictsProc( ISOCode lc )
{ {
String proc = String.format( "listDicts?vc=%d", String proc = String.format( "listDicts?vc=%d",
BuildConfig.VERSION_CODE ); BuildConfig.VERSION_CODE );
@ -1555,12 +1553,12 @@ public class DictsDelegate extends ListDelegateBase
public static void downloadForResult( Delegator delegator, public static void downloadForResult( Delegator delegator,
RequestCode requestCode, RequestCode requestCode,
String isoCode, String name ) ISOCode isoCode, String name )
{ {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putBoolean( DICT_SHOWREMOTE, true ); bundle.putBoolean( DICT_SHOWREMOTE, true );
if ( null != isoCode ) { if ( null != isoCode ) {
bundle.putString( DICT_LANG_EXTRA, isoCode ); bundle.putString( DICT_LANG_EXTRA, isoCode.toString() );
} }
if ( null != name ) { if ( null != name ) {
Assert.assertTrue( null != isoCode ); Assert.assertTrue( null != isoCode );

View file

@ -30,6 +30,7 @@ import java.io.Serializable;
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo; import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
import org.eehouse.android.xw4.Utils.ISOCode;
public class DlgDelegate { public class DlgDelegate {
private static final String TAG = DlgDelegate.class.getSimpleName(); private static final String TAG = DlgDelegate.class.getSimpleName();
@ -417,7 +418,7 @@ public class DlgDelegate {
m_dlgt.show( state ); m_dlgt.show( state );
} }
public void launchLookup( String[] words, String isoCode, boolean noStudy ) public void launchLookup( String[] words, ISOCode isoCode, boolean noStudy )
{ {
m_dlgt.show( LookupAlert.newInstance( words, isoCode, noStudy ) ); m_dlgt.show( LookupAlert.newInstance( words, isoCode, noStudy ) );
} }

View file

@ -49,6 +49,7 @@ import java.util.Set;
import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.Perms23.Perm; import org.eehouse.android.xw4.Perms23.Perm;
import org.eehouse.android.xw4.Utils.ISOCode;
public class DwnldDelegate extends ListDelegateBase { public class DwnldDelegate extends ListDelegateBase {
private static final String TAG = DwnldDelegate.class.getSimpleName(); private static final String TAG = DwnldDelegate.class.getSimpleName();
@ -64,11 +65,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 isoCode, String name, boolean success ); void downloadFinished( ISOCode isoCode, String name, boolean success );
} }
public interface OnGotLcDictListener { public interface OnGotLcDictListener {
void gotDictInfo( boolean success, String isoCode, String name ); void gotDictInfo( boolean success, ISOCode isoCode, String name );
} }
public DwnldDelegate( Delegator delegator, Bundle savedInstanceState ) public DwnldDelegate( Delegator delegator, Bundle savedInstanceState )
@ -444,10 +445,10 @@ public class DwnldDelegate extends ListDelegateBase {
return new File(path).getName(); return new File(path).getName();
} }
private static String langFromUri( Uri uri ) private static ISOCode langFromUri( Uri uri )
{ {
List<String> segs = uri.getPathSegments(); List<String> segs = uri.getPathSegments();
String result = segs.get( segs.size() - 2 ); ISOCode result = new ISOCode(segs.get( segs.size() - 2 ));
return result; return result;
} }
@ -469,7 +470,7 @@ public class DwnldDelegate extends ListDelegateBase {
} }
if ( null != ld ) { if ( null != ld ) {
String name = ld.m_name; String name = ld.m_name;
String lang = langFromUri( uri ); ISOCode lang = langFromUri( uri );
if ( null == name ) { if ( null == name ) {
name = uri.toString(); name = uri.toString();
} }
@ -478,7 +479,7 @@ public class DwnldDelegate extends ListDelegateBase {
} }
} }
public static void downloadDictInBack( Context context, String isoCode, public static void downloadDictInBack( Context context, ISOCode isoCode,
String dictName, String dictName,
DownloadFinishedListener lstnr ) DownloadFinishedListener lstnr )
{ {

View file

@ -58,6 +58,7 @@ import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
import org.eehouse.android.xw4.jni.JNIThread; import org.eehouse.android.xw4.jni.JNIThread;
import org.eehouse.android.xw4.jni.LocalPlayer; import org.eehouse.android.xw4.jni.LocalPlayer;
import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.Utils.ISOCode;
public class GameConfigDelegate extends DelegateBase public class GameConfigDelegate extends DelegateBase
implements View.OnClickListener, XWListItem.DeleteCallback { implements View.OnClickListener, XWListItem.DeleteCallback {
@ -353,7 +354,8 @@ 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.getLangNameForISOCode( m_activity, m_gi.isoCode ); 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 +365,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.isoCode, 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,13 +546,13 @@ 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.isoCode, dictName ); configDictSpinner( m_dictSpinner, m_gi.isoCode(), dictName );
configDictSpinner( m_playerDictSpinner, m_gi.isoCode, dictName ); configDictSpinner( m_playerDictSpinner, m_gi.isoCode(), dictName );
break; break;
case REQUEST_LANG_GC: case REQUEST_LANG_GC:
String langName = cancelled ISOCode isoCode = cancelled ? m_gi.isoCode()
? DictLangCache.getLangNameForISOCode( m_activity, m_gi.isoCode ) : (ISOCode)data.getSerializableExtra( DictsDelegate.RESULT_LAST_LANG );
: data.getStringExtra( DictsDelegate.RESULT_LAST_LANG ); String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
selLangChanged( langName ); selLangChanged( langName );
setLangSpinnerSelection( langName ); setLangSpinnerSelection( langName );
break; break;
@ -990,7 +992,7 @@ public class GameConfigDelegate extends DelegateBase
} }
} // loadPlayersList } // loadPlayersList
private void configDictSpinner( Spinner dictsSpinner, final String isoCode, private void configDictSpinner( Spinner dictsSpinner, final ISOCode isoCode,
String curDict ) String curDict )
{ {
if ( null != dictsSpinner ) { if ( null != dictsSpinner ) {
@ -1009,8 +1011,8 @@ 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.isoCode ); m_gi.isoCode() );
Assert.assertTrueNR( isoCode.equals(m_gi.isoCode) ); Assert.assertTrueNR( isoCode.equals(m_gi.isoCode()) );
} }
} }
}; };
@ -1049,17 +1051,17 @@ public class GameConfigDelegate extends DelegateBase
} }
}; };
String lang = DictLangCache.getLangNameForISOCode( m_activity, m_gi.isoCode ); 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 langName )
{ {
String isoCode = DictLangCache.getLangIsoCode( m_activity, chosen ); ISOCode isoCode = DictLangCache.getLangIsoCode( m_activity, langName );
m_gi.setLang( m_activity, isoCode ); m_gi.setLang( m_activity, isoCode );
loadPlayersList(); loadPlayersList();
configDictSpinner( m_dictSpinner, m_gi.isoCode, m_gi.dictName ); configDictSpinner( m_dictSpinner, m_gi.isoCode(), m_gi.dictName );
} }
private void configSpinnerWDownload( Spinner spinner, private void configSpinnerWDownload( Spinner spinner,

View file

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

View file

@ -53,6 +53,7 @@ import org.eehouse.android.xw4.jni.UtilCtxtImpl;
import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.jni.XwJNI.GamePtr; import org.eehouse.android.xw4.jni.XwJNI.GamePtr;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -406,7 +407,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.isoCode ); 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 +599,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 String[] {nli.isoCode}, addr, new ISOCode[] {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(),
@ -613,7 +614,7 @@ public class GameUtils {
} }
public static long makeNewMultiGame( Context context, long groupID, public static long makeNewMultiGame( Context context, long groupID,
String dict, String isoCode, String dict, ISOCode isoCode,
String jsonData, String jsonData,
CommsConnTypeSet addrSet, CommsConnTypeSet addrSet,
String gameName ) String gameName )
@ -625,11 +626,11 @@ public class GameUtils {
private static long makeNewMultiGame( Context context, long groupID, private static long makeNewMultiGame( Context context, long groupID,
String inviteID, String dict, String inviteID, String dict,
String isoCode, String jsonData, ISOCode isoCode, String jsonData,
CommsConnTypeSet addrSet, CommsConnTypeSet addrSet,
String gameName ) String gameName )
{ {
String[] langArray = {isoCode}; ISOCode[] langArray = {isoCode};
String[] dictArray = {dict}; String[] dictArray = {dict};
if ( null == addrSet ) { if ( null == addrSet ) {
addrSet = XWPrefs.getAddrTypes( context ); addrSet = XWPrefs.getAddrTypes( context );
@ -654,7 +655,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,
String[] isoCode, String[] dict, ISOCode[] isoCode, String[] dict,
String jsonData, String jsonData,
int nPlayersT, int nPlayersH, int nPlayersT, int nPlayersH,
int forceChannel, String inviteID, int forceChannel, String inviteID,
@ -668,7 +669,7 @@ public class GameUtils {
gi.setFrom( jsonData ); gi.setFrom( jsonData );
gi.setLang( context, isoCode[0], dict[0] ); gi.setLang( context, isoCode[0], dict[0] );
gi.forceChannel = forceChannel; gi.forceChannel = forceChannel;
isoCode[0] = gi.isoCode; 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();
@ -830,14 +831,14 @@ public class GameUtils {
} }
public static String[] dictNames( Context context, long rowid, public static String[] dictNames( Context context, long rowid,
String[] missingLang ) ISOCode[] 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.isoCode; missingLang[0] = gi.isoCode();
} }
result = gi.dictNames(); result = gi.dictNames();
} }
@ -864,7 +865,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,
String[] missingLang ) ISOCode[] missingLang )
{ {
String[] gameDicts = dictNames( context, rowid, missingLang ); String[] gameDicts = dictNames( context, rowid, missingLang );
return null != gameDicts return null != gameDicts
@ -1235,7 +1236,7 @@ public class GameUtils {
} }
private static void postMoveDroppedForDictNotification( Context context, long rowid, private static void postMoveDroppedForDictNotification( Context context, long rowid,
int gameID, String isoCode ) int gameID, ISOCode isoCode )
{ {
Intent intent = GamesListDelegate.makeGameIDIntent( context, gameID ); Intent intent = GamesListDelegate.makeGameIDIntent( context, gameID );

View file

@ -50,6 +50,7 @@ import android.widget.TextView;
import com.jakewharton.processphoenix.ProcessPhoenix; import com.jakewharton.processphoenix.ProcessPhoenix;
import org.eehouse.android.xw4.DBUtils.GameChangeType; import org.eehouse.android.xw4.DBUtils.GameChangeType;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.DBUtils.GameGroupInfo; import org.eehouse.android.xw4.DBUtils.GameGroupInfo;
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo; import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.Action;
@ -576,7 +577,6 @@ public class GamesListDelegate extends ListDelegateBase
private String m_missingDict; private String m_missingDict;
private long m_missingDictRowId = ROWID_NOTFOUND; private long m_missingDictRowId = ROWID_NOTFOUND;
private int m_missingDictMenuId; private int m_missingDictMenuId;
private int m_missingDictLang;
private String m_nameField; private String m_nameField;
private NetLaunchInfo m_netLaunchInfo; private NetLaunchInfo m_netLaunchInfo;
private boolean m_menuPrepared; private boolean m_menuPrepared;
@ -608,7 +608,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 String missingDictLang = (String)params[2]; final ISOCode missingDictLang = (ISOCode)params[2];
lstnr = new OnClickListener() { lstnr = new OnClickListener() {
@Override @Override
@ -631,7 +631,7 @@ public class GamesListDelegate extends ListDelegateBase
String message; String message;
String langName = String langName =
DictLangCache.getLangNameForISOCode( m_activity, missingDictLang ); DictLangCache.getLangNameForISOCode( m_activity, missingDictLang );
String locLang = xlateLang( langName ); String locLang = 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 ) {
message = getString( R.string.no_dict_fmt, gameName, locLang ); message = getString( R.string.no_dict_fmt, gameName, locLang );
@ -675,7 +675,7 @@ 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 String isoCode = (String)params[2]; final ISOCode isoCode = (ISOCode)params[2];
final String[] sameLangDicts = final String[] sameLangDicts =
DictLangCache.getHaveLangCounts( m_activity, isoCode ); DictLangCache.getHaveLangCounts( m_activity, isoCode );
@ -1494,16 +1494,16 @@ public class GamesListDelegate extends ListDelegateBase
clearSelections(); clearSelections();
break; break;
case DWNLD_LOC_DICT: case DWNLD_LOC_DICT:
String lang = (String)params[0]; ISOCode isoCode = (ISOCode)params[0];
String name = (String)params[1]; String name = (String)params[1];
DownloadFinishedListener lstnr = new DownloadFinishedListener() { DownloadFinishedListener lstnr = new DownloadFinishedListener() {
@Override @Override
public void downloadFinished( String lang, String name, boolean success ) public void downloadFinished( ISOCode isoCode, String name, boolean success )
{ {
if ( success ) { if ( success ) {
XWPrefs.setPrefsString( m_activity, XWPrefs.setPrefsString( m_activity,
R.string.key_default_language, R.string.key_default_language,
lang ); isoCode.toString() );
name = DictUtils.removeDictExtn( name ); name = DictUtils.removeDictExtn( name );
int[] ids = { R.string.key_default_dict, int[] ids = { R.string.key_default_dict,
R.string.key_default_robodict }; R.string.key_default_robodict };
@ -1517,7 +1517,7 @@ public class GamesListDelegate extends ListDelegateBase
} }
} }
}; };
DwnldDelegate.downloadDictInBack( m_activity, lang, name, lstnr ); DwnldDelegate.downloadDictInBack( m_activity, isoCode, name, lstnr );
break; break;
case NEW_GAME_DFLT_NAME: case NEW_GAME_DFLT_NAME:
m_newGameParams = params; m_newGameParams = params;
@ -2056,7 +2056,7 @@ public class GamesListDelegate extends ListDelegateBase
// DwnldActivity.DownloadFinishedListener interface // DwnldActivity.DownloadFinishedListener interface
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@Override @Override
public void downloadFinished( String lang, String name, public void downloadFinished( ISOCode isoCode, String name,
final boolean success ) final boolean success )
{ {
runWhenActive( new Runnable() { runWhenActive( new Runnable() {
@ -2388,7 +2388,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][];
String[] missingLang = { "en" }; ISOCode[] missingLang = { Utils.ISO_EN };
boolean hasDicts; boolean hasDicts;
try { try {
hasDicts = GameUtils.gameDictsHere( m_activity, rowid, missingNames, hasDicts = GameUtils.gameDictsHere( m_activity, rowid, missingNames,
@ -2399,7 +2399,7 @@ public class GamesListDelegate extends ListDelegateBase
if ( !hasDicts ) { if ( !hasDicts ) {
String missingDictName = null; String missingDictName = null;
String missingDictLang = missingLang[0]; ISOCode missingDictLang = missingLang[0];
if ( 0 < missingNames[0].length ) { if ( 0 < missingNames[0].length ) {
missingDictName = missingNames[0][0]; missingDictName = missingNames[0][0];
} }
@ -2484,7 +2484,7 @@ public class GamesListDelegate extends ListDelegateBase
DwnldDelegate.DownloadFinishedListener dfl = DwnldDelegate.DownloadFinishedListener dfl =
new DwnldDelegate.DownloadFinishedListener() { new DwnldDelegate.DownloadFinishedListener() {
@Override @Override
public void downloadFinished( String ignore, public void downloadFinished( ISOCode ignore,
String name, String name,
boolean success ) { boolean success ) {
int resid = success ? R.string.byod_success int resid = success ? R.string.byod_success
@ -2687,7 +2687,7 @@ 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 );
String isoCode = extras.getString( REMATCH_LANG_EXTRA ); ISOCode isoCode = ISOCode.newIf( 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 );
@ -2748,32 +2748,32 @@ public class GamesListDelegate extends ListDelegateBase
false ) ) { false ) ) {
m_haveShownGetDict = true; m_haveShownGetDict = true;
String isoCode = LocUtils.getCurLangCode( m_activity ); ISOCode isoCode = LocUtils.getCurLangCode( m_activity );
if ( !isoCode.equals("en") ) { if ( !isoCode.equals("en") ) {
String[] names = DictLangCache.getHaveLang( m_activity, isoCode ); String[] names = DictLangCache.getHaveLang( m_activity, isoCode );
if ( 0 == names.length ) { if ( 0 == names.length ) {
OnGotLcDictListener lstnr = new OnGotLcDictListener() { OnGotLcDictListener lstnr = new OnGotLcDictListener() {
@Override @Override
public void gotDictInfo( boolean success, String lang, public void gotDictInfo( boolean success, ISOCode isoCode,
String name ) { String name ) {
stopProgress(); stopProgress();
if ( success ) { if ( success ) {
String langName = DictLangCache
.getLangNameForISOCode( m_activity, isoCode );
String msg = String msg =
getString( R.string.confirm_get_locdict_fmt, getString( R.string.confirm_get_locdict_fmt, langName );
xlateLang( lang ) );
makeConfirmThenBuilder( msg, Action.DWNLD_LOC_DICT ) makeConfirmThenBuilder( msg, Action.DWNLD_LOC_DICT )
.setPosButton( R.string.button_download ) .setPosButton( R.string.button_download )
.setNegButton( R.string.button_no ) .setNegButton( R.string.button_no )
.setNAKey( R.string.key_got_langdict ) .setNAKey( R.string.key_got_langdict )
.setParams( lang, name ) .setParams( isoCode, name )
.show(); .show();
} }
} }
}; };
String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode ); String locLang = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
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, isoCode, lstnr ); DictsDelegate.downloadDefaultDict( m_activity, isoCode, lstnr );
@ -3196,7 +3196,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.isoCode ) .putExtra( REMATCH_LANG_EXTRA, gi.isoCode().toString() )
.putExtra( REMATCH_PREFS_EXTRA, gi.getJSONData() ) .putExtra( REMATCH_PREFS_EXTRA, gi.getJSONData() )
.putExtra( REMATCH_NEWNAME_EXTRA, newName ); .putExtra( REMATCH_NEWNAME_EXTRA, newName );

View file

@ -27,6 +27,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
public class LangListPreference extends XWListPreference public class LangListPreference extends XWListPreference
implements Preference.OnPreferenceChangeListener { implements Preference.OnPreferenceChangeListener {
@ -41,12 +42,6 @@ public class LangListPreference extends XWListPreference
mKey = context.getString( R.string.key_default_language ); mKey = context.getString( R.string.key_default_language );
} }
@Override
public void setSummary( CharSequence summary )
{
super.setSummary( LocUtils.xlateLang( mContext, summary.toString(), true ) );
}
@Override @Override
public void onAttached() public void onAttached()
{ {
@ -80,24 +75,24 @@ public class LangListPreference extends XWListPreference
for ( int ii = 0; ii < langs.length; ++ii ) { for ( int ii = 0; ii < langs.length; ++ii ) {
String lang = langs[ii]; String lang = langs[ii];
haveDictForLang = haveDictForLang || lang.equals( curLang ); haveDictForLang = haveDictForLang || lang.equals( curLang );
langsLoc[ii] = LocUtils.xlateLang( mContext, lang, true ); langsLoc[ii] = lang;
} }
if ( !haveDictForLang ) { if ( !haveDictForLang ) {
curLang = DictLangCache.getLangNameForISOCode( mContext, "en" ); // English, unlocalized curLang = DictLangCache.getLangNameForISOCode( mContext, Utils.ISO_EN );
setValue( curLang ); setValue( curLang );
} }
forceDictsMatch( curLang ); forceDictsMatch( curLang );
setEntries( langsLoc ); setEntries( langsLoc );
setDefaultValue( LocUtils.xlateLang( mContext, curLang, true ) ); setDefaultValue( curLang );
setEntryValues( langs ); setEntryValues( langs );
} }
private void forceDictsMatch( String newLang ) private void forceDictsMatch( String newLang )
{ {
if ( null != newLang ) { if ( null != newLang ) {
String isoCode = DictLangCache.getLangIsoCode( mContext, newLang ); ISOCode 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 ) {

View file

@ -23,14 +23,14 @@ import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
public class LookupAlert extends XWDialogFragment { 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, String isoCode, boolean noStudy ) public static LookupAlert newInstance( String[] words, ISOCode isoCode, boolean noStudy )
{ {
LookupAlert result = new LookupAlert(); LookupAlert result = new LookupAlert();
Bundle bundle = LookupAlertView.makeParams( words, isoCode, noStudy ); Bundle bundle = LookupAlertView.makeParams( words, isoCode, noStudy );

View file

@ -38,6 +38,7 @@ import android.widget.TextView;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import java.util.ArrayList; import java.util.ArrayList;
@ -50,9 +51,9 @@ public class LookupAlertView extends LinearLayout
void onDone(); void onDone();
} }
public static final String WORDS = "WORDS"; private static final String WORDS = "WORDS";
public static final String LANG = "LANG"; private static final String LANG = "LANG";
public static final String STUDY_ON = "STUDY_ON"; private static final String STUDY_ON = "STUDY_ON";
private static final String STATE = "STATE"; private static final String STATE = "STATE";
private static final String WORDINDEX = "WORDINDEX"; private static final String WORDINDEX = "WORDINDEX";
private static final String URLINDEX = "URLINDEX"; private static final String URLINDEX = "URLINDEX";
@ -67,7 +68,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 String s_lang = null; private static ISOCode 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,7 +94,7 @@ public class LookupAlertView extends LinearLayout
{ {
m_onDone = lstn; m_onDone = lstn;
m_words = bundle.getStringArray( WORDS ); m_words = bundle.getStringArray( WORDS );
String isoCode = bundle.getString( LANG ); ISOCode isoCode = ISOCode.newIf( bundle.getString( LANG ) );
setLang( m_context, isoCode ); 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 );
@ -246,7 +247,7 @@ public class LookupAlertView extends LinearLayout
} }
} // lookupWord } // lookupWord
private void setLang( Context context, String isoCode ) private void setLang( Context context, ISOCode isoCode )
{ {
if ( ! isoCode.equals( s_lang ) ) { if ( ! isoCode.equals( s_lang ) ) {
String[] urls = context.getResources().getStringArray( R.array.lookup_urls ); String[] urls = context.getResources().getStringArray( R.array.lookup_urls );
@ -268,8 +269,7 @@ public class LookupAlertView extends LinearLayout
s_urlsAdapter = new ArrayAdapter<>( context, LIST_LAYOUT, s_urlsAdapter = new ArrayAdapter<>( context, LIST_LAYOUT,
s_lookupNames ); s_lookupNames );
s_lang = isoCode; s_lang = isoCode;
String langName = DictLangCache.getLangNameForISOCode( context, isoCode ); s_langName = DictLangCache.getLangNameForISOCode( context, isoCode );
s_langName = LocUtils.xlateLang( context, langName );
} }
} }
@ -298,15 +298,15 @@ public class LookupAlertView extends LinearLayout
return handled; return handled;
} }
private static void addParams( Bundle bundle, String[] words, String isoCode, private static void addParams( Bundle bundle, String[] words,
boolean studyOn ) ISOCode isoCode, boolean studyOn )
{ {
bundle.putStringArray( WORDS, words ); bundle.putStringArray( WORDS, words );
bundle.putString( LANG, isoCode ); bundle.putString( LANG, isoCode.toString() );
bundle.putBoolean( STUDY_ON, studyOn ); bundle.putBoolean( STUDY_ON, studyOn );
} }
protected static Bundle makeParams( String[] words, String isoCode, protected static Bundle makeParams( String[] words, ISOCode isoCode,
boolean noStudyOption ) boolean noStudyOption )
{ {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();

View file

@ -31,6 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.Set; import java.util.Set;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
public class MultiService { public class MultiService {
private static final String TAG = MultiService.class.getSimpleName(); private static final String TAG = MultiService.class.getSimpleName();
@ -130,7 +131,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( ISO, nli.isoCode ); intent.putExtra( ISO, nli.isoCode.toString() );
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() );
@ -168,14 +169,13 @@ public class MultiService {
OnClickListener onDecline ) OnClickListener onDecline )
{ {
int lang = intent.getIntExtra( LANG, -1 ); int lang = intent.getIntExtra( LANG, -1 );
String isoCode = intent.getStringExtra( ISO ); ISOCode isoCode = ISOCode.newIf( intent.getStringExtra( ISO ) );
String langStr = DictLangCache.getLangNameForISOCode( context, isoCode ); String langName = 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
: R.string.invite_dict_missing_body_fmt; : R.string.invite_dict_missing_body_fmt;
String msg = LocUtils.getString( context, msgID, inviter, dict, String msg = LocUtils.getString( context, msgID, inviter, dict, langName );
LocUtils.xlateLang( context, langStr));
return LocUtils.makeAlertBuilder( context ) return LocUtils.makeAlertBuilder( context )
.setTitle( R.string.invite_dict_missing_title ) .setTitle( R.string.invite_dict_missing_title )
@ -199,7 +199,7 @@ public class MultiService {
{ {
boolean downloaded = isMissingDictIntent( intent ); boolean downloaded = isMissingDictIntent( intent );
if ( downloaded ) { if ( downloaded ) {
String isoCode = intent.getStringExtra( ISO ); ISOCode isoCode = ISOCode.newIf( intent.getStringExtra( ISO ) );
String dict = intent.getStringExtra( DICT ); String dict = intent.getStringExtra( DICT );
downloaded = DictLangCache.haveDict( context, isoCode, dict ); downloaded = DictLangCache.haveDict( context, isoCode, dict );
if ( downloaded ) { if ( downloaded ) {

View file

@ -40,6 +40,7 @@ import java.util.List;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.CommsAddrRec;
@ -74,7 +75,7 @@ public class NetLaunchInfo implements Serializable {
protected String gameName; protected String gameName;
protected String dict; protected String dict;
protected String isoCode; // added in version 2 protected ISOCode isoCode; // added in version 2
protected int forceChannel; protected int forceChannel;
protected int nPlayersT; protected int nPlayersT;
protected int nPlayersH; protected int nPlayersH;
@ -110,11 +111,11 @@ public class NetLaunchInfo implements Serializable {
private NetLaunchInfo( Bundle bundle ) private NetLaunchInfo( Bundle bundle )
{ {
isoCode = bundle.getString( MultiService.ISO ); isoCode = ISOCode.newIf( bundle.getString( MultiService.ISO ) );
if ( null == isoCode ) { if ( null == isoCode ) {
int lang = bundle.getInt( MultiService.LANG, 0 ); int lang = bundle.getInt( MultiService.LANG, 0 );
if ( 0 != lang ) { if ( 0 != lang ) {
isoCode = XwJNI.lcToLocale( lang ); isoCode = XwJNI.lcToLocaleJ( lang );
} }
} }
Assert.assertTrueNR( null != isoCode ); Assert.assertTrueNR( null != isoCode );
@ -257,12 +258,12 @@ public class NetLaunchInfo implements Serializable {
removeUnsupported( supported ); removeUnsupported( supported );
dict = data.getQueryParameter( WORDLIST_KEY ); dict = data.getQueryParameter( WORDLIST_KEY );
isoCode = data.getQueryParameter( ISO_KEY ); isoCode = ISOCode.newIf( data.getQueryParameter( ISO_KEY ) );
if ( null == isoCode ) { if ( null == isoCode ) {
String langStr = data.getQueryParameter( LANG_KEY ); String langStr = data.getQueryParameter( LANG_KEY );
if ( null != langStr && !langStr.equals("0") ) { if ( null != langStr && !langStr.equals("0") ) {
int lang = Integer.decode( langStr ); int lang = Integer.decode( langStr );
isoCode = XwJNI.lcToLocale( lang ); isoCode = XwJNI.lcToLocaleJ( lang );
} }
} }
Assert.assertTrueNR( null != isoCode ); Assert.assertTrueNR( null != isoCode );
@ -288,7 +289,7 @@ public class NetLaunchInfo implements Serializable {
calcValid(); calcValid();
} }
private NetLaunchInfo( int gamID, String gamNam, String isoCodeIn, private NetLaunchInfo( int gamID, String gamNam, ISOCode isoCodeIn,
String dictName, int nPlayers, boolean dupMode ) String dictName, int nPlayers, boolean dupMode )
{ {
this(); this();
@ -312,7 +313,7 @@ public class NetLaunchInfo implements Serializable {
public NetLaunchInfo( CurGameInfo gi ) public NetLaunchInfo( CurGameInfo gi )
{ {
this( gi.gameID, gi.getName(), gi.isoCode, this( gi.gameID, gi.getName(), gi.isoCode(),
gi.dictName, gi.nPlayers, gi.inDuplicateMode ); gi.dictName, gi.nPlayers, gi.inDuplicateMode );
} }
@ -392,7 +393,7 @@ public class NetLaunchInfo implements Serializable {
if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) { if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) {
bundle.putInt( MultiService.LANG, lang[0] ); bundle.putInt( MultiService.LANG, lang[0] );
} else { } else {
bundle.putString( MultiService.ISO, isoCode ); bundle.putString( MultiService.ISO, isoCode.toString() );
} }
bundle.putString( MultiService.DICT, dict ); bundle.putString( MultiService.DICT, dict );
bundle.putString( MultiService.GAMENAME, gameName ); bundle.putString( MultiService.GAMENAME, gameName );
@ -423,7 +424,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 )
&& TextUtils.equals( isoCode, other.isoCode ) && ISOCode.safeEquals( isoCode, other.isoCode )
&& forceChannel == other.forceChannel && forceChannel == other.forceChannel
&& nPlayersT == other.nPlayersT && nPlayersT == other.nPlayersT
&& nPlayersH == other.nPlayersH && nPlayersH == other.nPlayersH
@ -547,11 +548,11 @@ public class NetLaunchInfo implements Serializable {
boolean hasAddrs = -1 != flags; boolean hasAddrs = -1 != flags;
_conTypes = hasAddrs ? flags : EMPTY_SET; _conTypes = hasAddrs ? flags : EMPTY_SET;
isoCode = json.optString( MultiService.ISO, null ); isoCode = ISOCode.newIf( json.optString( MultiService.ISO, null ) );
if ( null == isoCode ) { if ( null == isoCode ) {
int lang = json.optInt( MultiService.LANG, 0 ); int lang = json.optInt( MultiService.LANG, 0 );
if ( 0 != lang ) { if ( 0 != lang ) {
isoCode = XwJNI.lcToLocale( lang ); isoCode = XwJNI.lcToLocaleJ( lang );
} }
} }
Assert.assertTrueNR( null != isoCode ); Assert.assertTrueNR( null != isoCode );
@ -636,7 +637,7 @@ public class NetLaunchInfo implements Serializable {
if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) { if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) {
appendInt( ub, LANG_KEY, lang[0] ); appendInt( ub, LANG_KEY, lang[0] );
} else { } else {
ub.appendQueryParameter( ISO_KEY, isoCode ); ub.appendQueryParameter( ISO_KEY, isoCode.toString() );
} }
appendInt( ub, TOTPLAYERS_KEY, nPlayersT ); appendInt( ub, TOTPLAYERS_KEY, nPlayersT );
appendInt( ub, HEREPLAYERS_KEY, nPlayersH ); appendInt( ub, HEREPLAYERS_KEY, nPlayersH );

View file

@ -38,6 +38,7 @@ import android.widget.Spinner;
import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.jni.GameSummary; import org.eehouse.android.xw4.jni.GameSummary;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
@ -58,7 +59,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 String[] m_langCodes; private ISOCode[] 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;
@ -181,7 +182,7 @@ public class StudyListDelegate extends ListDelegateBase
// DBUtils.StudyListListener // DBUtils.StudyListListener
////////////////////////////////////////////////// //////////////////////////////////////////////////
@Override @Override
public void onWordAdded( String word, String isoCode ) public void onWordAdded( String word, ISOCode isoCode )
{ {
if ( isoCode.equals( m_langCodes[m_langPosition] ) ) { if ( isoCode.equals( m_langCodes[m_langPosition] ) ) {
loadList(); loadList();
@ -293,14 +294,14 @@ public class StudyListDelegate extends ListDelegateBase
private void loadList() private void loadList()
{ {
String isoCode = m_langCodes[m_langPosition]; ISOCode isoCode = m_langCodes[m_langPosition];
m_words = DBUtils.studyListWords( m_activity, isoCode ); m_words = DBUtils.studyListWords( m_activity, isoCode );
makeAdapter(); makeAdapter();
String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode ); 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 ) ); langName );
setTitleBar(); setTitleBar();
} }
@ -328,9 +329,8 @@ public class StudyListDelegate extends ListDelegateBase
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 ) {
String isoCode = m_langCodes[ii]; ISOCode isoCode = m_langCodes[ii];
String name = DictLangCache.getLangNameForISOCode( m_activity, isoCode ); myNames[ii] = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
myNames[ii] = xlateLang( name, true );
if ( isoCode.equals( startLang ) ) { if ( isoCode.equals( startLang ) ) {
startIndex = ii; startIndex = ii;
} }
@ -388,7 +388,7 @@ public class StudyListDelegate extends ListDelegateBase
launchOrAlert( delegator, null, dlg ); launchOrAlert( delegator, null, dlg );
} }
public static void launchOrAlert( Delegator delegator, String isoCode, public static void launchOrAlert( Delegator delegator, ISOCode isoCode,
DlgDelegate.HasDlgDelegate dlg ) DlgDelegate.HasDlgDelegate dlg )
{ {
String msg = null; String msg = null;
@ -403,7 +403,7 @@ public class StudyListDelegate extends ListDelegateBase
} else { } else {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
if ( null != isoCode ) { if ( null != isoCode ) {
bundle.putString( START_LANG, isoCode ); bundle.putString( START_LANG, isoCode.toString() );
} }
delegator.addFragment( StudyListFrag.newInstance( delegator ), delegator.addFragment( StudyListFrag.newInstance( delegator ),

View file

@ -37,6 +37,7 @@ import javax.net.ssl.HttpsURLConnection;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
@ -214,7 +215,7 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
int index ) int index )
{ {
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
String isoCode = DictLangCache.getDictISOCode( context, dal ); ISOCode isoCode = DictLangCache.getDictISOCode( context, dal );
String langStr = DictLangCache.getLangNameForISOCode( context, isoCode ); String langStr = DictLangCache.getLangNameForISOCode( context, isoCode );
String[] sums = DictLangCache.getDictMD5Sums( context, dal.name ); String[] sums = DictLangCache.getDictMD5Sums( context, dal.name );
Assert.assertTrueNR( null != sums[1] ); Assert.assertTrueNR( null != sums[1] );

View file

@ -45,6 +45,7 @@ import android.os.Looper;
import android.provider.ContactsContract.PhoneLookup; import android.provider.ContactsContract.PhoneLookup;
import android.telephony.PhoneNumberUtils; import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Base64; import android.util.Base64;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -639,16 +640,16 @@ public class Utils {
public static Uri makeDictUriFromName( Context context, public static Uri makeDictUriFromName( Context context,
String langName, String dictName ) String langName, String dictName )
{ {
String isoCode = DictLangCache.getLangIsoCode( context, langName ); ISOCode isoCode = DictLangCache.getLangIsoCode( context, langName );
return makeDictUriFromCode( context, isoCode, dictName ); return makeDictUriFromCode( context, isoCode, dictName );
} }
public static Uri makeDictUriFromCode( Context context, String isoCode, String name ) public static Uri makeDictUriFromCode( Context context, ISOCode 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 != isoCode ) { if ( null != isoCode ) {
builder.appendPath( isoCode ); builder.appendPath( isoCode.toString() );
} }
if ( null != name ) { if ( null != name ) {
Assert.assertNotNull( isoCode ); Assert.assertNotNull( isoCode );
@ -889,4 +890,55 @@ public class Utils {
@Override @Override
public void onNothingSelected(AdapterView<?> parentView) {} public void onNothingSelected(AdapterView<?> parentView) {}
} }
// Let's get some type safety between language name and iso code.
public static class ISOCode implements Serializable {
final String mISOCode;
public ISOCode( String code )
{
// Log.d( TAG, "ISOCode(%s)", code );
Assert.assertTrueNR( 0 < code.length() );
Assert.assertTrueNR( 8 > code.length() );
mISOCode = code;
}
public static ISOCode newIf( String code )
{
ISOCode result = null;
if ( !TextUtils.isEmpty( code ) ) {
result = new ISOCode( code );
}
// Log.d( TAG, "newIf(%s) => %s", code, result );
return result;
}
public static boolean safeEquals( ISOCode ic1, ISOCode ic2 )
{
boolean result;
if ( ic1 == ic2 ) {
result = true;
} else if ( null == ic1 || null == ic2 ) {
result = false;
} else {
result = TextUtils.equals( ic1.mISOCode, ic2.mISOCode );
}
return result;
}
@Override
public String toString() { return mISOCode; }
@Override
public boolean equals( Object other )
{
return null != other
&& other instanceof ISOCode
&& ((ISOCode)other).mISOCode.equals(mISOCode);
}
@Override
public int hashCode() { return mISOCode.hashCode(); }
}
public static final ISOCode ISO_EN = new ISOCode( "en" );
} }

View file

@ -29,13 +29,13 @@ import java.util.HashSet;
import java.util.Random; import java.util.Random;
import org.json.JSONObject; import org.json.JSONObject;
import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.Assert;
import org.eehouse.android.xw4.BuildConfig; import org.eehouse.android.xw4.BuildConfig;
import org.eehouse.android.xw4.DictLangCache; import org.eehouse.android.xw4.DictLangCache;
import org.eehouse.android.xw4.DictUtils; import org.eehouse.android.xw4.DictUtils;
import org.eehouse.android.xw4.Log; import org.eehouse.android.xw4.Log;
import org.eehouse.android.xw4.R; import org.eehouse.android.xw4.R;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.Utils; import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.XWApp; import org.eehouse.android.xw4.XWApp;
import org.eehouse.android.xw4.XWPrefs; import org.eehouse.android.xw4.XWPrefs;
@ -60,7 +60,7 @@ public class CurGameInfo implements Serializable {
public String dictName; public String dictName;
public LocalPlayer[] players; public LocalPlayer[] players;
public String isoCode; public String isoCodeStr; // public only for access from JNI; use isoCode() from java
public int gameID; public int gameID;
public int gameSeconds; public int gameSeconds;
public int nPlayers; public int nPlayers;
@ -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;
isoCode = src.isoCode; isoCodeStr = src.isoCodeStr;
hintsNotAllowed = src.hintsNotAllowed; hintsNotAllowed = src.hintsNotAllowed;
inDuplicateMode = src.inDuplicateMode; inDuplicateMode = src.inDuplicateMode;
phoniesAction = src.phoniesAction; phoniesAction = src.phoniesAction;
@ -169,6 +169,11 @@ public class CurGameInfo implements Serializable {
Utils.testSerialization( this ); Utils.testSerialization( this );
} }
public ISOCode isoCode()
{
return ISOCode.newIf( isoCodeStr );
}
@Override @Override
public String toString() public String toString()
{ {
@ -246,7 +251,7 @@ public class CurGameInfo implements Serializable {
} }
} }
public void setLang( Context context, String isoCode, String dict ) public void setLang( Context context, ISOCode isoCode, String dict )
{ {
if ( null != dict ) { if ( null != dict ) {
dictName = dict; dictName = dict;
@ -254,7 +259,7 @@ public class CurGameInfo implements Serializable {
setLang( context, isoCode ); setLang( context, isoCode );
} }
public void setLang( Context context, String isoCodeNew ) public void setLang( Context context, ISOCode isoCodeNew )
{ {
if ( null == isoCodeNew ) { if ( null == isoCodeNew ) {
String dictName = CommonPrefs.getDefaultHumanDict( context ); String dictName = CommonPrefs.getDefaultHumanDict( context );
@ -262,8 +267,8 @@ public class CurGameInfo implements Serializable {
} }
Assert.assertTrueNR( null != isoCodeNew ); Assert.assertTrueNR( null != isoCodeNew );
if ( ! TextUtils.equals( isoCodeNew, this.isoCode ) ) { if ( ! TextUtils.equals( isoCodeNew.toString(), this.isoCodeStr ) ) {
isoCode = isoCodeNew; isoCodeStr = isoCodeNew.toString();
assignDicts( context ); assignDicts( context );
} }
} }
@ -301,7 +306,7 @@ public class CurGameInfo implements Serializable {
{ {
boolean matter = nPlayers != other.nPlayers boolean matter = nPlayers != other.nPlayers
|| serverRole != other.serverRole || serverRole != other.serverRole
|| ! TextUtils.equals(isoCode, other.isoCode) || ! TextUtils.equals(isoCodeStr, other.isoCodeStr)
|| boardSize != other.boardSize || boardSize != other.boardSize
|| traySize != other.traySize || traySize != other.traySize
|| bingoMin != other.bingoMin || bingoMin != other.bingoMin
@ -333,7 +338,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 = TextUtils.equals( isoCode, other.isoCode) result = TextUtils.equals( isoCodeStr, other.isoCodeStr)
&& gameID == other.gameID && gameID == other.gameID
&& gameSeconds == other.gameSeconds && gameSeconds == other.gameSeconds
&& nPlayers == other.nPlayers && nPlayers == other.nPlayers
@ -444,7 +449,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, isoCode ); 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 ) ) {
@ -463,7 +468,7 @@ public class CurGameInfo implements Serializable {
public String langName( Context context ) public String langName( Context context )
{ {
return DictLangCache.getLangNameForISOCode( context, isoCode ); return DictLangCache.getLangNameForISOCode( context, isoCode() );
} }
public String dictName( final LocalPlayer lp ) public String dictName( final LocalPlayer lp )
@ -588,14 +593,13 @@ public class CurGameInfo implements Serializable {
// right language. // right language.
String humanDict = String humanDict =
DictLangCache.getBestDefault( context, isoCode, true ); DictLangCache.getBestDefault( context, isoCode(), true );
String robotDict = String robotDict =
DictLangCache.getBestDefault( context, isoCode, false ); DictLangCache.getBestDefault( context, isoCode(), false );
if ( null == dictName if ( null == dictName
|| ! DictUtils.dictExists( context, dictName ) || ! DictUtils.dictExists( context, dictName )
|| ! isoCode.equals( DictLangCache.getDictISOCode( context, || ! DictLangCache.getDictISOCode( context, dictName ).equals( isoCode() ) ) {
dictName ) ) ) {
dictName = humanDict; dictName = humanDict;
} }
@ -603,8 +607,8 @@ public class CurGameInfo implements Serializable {
LocalPlayer lp = players[ii]; LocalPlayer lp = players[ii];
if ( null != lp.dictName && if ( null != lp.dictName &&
!isoCode.equals( DictLangCache.getDictISOCode( context, !ISOCode.safeEquals( DictLangCache.getDictISOCode(context, lp.dictName),
lp.dictName ) ) ) { isoCode() ) ) {
lp.dictName = null; lp.dictName = null;
} }

View file

@ -295,9 +295,9 @@ public class DUtilCtxt {
return msg; return msg;
} }
public void getDictPath( String isoCode, String name, String[] path, byte[][] bytes ) public void getDictPath( String name, String[] path, byte[][] bytes )
{ {
// Log.d( TAG, "getDictPath(%s, %s)", isoCode, name ); Log.d( TAG, "getDictPath(name='%s')", 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

@ -20,7 +20,9 @@
package org.eehouse.android.xw4.jni; package org.eehouse.android.xw4.jni;
import org.eehouse.android.xw4.Assert;
import org.eehouse.android.xw4.BuildConfig; import org.eehouse.android.xw4.BuildConfig;
import org.eehouse.android.xw4.Utils.ISOCode;
public class DictInfo { public class DictInfo {
// set in java code // set in java code
@ -29,17 +31,22 @@ public class DictInfo {
// set in jni code // set in jni code
public int wordCount; public int wordCount;
public String isoCode; public String isoCodeStr; // public only for access from JNI; use isoCode() from java
public String langName; public String langName;
public String md5Sum; // internal (skipping header?) public String md5Sum; // internal (skipping header?)
public ISOCode isoCode()
{
return ISOCode.newIf( isoCodeStr );
}
@Override @Override
public String toString() public String toString()
{ {
if ( BuildConfig.NON_RELEASE ) { if ( BuildConfig.NON_RELEASE ) {
return new StringBuilder("{") return new StringBuilder("{")
.append("name: ").append(name) .append("name: ").append(name)
.append(", isoCode: ").append(isoCode) .append(", isoCode: ").append(isoCodeStr)
.append(", langName: ").append(langName) .append(", langName: ").append(langName)
.append(", md5Sum: ").append(md5Sum) .append(", md5Sum: ").append(md5Sum)
.append(", fullSum: ").append(fullSum) .append(", fullSum: ").append(fullSum)

View file

@ -33,12 +33,13 @@ import org.eehouse.android.xw4.BuildConfig;
import org.eehouse.android.xw4.DBUtils; import org.eehouse.android.xw4.DBUtils;
import org.eehouse.android.xw4.Log; import org.eehouse.android.xw4.Log;
import org.eehouse.android.xw4.R; import org.eehouse.android.xw4.R;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.Utils; import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.XWApp; import org.eehouse.android.xw4.XWApp;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
import org.eehouse.android.xw4.jni.CurGameInfo;
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole; import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
import org.eehouse.android.xw4.jni.CurGameInfo;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
/** Info we want to access when the game's closed that's not available /** Info we want to access when the game's closed that's not available
@ -81,7 +82,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 String isoCode; public ISOCode isoCode;
public DeviceRole serverRole; public DeviceRole serverRole;
public int nPacketsPending; public int nPacketsPending;
@ -96,7 +97,7 @@ public class GameSummary implements Serializable {
public GameSummary( CurGameInfo gi ) public GameSummary( CurGameInfo gi )
{ {
nPlayers = gi.nPlayers; nPlayers = gi.nPlayers;
isoCode = gi.isoCode; isoCode = gi.isoCode();
serverRole = gi.serverRole; serverRole = gi.serverRole;
gameID = gi.gameID; gameID = gi.gameID;
m_gi = gi; m_gi = gi;
@ -127,7 +128,7 @@ public class GameSummary implements Serializable {
&& modtime == other.modtime && modtime == other.modtime
&& created == other.created && created == other.created
&& gameID == other.gameID && gameID == other.gameID
&& TextUtils.equals( isoCode, other.isoCode) && ISOCode.safeEquals( 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

@ -20,6 +20,7 @@
package org.eehouse.android.xw4.jni; package org.eehouse.android.xw4.jni;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
public interface UtilCtxt { public interface UtilCtxt {
@ -104,7 +105,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( String isoCode, String oldName, String newName, void informNetDict( ISOCode 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

@ -34,6 +34,7 @@ import java.util.Iterator;
import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.Assert;
import org.eehouse.android.xw4.Log; import org.eehouse.android.xw4.Log;
import org.eehouse.android.xw4.NetUtils; import org.eehouse.android.xw4.NetUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
import org.eehouse.android.xw4.jni.JNIThread.JNICmd; import org.eehouse.android.xw4.jni.JNIThread.JNICmd;
@ -217,7 +218,7 @@ public class UtilCtxtImpl implements UtilCtxt {
} }
@Override @Override
public void informNetDict( String isoCode, String oldName, public void informNetDict( ISOCode isoCode, String oldName,
String newName, String newSum, String newName, String newSum,
CurGameInfo.XWPhoniesChoice phonies ) CurGameInfo.XWPhoniesChoice phonies )
{ {

View file

@ -30,6 +30,7 @@ import org.eehouse.android.xw4.BuildConfig;
import org.eehouse.android.xw4.Log; import org.eehouse.android.xw4.Log;
import org.eehouse.android.xw4.NetLaunchInfo; import org.eehouse.android.xw4.NetLaunchInfo;
import org.eehouse.android.xw4.Quarantine; import org.eehouse.android.xw4.Quarantine;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.Utils; import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
@ -275,10 +276,21 @@ public class XwJNI {
return nli_from_stream( getJNI().m_ptrGlobals, stream ); return nli_from_stream( getJNI().m_ptrGlobals, stream );
} }
public static ISOCode lcToLocaleJ( int lc )
{
String code = lcToLocale( lc );
return ISOCode.newIf( code );
}
public static boolean haveLocaleToLc( ISOCode isoCode, int[] lc )
{
return haveLocaleToLc( isoCode.toString(), lc );
}
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 ); private static native String lcToLocale( int lc );
public static native boolean haveLocaleToLc( String isoCode, int[] lc ); private 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

@ -31,6 +31,7 @@ import android.view.View;
import org.eehouse.android.xw4.Assert; import org.eehouse.android.xw4.Assert;
import org.eehouse.android.xw4.BuildConfig; import org.eehouse.android.xw4.BuildConfig;
import org.eehouse.android.xw4.R; import org.eehouse.android.xw4.R;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.Utils; import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.XWApp; import org.eehouse.android.xw4.XWApp;
import org.eehouse.android.xw4.XWPrefs; import org.eehouse.android.xw4.XWPrefs;
@ -43,7 +44,7 @@ import java.util.Map;
public class LocUtils { public class LocUtils {
protected static final String RES_FORMAT = "%[\\d]\\$[ds]"; protected static final String RES_FORMAT = "%[\\d]\\$[ds]";
private static String s_curLocale; private static String s_curLocale;
private static String s_curLang; private static ISOCode s_curLang;
private static Map<String, String> s_langMap = null; private static Map<String, String> s_langMap = null;
public static View inflate( Context context, int resID ) public static View inflate( Context context, int resID )
@ -56,44 +57,6 @@ public class LocUtils {
{ {
} }
public static String xlateLang( Context context, String lang )
{
return xlateLang( context, lang, false );
}
public static String xlateLang( Context context, String lang, boolean caps )
{
if ( null == s_langMap ) {
s_langMap = new HashMap<>();
s_langMap.put( "English", context.getString( R.string.lang_name_english ) );
s_langMap.put( "French", context.getString( R.string.lang_name_french ) );
s_langMap.put( "German", context.getString( R.string.lang_name_german ) );
s_langMap.put( "Turkish", context.getString( R.string.lang_name_turkish ) );
s_langMap.put( "Arabic", context.getString( R.string.lang_name_arabic ) );
s_langMap.put( "Spanish", context.getString( R.string.lang_name_spanish ) );
s_langMap.put( "Swedish", context.getString( R.string.lang_name_swedish ) );
s_langMap.put( "Polish", context.getString( R.string.lang_name_polish ) );
s_langMap.put( "Danish", context.getString( R.string.lang_name_danish ) );
s_langMap.put( "Italian", context.getString( R.string.lang_name_italian ) );
s_langMap.put( "Dutch", context.getString( R.string.lang_name_dutch ) );
s_langMap.put( "Catalan", context.getString( R.string.lang_name_catalan ) );
s_langMap.put( "Portuguese", context.getString( R.string.lang_name_portuguese ) );
s_langMap.put( "Russian", context.getString( R.string.lang_name_russian ) );
s_langMap.put( "Czech", context.getString( R.string.lang_name_czech ) );
s_langMap.put( "Greek", context.getString( R.string.lang_name_greek ) );
s_langMap.put( "Slovak", context.getString( R.string.lang_name_slovak ) );
}
String xlated = s_langMap.get( lang );
if ( null == xlated ) {
xlated = lang;
}
if ( caps ) {
xlated = Utils.capitalize( xlated );
}
return xlated;
}
public static void xlateView( Activity activity ) public static void xlateView( Activity activity )
{ {
} }
@ -193,7 +156,7 @@ public class LocUtils {
return name; return name;
} }
public static String getCurLangCode( Context context ) public static ISOCode getCurLangCode( Context context )
{ {
if ( null == s_curLang ) { if ( null == s_curLang ) {
String lang = Locale.getDefault().getLanguage(); String lang = Locale.getDefault().getLanguage();
@ -203,7 +166,7 @@ public class LocUtils {
lang = TextUtils.split(lang, "-")[0]; lang = TextUtils.split(lang, "-")[0];
} }
Assert.assertTrueNR( 2 == lang.length() ); Assert.assertTrueNR( 2 == lang.length() );
s_curLang = lang; s_curLang = new ISOCode( lang );
} }
return s_curLang; return s_curLang;
} }

View file

@ -270,7 +270,8 @@ and_util_informNetDict( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR* isoCode,
const DictionaryCtxt* const DictionaryCtxt*
and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe, and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
const XP_UCHAR* isoCode, const XP_UCHAR* dictName ) const XP_UCHAR* XP_UNUSED_DBG(isoCode),
const XP_UCHAR* dictName )
{ {
XP_LOGFF( "(isoCode: %s, name: %s)", isoCode, dictName ); XP_LOGFF( "(isoCode: %s, name: %s)", isoCode, dictName );
JNIEnv* env = xwe; JNIEnv* env = xwe;
@ -281,14 +282,13 @@ 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", DUTIL_CBK_HEADER( "getDictPath",
"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[[B)V" ); "(Ljava/lang/String;[Ljava/lang/String;[[B)V" );
(*env)->CallVoidMethod( env, dutil->jdutil, mid, jISOCode, jname, jstrs, jbytes ); (*env)->CallVoidMethod( env, dutil->jdutil, mid, jname, jstrs, jbytes );
DUTIL_CBK_TAIL(); DUTIL_CBK_TAIL();
jstring jpath = (*env)->GetObjectArrayElement( env, jstrs, 0 ); jstring jpath = (*env)->GetObjectArrayElement( env, jstrs, 0 );
@ -298,9 +298,8 @@ 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, jISOCode, DELETE_NO_REF ); deleteLocalRefs( env, jname, jstrs, jbytes, jdata, jpath, DELETE_NO_REF );
} }
LOG_RETURNF( "%p", dict );
return dict; return dict;
} }

View file

@ -468,7 +468,7 @@ 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) ); getString( env, jgi, "isoCodeStr", AANDS(buf) );
XP_STRNCPY( gi->isoCode, buf, VSIZE(gi->isoCode) ); XP_STRNCPY( gi->isoCode, buf, VSIZE(gi->isoCode) );
XP_ASSERT( gi->nPlayers <= MAX_NUM_PLAYERS ); XP_ASSERT( gi->nPlayers <= MAX_NUM_PLAYERS );
@ -508,7 +508,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 ); setString( env, jgi, "isoCodeStr", gi->isoCode );
intToJenumField( env, jgi, gi->phoniesAction, "phoniesAction", intToJenumField( env, jgi, gi->phoniesAction, "phoniesAction",
PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") ); PKG_PATH("jni/CurGameInfo$XWPhoniesChoice") );
@ -1163,7 +1163,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getInfo
jinfo = makeObjectEmptyConst( env, PKG_PATH("jni/DictInfo") ); jinfo = makeObjectEmptyConst( env, PKG_PATH("jni/DictInfo") );
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, "isoCodeStr", dict_getISOCode( dict ) );
setString( env, jinfo, "langName", dict_getLangName( dict ) ); setString( env, jinfo, "langName", dict_getLangName( dict ) );
} }