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.TilePickAlert.TilePickState;
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.jni.CommonPrefs.TileValueType;
import org.eehouse.android.xw4.jni.CommonPrefs;
@ -254,7 +255,7 @@ public class BoardDelegate extends DelegateBase
setGotGameDict( m_mySIS.getDict );
} else {
DwnldDelegate
.downloadDictInBack( m_activity, m_gi.isoCode,
.downloadDictInBack( m_activity, m_gi.isoCode(),
m_mySIS.getDict,
BoardDelegate.this );
}
@ -925,7 +926,7 @@ public class BoardDelegate extends DelegateBase
cmd = JNICmd.CMD_TOGGLE_TRAY;
break;
case R.id.board_menu_study:
StudyListDelegate.launchOrAlert( getDelegator(), m_gi.isoCode, this );
StudyListDelegate.launchOrAlert( getDelegator(), m_gi.isoCode(), this );
break;
case R.id.board_menu_game_netstats:
handleViaThread( JNICmd.CMD_NETSTATS, R.string.netstats_title );
@ -1021,13 +1022,13 @@ public class BoardDelegate extends DelegateBase
case BUTTON_BROWSE_ACTION:
String curDict = m_gi.dictName( m_view.getCurPlayer() );
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 &&
DictsDelegate.handleDictsPopup( getDelegator(), button,
curDict, m_gi.isoCode ) ) {
curDict, m_gi.isoCode() ) ) {
// do nothing
} else {
String selDict = DictsDelegate.prevSelFor( m_activity, m_gi.isoCode );
String selDict = DictsDelegate.prevSelFor( m_activity, m_gi.isoCode() );
if ( null == selDict ) {
selDict = curDict;
}
@ -1060,7 +1061,7 @@ public class BoardDelegate extends DelegateBase
cmd = JNICmd.CMD_TRADE;
break;
case LOOKUP_ACTION:
launchLookup( m_mySIS.words, m_gi.isoCode );
launchLookup( m_mySIS.words, m_gi.isoCode() );
break;
case DROP_MQTT_ACTION:
dropConViaAndRestart( CommsConnType.COMMS_CONN_MQTT );
@ -1432,7 +1433,7 @@ public class BoardDelegate extends DelegateBase
// DwnldActivity.DownloadFinishedListener interface
//////////////////////////////////////////////////
@Override
public void downloadFinished( String lang, final String name,
public void downloadFinished( ISOCode isoCode, final String name,
boolean success )
{
if ( success ) {
@ -1762,7 +1763,7 @@ public class BoardDelegate extends DelegateBase
post( new Runnable() {
@Override
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
public void informNetDict( String isoCode, String oldName,
public void informNetDict( ISOCode isoCode, String oldName,
String newName, String newSum,
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.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import java.util.ArrayList;
import java.util.Arrays;
@ -391,13 +392,13 @@ public class DBHelper extends SQLiteOpenHelper {
String groupBy = columns[0];
// First gather all the lang codes
Map<Integer, String> map = new HashMap<>();
Map<Integer, ISOCode> map = new HashMap<>();
Cursor cursor = db.query( table.toString(),
columns, null, null, groupBy, null, null );
int colIndex = cursor.getColumnIndex( columns[0] );
while ( cursor.moveToNext() ) {
int code = cursor.getInt( colIndex );
String isoCode = XwJNI.lcToLocale( code );
ISOCode isoCode = XwJNI.lcToLocaleJ( code );
map.put( 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.DictUtils.DictLoc;
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.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;
import org.eehouse.android.xw4.jni.DictInfo;
import org.eehouse.android.xw4.jni.GameSummary;
import org.eehouse.android.xw4.jni.XwJNI;
@ -99,7 +100,7 @@ public class DBUtils {
new HashSet<>();
public static interface StudyListListener {
void onWordAdded( String word, String isoCode );
void onWordAdded( String word, ISOCode isoCode );
}
private static Set<StudyListListener> s_slListeners
= new HashSet<>();
@ -176,8 +177,8 @@ public class DBUtils {
summary.readPlayers( context, players );
// isoCode will be null when game first created
summary.isoCode = cursor
.getString(cursor.getColumnIndex(DBHelper.ISOCODE));
summary.isoCode =
ISOCode.newIf( cursor.getString(cursor.getColumnIndex(DBHelper.ISOCODE)) );
summary.modtime =
cursor.getLong(cursor.
@ -296,7 +297,7 @@ public class DBUtils {
values.put( DBHelper.PLAYERS,
summary.summarizePlayers() );
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.GAME_OVER, summary.gameOver? 1 : 0 );
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;
String[] columns = { DBHelper.ISOCODE };
@ -1912,8 +1913,8 @@ public class DBUtils {
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
result = new DictInfo();
result.name = name;
result.isoCode =
cursor.getString( cursor.getColumnIndex(DBHelper.ISOCODE));
result.isoCodeStr
= cursor.getString( cursor.getColumnIndex(DBHelper.ISOCODE));
result.wordCount =
cursor.getInt( cursor.getColumnIndex(DBHelper.WORDCOUNT));
result.md5Sum =
@ -1930,25 +1931,25 @@ public class DBUtils {
}
if ( null != result ) {
Assert.assertTrueNR( !TextUtils.isEmpty(result.isoCode ) );
if ( null == result.fullSum ) { // force generation
result = null;
}
}
Log.d( TAG, "dictsGetInfo(%s) => %s", name, result );
return result;
}
public static void dictsSetInfo( Context context, DictUtils.DictAndLoc dal,
DictInfo info )
{
Assert.assertTrueNR( ! TextUtils.isEmpty( info.isoCode ) );
Assert.assertTrueNR( null != info.isoCode() );
String selection =
String.format( NAME_FMT, DBHelper.DICTNAME, dal.name );
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.WORDCOUNT, info.wordCount );
values.put( DBHelper.MD5SUM, info.md5Sum );
@ -1997,11 +1998,11 @@ public class DBUtils {
}
public static void addToStudyList( Context context, String word,
String isoCode )
ISOCode isoCode )
{
ContentValues values = new ContentValues();
values.put( DBHelper.WORD, word );
values.put( DBHelper.ISOCODE, isoCode );
values.put( DBHelper.ISOCODE, isoCode.toString() );
initDB( context );
synchronized( s_dbHelper ) {
@ -2010,9 +2011,9 @@ public class DBUtils {
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 groupBy = columns[0];
@ -2021,12 +2022,12 @@ public class DBUtils {
Cursor cursor = s_db.query( TABLE_NAMES.STUDYLIST.toString(), columns,
null, null, groupBy, null, null );
int count = cursor.getCount();
result = new String[count];
result = new ISOCode[count];
if ( 0 < count ) {
int index = 0;
int colIndex = cursor.getColumnIndex( columns[0] );
while ( cursor.moveToNext() ) {
result[index++] = cursor.getString(colIndex);
result[index++] = new ISOCode(cursor.getString(colIndex));
}
}
cursor.close();
@ -2034,7 +2035,7 @@ public class DBUtils {
return result;
}
public static String[] studyListWords( Context context, String isoCode )
public static String[] studyListWords( Context context, ISOCode isoCode )
{
String[] result = null;
String selection = String.format( "%s = '%s'", DBHelper.ISOCODE, isoCode );
@ -2059,7 +2060,7 @@ public class DBUtils {
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 );
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 );
}
@ -2554,7 +2555,7 @@ public class DBUtils {
return result;
}
private static void notifyStudyListListeners( String word, String isoCode )
private static void notifyStudyListListeners( String word, ISOCode isoCode )
{
synchronized( 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;
import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
@ -331,16 +332,6 @@ public abstract class DelegateBase implements DlgClickNotify,
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,
Object... params )
{
@ -593,12 +584,12 @@ public abstract class DelegateBase implements DlgClickNotify,
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 );
}
protected void launchLookup( String[] words, String isoCode )
protected void launchLookup( String[] words, ISOCode isoCode )
{
boolean studyOn = XWPrefs.getStudyEnabled( m_activity );
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;
import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import java.util.Arrays;
import java.io.Serializable;
@ -127,7 +128,7 @@ public class DictBrowseDelegate extends DelegateBase
}
private Activity m_activity;
private String m_lang;
private ISOCode m_lang;
private String m_name;
private String mAboutStr;
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.XwJNI;
import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import java.io.File;
import java.util.ArrayList;
@ -47,10 +48,10 @@ import java.util.Set;
public class DictLangCache {
private static final String TAG = DictLangCache.class.getSimpleName();
private static Map<String, String> s_langNames;
private static Map<String, String> s_langCodes;
private static Map<ISOCode, String> s_langNames;
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 ArrayAdapter<String> s_dictsAdapter;
private static String s_last;
@ -58,7 +59,6 @@ public class DictLangCache {
public static class LangsArrayAdapter extends ArrayAdapter<String> {
private Context m_context;
private Map<String, String> m_map;
public LangsArrayAdapter( Context context, int itemLayout ) {
super( context, itemLayout );
@ -67,25 +67,20 @@ public class DictLangCache {
public void rebuild()
{
m_map = new HashMap<>();
Set<String> langsSet = new HashSet<>();
DictAndLoc[] dals = DictUtils.dictList( m_context );
for ( DictAndLoc dal : dals ) {
String lang = getLangName( m_context, dal.name );
if ( null != lang && 0 != lang.length() ) {
if ( ! m_map.containsValue( lang ) ) {
String locName = LocUtils.xlateLang( m_context, lang,
true );
m_map.put( locName, lang );
}
langsSet.add( lang );
}
}
// Now build the array data
clear();
for ( Iterator<String> iter = m_map.keySet().iterator();
for ( Iterator<String> iter = langsSet.iterator();
iter.hasNext(); ) {
String locName = iter.next();
add( locName );
add( iter.next() );
}
if ( null != s_last ) {
add( s_last );
@ -93,11 +88,11 @@ public class DictLangCache {
sort( KeepLast );
}
public int getPosForLang( String lang )
public int getPosForLang( String langName )
{
int result = -1;
for ( int ii = 0; ii < getCount(); ++ii ) {
if ( lang.equals( getLangAtPosition( ii ) ) ) {
if ( langName.equals( getLangAtPosition( ii ) ) ) {
result = ii;
break;
}
@ -107,9 +102,7 @@ public class DictLangCache {
public String getLangAtPosition( int position )
{
String locName = getItem( position );
String result = m_map.get( locName );
return result;
return getItem( position );
}
}
@ -135,9 +128,8 @@ public class DictLangCache {
int wordCount = info.wordCount;
String langName = getLangName( context, dal.name );
String locName = LocUtils.xlateLang( context, langName );
result = LocUtils.getString( context, R.string.dict_desc_fmt,
dal.name, locName,
dal.name, langName,
wordCount );
}
return result;
@ -145,7 +137,7 @@ public class DictLangCache {
// This populates the cache and will take significant time if it's mostly
// empty and there are a lot of dicts.
public static int getLangCount( Context context, String isoCode )
public static int getLangCount( Context context, ISOCode isoCode )
{
int count = 0;
DictAndLoc[] dals = DictUtils.dictList( context );
@ -157,13 +149,13 @@ public class DictLangCache {
return count;
}
private static DictInfo[] getInfosHaveLang( Context context, String isoCode )
private static DictInfo[] getInfosHaveLang( Context context, ISOCode isoCode )
{
List<DictInfo> al = new ArrayList<>();
DictAndLoc[] dals = DictUtils.dictList( context );
for ( DictAndLoc dal : dals ) {
DictInfo info = getInfo( context, dal );
if ( null != info && isoCode.equals( info.isoCode ) ) {
if ( null != info && isoCode.equals( info.isoCode() ) ) {
al.add( info );
}
}
@ -171,12 +163,12 @@ public class DictLangCache {
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;
DictInfo[] infos = getInfosHaveLang( context, isoCode );
for ( DictInfo info : infos ) {
if ( name.equals( info.name ) ) {
if ( dictName.equals( info.name ) ) {
found = true;
break;
}
@ -184,7 +176,7 @@ public class DictLangCache {
return found;
}
private static String[] getHaveLang( Context context, String isoCode,
private static String[] getHaveLang( Context context, ISOCode isoCode,
Comparator<DictInfo> comp,
boolean withCounts )
{
@ -210,12 +202,12 @@ public class DictLangCache {
return result;
}
public static String[] getHaveLang( Context context, String isoCode )
public static String[] getHaveLang( Context context, ISOCode isoCode )
{
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 );
List<DictAndLoc> al = new ArrayList<>();
@ -226,8 +218,8 @@ public class DictLangCache {
for ( DictAndLoc dal : dals ) {
DictInfo info = getInfo( context, dal );
if ( null != info ) {
Assert.assertTrueNR( s_langNames.containsKey( info.isoCode ) );
if ( isoCode.equals( info.isoCode ) ) {
Assert.assertTrueNR( s_langNames.containsKey( info.isoCode() ) );
if ( isoCode.equals( info.isoCode() ) ) {
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 );
}
public static String[] getHaveLangCounts( Context context, String isoCode )
public static String[] getHaveLangCounts( Context context, ISOCode isoCode )
{
return getHaveLang( context, isoCode, null, true );
}
@ -261,41 +253,41 @@ public class DictLangCache {
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 );
return info.isoCode;
return info.isoCode();
}
public static String getLangNameForISOCode( Context context, String isoCode )
public static String getLangNameForISOCode( Context context, ISOCode isoCode )
{
makeMaps( context );
return s_langNames.get( isoCode );
}
public static void setLangNameForISOCode( Context context, String isoCode,
public static void setLangNameForISOCode( Context context, ISOCode isoCode,
String langName )
{
makeMaps( context );
putTwo( isoCode, langName );
}
public static String getLangIsoCode( Context context, String langName )
public static ISOCode getLangIsoCode( Context context, String langName )
{
makeMaps( context );
String result = s_langCodes.get( langName );
ISOCode result = s_langCodes.get( langName );
// Log.d( TAG, "getLangIsoCode(%s) => %s", langName, result );
return result;
}
public static String getDictLangName( Context context, String dictName )
{
String isoCode = getDictISOCode( context, dictName );
ISOCode isoCode = getDictISOCode( context, dictName );
return getLangNameForISOCode( context, isoCode );
}
@ -318,7 +310,7 @@ public class DictLangCache {
public static String getLangName( Context context, String dictName )
{
String isoCode = getDictISOCode( context, dictName );
ISOCode isoCode = getDictISOCode( context, dictName );
return getLangNameForISOCode( context, isoCode );
}
@ -370,7 +362,7 @@ public class DictLangCache {
return langs.toArray( result );
}
public static String getBestDefault( Context context, String isoCode,
public static String getBestDefault( Context context, ISOCode isoCode,
boolean human )
{
String dictName = human? CommonPrefs.getDefaultHumanDict( context )
@ -419,21 +411,21 @@ public class DictLangCache {
}
public static ArrayAdapter<String> getDictsAdapter( Context context,
String isoCode )
ISOCode isoCode )
{
if ( ! isoCode.equals( s_adaptedLang ) ) {
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 ) );
s_adaptedLang = isoCode;
}
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 );
Assert.assertTrueNR( !TextUtils.isEmpty(isoCode)
Assert.assertTrueNR( null != isoCode
&& !TextUtils.isEmpty(langName) );
s_langCodes.put( langName, isoCode );
s_langNames.put( isoCode, langName );
@ -448,7 +440,7 @@ public class DictLangCache {
Resources res = context.getResources();
String[] entries = res.getStringArray( R.array.language_names );
for ( int ii = 0; ii < entries.length; ii += 2 ) {
String isoCode = entries[ii];
ISOCode isoCode = new ISOCode(entries[ii]);
String langName = entries[ii+1];
putTwo( isoCode, langName );
}
@ -458,7 +450,7 @@ public class DictLangCache {
DictAndLoc[] dals = DictUtils.dictList( context ) ;
for ( DictAndLoc dal : dals ) {
DictInfo info = getInfo( context, dal );
String isoCode = info.isoCode;
ISOCode isoCode = info.isoCode();
Assert.assertTrueNR( null != isoCode );
if ( !s_langNames.containsKey( isoCode ) ) {
// Log.d( TAG, "looking at info %s", info );
@ -484,7 +476,7 @@ public class DictLangCache {
DictInfo info = DBUtils.dictsGetInfo( context, dal.name );
// 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",
dal.name );
info = null;

View file

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

View file

@ -49,6 +49,7 @@ import java.util.Set;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.Perms23.Perm;
import org.eehouse.android.xw4.Utils.ISOCode;
public class DwnldDelegate extends ListDelegateBase {
private static final String TAG = DwnldDelegate.class.getSimpleName();
@ -64,11 +65,11 @@ public class DwnldDelegate extends ListDelegateBase {
private ArrayList<DownloadFilesTask> m_dfts;
public interface DownloadFinishedListener {
void downloadFinished( String isoCode, String name, boolean success );
void downloadFinished( ISOCode isoCode, String name, boolean success );
}
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 )
@ -444,10 +445,10 @@ public class DwnldDelegate extends ListDelegateBase {
return new File(path).getName();
}
private static String langFromUri( Uri uri )
private static ISOCode langFromUri( Uri uri )
{
List<String> segs = uri.getPathSegments();
String result = segs.get( segs.size() - 2 );
ISOCode result = new ISOCode(segs.get( segs.size() - 2 ));
return result;
}
@ -469,7 +470,7 @@ public class DwnldDelegate extends ListDelegateBase {
}
if ( null != ld ) {
String name = ld.m_name;
String lang = langFromUri( uri );
ISOCode lang = langFromUri( uri );
if ( null == name ) {
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,
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.LocalPlayer;
import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.Utils.ISOCode;
public class GameConfigDelegate extends DelegateBase
implements View.OnClickListener, XWListItem.DeleteCallback {
@ -353,7 +354,8 @@ public class GameConfigDelegate extends DelegateBase
TextView dictLabel = (TextView)playerView
.findViewById( R.id.dict_label );
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 );
dictLabel.setText( label );
} else {
@ -363,7 +365,7 @@ public class GameConfigDelegate extends DelegateBase
.findViewById( R.id.player_dict_spinner ))
.getSpinner();
if ( localOnlyGame() ) {
configDictSpinner( m_playerDictSpinner, m_gi.isoCode, m_gi.dictName(lp) );
configDictSpinner( m_playerDictSpinner, m_gi.isoCode(), m_gi.dictName(lp) );
} else {
m_playerDictSpinner.setVisibility( View.GONE );
m_playerDictSpinner = null;
@ -544,13 +546,13 @@ public class GameConfigDelegate extends DelegateBase
case REQUEST_DICT:
String dictName = cancelled ? m_gi.dictName
: data.getStringExtra( DictsDelegate.RESULT_LAST_DICT );
configDictSpinner( m_dictSpinner, m_gi.isoCode, dictName );
configDictSpinner( m_playerDictSpinner, m_gi.isoCode, dictName );
configDictSpinner( m_dictSpinner, m_gi.isoCode(), dictName );
configDictSpinner( m_playerDictSpinner, m_gi.isoCode(), dictName );
break;
case REQUEST_LANG_GC:
String langName = cancelled
? DictLangCache.getLangNameForISOCode( m_activity, m_gi.isoCode )
: data.getStringExtra( DictsDelegate.RESULT_LAST_LANG );
ISOCode isoCode = cancelled ? m_gi.isoCode()
: (ISOCode)data.getSerializableExtra( DictsDelegate.RESULT_LAST_LANG );
String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
selLangChanged( langName );
setLangSpinnerSelection( langName );
break;
@ -990,7 +992,7 @@ public class GameConfigDelegate extends DelegateBase
}
} // loadPlayersList
private void configDictSpinner( Spinner dictsSpinner, final String isoCode,
private void configDictSpinner( Spinner dictsSpinner, final ISOCode isoCode,
String curDict )
{
if ( null != dictsSpinner ) {
@ -1009,8 +1011,8 @@ public class GameConfigDelegate extends DelegateBase
if ( chosen.equals( m_browseText ) ) {
DictsDelegate.downloadForResult( getDelegator(),
RequestCode.REQUEST_DICT,
m_gi.isoCode );
Assert.assertTrueNR( isoCode.equals(m_gi.isoCode) );
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 );
}
}
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 );
loadPlayersList();
configDictSpinner( m_dictSpinner, m_gi.isoCode, m_gi.dictName );
configDictSpinner( m_dictSpinner, m_gi.isoCode(), m_gi.dictName );
}
private void configSpinnerWDownload( Spinner spinner,

View file

@ -276,7 +276,6 @@ public class GameListItem extends LinearLayout
case R.string.game_summary_field_language:
value =
DictLangCache.getLangNameForISOCode( m_context, m_summary.isoCode );
value = LocUtils.xlateLang( m_context, value, true );
break;
case R.string.game_summary_field_opponents:
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.GamePtr;
import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.Utils.ISOCode;
import java.io.File;
import java.io.FileOutputStream;
@ -406,7 +407,7 @@ public class GameUtils {
DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames );
if ( pairs.anyMissing( dictNames ) ) {
postMoveDroppedForDictNotification( context, rowid, gi.gameID,
gi.isoCode );
gi.isoCode() );
} else {
String langName = gi.langName( context );
gamePtr = XwJNI.initFromStream( rowid, stream, gi, util, null,
@ -598,7 +599,7 @@ public class GameUtils {
CommsAddrRec addr = nli.makeAddrRec( context );
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,
nli.nPlayersH, nli.forceChannel,
nli.inviteID(), nli.gameID(),
@ -613,7 +614,7 @@ public class GameUtils {
}
public static long makeNewMultiGame( Context context, long groupID,
String dict, String isoCode,
String dict, ISOCode isoCode,
String jsonData,
CommsConnTypeSet addrSet,
String gameName )
@ -625,11 +626,11 @@ public class GameUtils {
private static long makeNewMultiGame( Context context, long groupID,
String inviteID, String dict,
String isoCode, String jsonData,
ISOCode isoCode, String jsonData,
CommsConnTypeSet addrSet,
String gameName )
{
String[] langArray = {isoCode};
ISOCode[] langArray = {isoCode};
String[] dictArray = {dict};
if ( null == addrSet ) {
addrSet = XWPrefs.getAddrTypes( context );
@ -654,7 +655,7 @@ public class GameUtils {
private static long makeNewMultiGame( Context context, MultiMsgSink sink,
UtilCtxt util, long groupID,
CommsAddrRec addr,
String[] isoCode, String[] dict,
ISOCode[] isoCode, String[] dict,
String jsonData,
int nPlayersT, int nPlayersH,
int forceChannel, String inviteID,
@ -668,7 +669,7 @@ public class GameUtils {
gi.setFrom( jsonData );
gi.setLang( context, isoCode[0], dict[0] );
gi.forceChannel = forceChannel;
isoCode[0] = gi.isoCode;
isoCode[0] = gi.isoCode();
dict[0] = gi.dictName;
gi.setNPlayers( nPlayersT, nPlayersH, localsRobots );
gi.juggle();
@ -830,14 +831,14 @@ public class GameUtils {
}
public static String[] dictNames( Context context, long rowid,
String[] missingLang )
ISOCode[] missingLang )
{
String[] result = null;
byte[] stream = savedGame( context, rowid );
CurGameInfo gi = giFromStream( context, stream );
if ( null != gi ) {
if ( null != missingLang ) {
missingLang[0] = gi.isoCode;
missingLang[0] = gi.isoCode();
}
result = gi.dictNames();
}
@ -864,7 +865,7 @@ public class GameUtils {
// are not.
public static boolean gameDictsHere( Context context, long rowid,
String[][] missingNames,
String[] missingLang )
ISOCode[] missingLang )
{
String[] gameDicts = dictNames( context, rowid, missingLang );
return null != gameDicts
@ -1235,7 +1236,7 @@ public class GameUtils {
}
private static void postMoveDroppedForDictNotification( Context context, long rowid,
int gameID, String isoCode )
int gameID, ISOCode isoCode )
{
Intent intent = GamesListDelegate.makeGameIDIntent( context, gameID );

View file

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

View file

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

View file

@ -23,14 +23,14 @@ import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.loc.LocUtils;
public class LookupAlert extends XWDialogFragment {
private static final String TAG = LookupAlert.class.getSimpleName();
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();
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.Utils.ISOCode;
import java.util.ArrayList;
@ -50,9 +51,9 @@ public class LookupAlertView extends LinearLayout
void onDone();
}
public static final String WORDS = "WORDS";
public static final String LANG = "LANG";
public static final String STUDY_ON = "STUDY_ON";
private static final String WORDS = "WORDS";
private static final String LANG = "LANG";
private static final String STUDY_ON = "STUDY_ON";
private static final String STATE = "STATE";
private static final String WORDINDEX = "WORDINDEX";
private static final String URLINDEX = "URLINDEX";
@ -67,7 +68,7 @@ public class LookupAlertView extends LinearLayout
private static ArrayAdapter<String> s_urlsAdapter;
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;
// These two are probably always the same object
@ -93,7 +94,7 @@ public class LookupAlertView extends LinearLayout
{
m_onDone = lstn;
m_words = bundle.getStringArray( WORDS );
String isoCode = bundle.getString( LANG );
ISOCode isoCode = ISOCode.newIf( bundle.getString( LANG ) );
setLang( m_context, isoCode );
m_studyOn = XWPrefs.getStudyEnabled( m_context )
&& bundle.getBoolean( STUDY_ON, true );
@ -246,7 +247,7 @@ public class LookupAlertView extends LinearLayout
}
} // lookupWord
private void setLang( Context context, String isoCode )
private void setLang( Context context, ISOCode isoCode )
{
if ( ! isoCode.equals( s_lang ) ) {
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_lookupNames );
s_lang = isoCode;
String langName = DictLangCache.getLangNameForISOCode( context, isoCode );
s_langName = LocUtils.xlateLang( context, langName );
s_langName = DictLangCache.getLangNameForISOCode( context, isoCode );
}
}
@ -298,15 +298,15 @@ public class LookupAlertView extends LinearLayout
return handled;
}
private static void addParams( Bundle bundle, String[] words, String isoCode,
boolean studyOn )
private static void addParams( Bundle bundle, String[] words,
ISOCode isoCode, boolean studyOn )
{
bundle.putStringArray( WORDS, words );
bundle.putString( LANG, isoCode );
bundle.putString( LANG, isoCode.toString() );
bundle.putBoolean( STUDY_ON, studyOn );
}
protected static Bundle makeParams( String[] words, String isoCode,
protected static Bundle makeParams( String[] words, ISOCode isoCode,
boolean noStudyOption )
{
Bundle bundle = new Bundle();

View file

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

View file

@ -40,6 +40,7 @@ import java.util.List;
import org.json.JSONException;
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.CommsConnTypeSet;
import org.eehouse.android.xw4.jni.CommsAddrRec;
@ -74,7 +75,7 @@ public class NetLaunchInfo implements Serializable {
protected String gameName;
protected String dict;
protected String isoCode; // added in version 2
protected ISOCode isoCode; // added in version 2
protected int forceChannel;
protected int nPlayersT;
protected int nPlayersH;
@ -110,11 +111,11 @@ public class NetLaunchInfo implements Serializable {
private NetLaunchInfo( Bundle bundle )
{
isoCode = bundle.getString( MultiService.ISO );
isoCode = ISOCode.newIf( bundle.getString( MultiService.ISO ) );
if ( null == isoCode ) {
int lang = bundle.getInt( MultiService.LANG, 0 );
if ( 0 != lang ) {
isoCode = XwJNI.lcToLocale( lang );
isoCode = XwJNI.lcToLocaleJ( lang );
}
}
Assert.assertTrueNR( null != isoCode );
@ -257,12 +258,12 @@ public class NetLaunchInfo implements Serializable {
removeUnsupported( supported );
dict = data.getQueryParameter( WORDLIST_KEY );
isoCode = data.getQueryParameter( ISO_KEY );
isoCode = ISOCode.newIf( data.getQueryParameter( ISO_KEY ) );
if ( null == isoCode ) {
String langStr = data.getQueryParameter( LANG_KEY );
if ( null != langStr && !langStr.equals("0") ) {
int lang = Integer.decode( langStr );
isoCode = XwJNI.lcToLocale( lang );
isoCode = XwJNI.lcToLocaleJ( lang );
}
}
Assert.assertTrueNR( null != isoCode );
@ -288,7 +289,7 @@ public class NetLaunchInfo implements Serializable {
calcValid();
}
private NetLaunchInfo( int gamID, String gamNam, String isoCodeIn,
private NetLaunchInfo( int gamID, String gamNam, ISOCode isoCodeIn,
String dictName, int nPlayers, boolean dupMode )
{
this();
@ -312,7 +313,7 @@ public class NetLaunchInfo implements Serializable {
public NetLaunchInfo( CurGameInfo gi )
{
this( gi.gameID, gi.getName(), gi.isoCode,
this( gi.gameID, gi.getName(), gi.isoCode(),
gi.dictName, gi.nPlayers, gi.inDuplicateMode );
}
@ -392,7 +393,7 @@ public class NetLaunchInfo implements Serializable {
if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) {
bundle.putInt( MultiService.LANG, lang[0] );
} else {
bundle.putString( MultiService.ISO, isoCode );
bundle.putString( MultiService.ISO, isoCode.toString() );
}
bundle.putString( MultiService.DICT, dict );
bundle.putString( MultiService.GAMENAME, gameName );
@ -423,7 +424,7 @@ public class NetLaunchInfo implements Serializable {
other = (NetLaunchInfo)obj;
result = TextUtils.equals( gameName, other.gameName )
&& TextUtils.equals( dict, other.dict )
&& TextUtils.equals( isoCode, other.isoCode )
&& ISOCode.safeEquals( isoCode, other.isoCode )
&& forceChannel == other.forceChannel
&& nPlayersT == other.nPlayersT
&& nPlayersH == other.nPlayersH
@ -547,11 +548,11 @@ public class NetLaunchInfo implements Serializable {
boolean hasAddrs = -1 != flags;
_conTypes = hasAddrs ? flags : EMPTY_SET;
isoCode = json.optString( MultiService.ISO, null );
isoCode = ISOCode.newIf( json.optString( MultiService.ISO, null ) );
if ( null == isoCode ) {
int lang = json.optInt( MultiService.LANG, 0 );
if ( 0 != lang ) {
isoCode = XwJNI.lcToLocale( lang );
isoCode = XwJNI.lcToLocaleJ( lang );
}
}
Assert.assertTrueNR( null != isoCode );
@ -636,7 +637,7 @@ public class NetLaunchInfo implements Serializable {
if ( XwJNI.haveLocaleToLc( isoCode, lang ) ) {
appendInt( ub, LANG_KEY, lang[0] );
} else {
ub.appendQueryParameter( ISO_KEY, isoCode );
ub.appendQueryParameter( ISO_KEY, isoCode.toString() );
}
appendInt( ub, TOTPLAYERS_KEY, nPlayersT );
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.Utils.ISOCode;
import org.eehouse.android.xw4.jni.GameSummary;
import org.eehouse.android.xw4.loc.LocUtils;
@ -58,7 +59,7 @@ public class StudyListDelegate extends ListDelegateBase
private Activity m_activity;
private Spinner m_spinner;
private LabeledSpinner m_pickView;
private String[] m_langCodes;
private ISOCode[] m_langCodes;
private String[] m_words;
private Set<String> m_checkeds;
private int m_langPosition;
@ -181,7 +182,7 @@ public class StudyListDelegate extends ListDelegateBase
// DBUtils.StudyListListener
//////////////////////////////////////////////////
@Override
public void onWordAdded( String word, String isoCode )
public void onWordAdded( String word, ISOCode isoCode )
{
if ( isoCode.equals( m_langCodes[m_langPosition] ) ) {
loadList();
@ -293,14 +294,14 @@ public class StudyListDelegate extends ListDelegateBase
private void loadList()
{
String isoCode = m_langCodes[m_langPosition];
ISOCode isoCode = m_langCodes[m_langPosition];
m_words = DBUtils.studyListWords( m_activity, isoCode );
makeAdapter();
String langName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
m_origTitle = getString( R.string.studylist_title_fmt,
xlateLang( langName ) );
langName );
setTitleBar();
}
@ -328,9 +329,8 @@ public class StudyListDelegate extends ListDelegateBase
String[] myNames = new String[m_langCodes.length];
for ( int ii = 0; ii < m_langCodes.length; ++ii ) {
String isoCode = m_langCodes[ii];
String name = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
myNames[ii] = xlateLang( name, true );
ISOCode isoCode = m_langCodes[ii];
myNames[ii] = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
if ( isoCode.equals( startLang ) ) {
startIndex = ii;
}
@ -388,7 +388,7 @@ public class StudyListDelegate extends ListDelegateBase
launchOrAlert( delegator, null, dlg );
}
public static void launchOrAlert( Delegator delegator, String isoCode,
public static void launchOrAlert( Delegator delegator, ISOCode isoCode,
DlgDelegate.HasDlgDelegate dlg )
{
String msg = null;
@ -403,7 +403,7 @@ public class StudyListDelegate extends ListDelegateBase
} else {
Bundle bundle = new Bundle();
if ( null != isoCode ) {
bundle.putString( START_LANG, isoCode );
bundle.putString( START_LANG, isoCode.toString() );
}
delegator.addFragment( StudyListFrag.newInstance( delegator ),

View file

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

View file

@ -45,6 +45,7 @@ import android.os.Looper;
import android.provider.ContactsContract.PhoneLookup;
import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Base64;
import android.view.Menu;
import android.view.MenuItem;
@ -639,16 +640,16 @@ public class Utils {
public static Uri makeDictUriFromName( Context context,
String langName, String dictName )
{
String isoCode = DictLangCache.getLangIsoCode( context, langName );
ISOCode isoCode = DictLangCache.getLangIsoCode( context, langName );
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 );
Uri.Builder builder = Uri.parse( dictUrl ).buildUpon();
if ( null != isoCode ) {
builder.appendPath( isoCode );
builder.appendPath( isoCode.toString() );
}
if ( null != name ) {
Assert.assertNotNull( isoCode );
@ -889,4 +890,55 @@ public class Utils {
@Override
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 org.json.JSONObject;
import org.eehouse.android.xw4.Assert;
import org.eehouse.android.xw4.BuildConfig;
import org.eehouse.android.xw4.DictLangCache;
import org.eehouse.android.xw4.DictUtils;
import org.eehouse.android.xw4.Log;
import org.eehouse.android.xw4.R;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.XWApp;
import org.eehouse.android.xw4.XWPrefs;
@ -60,7 +60,7 @@ public class CurGameInfo implements Serializable {
public String dictName;
public LocalPlayer[] players;
public String isoCode;
public String isoCodeStr; // public only for access from JNI; use isoCode() from java
public int gameID;
public int gameSeconds;
public int nPlayers;
@ -153,7 +153,7 @@ public class CurGameInfo implements Serializable {
players = new LocalPlayer[MAX_NUM_PLAYERS];
serverRole = src.serverRole;
dictName = src.dictName;
isoCode = src.isoCode;
isoCodeStr = src.isoCodeStr;
hintsNotAllowed = src.hintsNotAllowed;
inDuplicateMode = src.inDuplicateMode;
phoniesAction = src.phoniesAction;
@ -169,6 +169,11 @@ public class CurGameInfo implements Serializable {
Utils.testSerialization( this );
}
public ISOCode isoCode()
{
return ISOCode.newIf( isoCodeStr );
}
@Override
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 ) {
dictName = dict;
@ -254,7 +259,7 @@ public class CurGameInfo implements Serializable {
setLang( context, isoCode );
}
public void setLang( Context context, String isoCodeNew )
public void setLang( Context context, ISOCode isoCodeNew )
{
if ( null == isoCodeNew ) {
String dictName = CommonPrefs.getDefaultHumanDict( context );
@ -262,8 +267,8 @@ public class CurGameInfo implements Serializable {
}
Assert.assertTrueNR( null != isoCodeNew );
if ( ! TextUtils.equals( isoCodeNew, this.isoCode ) ) {
isoCode = isoCodeNew;
if ( ! TextUtils.equals( isoCodeNew.toString(), this.isoCodeStr ) ) {
isoCodeStr = isoCodeNew.toString();
assignDicts( context );
}
}
@ -301,7 +306,7 @@ public class CurGameInfo implements Serializable {
{
boolean matter = nPlayers != other.nPlayers
|| serverRole != other.serverRole
|| ! TextUtils.equals(isoCode, other.isoCode)
|| ! TextUtils.equals(isoCodeStr, other.isoCodeStr)
|| boardSize != other.boardSize
|| traySize != other.traySize
|| bingoMin != other.bingoMin
@ -333,7 +338,7 @@ public class CurGameInfo implements Serializable {
result = null != obj && obj instanceof CurGameInfo;
if ( result ) {
other = (CurGameInfo)obj;
result = TextUtils.equals( isoCode, other.isoCode)
result = TextUtils.equals( isoCodeStr, other.isoCodeStr)
&& gameID == other.gameID
&& gameSeconds == other.gameSeconds
&& nPlayers == other.nPlayers
@ -444,7 +449,7 @@ public class CurGameInfo implements Serializable {
public void replaceDicts( Context context, String newDict )
{
String[] dicts =
DictLangCache.getHaveLang( context, isoCode );
DictLangCache.getHaveLang( context, isoCode() );
HashSet<String> installed = new HashSet<>( Arrays.asList(dicts) );
if ( !installed.contains( dictName ) ) {
@ -463,7 +468,7 @@ public class CurGameInfo implements Serializable {
public String langName( Context context )
{
return DictLangCache.getLangNameForISOCode( context, isoCode );
return DictLangCache.getLangNameForISOCode( context, isoCode() );
}
public String dictName( final LocalPlayer lp )
@ -588,14 +593,13 @@ public class CurGameInfo implements Serializable {
// right language.
String humanDict =
DictLangCache.getBestDefault( context, isoCode, true );
DictLangCache.getBestDefault( context, isoCode(), true );
String robotDict =
DictLangCache.getBestDefault( context, isoCode, false );
DictLangCache.getBestDefault( context, isoCode(), false );
if ( null == dictName
|| ! DictUtils.dictExists( context, dictName )
|| ! isoCode.equals( DictLangCache.getDictISOCode( context,
dictName ) ) ) {
|| ! DictLangCache.getDictISOCode( context, dictName ).equals( isoCode() ) ) {
dictName = humanDict;
}
@ -603,8 +607,8 @@ public class CurGameInfo implements Serializable {
LocalPlayer lp = players[ii];
if ( null != lp.dictName &&
!isoCode.equals( DictLangCache.getDictISOCode( context,
lp.dictName ) ) ) {
!ISOCode.safeEquals( DictLangCache.getDictISOCode(context, lp.dictName),
isoCode() ) ) {
lp.dictName = null;
}

View file

@ -295,9 +295,9 @@ public class DUtilCtxt {
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 };
DictUtils.DictPairs pairs = DictUtils.openDicts( m_context, names );
// Log.d( TAG, "openDicts() => %s", pairs );

View file

@ -20,7 +20,9 @@
package org.eehouse.android.xw4.jni;
import org.eehouse.android.xw4.Assert;
import org.eehouse.android.xw4.BuildConfig;
import org.eehouse.android.xw4.Utils.ISOCode;
public class DictInfo {
// set in java code
@ -29,17 +31,22 @@ public class DictInfo {
// set in jni code
public int wordCount;
public String isoCode;
public String isoCodeStr; // public only for access from JNI; use isoCode() from java
public String langName;
public String md5Sum; // internal (skipping header?)
public ISOCode isoCode()
{
return ISOCode.newIf( isoCodeStr );
}
@Override
public String toString()
{
if ( BuildConfig.NON_RELEASE ) {
return new StringBuilder("{")
.append("name: ").append(name)
.append(", isoCode: ").append(isoCode)
.append(", isoCode: ").append(isoCodeStr)
.append(", langName: ").append(langName)
.append(", md5Sum: ").append(md5Sum)
.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.Log;
import org.eehouse.android.xw4.R;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.XWApp;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
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;
import org.eehouse.android.xw4.loc.LocUtils;
/** 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 String[] remoteDevs; // BTAddrs and phone numbers
public String isoCode;
public ISOCode isoCode;
public DeviceRole serverRole;
public int nPacketsPending;
@ -96,7 +97,7 @@ public class GameSummary implements Serializable {
public GameSummary( CurGameInfo gi )
{
nPlayers = gi.nPlayers;
isoCode = gi.isoCode;
isoCode = gi.isoCode();
serverRole = gi.serverRole;
gameID = gi.gameID;
m_gi = gi;
@ -127,7 +128,7 @@ public class GameSummary implements Serializable {
&& modtime == other.modtime
&& created == other.created
&& gameID == other.gameID
&& TextUtils.equals( isoCode, other.isoCode)
&& ISOCode.safeEquals( isoCode, other.isoCode )
&& nPacketsPending == other.nPacketsPending
&& Arrays.equals( scores, other.scores )
&& Arrays.equals( m_players, other.m_players )

View file

@ -20,6 +20,7 @@
package org.eehouse.android.xw4.jni;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
public interface UtilCtxt {
@ -104,7 +105,7 @@ public interface UtilCtxt {
void informMove( int turn, String expl, String words );
void informUndo();
void informNetDict( String isoCode, String oldName, String newName,
void informNetDict( ISOCode isoCode, String oldName, String newName,
String newSum, CurGameInfo.XWPhoniesChoice phonies );
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.Log;
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.JNIThread.JNICmd;
@ -217,7 +218,7 @@ public class UtilCtxtImpl implements UtilCtxt {
}
@Override
public void informNetDict( String isoCode, String oldName,
public void informNetDict( ISOCode isoCode, String oldName,
String newName, String newSum,
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.NetLaunchInfo;
import org.eehouse.android.xw4.Quarantine;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
@ -275,10 +276,21 @@ public class XwJNI {
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 String comms_getUUID();
public static native String lcToLocale( int lc );
public static native boolean haveLocaleToLc( String isoCode, int[] lc );
private static native String lcToLocale( int lc );
private static native boolean haveLocaleToLc( String isoCode, int[] lc );
// Game methods
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.BuildConfig;
import org.eehouse.android.xw4.R;
import org.eehouse.android.xw4.Utils.ISOCode;
import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.XWApp;
import org.eehouse.android.xw4.XWPrefs;
@ -43,7 +44,7 @@ import java.util.Map;
public class LocUtils {
protected static final String RES_FORMAT = "%[\\d]\\$[ds]";
private static String s_curLocale;
private static String s_curLang;
private static ISOCode s_curLang;
private static Map<String, String> s_langMap = null;
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 )
{
}
@ -193,7 +156,7 @@ public class LocUtils {
return name;
}
public static String getCurLangCode( Context context )
public static ISOCode getCurLangCode( Context context )
{
if ( null == s_curLang ) {
String lang = Locale.getDefault().getLanguage();
@ -203,7 +166,7 @@ public class LocUtils {
lang = TextUtils.split(lang, "-")[0];
}
Assert.assertTrueNR( 2 == lang.length() );
s_curLang = lang;
s_curLang = new ISOCode( lang );
}
return s_curLang;
}

View file

@ -270,7 +270,8 @@ and_util_informNetDict( XW_UtilCtxt* uc, XWEnv xwe, const XP_UCHAR* isoCode,
const DictionaryCtxt*
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 );
JNIEnv* env = xwe;
@ -281,14 +282,13 @@ and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
dmgr_get( dictMgr, xwe, dictName );
if ( !dict ) {
jstring jname = (*env)->NewStringUTF( env, dictName );
jstring jISOCode = (*env)->NewStringUTF( env, isoCode );
jobjectArray jstrs = makeStringArray( env, 1, NULL );
jobjectArray jbytes = makeByteArrayArray( env, 1 );
DUTIL_CBK_HEADER( "getDictPath",
"(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[[B)V" );
(*env)->CallVoidMethod( env, dutil->jdutil, mid, jISOCode, jname, jstrs, jbytes );
"(Ljava/lang/String;[Ljava/lang/String;[[B)V" );
(*env)->CallVoidMethod( env, dutil->jdutil, mid, jname, jstrs, jbytes );
DUTIL_CBK_TAIL();
jstring jpath = (*env)->GetObjectArrayElement( env, jstrs, 0 );
@ -298,9 +298,8 @@ and_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
TI_IF(&globalState->ti)
dictMgr, ((AndDUtil*)duc)->jniutil,
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;
}

View file

@ -468,7 +468,7 @@ makeGI( MPFORMAL JNIEnv* env, jobject jgi )
getString( env, jgi, "dictName", AANDS(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_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) );
setString( env, jgi, "dictName", gi->dictName );
setString( env, jgi, "isoCode", gi->isoCode );
setString( env, jgi, "isoCodeStr", gi->isoCode );
intToJenumField( env, jgi, gi->phoniesAction, "phoniesAction",
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") );
setInt( env, jinfo, "wordCount", dict_getWordCount( dict, env ) );
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 ) );
}