mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-23 07:27:22 +01:00
don't crash when first run without network connection
This commit is contained in:
parent
013e0e3a4c
commit
3064420c78
2 changed files with 43 additions and 38 deletions
|
@ -1140,50 +1140,53 @@ public class DictsDelegate extends ListDelegateBase
|
||||||
JSONObject theOne = null;
|
JSONObject theOne = null;
|
||||||
String langName = null;
|
String langName = null;
|
||||||
String json = NetUtils.runPost( post, new JSONObject() );
|
String json = NetUtils.runPost( post, new JSONObject() );
|
||||||
try {
|
if ( null != json ) {
|
||||||
JSONObject obj = new JSONObject( json );
|
try {
|
||||||
JSONArray langs = obj.optJSONArray( "langs" );
|
JSONObject obj = new JSONObject( json );
|
||||||
int nLangs = langs.length();
|
JSONArray langs = obj.optJSONArray( "langs" );
|
||||||
for ( int ii = 0; ii < nLangs; ++ii ) {
|
int nLangs = langs.length();
|
||||||
JSONObject langObj = langs.getJSONObject( ii );
|
for ( int ii = 0; ii < nLangs; ++ii ) {
|
||||||
String langCode = langObj.getString( "lc" );
|
JSONObject langObj = langs.getJSONObject( ii );
|
||||||
if ( ! langCode.equals( m_lc ) ) {
|
String langCode = langObj.getString( "lc" );
|
||||||
continue;
|
if ( ! langCode.equals( m_lc ) ) {
|
||||||
}
|
continue;
|
||||||
// we have our language; look for one marked default;
|
}
|
||||||
// otherwise take the largest.
|
// we have our language; look for one marked default;
|
||||||
m_langName = langObj.getString( "lang" );
|
// otherwise take the largest.
|
||||||
JSONArray dicts = langObj.getJSONArray( "dicts" );
|
m_langName = langObj.getString( "lang" );
|
||||||
int nDicts = dicts.length();
|
JSONArray dicts = langObj.getJSONArray( "dicts" );
|
||||||
int theOneNWords = 0;
|
int nDicts = dicts.length();
|
||||||
for ( int jj = 0; jj < nDicts; ++jj ) {
|
int theOneNWords = 0;
|
||||||
JSONObject dict = dicts.getJSONObject( jj );
|
for ( int jj = 0; jj < nDicts; ++jj ) {
|
||||||
if ( dict.optBoolean( "isDflt", false ) ) {
|
JSONObject dict = dicts.getJSONObject( jj );
|
||||||
theOne = dict;
|
if ( dict.optBoolean( "isDflt", false ) ) {
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
int nWords = dict.getInt( "nWords" );
|
|
||||||
if ( null == theOne || nWords > theOneNWords ) {
|
|
||||||
theOne = dict;
|
theOne = dict;
|
||||||
theOneNWords = nWords;
|
break;
|
||||||
|
} else {
|
||||||
|
int nWords = dict.getInt( "nWords" );
|
||||||
|
if ( null == theOne
|
||||||
|
|| nWords > theOneNWords ) {
|
||||||
|
theOne = dict;
|
||||||
|
theOneNWords = nWords;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If we got here and theOne isn't set, there is
|
// If we got here and theOne isn't set, there is
|
||||||
// no wordlist available for this language. Set
|
// no wordlist available for this language. Set
|
||||||
// the flag so we don't try again, even though
|
// the flag so we don't try again, even though
|
||||||
// we've failed.
|
// we've failed.
|
||||||
if ( null == theOne ) {
|
if ( null == theOne ) {
|
||||||
XWPrefs.setPrefsBoolean( m_context,
|
XWPrefs.setPrefsBoolean( m_context,
|
||||||
R.string.key_got_langdict,
|
R.string.key_got_langdict,
|
||||||
true );
|
true );
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch ( JSONException ex ) {
|
} catch ( JSONException ex ) {
|
||||||
DbgUtils.loge( ex );
|
DbgUtils.loge( ex );
|
||||||
theOne = null;
|
theOne = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( null != theOne ) {
|
if ( null != theOne ) {
|
||||||
|
|
|
@ -234,6 +234,8 @@ public class NetUtils {
|
||||||
}
|
}
|
||||||
} catch( java.io.UnsupportedEncodingException uee ) {
|
} catch( java.io.UnsupportedEncodingException uee ) {
|
||||||
DbgUtils.loge( uee );
|
DbgUtils.loge( uee );
|
||||||
|
} catch( java.net.UnknownHostException uhe ) {
|
||||||
|
DbgUtils.loge( uhe );
|
||||||
} catch( java.io.IOException ioe ) {
|
} catch( java.io.IOException ioe ) {
|
||||||
DbgUtils.loge( ioe );
|
DbgUtils.loge( ioe );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue