mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-01 19:57:11 +01:00
don't offer to upgrade built-in wordlists
This commit is contained in:
parent
4b470f5e0f
commit
49ade38aca
1 changed files with 93 additions and 88 deletions
|
@ -1423,107 +1423,112 @@ public class DictsDelegate extends ListDelegateBase
|
||||||
stopProgress();
|
stopProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean digestData( String jsonData )
|
private Set<String> parseLangs( JSONArray langs ) throws JSONException
|
||||||
{
|
{
|
||||||
boolean success = false;
|
Set<String> closedLangs = new HashSet<>();
|
||||||
JSONArray langs = null;
|
Set<String> curLangs = new HashSet<>( Arrays.asList( m_langs ) );
|
||||||
|
|
||||||
m_needUpdates = new HashMap<>();
|
int nLangs = langs.length();
|
||||||
if ( null != jsonData ) {
|
m_remoteInfo = new HashMap<>();
|
||||||
Set<String> closedLangs = new HashSet<>();
|
for ( int ii = 0; !isCancelled() && ii < nLangs; ++ii ) {
|
||||||
final Set<String> curLangs =
|
JSONObject langObj = langs.getJSONObject( ii );
|
||||||
new HashSet<>( Arrays.asList( m_langs ) );
|
ISOCode isoCode = ISOCode.newIf( langObj.optString( "lc", null ) );
|
||||||
|
String urlLangName = langObj.getString( "lang" );
|
||||||
|
String localLangName = null;
|
||||||
|
if ( null != isoCode ) {
|
||||||
|
localLangName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
|
||||||
|
}
|
||||||
|
if ( null == localLangName ) {
|
||||||
|
localLangName = urlLangName;
|
||||||
|
DictLangCache.setLangNameForISOCode( m_context,
|
||||||
|
isoCode,
|
||||||
|
urlLangName );
|
||||||
|
}
|
||||||
|
|
||||||
// DictLangCache hits the DB hundreds of times below. Fix!
|
if ( null != m_filterLang &&
|
||||||
Log.w( TAG, "Fix me I'm stupid" );
|
! m_filterLang.equals( localLangName ) ) {
|
||||||
try {
|
continue;
|
||||||
// Log.d( TAG, "digestData(%s)", jsonData );
|
}
|
||||||
JSONObject obj = new JSONObject( jsonData );
|
|
||||||
langs = obj.optJSONArray( "langs" );
|
|
||||||
|
|
||||||
int nLangs = langs.length();
|
if ( ! curLangs.contains( localLangName ) ) {
|
||||||
m_remoteInfo = new HashMap<>();
|
closedLangs.add( localLangName );
|
||||||
for ( int ii = 0; !isCancelled() && ii < nLangs; ++ii ) {
|
}
|
||||||
JSONObject langObj = langs.getJSONObject( ii );
|
|
||||||
ISOCode isoCode = ISOCode.newIf( langObj.optString( "lc", null ) );
|
|
||||||
String urlLangName = langObj.getString( "lang" );
|
|
||||||
String localLangName = null;
|
|
||||||
if ( null != isoCode ) {
|
|
||||||
localLangName = DictLangCache.getLangNameForISOCode( m_activity, isoCode );
|
|
||||||
}
|
|
||||||
if ( null == localLangName ) {
|
|
||||||
localLangName = urlLangName;
|
|
||||||
DictLangCache.setLangNameForISOCode( m_context,
|
|
||||||
isoCode,
|
|
||||||
urlLangName );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( null != m_filterLang &&
|
JSONArray dicts = langObj.getJSONArray( "dicts" );
|
||||||
! m_filterLang.equals( localLangName ) ) {
|
int nDicts = dicts.length();
|
||||||
continue;
|
ArrayList<AvailDictInfo> dictNames = new ArrayList<>();
|
||||||
}
|
for ( int jj = 0; !isCancelled() && jj < nDicts;
|
||||||
|
++jj ) {
|
||||||
|
JSONObject dict = dicts.getJSONObject( jj );
|
||||||
|
String name = dict.getString( "xwd" );
|
||||||
|
name = DictUtils.removeDictExtn( name );
|
||||||
|
long nBytes = dict.optLong( "nBytes", -1 );
|
||||||
|
int nWords = dict.optInt( "nWords", -1 );
|
||||||
|
String note = dict.optString( "note" );
|
||||||
|
if ( 0 == note.length() ) {
|
||||||
|
note = null;
|
||||||
|
}
|
||||||
|
AvailDictInfo info =
|
||||||
|
new AvailDictInfo( name, isoCode, localLangName,
|
||||||
|
nWords, nBytes, note );
|
||||||
|
|
||||||
if ( ! curLangs.contains( localLangName ) ) {
|
if ( !m_quickFetchMode ) {
|
||||||
closedLangs.add( localLangName );
|
// Check if we have it and it needs an update
|
||||||
}
|
if ( DictLangCache.haveDict( m_activity, isoCode, name )
|
||||||
|
&& !DictUtils.dictIsBuiltin( m_activity, name ) ) {
|
||||||
JSONArray dicts = langObj.getJSONArray( "dicts" );
|
boolean matches = true;
|
||||||
int nDicts = dicts.length();
|
JSONArray sums = dict.optJSONArray("md5sums");
|
||||||
ArrayList<AvailDictInfo> dictNames = new ArrayList<>();
|
if ( null != sums ) {
|
||||||
for ( int jj = 0; !isCancelled() && jj < nDicts;
|
matches = false;
|
||||||
++jj ) {
|
String[] curSums = DictLangCache.getDictMD5Sums( m_activity, name );
|
||||||
JSONObject dict = dicts.getJSONObject( jj );
|
for ( String curSum : curSums ) {
|
||||||
String name = dict.getString( "xwd" );
|
for ( int kk = 0; !matches && kk < sums.length();
|
||||||
name = DictUtils.removeDictExtn( name );
|
++kk ) {
|
||||||
long nBytes = dict.optLong( "nBytes", -1 );
|
String sum = sums.getString( kk );
|
||||||
int nWords = dict.optInt( "nWords", -1 );
|
matches = sum.equals( curSum );
|
||||||
String note = dict.optString( "note" );
|
|
||||||
if ( 0 == note.length() ) {
|
|
||||||
note = null;
|
|
||||||
}
|
|
||||||
AvailDictInfo info =
|
|
||||||
new AvailDictInfo( name, isoCode, localLangName,
|
|
||||||
nWords, nBytes, note );
|
|
||||||
|
|
||||||
if ( !m_quickFetchMode ) {
|
|
||||||
// Check if we have it and it needs an update
|
|
||||||
if ( DictLangCache.haveDict( m_activity, isoCode, name )
|
|
||||||
&& !DictUtils.dictIsBuiltin( m_activity, name ) ) {
|
|
||||||
boolean matches = true;
|
|
||||||
JSONArray sums = dict.optJSONArray("md5sums");
|
|
||||||
if ( null != sums ) {
|
|
||||||
matches = false;
|
|
||||||
String[] curSums = DictLangCache.getDictMD5Sums( m_activity, name );
|
|
||||||
for ( String curSum : curSums ) {
|
|
||||||
for ( int kk = 0; !matches && kk < sums.length();
|
|
||||||
++kk ) {
|
|
||||||
String sum = sums.getString( kk );
|
|
||||||
matches = sum.equals( curSum );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( !matches ) {
|
|
||||||
Uri uri =
|
|
||||||
Utils.makeDictUriFromName( m_activity,
|
|
||||||
urlLangName, name );
|
|
||||||
m_needUpdates.put( name, uri );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dictNames.add( info );
|
if ( !matches ) {
|
||||||
}
|
Uri uri =
|
||||||
if ( 0 < dictNames.size() ) {
|
Utils.makeDictUriFromName( m_activity,
|
||||||
AvailDictInfo[] asArray = dictNames
|
urlLangName, name );
|
||||||
.toArray( new AvailDictInfo[dictNames.size()] );
|
m_needUpdates.put( name, uri );
|
||||||
Arrays.sort( asArray );
|
}
|
||||||
m_remoteInfo.put( localLangName, asArray );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dictNames.add( info );
|
||||||
|
}
|
||||||
|
if ( 0 < dictNames.size() ) {
|
||||||
|
AvailDictInfo[] asArray = dictNames
|
||||||
|
.toArray( new AvailDictInfo[dictNames.size()] );
|
||||||
|
Arrays.sort( asArray );
|
||||||
|
m_remoteInfo.put( localLangName, asArray );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return closedLangs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean digestData( String jsonData )
|
||||||
|
{
|
||||||
|
boolean success = false;
|
||||||
|
// JSONArray langs = null;
|
||||||
|
|
||||||
closedLangs.remove( m_filterLang );
|
m_needUpdates = new HashMap<>();
|
||||||
m_closedLangs.addAll( closedLangs );
|
if ( null != jsonData ) {
|
||||||
|
// DictLangCache hits the DB hundreds of times below. Fix!
|
||||||
|
Log.w( TAG, "Fix me I'm stupid" );
|
||||||
|
try {
|
||||||
|
Log.d( TAG, "digestData(%s)", jsonData );
|
||||||
|
JSONObject obj = new JSONObject( jsonData );
|
||||||
|
JSONArray langs = obj.optJSONArray( "langs" );
|
||||||
|
if ( null != langs ) {
|
||||||
|
Set<String> closedLangs = parseLangs( langs );
|
||||||
|
|
||||||
success = true;
|
closedLangs.remove( m_filterLang );
|
||||||
|
m_closedLangs.addAll( closedLangs );
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
} catch ( JSONException ex ) {
|
} catch ( JSONException ex ) {
|
||||||
Log.ex( TAG, ex );
|
Log.ex( TAG, ex );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue