enable changing reminder intervals via debug setting, and format time

since last move dynamically using days, hours and minutes.
This commit is contained in:
Eric House 2014-08-22 20:37:50 -07:00
parent e42dd971cb
commit d255231179
8 changed files with 725 additions and 624 deletions

File diff suppressed because it is too large Load diff

View file

@ -115,6 +115,7 @@
<string name="key_na_dicts">key_na_dicts</string> <string name="key_na_dicts">key_na_dicts</string>
<string name="key_enable_debug">key_enable_debug</string> <string name="key_enable_debug">key_enable_debug</string>
<string name="key_enable_dup_invite">key_enable_dup_invite</string> <string name="key_enable_dup_invite">key_enable_dup_invite</string>
<string name="key_nag_intervals">key_nag_intervals</string>
<string name="key_download_path">key_download_path</string> <string name="key_download_path">key_download_path</string>
<string name="key_xlations_locale">key_xlations_locale</string> <string name="key_xlations_locale">key_xlations_locale</string>
<string name="key_xlations_enabled">key_xlations_enabled</string> <string name="key_xlations_enabled">key_xlations_enabled</string>
@ -162,7 +163,7 @@
<string name="enable_dupes_title">Accept duplicate invites</string> <string name="enable_dupes_title">Accept duplicate invites</string>
<string name="xlations_locale">Fake locale for translation</string> <string name="xlations_locale">Fake locale for translation</string>
<string name="enable_dupes_summary">Accept invitations more than once</string> <string name="enable_dupes_summary">Accept invitations more than once</string>
<string name="nag_intervals">Reminder intervals (minutes1,minutes2,...)</string>
<!--string name="dict_url">http://10.0.2.2/~eehouse/and_dicts</string--> <!--string name="dict_url">http://10.0.2.2/~eehouse/and_dicts</string-->
<string-array name="board_sizes"> <string-array name="board_sizes">

View file

@ -2268,10 +2268,17 @@
<!-- Nagging: title of notification reminder message --> <!-- Nagging: title of notification reminder message -->
<string name="nag_title">Reminder: It\'s your turn</string> <string name="nag_title">Reminder: It\'s your turn</string>
<!-- body of warning notification reminder message --> <!-- body of warning notification reminder message. First three
<string name="nag_body_fmt">%1$s moved more than %2$d hours ago.</string> are used to build a string based on the length of time that's then
inserted in the fourth. E.g "PlayerName moved more than 2 day[s],
4 hour[s] ago." -->
<string name="nag_minutes_fmt">%1$d minute[s]</string>
<string name="nag_hours_fmt">%1$d hour[s]</string>
<string name="nag_days_fmt">%1$d day[s]</string>
<string name="nag_body_fmt">%1$s moved more than %2$s ago.</string>
<!-- above is inserted in this the last time I warn --> <!-- above is inserted in this the last time I warn -->
<string name="nag_warn_last_fmt">Last warning: %1$s</string> <string name="nag_warn_last_fmt">Last warning: %1$s</string>
<!-- Used when prev player's name can't be looked up --> <!-- Used when prev player's name can't be looked up -->
<string name="prev_player">Your opponent</string> <string name="prev_player">Your opponent</string>
</resources> </resources>

View file

@ -315,6 +315,11 @@
android:defaultValue="false" android:defaultValue="false"
/> />
<org.eehouse.android.xw4.XWEditTextPreference
android:key="@string/key_nag_intervals"
android:title="@string/nag_intervals"
/>
<CheckBoxPreference android:key="@string/key_enable_dup_invite" <CheckBoxPreference android:key="@string/key_enable_dup_invite"
android:title="@string/enable_dupes_title" android:title="@string/enable_dupes_title"
android:summary="@string/enable_dupes_summary" android:summary="@string/enable_dupes_summary"

View file

