use of org.awesomeapp.messenger.model.Presence in project Zom-Android by zom.
the class XmppConnection method do_login_async.
private void do_login_async() {
if (getState() == LOGGED_IN || getState() == SUSPENDED || getState() == SUSPENDING) {
mNeedReconnect = false;
return;
}
/*
if (mConnection != null) {
setState(getState(), new ImErrorInfo(ImErrorInfo.CANT_CONNECT_TO_SERVER,
"still trying..."));
return;
}*/
ContentResolver contentResolver = mContext.getContentResolver();
Cursor cursor = contentResolver.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(mProviderId) }, null);
if (cursor == null)
// not going to work
return;
Imps.ProviderSettings.QueryMap providerSettings = new Imps.ProviderSettings.QueryMap(cursor, contentResolver, mProviderId, false, null);
// providerSettings is closed in initConnection();
mUsername = Imps.Account.getUserName(contentResolver, mAccountId);
String defaultStatus = null;
mNeedReconnect = true;
setState(LOGGING_IN, null);
mUserPresence = new Presence(Presence.AVAILABLE, defaultStatus, Presence.CLIENT_TYPE_MOBILE);
try {
if (mUsername == null || mUsername.length() == 0)
throw new Exception("empty username not allowed");
initConnectionAndLogin(providerSettings, mUsername);
setState(LOGGED_IN, null);
debug(TAG, "logged in");
mNeedReconnect = false;
} catch (XMPPException e) {
debug(TAG, "exception thrown on connection", e);
ImErrorInfo info = new ImErrorInfo(ImErrorInfo.CANT_CONNECT_TO_SERVER, e.getMessage());
// our default behavior is to retry
mRetryLogin = true;
if (mConnection != null && mConnection.isConnected()) {
if (!mConnection.isAuthenticated()) {
debug(TAG, "not authorized - will not retry");
info = new ImErrorInfo(ImErrorInfo.INVALID_USERNAME, "invalid user/password");
setState(SUSPENDED, info);
mRetryLogin = false;
mNeedReconnect = false;
}
}
if (mRetryLogin && getState() != SUSPENDED) {
debug(TAG, "will retry");
setState(LOGGING_IN, info);
maybe_reconnect();
} else {
// debug(TAG, "will not retry"); //WE MUST ALWAYS RETRY!
disconnect();
disconnected(info);
}
} catch (Exception e) {
debug(TAG, "login failed: " + e.getMessage(), e);
if (getState() != SUSPENDED || getState() != SUSPENDING) {
mRetryLogin = true;
mNeedReconnect = true;
debug(TAG, "will retry");
ImErrorInfo info = new ImErrorInfo(ImErrorInfo.UNKNOWN_ERROR, "keymanagement exception");
setState(LOGGING_IN, info);
} else {
mRetryLogin = false;
mNeedReconnect = true;
}
} finally {
providerSettings.close();
if (!cursor.isClosed())
cursor.close();
}
}
use of org.awesomeapp.messenger.model.Presence in project Zom-Android by zom.
the class ImConnectionAdapter method loadSavedPresence.
private void loadSavedPresence() {
ContentResolver cr = mService.getContentResolver();
// Imps.ProviderSettings.setPresence(cr, mProviderId, status, statusText);
int presenceState = Imps.ProviderSettings.getIntValue(cr, mProviderId, Imps.ProviderSettings.PRESENCE_STATE);
String presenceStatusMessage = Imps.ProviderSettings.getStringValue(cr, mProviderId, Imps.ProviderSettings.PRESENCE_STATUS_MESSAGE);
if (presenceState != -1) {
Presence presence = new Presence();
presence.setStatus(presenceState);
presence.setStatusText(presenceStatusMessage);
try {
mConnection.updateUserPresenceAsync(presence);
} catch (ImException e) {
Log.e(ImApp.LOG_TAG, "unable able to update presence", e);
}
}
}
use of org.awesomeapp.messenger.model.Presence in project Zom-Android by zom.
the class ContactListManagerAdapter method updatePresenceContent.
void updatePresenceContent(Contact[] contacts) {
if (mAdaptee == null)
return;
ArrayList<String> usernames = new ArrayList<String>();
ArrayList<String> nicknames = new ArrayList<String>();
ArrayList<String> statusArray = new ArrayList<String>();
ArrayList<String> customStatusArray = new ArrayList<String>();
ArrayList<String> clientTypeArray = new ArrayList<String>();
ArrayList<String> resourceArray = new ArrayList<String>();
for (Contact c : contacts) {
String username = mAdaptee.normalizeAddress(c.getAddress().getAddress());
Presence p = c.getPresence();
int status = convertPresenceStatus(p);
String customStatus = p.getStatusText();
int clientType = translateClientType(p);
usernames.add(username);
nicknames.add(c.getName());
statusArray.add(String.valueOf(status));
customStatusArray.add(customStatus);
clientTypeArray.add(String.valueOf(clientType));
if (!TextUtils.isEmpty(p.getResource()))
resourceArray.add(p.getResource());
else
resourceArray.add("");
}
ContentValues values = new ContentValues();
values.put(Imps.Contacts.ACCOUNT, mConn.getAccountId());
values.put(Imps.Contacts.PROVIDER, mConn.getProviderId());
putStringArrayList(values, Imps.Contacts.USERNAME, usernames);
putStringArrayList(values, Imps.Contacts.NICKNAME, nicknames);
mResolver.update(Imps.Contacts.BULK_CONTENT_URI, values, null, null);
values = new ContentValues();
values.put(Imps.Contacts.ACCOUNT, mConn.getAccountId());
values.put(Imps.Contacts.PROVIDER, mConn.getProviderId());
putStringArrayList(values, Imps.Contacts.USERNAME, usernames);
putStringArrayList(values, Imps.Presence.PRESENCE_STATUS, statusArray);
putStringArrayList(values, Imps.Presence.PRESENCE_CUSTOM_STATUS, customStatusArray);
putStringArrayList(values, Imps.Presence.CONTENT_TYPE, clientTypeArray);
putStringArrayList(values, Imps.Presence.JID_RESOURCE, resourceArray);
mResolver.update(Imps.Presence.BULK_CONTENT_URI, values, null, null);
}
use of org.awesomeapp.messenger.model.Presence in project Zom-Android by zom.
the class ContactListManagerAdapter method getPresenceValues.
private ContentValues getPresenceValues(Contact c) {
Presence p = c.getPresence();
ContentValues values = new ContentValues(3);
values.put(Imps.Contacts.PRESENCE_STATUS, convertPresenceStatus(p));
values.put(Imps.Contacts.PRESENCE_CUSTOM_STATUS, p.getStatusText());
values.put(Imps.Presence.CLIENT_TYPE, translateClientType(p));
return values;
}
use of org.awesomeapp.messenger.model.Presence in project Zom-Android by zom.
the class ImConnectionAdapter method updateAccountStatusInDb.
void updateAccountStatusInDb() {
Presence p = getUserPresence();
int presenceStatus = Imps.Presence.OFFLINE;
int connectionStatus = convertConnStateForDb(mConnectionState);
if (p != null) {
presenceStatus = ContactListManagerAdapter.convertPresenceStatus(p);
}
ContentResolver cr = mService.getContentResolver();
Uri uri = Imps.AccountStatus.CONTENT_URI;
ContentValues values = new ContentValues();
values.put(Imps.AccountStatus.ACCOUNT, mAccountId);
values.put(Imps.AccountStatus.PRESENCE_STATUS, presenceStatus);
values.put(Imps.AccountStatus.CONNECTION_STATUS, connectionStatus);
cr.insert(uri, values);
}
Aggregations