use of com.xabber.xmpp.time.Time in project xabber-android by redsolution.
the class TimeManager method onServerInfoReceived.
@Override
public void onServerInfoReceived(ConnectionItem connection) {
if (!(connection instanceof AccountItem)) {
onAvailable(connection);
return;
}
String account = ((AccountItem) connection).getAccount();
if (ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE) && offsets.get(account) == null) {
sents.put(account, new Date());
Time packet = new Time();
packet.setTo(Jid.getServer(account));
packet.setType(Type.get);
try {
ConnectionManager.getInstance().sendRequest(account, packet, this);
} catch (NetworkException e) {
}
return;
}
onAvailable(connection);
}
use of com.xabber.xmpp.time.Time in project xabber-android by redsolution.
the class TimeManager method onReceived.
@Override
public void onReceived(String account, String packetId, IQ iq) {
if (!(iq instanceof Time) || !((Time) iq).isValid()) {
onError(account, packetId, iq);
return;
}
Date t1 = sents.remove(account);
Date t2_3 = ((Time) iq).getUtc();
Date t4 = ((Time) iq).getCreated();
long offset = ((t2_3.getTime() - t1.getTime()) + (t2_3.getTime() - t4.getTime())) / 2;
offsets.put(account, offset);
onAvailable(AccountManager.getInstance().getAccount(account));
}
use of com.xabber.xmpp.time.Time in project xabber-android by redsolution.
the class TimeManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
if (!(connection instanceof AccountItem))
return;
String account = ((AccountItem) connection).getAccount();
if (!(packet instanceof Time))
return;
Time time = (Time) packet;
if (time.getType() == Type.get) {
Time result = new Time();
result.setType(Type.result);
result.setPacketID(time.getPacketID());
result.setFrom(time.getTo());
result.setTo(time.getFrom());
Calendar calendar = Calendar.getInstance();
result.setTzo((calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / 60000);
result.setUtc(calendar.getTime());
try {
ConnectionManager.getInstance().sendStanza(account, result);
} catch (NetworkException e) {
}
}
}
Aggregations