mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
on startup, if you don't have a wordlist installed for your locale
install one. TODO: only do it once, since if user later deletes the wordlist he's presumed not to want it or to know how to install again; better completion message; set default language to match wordlist; deal with case where language has no wordlist (don't try again.)
This commit is contained in:
parent
398d5de369
commit
2c1ee29c2f
3 changed files with 131 additions and 4 deletions
|
@ -69,13 +69,13 @@ import org.eehouse.android.xw4.DictUtils.DictLoc;
|
||||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||||
import org.eehouse.android.xw4.jni.GameSummary;
|
import org.eehouse.android.xw4.jni.GameSummary;
|
||||||
import org.eehouse.android.xw4.loc.LocUtils;
|
import org.eehouse.android.xw4.loc.LocUtils;
|
||||||
|
import org.eehouse.android.xw4.DwnldDelegate.DownloadFinishedListener;
|
||||||
|
|
||||||
public class DictsDelegate extends ListDelegateBase
|
public class DictsDelegate extends ListDelegateBase
|
||||||
implements View.OnClickListener, AdapterView.OnItemLongClickListener,
|
implements View.OnClickListener, AdapterView.OnItemLongClickListener,
|
||||||
SelectableItem, MountEventReceiver.SDCardNotifiee,
|
SelectableItem, MountEventReceiver.SDCardNotifiee,
|
||||||
DlgDelegate.DlgClickNotify, GroupStateListener,
|
DlgDelegate.DlgClickNotify, GroupStateListener,
|
||||||
DwnldDelegate.DownloadFinishedListener,
|
DownloadFinishedListener, XWListItem.ExpandedListener {
|
||||||
XWListItem.ExpandedListener {
|
|
||||||
|
|
||||||
protected static final String DICT_SHOWREMOTE = "do_launch";
|
protected static final String DICT_SHOWREMOTE = "do_launch";
|
||||||
protected static final String DICT_LANG_EXTRA = "use_lang";
|
protected static final String DICT_LANG_EXTRA = "use_lang";
|
||||||
|
@ -989,6 +989,12 @@ public class DictsDelegate extends ListDelegateBase
|
||||||
downloadForResult( activity, requestCode, 0, null );
|
downloadForResult( activity, requestCode, 0, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void downloadDefaultDict( Context context, String lc,
|
||||||
|
DownloadFinishedListener lstnr )
|
||||||
|
{
|
||||||
|
new GetDefaultDictTask( context, lc, lstnr ).execute();
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// XWListItem.ExpandedListener interface
|
// XWListItem.ExpandedListener interface
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1086,6 +1092,75 @@ public class DictsDelegate extends ListDelegateBase
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class GetDefaultDictTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
private Context m_context;
|
||||||
|
private String m_lc;
|
||||||
|
private DownloadFinishedListener m_lstnr;
|
||||||
|
|
||||||
|
public GetDefaultDictTask( Context context, String lc,
|
||||||
|
DownloadFinishedListener lnr ) {
|
||||||
|
m_context = context;
|
||||||
|
m_lc = lc;
|
||||||
|
m_lstnr = lnr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doInBackground( Void... unused )
|
||||||
|
{
|
||||||
|
// FIXME: this should pass up the language code to retrieve and
|
||||||
|
// parse less data
|
||||||
|
HttpPost post = UpdateCheckReceiver.makePost( m_context, "listDicts" );
|
||||||
|
if ( null != post ) {
|
||||||
|
JSONObject theOne = null;
|
||||||
|
String langName = null;
|
||||||
|
String json = UpdateCheckReceiver.runPost( post, new JSONObject() );
|
||||||
|
try {
|
||||||
|
JSONObject obj = new JSONObject( json );
|
||||||
|
JSONArray langs = obj.optJSONArray( "langs" );
|
||||||
|
int nLangs = langs.length();
|
||||||
|
for ( int ii = 0; ii < nLangs; ++ii ) {
|
||||||
|
JSONObject langObj = langs.getJSONObject( ii );
|
||||||
|
String langCode = langObj.getString( "lc" );
|
||||||
|
if ( ! langCode.equals( m_lc ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// we have our language; look for one marked default;
|
||||||
|
// otherwise take the largest.
|
||||||
|
langName = langObj.getString( "lang" );
|
||||||
|
JSONArray dicts = langObj.getJSONArray( "dicts" );
|
||||||
|
int nDicts = dicts.length();
|
||||||
|
int theOneNWords = 0;
|
||||||
|
for ( int jj = 0; jj < nDicts; ++jj ) {
|
||||||
|
JSONObject dict = dicts.getJSONObject( jj );
|
||||||
|
if ( dict.optBoolean( "isDflt", false ) ) {
|
||||||
|
theOne = dict;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
int nWords = dict.getInt( "nWords" );
|
||||||
|
if ( null == theOne || nWords > theOneNWords ) {
|
||||||
|
theOne = dict;
|
||||||
|
theOneNWords = nWords;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch ( JSONException ex ) {
|
||||||
|
DbgUtils.loge( ex );
|
||||||
|
theOne = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( null != theOne ) {
|
||||||
|
String name = theOne.optString( "xwd" );
|
||||||
|
if ( null != name ) {
|
||||||
|
DwnldDelegate.downloadDictInBack( m_context, langName,
|
||||||
|
name, m_lstnr );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class FetchListTask extends AsyncTask<Void, Void, Boolean>
|
private class FetchListTask extends AsyncTask<Void, Void, Boolean>
|
||||||
implements OnCancelListener {
|
implements OnCancelListener {
|
||||||
private Context m_context;
|
private Context m_context;
|
||||||
|
|
|
@ -50,6 +50,7 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -63,12 +64,13 @@ import org.eehouse.android.xw4.jni.*;
|
||||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
||||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
|
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
|
||||||
import org.eehouse.android.xw4.loc.LocUtils;
|
import org.eehouse.android.xw4.loc.LocUtils;
|
||||||
|
import org.eehouse.android.xw4.DwnldDelegate.DownloadFinishedListener;
|
||||||
|
|
||||||
public class GamesListDelegate extends ListDelegateBase
|
public class GamesListDelegate extends ListDelegateBase
|
||||||
implements OnItemLongClickListener,
|
implements OnItemLongClickListener,
|
||||||
DBUtils.DBChangeListener, SelectableItem,
|
DBUtils.DBChangeListener, SelectableItem,
|
||||||
DwnldDelegate.DownloadFinishedListener,
|
DownloadFinishedListener, DlgDelegate.HasDlgDelegate,
|
||||||
DlgDelegate.HasDlgDelegate, GroupStateListener {
|
GroupStateListener {
|
||||||
|
|
||||||
|
|
||||||
private static final String SAVE_ROWID = "SAVE_ROWID";
|
private static final String SAVE_ROWID = "SAVE_ROWID";
|
||||||
|
@ -909,6 +911,8 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
|
|
||||||
askDefaultNameIf();
|
askDefaultNameIf();
|
||||||
|
|
||||||
|
getDictForLangIf();
|
||||||
|
|
||||||
m_origTitle = getTitle();
|
m_origTitle = getTitle();
|
||||||
} // init
|
} // init
|
||||||
|
|
||||||
|
@ -1865,6 +1869,36 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getDictForLangIf()
|
||||||
|
{
|
||||||
|
String lc = Locale.getDefault().getLanguage();
|
||||||
|
if ( !lc.equals("en") ) {
|
||||||
|
int code = LocUtils.codeForLangCode( m_activity, lc );
|
||||||
|
String[] names = DictLangCache.getHaveLang( m_activity, code );
|
||||||
|
if ( 0 == names.length ) {
|
||||||
|
DownloadFinishedListener lstnr = new DownloadFinishedListener() {
|
||||||
|
public void downloadFinished( final String lang,
|
||||||
|
String name,
|
||||||
|
boolean success ) {
|
||||||
|
if ( success ) {
|
||||||
|
runOnUiThread( new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
showGotDictForLang( lang );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
DictsDelegate.downloadDefaultDict( m_activity, lc, lstnr );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showGotDictForLang( String lang )
|
||||||
|
{
|
||||||
|
showOKOnlyDialog( String.format( "got dict for %s", lang ) );
|
||||||
|
}
|
||||||
|
|
||||||
private void updateField()
|
private void updateField()
|
||||||
{
|
{
|
||||||
String newField = CommonPrefs.getSummaryField( m_activity );
|
String newField = CommonPrefs.getSummaryField( m_activity );
|
||||||
|
|
|
@ -142,6 +142,24 @@ public class LocUtils {
|
||||||
return xlated;
|
return xlated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Map<String, Integer> s_langCodeMap = null;
|
||||||
|
public static int codeForLangCode( Context context, String lc )
|
||||||
|
{
|
||||||
|
if ( null == s_langCodeMap ) {
|
||||||
|
s_langCodeMap = new HashMap<String, Integer>();
|
||||||
|
String[] langCodes =
|
||||||
|
context.getResources().getStringArray( R.array.language_codes );
|
||||||
|
for ( int ii = 0; ii < langCodes.length; ++ii ) {
|
||||||
|
String item = langCodes[ii];
|
||||||
|
if ( 0 < item.length() ) {
|
||||||
|
s_langCodeMap.put( item, ii );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s_langCodeMap.get( lc );
|
||||||
|
}
|
||||||
|
|
||||||
public static void xlateView( Activity activity )
|
public static void xlateView( Activity activity )
|
||||||
{
|
{
|
||||||
xlateView( activity, Utils.getContentView( activity ) );
|
xlateView( activity, Utils.getContentView( activity ) );
|
||||||
|
|
Loading…
Add table
Reference in a new issue