mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
let caller deal with result of message resend
Use a new interface to let caller of resendAllIf() know how many messages were resent. If none, a new timer might not be called for.
This commit is contained in:
parent
bdc1f5ff51
commit
d6bbccb773
3 changed files with 52 additions and 16 deletions
|
@ -65,6 +65,10 @@ public class GameUtils {
|
||||||
public static final String INVITED = "invited";
|
public static final String INVITED = "invited";
|
||||||
public static final String INTENT_KEY_ROWID = "rowid";
|
public static final String INTENT_KEY_ROWID = "rowid";
|
||||||
|
|
||||||
|
interface ResendDoneProc {
|
||||||
|
void onResendDone( Context context, int numSent );
|
||||||
|
}
|
||||||
|
|
||||||
private static Integer s_minScreen;
|
private static Integer s_minScreen;
|
||||||
// Used to determine whether to resend all messages on networking coming
|
// Used to determine whether to resend all messages on networking coming
|
||||||
// back up. The length of the array determines the number of times in the
|
// back up. The length of the array determines the number of times in the
|
||||||
|
@ -435,6 +439,26 @@ public class GameUtils {
|
||||||
|
|
||||||
public static void resendAllIf( Context context, CommsConnType filter,
|
public static void resendAllIf( Context context, CommsConnType filter,
|
||||||
boolean force, boolean showUI )
|
boolean force, boolean showUI )
|
||||||
|
{
|
||||||
|
ResendDoneProc proc = null;
|
||||||
|
if ( showUI ) {
|
||||||
|
proc = new ResendDoneProc() {
|
||||||
|
@Override
|
||||||
|
public void onResendDone( Context context, int nSent )
|
||||||
|
{
|
||||||
|
String msg = LocUtils
|
||||||
|
.getQuantityString( context,
|
||||||
|
R.plurals.resent_msgs_fmt,
|
||||||
|
nSent, nSent );
|
||||||
|
DbgUtils.showf( context, msg );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
resendAllIf( context, filter, force, proc );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resendAllIf( Context context, CommsConnType filter,
|
||||||
|
boolean force, ResendDoneProc proc )
|
||||||
{
|
{
|
||||||
long now = Utils.getCurSeconds();
|
long now = Utils.getCurSeconds();
|
||||||
|
|
||||||
|
@ -450,7 +474,7 @@ public class GameUtils {
|
||||||
HashMap<Long,CommsConnTypeSet> games =
|
HashMap<Long,CommsConnTypeSet> games =
|
||||||
DBUtils.getGamesWithSendsPending( context );
|
DBUtils.getGamesWithSendsPending( context );
|
||||||
if ( 0 < games.size() ) {
|
if ( 0 < games.size() ) {
|
||||||
new ResendTask( context, games, filter, showUI ).execute();
|
new ResendTask( context, games, filter, proc ).execute();
|
||||||
|
|
||||||
System.arraycopy( s_sendTimes, 0, /* src */
|
System.arraycopy( s_sendTimes, 0, /* src */
|
||||||
s_sendTimes, 1, /* dest */
|
s_sendTimes, 1, /* dest */
|
||||||
|
@ -1216,17 +1240,17 @@ public class GameUtils {
|
||||||
private static class ResendTask extends AsyncTask<Void, Void, Void> {
|
private static class ResendTask extends AsyncTask<Void, Void, Void> {
|
||||||
private Context m_context;
|
private Context m_context;
|
||||||
private HashMap<Long,CommsConnTypeSet> m_games;
|
private HashMap<Long,CommsConnTypeSet> m_games;
|
||||||
private boolean m_showUI;
|
private ResendDoneProc m_doneProc;
|
||||||
private CommsConnType m_filter;
|
private CommsConnType m_filter;
|
||||||
private MultiMsgSink m_sink;
|
private MultiMsgSink m_sink;
|
||||||
|
|
||||||
public ResendTask( Context context, HashMap<Long,CommsConnTypeSet> games,
|
public ResendTask( Context context, HashMap<Long,CommsConnTypeSet> games,
|
||||||
CommsConnType filter, boolean showUI )
|
CommsConnType filter, ResendDoneProc proc )
|
||||||
{
|
{
|
||||||
m_context = context;
|
m_context = context;
|
||||||
m_games = games;
|
m_games = games;
|
||||||
m_filter = filter;
|
m_filter = filter;
|
||||||
m_showUI = showUI;
|
m_doneProc = proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1278,13 +1302,9 @@ public class GameUtils {
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute( Void unused )
|
protected void onPostExecute( Void unused )
|
||||||
{
|
{
|
||||||
if ( m_showUI ) {
|
if ( null != m_doneProc ) {
|
||||||
int nSent = null == m_sink ? 0 : m_sink.numSent();
|
int nSent = null == m_sink ? 0 : m_sink.numSent();
|
||||||
String msg =
|
m_doneProc.onResendDone( m_context, nSent );
|
||||||
LocUtils.getQuantityString( m_context,
|
|
||||||
R.plurals.resent_msgs_fmt,
|
|
||||||
nSent, nSent );
|
|
||||||
DbgUtils.showf( m_context, msg );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,22 @@ public class SMSResendReceiver extends BroadcastReceiver {
|
||||||
public void onReceive( Context context, Intent intent )
|
public void onReceive( Context context, Intent intent )
|
||||||
{
|
{
|
||||||
GameUtils.resendAllIf( context, CommsConnType.COMMS_CONN_SMS, true,
|
GameUtils.resendAllIf( context, CommsConnType.COMMS_CONN_SMS, true,
|
||||||
BuildConfig.DEBUG );
|
new GameUtils.ResendDoneProc() {
|
||||||
setTimer( context, true );
|
@Override
|
||||||
|
public void onResendDone( Context context,
|
||||||
|
int nSent ) {
|
||||||
|
int backoff = -1;
|
||||||
|
if ( 0 < nSent ) {
|
||||||
|
backoff = setTimer( context, true );
|
||||||
|
}
|
||||||
|
if ( BuildConfig.DEBUG ) {
|
||||||
|
DbgUtils.showf( context,
|
||||||
|
"%d SMS msgs resent;"
|
||||||
|
+ " backoff: %d",
|
||||||
|
nSent, backoff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resetTimer( Context context )
|
static void resetTimer( Context context )
|
||||||
|
@ -58,12 +72,12 @@ public class SMSResendReceiver extends BroadcastReceiver {
|
||||||
setTimer( context );
|
setTimer( context );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setTimer( Context context )
|
static int setTimer( Context context )
|
||||||
{
|
{
|
||||||
setTimer( context, false );
|
return setTimer( context, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setTimer( Context context, boolean advance )
|
private static int setTimer( Context context, boolean advance )
|
||||||
{
|
{
|
||||||
AlarmManager am =
|
AlarmManager am =
|
||||||
(AlarmManager)context.getSystemService( Context.ALARM_SERVICE );
|
(AlarmManager)context.getSystemService( Context.ALARM_SERVICE );
|
||||||
|
@ -82,5 +96,6 @@ public class SMSResendReceiver extends BroadcastReceiver {
|
||||||
Log.d( TAG, "set for %d seconds from now", millis / 1000 );
|
Log.d( TAG, "set for %d seconds from now", millis / 1000 );
|
||||||
millis += SystemClock.elapsedRealtime();
|
millis += SystemClock.elapsedRealtime();
|
||||||
am.set( AlarmManager.ELAPSED_REALTIME, millis, pi );
|
am.set( AlarmManager.ELAPSED_REALTIME, millis, pi );
|
||||||
|
return backoff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -625,7 +625,8 @@ public class SMSService extends XWService {
|
||||||
} catch ( java.io.IOException ioe ) {
|
} catch ( java.io.IOException ioe ) {
|
||||||
Log.ex( TAG, ioe );
|
Log.ex( TAG, ioe );
|
||||||
} catch ( ArrayIndexOutOfBoundsException oob ) {
|
} catch ( ArrayIndexOutOfBoundsException oob ) {
|
||||||
// enum this older code doesn't know about; drop it
|
// enum this older code doesn't know about, or just another app's
|
||||||
|
// message; drop it
|
||||||
Log.w( TAG, "disAssemble: dropping message with too-new enum" );
|
Log.w( TAG, "disAssemble: dropping message with too-new enum" );
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
|
|
Loading…
Reference in a new issue