fix nag timers firing when display disabled

Logic to set the fire time in the future wasn't firing when display of
the nag was diabled, so timers fired every few ms because they always
existed in the past.
This commit is contained in:
Eric House 2022-06-22 20:45:31 -07:00
parent 2f6680b9a3
commit b0d0fa8da7
2 changed files with 31 additions and 32 deletions

View file

@ -79,41 +79,40 @@ public class NagTurnReceiver {
for ( NeedsNagInfo info : needNagging ) {
Assert.assertTrueNR( info.m_nextNag < now );
// Skip processing if notifications disabled for this type
// of game
if ( s_nagsDisabledSolo && info.isSolo() ) {
continue;
} else if ( s_nagsDisabledNet && !info.isSolo() ) {
continue;
}
info.m_nextNag = figureNextNag( context,
info.m_lastMoveMillis );
boolean lastWarning = 0 == info.m_nextNag;
long rowid = info.m_rowid;
GameSummary summary = GameUtils.getSummary( context, rowid,
10 );
String prevPlayer = null == summary
? LocUtils.getString(context, R.string.prev_player)
: summary.getPrevPlayer();
// Skip display of notifications disabled for this type
// of game
if ( s_nagsDisabledSolo && info.isSolo() ) {
// do nothing
} else if ( s_nagsDisabledNet && !info.isSolo() ) {
// do nothing
} else {
boolean lastWarning = 0 == info.m_nextNag;
long rowid = info.m_rowid;
GameSummary summary = GameUtils.getSummary( context, rowid,
10 );
String prevPlayer = null == summary
? LocUtils.getString(context, R.string.prev_player)
: summary.getPrevPlayer();
Intent msgIntent =
GamesListDelegate.makeRowidIntent( context, rowid );
String millis = formatMillis( context,
now - info.m_lastMoveMillis);
String body =
String.format( LocUtils.getString(context,
R.string.nag_body_fmt),
prevPlayer, millis );
if ( lastWarning ) {
body = LocUtils
.getString( context, R.string.nag_warn_last_fmt, body );
Intent msgIntent =
GamesListDelegate.makeRowidIntent( context, rowid );
String millis = formatMillis( context,
now - info.m_lastMoveMillis);
String body =
String.format( LocUtils.getString(context,
R.string.nag_body_fmt),
prevPlayer, millis );
if ( lastWarning ) {
body = LocUtils
.getString( context, R.string.nag_warn_last_fmt, body );
}
Utils.postNotification( context, msgIntent,
R.string.nag_title, body,
rowid );
}
Utils.postNotification( context, msgIntent,
R.string.nag_title, body,
rowid );
}
DBUtils.updateNeedNagging( context, needNagging );

View file

@ -373,8 +373,8 @@ public class TimerReceiver extends BroadcastReceiver {
final long curNextFire = data.getFor( CLIENT_STATS, KEY_NEXT_FIRE, 0 );
if ( 1000L < Math.abs( firstFireTime - curNextFire ) ) {
if ( firstFireTime - now < MIN_FUTURE ) { // Less than a 2 seconds in the future?
Log.d( TAG, "moving firstFireTime to the future: %s -> %s",
fmtLong(firstFireTime), fmtLong(now + MIN_FUTURE) );
Log.d( TAG, "setNextTimer(): moving firstFireTime (for %s) to the future: %s -> %s",
firstClient, fmtLong(firstFireTime), fmtLong(now + MIN_FUTURE) );
firstFireTime = now + MIN_FUTURE;
data.setFor( firstClient, KEY_FIREWHEN, firstFireTime );
}