resend all messages from the network change broadcast receiver itself instead of GamesList, which will not be listening if another activity is in front or if the app's in the background.

This commit is contained in:
Eric House 2014-03-04 19:03:39 -08:00
parent 3c0b4a899f
commit cfee7ef8ac
3 changed files with 7 additions and 37 deletions

View file

@ -153,9 +153,6 @@
<string name="enable_dupes_title">Accept duplicate invites</string>
<string name="enable_dupes_summary">Accept invitations more than once</string>
<string name="net_change_gained">Network connectivity GAINED</string>
<string name="net_change_lost">Network connectivity LOST</string>
<!--string name="dict_url">http://10.0.2.2/~eehouse/and_dicts</string-->
<string-array name="board_sizes">

View file

@ -60,8 +60,7 @@ import org.eehouse.android.xw4.jni.*;
public class GamesList extends XWExpandableListActivity
implements OnItemLongClickListener,
DBUtils.DBChangeListener, SelectableItem,
DictImportActivity.DownloadFinishedListener,
NetStateCache.StateChangedIf {
DictImportActivity.DownloadFinishedListener {
private static final int WARN_NODICT = DlgDelegate.DIALOG_LAST + 1;
private static final int WARN_NODICT_SUBST = WARN_NODICT + 1;
@ -135,7 +134,6 @@ public class GamesList extends XWExpandableListActivity
private GameNamer m_namer;
private long m_launchedGame = DBUtils.ROWID_NOTFOUND;
private boolean m_menuPrepared;
private boolean m_netAvail;
private HashSet<Long> m_selGames;
private HashSet<Long> m_selGroupIDs;
private CharSequence m_origTitle;
@ -375,8 +373,6 @@ public class GamesList extends XWExpandableListActivity
CrashTrack.init( this );
m_netAvail = NetStateCache.netAvail( this );
m_selGames = new HashSet<Long>();
m_selGroupIDs = new HashSet<Long>();
getBundledData( savedInstanceState );
@ -417,17 +413,9 @@ public class GamesList extends XWExpandableListActivity
tryStartsFromIntent( intent );
}
@Override
protected void onStart()
{
super.onStart();
NetStateCache.register( this, this );
}
@Override
protected void onStop()
{
NetStateCache.unregister( this, this );
// TelephonyManager mgr =
// (TelephonyManager)getSystemService( Context.TELEPHONY_SERVICE );
// mgr.listen( m_phoneStateListener, PhoneStateListener.LISTEN_NONE );
@ -956,23 +944,6 @@ public class GamesList extends XWExpandableListActivity
} );
}
//////////////////////////////////////////////////////////////////////
// NetStateCache.StateChangedIf
//////////////////////////////////////////////////////////////////////
public void netAvail( boolean nowAvailable )
{
if ( m_netAvail != nowAvailable ) {
m_netAvail = nowAvailable;
if ( BuildConfig.DEBUG ) {
int id = nowAvailable ?
R.string.net_change_gained : R.string.net_change_lost;
Utils.showToast( this, id );
DbgUtils.logf( "GamesList.netAvail(%s)", getString( id ) );
}
GameUtils.resendAllIf( this, false );
}
}
private void setTitleBar()
{
int fmt = 0;

View file

@ -107,7 +107,7 @@ public class NetStateCache {
}
@Override
public void onReceive( Context context, Intent intent )
public void onReceive( final Context context, Intent intent )
{
DbgUtils.assertOnUIThread();
@ -117,8 +117,6 @@ public class NetStateCache {
NetworkInfo ni = (NetworkInfo)intent.
getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
NetworkInfo.State state = ni.getState();
DbgUtils.logf( "PvtBroadcastReceiver.onReceive: "
+ "new network state: %s", state.toString() );
boolean netAvail;
switch ( state ) {
@ -151,15 +149,19 @@ public class NetStateCache {
mNotifyLater = new Runnable() {
@Override
public void run() {
DbgUtils.logf( "PvtBroadcastReceiver: run() fired." );
Assert.assertTrue( mLastStateSent != s_netAvail );
mLastStateSent = s_netAvail;
synchronized( s_ifs ) {
Iterator<StateChangedIf> iter = s_ifs.iterator();
while ( iter.hasNext() ) {
iter.next().netAvail( s_netAvail );
}
}
if ( s_netAvail ) {
GameUtils.resendAllIf( context, false );
}
}
};
mHandler.postDelayed( mNotifyLater, WAIT_STABLE_MILLIS );