Java 类org.jivesoftware.smackx.iqlast.LastActivityManager 实例源码

项目:X-Messenger    文件:XMPPManager.java   
public String getLastSeenMessage(String jid) {
    if (!isConnected() || !connection.isAuthenticated()) {
        return LocaleController.getString("Offline", R.string.Offline);
    }
    try {
        LastActivityManager lastActivityManager = LastActivityManager.getInstanceFor(connection);
        LastActivity activity = lastActivityManager.getLastActivity(JidCreate.bareFrom(jid));

        int lastSeenBySeconds = Utilities.parseInt(activity.lastActivity + "");

        String lastSeenMessage = "";
        lastSeenMessage = LocaleController.getString("Offline", R.string.Offline);
        if (lastSeenBySeconds >= 1) {
            PrettyTime p = new PrettyTime();
            Date date = new Date();
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.SECOND, -1 * lastSeenBySeconds);

            lastSeenMessage = LocaleController.formatDateOnline(cal.getTime()); //p.format(cal.getTime());
        } else {
            lastSeenMessage = LocaleController.getString("Offline", R.string.Offline);
        }
        //FileLog.e("LAST ACTIVITY","" + ""+ "" + lastSeenBySeconds +"  "+jid);
        return lastSeenMessage;

    } catch (Exception e) {
        e.printStackTrace();
        return LocaleController.getString("Offline", R.string.Offline);
    }
    //return "Offline";
}