nag based on a array of times rather than a fixed interval, and append

an additional warning after the last is used.
This commit is contained in:
Eric House 2014-08-10 19:58:03 -07:00
parent 8c3180573a
commit 3655d0c9ff
5 changed files with 42 additions and 13 deletions

View file

@ -1605,9 +1605,11 @@ public final class R {
/** Text of progress indicator shown while check is being conducted /** Text of progress indicator shown while check is being conducted
*/ */
public static final int msgs_progress=0x7f06009d; public static final int msgs_progress=0x7f06009d;
public static final int nag_body_fmt=0x7f0602c6;
/** Nagging /** Nagging
*/ */
public static final int nag_title=0x7f0602c5; public static final int nag_title=0x7f0602c5;
public static final int nag_warn_last=0x7f0602c7;
public static final int name_dict_fmt=0x7f060086; public static final int name_dict_fmt=0x7f060086;
/** text of checkbox. If this checkbox is checked, games created /** text of checkbox. If this checkbox is checked, games created
for network play will by default have the hint feature for network play will by default have the hint feature

View file

@ -2267,5 +2267,7 @@
<string name="force_tablet_summary">Even if my screen is too small</string> <string name="force_tablet_summary">Even if my screen is too small</string>
<!-- Nagging --> <!-- Nagging -->
<string name="nag_title">Make your move already</string> <string name="nag_title">Reminder: It\'s your turn</string>
<string name="nag_body_fmt">And it\'s been your turn for more than %1$d minutes.</string>
<string name="nag_warn_last">(This is your last warning.)</string>
</resources> </resources>

View file

@ -1938,5 +1938,7 @@
<string name="force_tablet_title">Ecrof telbat tuoyal</string> <string name="force_tablet_title">Ecrof telbat tuoyal</string>
<string name="force_tablet_summary">Neve fi ym neercs si oot llams</string> <string name="force_tablet_summary">Neve fi ym neercs si oot llams</string>
<!-- Nagging --> <!-- Nagging -->
<string name="nag_title">Ekam ruoy evom ydaerla</string> <string name="nag_title">Rednimer: Ti\'s ruoy nrut</string>
<string name="nag_body_fmt">Dna ti\'s neeb ruoy nrut rof erom naht %1$d setunim</string>
<string name="nag_warn_last">sIht( si ruoy tsal gninraw.)</string>
</resources> </resources>

View file

@ -1938,5 +1938,7 @@
<string name="force_tablet_title">FORCE TABLET LAYOUT</string> <string name="force_tablet_title">FORCE TABLET LAYOUT</string>
<string name="force_tablet_summary">EVEN IF MY SCREEN IS TOO SMALL</string> <string name="force_tablet_summary">EVEN IF MY SCREEN IS TOO SMALL</string>
<!-- Nagging --> <!-- Nagging -->
<string name="nag_title">MAKE YOUR MOVE ALREADY</string> <string name="nag_title">REMINDER: IT\'S YOUR TURN</string>
<string name="nag_body_fmt">AND IT\'S BEEN YOUR TURN FOR MORE THAN %1$d MINUTES</string>
<string name="nag_warn_last">(THIS IS YOUR LAST WARNING.)</string>
</resources> </resources>

View file

@ -31,11 +31,17 @@ import java.util.Date;
import junit.framework.Assert; import junit.framework.Assert;
import org.eehouse.android.xw4.DBUtils.NeedsNagInfo; import org.eehouse.android.xw4.DBUtils.NeedsNagInfo;
import org.eehouse.android.xw4.loc.LocUtils;
public class NagTurnReceiver extends BroadcastReceiver { public class NagTurnReceiver extends BroadcastReceiver {
private static final long INTERVAL_MILLIS = 1000 * 30; // every half minute for now private static final long INTERVAL_MILLIS = 1000 * 30; // every half minute for now
private static final long NAG_INTERVAL = 1000 * 60 * 30; // 90 seconds for now private static final long[] NAG_INTERVAL_SECONDS = {2*60, // five minutes (for testing)
5*60,
// 60*1*24, // one day
// 60*2*24, // two days
// 60*3*24, // three days
};
@Override @Override
public void onReceive( Context context, Intent intent ) public void onReceive( Context context, Intent intent )
@ -47,13 +53,21 @@ public class NagTurnReceiver extends BroadcastReceiver {
long now = new Date().getTime(); // in milliseconds long now = new Date().getTime(); // in milliseconds
for ( NeedsNagInfo info : needNagging ) { for ( NeedsNagInfo info : needNagging ) {
Assert.assertTrue( info.m_nextNag < now ); Assert.assertTrue( info.m_nextNag < now );
info.m_nextNag = figureNextNag( info.m_lastMoveMillis );
boolean lastWarning = 0 == info.m_nextNag;
long rowid = info.m_rowid; long rowid = info.m_rowid;
Intent msgIntent = GamesListDelegate.makeRowidIntent( context, rowid ); Intent msgIntent = GamesListDelegate.makeRowidIntent( context, rowid );
String body = String.format( "It's been your turn in game %d for %d seconds", // Change this to hours or days before ship
rowid, (now - info.m_lastMoveMillis)/ 1000 ); int nMinutes = (int)(now - info.m_lastMoveMillis) / (1000 * 60);
Utils.postNotification( context, msgIntent, R.string.nag_title, body, (int)rowid ); String body = String.format( LocUtils.getString(context, R.string.nag_body_fmt),
nMinutes );
if ( lastWarning ) {
body += " " + LocUtils.getString( context, R.string.nag_warn_last );
}
Utils.postNotification( context, msgIntent, R.string.nag_title,
body, (int)rowid );
info.m_nextNag = figureNextNag( info.m_lastMoveMillis );
} }
DBUtils.updateNeedNagging( context, needNagging ); DBUtils.updateNeedNagging( context, needNagging );
@ -91,12 +105,19 @@ public class NagTurnReceiver extends BroadcastReceiver {
public static long figureNextNag( long moveTimeMillis ) public static long figureNextNag( long moveTimeMillis )
{ {
long result = 0;
long now = new Date().getTime(); // in milliseconds long now = new Date().getTime(); // in milliseconds
while ( moveTimeMillis < now ) { Assert.assertTrue( now >= moveTimeMillis );
moveTimeMillis += NAG_INTERVAL; for ( long nSecs : NAG_INTERVAL_SECONDS ) {
long asMillis = moveTimeMillis + (nSecs * 1000);
if ( asMillis >= now ) {
result = asMillis;
break;
}
} }
DbgUtils.logf( "figureNextNag => %d (%d seconds in future)", moveTimeMillis,
(moveTimeMillis - now) / 1000 ); DbgUtils.logf( "figureNextNag => %d (%s)", result,
return moveTimeMillis; DbgUtils.millisToDateStr(result) );
return result;
} }
} }