don't show check-for-updates menuitem unless we can update something: we're not installed from the Play store OR we've installed at least one wordlist.

This commit is contained in:
Eric House 2014-03-24 07:37:44 -07:00
parent b4df0125cc
commit 6256e2a843
2 changed files with 44 additions and 13 deletions

View file

@ -77,7 +77,6 @@ public class GamesList extends XWExpandableListActivity
private static final int[] DEBUG_ITEMS = {
// R.id.games_menu_loaddb,
R.id.games_menu_storedb,
R.id.games_menu_checkupdates,
};
private static final int[] NOSEL_ITEMS = {
R.id.games_menu_newgroup,
@ -658,6 +657,10 @@ public class GamesList extends XWExpandableListActivity
showItemsIf( ONEGAME_ITEMS, menu, 1 == nGamesSelected );
showItemsIf( ONEGROUP_ITEMS, menu, 1 == nGroupsSelected );
boolean enable = showDbg && nothingSelected
&& UpdateCheckReceiver.haveToCheck( this );
Utils.setItemVisible( menu, R.id.games_menu_checkupdates, enable );
int selGroupPos = -1;
if ( 1 == nGroupsSelected ) {
long id = m_selGroupIDs.iterator().next();
@ -677,7 +680,7 @@ public class GamesList extends XWExpandableListActivity
// selected
Utils.setItemVisible( menu, R.id.games_group_moveup,
0 < selGroupPos );
boolean enable = 0 <= selGroupPos
enable = 0 <= selGroupPos
&& (selGroupPos + 1) < m_adapter.getGroupCount();
Utils.setItemVisible( menu, R.id.games_group_movedown, enable );

View file

@ -103,6 +103,16 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
interval_millis, pi );
}
// Is app upgradeable OR have we installed any dicts?
public static boolean haveToCheck( Context context )
{
boolean result = !Utils.isGooglePlayApp( context );
if ( !result ) { // give another chance
result = null != getDownloadedDicts( context );
}
return result;
}
public static void checkVersions( Context context, boolean fromUI )
{
JSONObject params = new JSONObject();
@ -134,18 +144,12 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
DbgUtils.loge( jse );
}
}
JSONArray dictParams = new JSONArray();
DictUtils.DictAndLoc[] dals = DictUtils.dictList( context );
for ( int ii = 0; ii < dals.length; ++ii ) {
DictUtils.DictAndLoc dal = dals[ii];
switch ( dal.loc ) {
// case DOWNLOAD:
case EXTERNAL:
case INTERNAL:
dictParams.put( makeDictParams( context, dal, ii ) );
DictUtils.DictAndLoc[] dals = getDownloadedDicts( context );
if ( null != dals ) {
JSONArray dictParams = new JSONArray();
for ( int ii = 0; ii < dals.length; ++ii ) {
dictParams.put( makeDictParams( context, dals[ii], ii ) );
}
}
if ( 0 < dictParams.length() ) {
try {
params.put( k_DICTS, dictParams );
params.put( k_DEVID, XWPrefs.getDevID( context ) );
@ -160,6 +164,30 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
}
}
private static DictUtils.DictAndLoc[] getDownloadedDicts( Context context )
{
DictUtils.DictAndLoc[] result = null;
DictUtils.DictAndLoc[] dals = DictUtils.dictList( context );
DictUtils.DictAndLoc[] tmp = new DictUtils.DictAndLoc[dals.length];
int indx = 0;
for ( int ii = 0; ii < dals.length; ++ii ) {
DictUtils.DictAndLoc dal = dals[ii];
switch ( dal.loc ) {
// case DOWNLOAD:
case EXTERNAL:
case INTERNAL:
tmp[indx++] = dal;
break;
}
}
if ( 0 < indx ) {
result = new DictUtils.DictAndLoc[indx];
System.arraycopy( tmp, 0, result, 0, indx );
}
return result;
}
private static HttpPost makePost( Context context, String proc )
{
String url = String.format( "%s/%s",