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
*/
public static final int msgs_progress=0x7f06009d;
public static final int nag_body_fmt=0x7f0602c6;
/** Nagging
*/
public static final int nag_title=0x7f0602c5;
public static final int nag_warn_last=0x7f0602c7;
public static final int name_dict_fmt=0x7f060086;
/** text of checkbox. If this checkbox is checked, games created
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>
<!-- 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>

View file

@ -1938,5 +1938,7 @@
<string name="force_tablet_title">Ecrof telbat tuoyal</string>
<string name="force_tablet_summary">Neve fi ym neercs si oot llams</string>
<!-- 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>

View file

@ -1938,5 +1938,7 @@
<string name="force_tablet_title">FORCE TABLET LAYOUT</string>
<string name="force_tablet_summary">EVEN IF MY SCREEN IS TOO SMALL</string>
<!-- 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>

View file

@ -31,11 +31,17 @@ import java.util.Date;
import junit.framework.Assert;
import org.eehouse.android.xw4.DBUtils.NeedsNagInfo;
import org.eehouse.android.xw4.loc.LocUtils;
public class NagTurnReceiver extends BroadcastReceiver {
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
public void onReceive( Context context, Intent intent )
@ -47,13 +53,21 @@ public class NagTurnReceiver extends BroadcastReceiver {
long now = new Date().getTime(); // in milliseconds
for ( NeedsNagInfo info : needNagging ) {
Assert.assertTrue( info.m_nextNag < now );
info.m_nextNag = figureNextNag( info.m_lastMoveMillis );
boolean lastWarning = 0 == info.m_nextNag;
long rowid = info.m_rowid;
Intent msgIntent = GamesListDelegate.makeRowidIntent( context, rowid );
String body = String.format( "It's been your turn in game %d for %d seconds",
rowid, (now - info.m_lastMoveMillis)/ 1000 );
Utils.postNotification( context, msgIntent, R.string.nag_title, body, (int)rowid );
// Change this to hours or days before ship
int nMinutes = (int)(now - info.m_lastMoveMillis) / (1000 * 60);
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 );
@ -91,12 +105,19 @@ public class NagTurnReceiver extends BroadcastReceiver {
public static long figureNextNag( long moveTimeMillis )
{
long result = 0;
long now = new Date().getTime(); // in milliseconds
while ( moveTimeMillis < now ) {
moveTimeMillis += NAG_INTERVAL;
Assert.assertTrue( now >= moveTimeMillis );
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 );
return moveTimeMillis;
DbgUtils.logf( "figureNextNag => %d (%s)", result,
DbgUtils.millisToDateStr(result) );
return result;
}
}