@ -1939,8 +1939,14 @@
<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: title of notification reminder message --> <!-- Nagging: title of notification reminder message -->
<string name="nag_title">Rednimer: Ti\'s ruoy nrut</string> <string name="nag_title">Rednimer: Ti\'s ruoy nrut</string>
<!-- body of warning notification reminder message --> <!-- body of warning notification reminder message. First three
<string name="nag_body_fmt">%1$s devom erom naht %2$d sruoh oga.</string> are used to build a string based on the length of time that's then
inserted in the fourth. E.g "PlayerName moved more than 2 day[s],
4 hour[s] ago." -->
<string name="nag_minutes_fmt">%1$d ]s[etunim</string>
<string name="nag_hours_fmt">%1$d ]s[ruoh</string>
<string name="nag_days_fmt">%1$d ]s[yad</string>
<string name="nag_body_fmt">%1$s devom erom naht %2$s oga.</string>
<!-- above is inserted in this the last time I warn --> <!-- above is inserted in this the last time I warn -->
<string name="nag_warn_last_fmt">Tsal gninraw: %1$s</string> <string name="nag_warn_last_fmt">Tsal gninraw: %1$s</string>
<!-- Used when prev player's name can't be looked up --> <!-- Used when prev player's name can't be looked up -->

View file

@ -1939,8 +1939,14 @@
<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: title of notification reminder message --> <!-- Nagging: title of notification reminder message -->
<string name="nag_title">REMINDER: IT\'S YOUR TURN</string> <string name="nag_title">REMINDER: IT\'S YOUR TURN</string>
<!-- body of warning notification reminder message --> <!-- body of warning notification reminder message. First three
<string name="nag_body_fmt">%1$s MOVED MORE THAN %2$d HOURS AGO.</string> are used to build a string based on the length of time that's then
inserted in the fourth. E.g "PlayerName moved more than 2 day[s],
4 hour[s] ago." -->
<string name="nag_minutes_fmt">%1$d MINUTE[S]</string>
<string name="nag_hours_fmt">%1$d HOUR[S]</string>
<string name="nag_days_fmt">%1$d DAY[S]</string>
<string name="nag_body_fmt">%1$s MOVED MORE THAN %2$s AGO.</string>
<!-- above is inserted in this the last time I warn --> <!-- above is inserted in this the last time I warn -->
<string name="nag_warn_last_fmt">LAST WARNING: %1$s</string> <string name="nag_warn_last_fmt">LAST WARNING: %1$s</string>
<!-- Used when prev player's name can't be looked up --> <!-- Used when prev player's name can't be looked up -->

View file

@ -290,7 +290,8 @@ public class DBUtils {
values.put( DBHelper.GAME_OVER, summary.gameOver? 1 : 0 ); values.put( DBHelper.GAME_OVER, summary.gameOver? 1 : 0 );
values.put( DBHelper.LASTMOVE, summary.lastMoveTime ); values.put( DBHelper.LASTMOVE, summary.lastMoveTime );
long nextNag = summary.nextTurnIsLocal() ? long nextNag = summary.nextTurnIsLocal() ?
NagTurnReceiver.figureNextNag( 1000*(long)summary.lastMoveTime ) NagTurnReceiver.figureNextNag( context,
1000*(long)summary.lastMoveTime )
: 0; : 0;
values.put( DBHelper.NEXTNAG, nextNag ); values.put( DBHelper.NEXTNAG, nextNag );

View file

@ -26,6 +26,9 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.SystemClock; import android.os.SystemClock;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Date; import java.util.Date;
import junit.framework.Assert; import junit.framework.Assert;
@ -45,6 +48,12 @@ public class NagTurnReceiver extends BroadcastReceiver {
60*60*24*3, // three days 60*60*24*3, // three days
}; };
private static final int[][] s_fmtData = {
{ 60*60*24, R.string.nag_days_fmt },
{ 60*60, R.string.nag_hours_fmt },
{ 60, R.string.nag_minutes_fmt },
};
@Override @Override
public void onReceive( Context context, Intent intent ) public void onReceive( Context context, Intent intent )
{ {
@ -54,7 +63,7 @@ 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 ); info.m_nextNag = figureNextNag( context, info.m_lastMoveMillis );
boolean lastWarning = 0 == info.m_nextNag; boolean lastWarning = 0 == info.m_nextNag;
long rowid = info.m_rowid; long rowid = info.m_rowid;
@ -64,9 +73,12 @@ public class NagTurnReceiver extends BroadcastReceiver {
: summary.getPrevPlayer(); : summary.getPrevPlayer();
Intent msgIntent = GamesListDelegate.makeRowidIntent( context, rowid ); Intent msgIntent = GamesListDelegate.makeRowidIntent( context, rowid );
int nHours = (int)(now - info.m_lastMoveMillis) / (1000 * 60 * 60); String body =
String body = String.format( LocUtils.getString(context, R.string.nag_body_fmt), String.format( LocUtils.getString(context,
prevPlayer, nHours ); R.string.nag_body_fmt),
prevPlayer,
formatMillis( context,
now - info.m_lastMoveMillis) );
if ( lastWarning ) { if ( lastWarning ) {
body = LocUtils body = LocUtils
.getString( context, R.string.nag_warn_last_fmt, body ); .getString( context, R.string.nag_warn_last_fmt, body );
@ -106,12 +118,13 @@ public class NagTurnReceiver extends BroadcastReceiver {
} }
} }
public static long figureNextNag( long moveTimeMillis ) public static long figureNextNag( Context context, long moveTimeMillis )
{ {
long result = 0; long result = 0;
long now = new Date().getTime(); // in milliseconds long now = new Date().getTime(); // in milliseconds
Assert.assertTrue( now >= moveTimeMillis ); Assert.assertTrue( now >= moveTimeMillis );
for ( long nSecs : NAG_INTERVAL_SECONDS ) { long[] intervals = getIntervals( context );
for ( long nSecs : intervals ) {
long asMillis = moveTimeMillis + (nSecs * 1000); long asMillis = moveTimeMillis + (nSecs * 1000);
if ( asMillis >= now ) { if ( asMillis >= now ) {
result = asMillis; result = asMillis;
@ -121,4 +134,61 @@ public class NagTurnReceiver extends BroadcastReceiver {
return result; return result;
} }
private static long[] s_lastIntervals = null;
private static String s_lastStr = null;
private static long[] getIntervals( Context context )
{
long[] result = null;
String pref =
XWPrefs.getPrefsString( context, R.string.key_nag_intervals );
if ( null != pref && 0 < pref.length() ) {
if ( pref.equals( s_lastStr ) ) {
result = s_lastIntervals;
} else {
String[] strs = TextUtils.split( pref, "," );
ArrayList<Long> al = new ArrayList<Long>();
for ( String str : strs ) {
try {
long value = Long.parseLong(str);
if ( 0 < value ) {
al.add(value);
}
} catch ( Exception ex ) {
DbgUtils.loge(ex);
}
}
if ( 0 < al.size() ) {
result = new long[al.size()];
Iterator<Long> iter = al.iterator();
for ( int ii = 0; iter.hasNext(); ++ii ) {
result[ii] = 60 * iter.next();
}
}
s_lastStr = pref;
s_lastIntervals = result;
}
}
if ( null == result ) {
result = NAG_INTERVAL_SECONDS;
}
return result;
}
private static String formatMillis( Context context, long millis )
{
long seconds = millis / 1000;
ArrayList<String> results = new ArrayList<String>();
for ( int[] datum : s_fmtData ) {
long val = seconds / datum[0];
if ( 1 <= val ) {
results.add( LocUtils.getString( context, datum[1], val ) );
seconds %= datum[0];
}
}
String result = TextUtils.join( ", ", results );
DbgUtils.logf( "formatMillis(%d) => %s", millis, result );
return result;
}
} }