add prefs checkbox to disable it's-your-turn notifications

This commit is contained in:
Eric House 2015-03-23 07:30:42 -07:00
parent bd7bfb328e
commit 2631ab1094
8 changed files with 828 additions and 777 deletions

File diff suppressed because it is too large Load diff

View file

@ -11,6 +11,7 @@
<string name="key_square_tiles">key_square_tiles</string>
<string name="key_explain_robot">key_explain_robot</string>
<string name="key_skip_confirm">key_skip_confirm</string>
<string name="key_disable_nag">key_disable_nag</string>
<string name="key_sort_tiles">key_sort_tiles</string>
<string name="key_peek_other">key_peek_other</string>
<string name="key_hide_crosshairs">key_hide_crosshairs</string>

View file

@ -2393,6 +2393,10 @@
and want them back, enable them now. You can turn them off again
in Settings.</string>
<string name="disable_nag_title">Disable turn reminders</string>
<string name="disable_nag_summary">Do not notify me no matter
how long it\'s been my turn</string>
<!-- Debugging stuff. Localize if you think your langauge users will
care. -->
<string name="advanced">For debugging</string>

View file

@ -231,6 +231,11 @@
android:summary="@string/skip_confirm_turn_summary"
android:defaultValue="false"
/>
<CheckBoxPreference android:key="@string/key_disable_nag"
android:title="@string/disable_nag_title"
android:summary="@string/disable_nag_summary"
android:defaultValue="false"
/>
<CheckBoxPreference android:key="@string/key_default_loc"
android:title="@string/default_loc"
android:summary="@string/default_loc_summary"

View file

@ -2073,6 +2073,9 @@
na \"decnavda\" erutaef ni siht esaeler. Fi uoy erew gnisu meht
dna tnaw meht ,kcab elbane meht won. Uoy nac nrut meht ffo niaga
ni Sgnittes.</string>
<string name="disable_nag_title">Elbasid nrut srednimer</string>
<string name="disable_nag_summary">Od ton yfiton em on rettam
woh gnol ti\'s neeb ym nrut</string>
<!-- Debugging stuff. Localize if you think your langauge users will
care. -->
<string name="advanced">Rof gniggubed</string>

View file

@ -2073,6 +2073,9 @@
AN \"ADVANCED\" FEATURE IN THIS RELEASE. IF YOU WERE USING THEM
AND WANT THEM BACK, ENABLE THEM NOW. YOU CAN TURN THEM OFF AGAIN
IN SETTINGS.</string>
<string name="disable_nag_title">DISABLE TURN REMINDERS</string>
<string name="disable_nag_summary">DO NOT NOTIFY ME NO MATTER
HOW LONG IT\'S BEEN MY TURN</string>
<!-- Debugging stuff. Localize if you think your langauge users will
care. -->
<string name="advanced">FOR DEBUGGING</string>

View file

@ -54,37 +54,44 @@ public class NagTurnReceiver extends BroadcastReceiver {
{ 60, R.plurals.nag_minutes_fmt },
};
private static Boolean s_nagsDisabled = null;
@Override
public void onReceive( Context context, Intent intent )
{
// loop through all games testing who's been sitting on a turn
if ( !getNagsDisabled( context ) ) {
NeedsNagInfo[] needNagging = DBUtils.getNeedNagging( context );
if ( null != needNagging ) {
long now = new Date().getTime(); // in milliseconds
for ( NeedsNagInfo info : needNagging ) {
Assert.assertTrue( info.m_nextNag < now );
info.m_nextNag = figureNextNag( context, info.m_lastMoveMillis );
info.m_nextNag = figureNextNag( context,
info.m_lastMoveMillis );
boolean lastWarning = 0 == info.m_nextNag;
long rowid = info.m_rowid;
GameSummary summary = DBUtils.getSummary( context, rowid, 10 );
GameSummary summary = DBUtils.getSummary( context, rowid,
10 );
String prevPlayer = null == summary
? LocUtils.getString(context, R.string.prev_player)
: summary.getPrevPlayer();
Intent msgIntent = GamesListDelegate.makeRowidIntent( context, rowid );
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,
formatMillis( context,
now - info.m_lastMoveMillis) );
prevPlayer, millis );
if ( lastWarning ) {
body = LocUtils
.getString( context, R.string.nag_warn_last_fmt, body );
}
Utils.postNotification( context, msgIntent, R.string.nag_title,
body, (int)rowid );
Utils.postNotification( context, msgIntent,
R.string.nag_title, body,
(int)rowid );
}
DBUtils.updateNeedNagging( context, needNagging );
@ -92,6 +99,7 @@ public class NagTurnReceiver extends BroadcastReceiver {
setNagTimer( context );
}
}
}
public static void restartTimer( Context context )
{
@ -100,6 +108,7 @@ public class NagTurnReceiver extends BroadcastReceiver {
private static void restartTimer( Context context, long atMillis )
{
if ( !getNagsDisabled( context ) ) {
AlarmManager am =
(AlarmManager)context.getSystemService( Context.ALARM_SERVICE );
@ -109,14 +118,17 @@ public class NagTurnReceiver extends BroadcastReceiver {
long now = new Date().getTime(); // in milliseconds
am.set( AlarmManager.RTC, atMillis, pi );
}
}
public static void setNagTimer( Context context )
{
if ( !getNagsDisabled( context ) ) {
long nextNag = DBUtils.getNextNag( context );
if ( 0 < nextNag ) {
restartTimer( context, nextNag );
}
}
}
public static long figureNextNag( Context context, long moveTimeMillis )
{
@ -188,7 +200,23 @@ public class NagTurnReceiver extends BroadcastReceiver {
}
}
String result = TextUtils.join( ", ", results );
DbgUtils.logf( "formatMillis(%d) => %s", millis, result );
return result;
}
private static boolean getNagsDisabled( Context context )
{
if ( null == s_nagsDisabled ) {
boolean nagsDisabled =
XWPrefs.getPrefsBoolean( context, R.string.key_disable_nag,
false );
s_nagsDisabled = new Boolean( nagsDisabled );
}
return s_nagsDisabled;
}
public static void resetNagsDisabled( Context context )
{
s_nagsDisabled = null;
restartTimer( context );
}
}

View file

@ -52,6 +52,7 @@ public class PrefsDelegate extends DelegateBase
private String m_keyLocale;
private String m_keyLangs;
private String m_keyFakeRadio;
private String m_keyNagsDisabled;
public PrefsDelegate( PreferenceActivity activity, Delegator delegator,
Bundle savedInstanceState )
@ -136,6 +137,7 @@ public class PrefsDelegate extends DelegateBase
m_keyLocale = getString( R.string.key_xlations_locale );
m_keyLangs = getString( R.string.key_default_language );
m_keyFakeRadio = getString( R.string.key_force_radio );
m_keyNagsDisabled = getString( R.string.key_disable_nag );
Button button = (Button)findViewById( R.id.revert_colors );
button.setOnClickListener( new View.OnClickListener() {
@ -205,6 +207,8 @@ public class PrefsDelegate extends DelegateBase
forceDictsMatch( sp.getString( key, null ) );
} else if ( key.equals( m_keyFakeRadio ) ) {
SMSService.resetPhoneInfo();
} else if ( key.equals( m_keyNagsDisabled ) ) {
NagTurnReceiver.resetNagsDisabled( m_activity );
}
}