}
return (Long.valueOf(when).compareTo(Long.valueOf(m.when)));
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (! (o instanceof Msg)) {
+ return false;
+ }
+ return 0 == this.compareTo((Msg)o);
+ }
}
private final List<Msg> msgs = new ArrayList<>();
private long lastMsgTimestamp;
try {
t = s.nextLong();
} catch (NoSuchElementException nse) {
- // Maybe they forgot a time stamp; use round start.
- // That's not ideal, but... fake it?
- // XXX Back off a bit, for time sync reasons
+ // Maybe they forgot a time stamp? Fake one up, a second ago or so,
+ // to allow for some clock drift and another message with a timestamp.
synchronized (this) {
- lastMsgTimestamp = 0;
- m = new Msg(lastMsgTimestamp, str);
+ m = new Msg(mT.wallMS() - 1000, str);
}
}
if (m == null) {
s.useDelimiter("\\z");
- new Msg(t, s.next().trim());
+ m = new Msg(t, s.next().trim());
}
synchronized (this) {
- // If there is no configuration, assume the message is new enough
- // If there *is* a configuration, check the time.
+ // Advance message clock monotonically; accept any message if there
+ // is no configuration, or check the start time to suppress old
+ // messages if we're just now coming online.
+ //
+ // XXX this is bogus
if (isMessageTimeWithin(t) && (lastMsgTimestamp <= t)) {
lastMsgTimestamp = t;
if (!msgs.contains(m)) {
import com.acmetensortoys.ctfwstimer.lib.CtFwSGameStateManager;
import java.util.List;
+import java.util.ListIterator;
import static android.view.View.INVISIBLE;
});
}
+ private CtFwSGameStateManager.Msg lastMsg;
@Override
public void onCtFwSMessage(CtFwSGameStateManager gs, List<CtFwSGameStateManager.Msg> msgs) {
final TextView msgstv = (TextView) (mAct.findViewById(R.id.msgs));
msgstv.setText("");
}
});
+ return;
+ }
+
+ int ix;
+ if (lastMsg == null) {
+ ix = 0;
} else {
- CtFwSGameStateManager.Msg m = msgs.get(s - 1);
+ ix = msgs.indexOf(lastMsg);
+ if (ix == -1) {
+ ix = 0;
+ } else if (ix == s) {
+ return;
+ } else {
+ ix = ix + 1;
+ }
+ }
+ final StringBuffer sb = new StringBuffer();
+ for (ListIterator<CtFwSGameStateManager.Msg> news = msgs.listIterator(ix);
+ news.hasNext(); ) {
+
+ CtFwSGameStateManager.Msg m = news.next();
long td = (m.when == 0) ? 0 : (gs.isConfigured()) ? m.when - gs.getStartT() : 0;
- final StringBuffer sb = new StringBuffer();
sb.append(DateUtils.formatElapsedTime(td));
sb.append(": ");
sb.append(m.msg);
sb.append("\n");
- msgstv.post(new Runnable() {
- @Override
- public void run() {
- msgstv.append(sb);
- }
- });
+ lastMsg = m;
}
+
+ msgstv.post(new Runnable() {
+ @Override
+ public void run() {
+ msgstv.append(sb);
+ }
+ });
}
// Stun timers
if (mSrvBinder == null) {
Intent si = new Intent(this, MainService.class);
bindService(si, ctfwssc, Context.BIND_AUTO_CREATE | Context.BIND_ABOVE_CLIENT);
- } else {
+ }
+ }
+
+ @Override
+ public void onResume() {
+ Log.d("CtFwS", "onResume");
+ super.onResume();
+
+ if (mSrvBinder != null) {
mSrvBinder.getGameState().registerObserver(mCdl);
mSrvBinder.registerObserver(mSrvObs);
}
}
@Override
- protected void onStop() {
- Log.d("CtFwS", "onStop");
+ protected void onPause() {
+ Log.d("CtFwS", "onPause");
if (mSrvBinder != null) {
mSrvBinder.getGameState().unregisterObserver(mCdl);
mSrvBinder.unregisterObserver(mSrvObs);
}
+ super.onPause();
+ }
+
+ @Override
+ protected void onStop() {
+ Log.d("CtFwS", "onStop");
super.onStop();
}