use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class XabberAccountManager method createSyncList.
/**
* @param remoteList is list of settings from cloud
* @return list of settings for displaying in sync-dialog
*/
public List<XMPPAccountSettings> createSyncList(List<XMPPAccountSettings> remoteList) {
List<XMPPAccountSettings> resultList = new ArrayList<>();
// add remote accounts to list
for (XMPPAccountSettings remoteItem : remoteList) {
XMPPAccountSettings.SyncStatus status = XMPPAccountSettings.SyncStatus.remote;
// if account already exist
AccountJid accountJid = getExistingAccount(remoteItem.getJid());
if (accountJid != null) {
AccountItem localItem = AccountManager.getInstance().getAccount(accountJid);
if (localItem != null) {
if (remoteItem.getTimestamp() == localItem.getTimestamp())
status = XMPPAccountSettings.SyncStatus.localEqualsRemote;
else if (remoteItem.getTimestamp() > localItem.getTimestamp())
status = XMPPAccountSettings.SyncStatus.remoteNewer;
else {
status = XMPPAccountSettings.SyncStatus.localNewer;
remoteItem.setTimestamp(localItem.getTimestamp());
}
remoteItem.setSyncNotAllowed(localItem.isSyncNotAllowed());
}
remoteItem.setStatus(status);
remoteItem.setSynchronization(isAccountSynchronize(remoteItem.getJid()));
resultList.add(remoteItem);
} else if (!remoteItem.isDeleted()) {
remoteItem.setStatus(status);
remoteItem.setSynchronization(isAccountSynchronize(remoteItem.getJid()));
resultList.add(remoteItem);
}
}
// add local accounts to list
Collection<AccountItem> localAccounts = AccountManager.getInstance().getAllAccountItems();
for (AccountItem localAccount : localAccounts) {
String localJid = localAccount.getAccount().getFullJid().asBareJid().toString();
boolean exist = false;
for (XMPPAccountSettings remoteItem : remoteList) {
if (localJid.equals(remoteItem.getJid())) {
exist = true;
}
}
if (!exist) {
XMPPAccountSettings localItem = new XMPPAccountSettings(localJid, false, localAccount.getTimestamp());
localItem.setOrder(remoteList.size() + localAccount.getOrder());
localItem.setColor(ColorManager.getInstance().convertIndexToColorName(localAccount.getColorIndex()));
localItem.setStatus(XMPPAccountSettings.SyncStatus.local);
localItem.setSynchronization(isAccountSynchronize(localItem.getJid()));
localItem.setSyncNotAllowed(localAccount.isSyncNotAllowed());
resultList.add(localItem);
}
}
return resultList;
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class XabberAccountManager method createSettingsList.
/**
* @return list of settings from local account for patch to server
*/
public List<XMPPAccountSettings> createSettingsList() {
List<XMPPAccountSettings> resultList = new ArrayList<>();
Collection<AccountItem> localAccounts = AccountManager.getInstance().getAllAccountItems();
for (AccountItem localAccount : localAccounts) {
String localJid = localAccount.getAccount().getFullJid().asBareJid().toString();
if (SettingsManager.isSyncAllAccounts() || isAccountSynchronize(localJid)) {
XMPPAccountSettings item = new XMPPAccountSettings(localJid, true, localAccount.getTimestamp());
item.setOrder(localAccount.getOrder());
item.setColor(ColorManager.getInstance().convertIndexToColorName(localAccount.getColorIndex()));
item.setTimestamp(localAccount.getTimestamp());
resultList.add(item);
}
}
return resultList;
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class PushManager method onEndpointRegistered.
public void onEndpointRegistered(String jid, String pushServiceJid, String node) {
LogManager.d(LOG_TAG, "Received endpoint-registered push. Send push enable iq.");
AccountJid accountJid = null;
Collection<AccountJid> accounts = AccountManager.getInstance().getEnabledAccounts();
for (AccountJid account : accounts) {
if ((account.getFullJid().asBareJid() + getAndroidId()).equals(jid)) {
accountJid = account;
break;
}
}
if (accountJid != null) {
AccountItem account = AccountManager.getInstance().getAccount(accountJid);
if (account != null) {
// save node to account
AccountManager.getInstance().setPushNode(account, node, pushServiceJid);
// update push nodes
updateEnabledPushNodes();
// enable push on XMPP-server
sendEnablePushIQ(account, pushServiceJid, node);
}
}
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class NotificationManager method updatePersistentNotification.
private void updatePersistentNotification() {
if (XabberService.getInstance() == null)
return;
// we do not want to show persistent notification if there are no enabled accounts
XabberService.getInstance().changeForeground();
if (!XabberService.getInstance().needForeground())
return;
Collection<AccountJid> accountList = AccountManager.getInstance().getEnabledAccounts();
if (accountList.isEmpty()) {
return;
}
int waiting = 0;
int connecting = 0;
int connected = 0;
for (AccountJid account : accountList) {
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
continue;
}
ConnectionState state = accountItem.getState();
LogManager.i(this, "updatePersistentNotification account " + account + " state " + state);
switch(state) {
case offline:
break;
case waiting:
waiting++;
break;
case connecting:
case registration:
case authentication:
connecting++;
break;
case connected:
connected++;
break;
}
}
final Intent persistentIntent;
persistentIntent = ContactListActivity.createPersistentIntent(application);
if (SyncManager.getInstance().isSyncMode()) {
persistentNotificationBuilder.setColor(NotificationCompat.COLOR_DEFAULT);
persistentNotificationBuilder.setSmallIcon(R.drawable.ic_sync);
persistentNotificationBuilder.setContentText(application.getString(R.string.connection_state_sync));
} else {
if (connected > 0) {
persistentNotificationBuilder.setColor(persistentNotificationColor);
persistentNotificationBuilder.setSmallIcon(R.drawable.ic_stat_online);
} else {
persistentNotificationBuilder.setColor(NotificationCompat.COLOR_DEFAULT);
persistentNotificationBuilder.setSmallIcon(R.drawable.ic_stat_offline);
}
persistentNotificationBuilder.setContentText(getConnectionState(waiting, connecting, connected, accountList.size()));
}
persistentNotificationBuilder.setContentIntent(PendingIntent.getActivity(application, 0, persistentIntent, PendingIntent.FLAG_UPDATE_CURRENT));
notify(PERSISTENT_NOTIFICATION_ID, persistentNotificationBuilder.build());
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class ReceiptManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza packet) {
if (!(connection instanceof AccountItem)) {
return;
}
final AccountJid account = ((AccountItem) connection).getAccount();
final Jid from = packet.getFrom();
if (from == null) {
return;
}
if (!(packet instanceof Message)) {
return;
}
final Message message = (Message) packet;
if (message.getType() == Message.Type.error) {
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
markAsError(account, message);
}
});
} else {
// TODO setDefaultAutoReceiptMode should be used
for (ExtensionElement packetExtension : message.getExtensions()) {
if (packetExtension instanceof DeliveryReceiptRequest) {
String id = AbstractChat.getStanzaId(message);
if (id == null) {
continue;
}
Message receipt = new Message(from);
receipt.addExtension(new DeliveryReceipt(id));
// the key problem is Thread - smack does not keep it in auto reply
receipt.setThread(message.getThread());
receipt.setType(Message.Type.chat);
try {
StanzaSender.sendStanza(account, receipt);
} catch (NetworkException e) {
LogManager.exception(this, e);
}
}
}
}
}
Aggregations