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 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 AccountRosterListener method onRosterLoaded.
@Override
public void onRosterLoaded(Roster roster) {
LogManager.i(getLogTag(), "onRosterLoaded");
final AccountItem accountItem = AccountManager.getInstance().getAccount(AccountRosterListener.this.account);
if (accountItem != null) {
for (OnRosterReceivedListener listener : Application.getInstance().getManagers(OnRosterReceivedListener.class)) {
listener.onRosterReceived(accountItem);
}
}
AccountManager.getInstance().onAccountChanged(AccountRosterListener.this.account);
}
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 UploadService method startWork.
private void startWork(AccountJid account, UserJid user, List<String> filePaths, CharSequence uploadServerUrl, String existMessageId) {
// get account item
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
publishError(null, "Account not found");
return;
}
// get upload jid
Jid uploadJid;
try {
uploadJid = JidCreate.bareFrom(uploadServerUrl);
} catch (XmppStringprepException e) {
publishError(null, "Wrong upload jid");
return;
}
final String fileMessageId;
if (existMessageId == null) {
// create fileMessage with files
List<File> files = new ArrayList<>();
for (String filePath : filePaths) {
files.add(new File(filePath));
}
fileMessageId = MessageManager.getInstance().createFileMessage(account, user, files);
} else
// use existing fileMessage
fileMessageId = existMessageId;
HashMap<String, String> uploadedFilesUrls = new HashMap<>();
List<String> notUploadedFilesPaths = new ArrayList<>();
List<File> notUploadedFiles = new ArrayList<>();
List<String> errors = new ArrayList<>();
for (String filePath : filePaths) {
if (needStop) {
stopWork(fileMessageId);
return;
}
try {
File uncompressedFile = new File(filePath);
final File file;
// compress file if image
if (FileManager.fileIsImage(uncompressedFile) && SettingsManager.connectionCompressImage()) {
file = ImageCompressor.compressImage(uncompressedFile, getCompressedDirPath());
if (file == null)
throw new Exception("Compress image failed");
} else
file = uncompressedFile;
// request slot
Stanza slot = requestSlot(accountItem, file, uploadJid);
if (!(slot instanceof Slot))
throw new Exception("Could not request upload slot");
// upload file
Response response = uploadFileToSlot(account, (Slot) slot, file);
if (response.isSuccessful())
uploadedFilesUrls.put(filePath, ((Slot) slot).getGetUrl());
else
throw new Exception("Upload failed: " + response.message());
} catch (Exception e) {
notUploadedFilesPaths.add(filePath);
notUploadedFiles.add(new File(filePath));
errors.add(e.toString());
}
publishProgress(fileMessageId, uploadedFilesUrls.size(), filePaths.size());
}
removeTempDirectory();
// check that files are uploaded
if (uploadedFilesUrls.size() == 0) {
setErrorForMessage(fileMessageId, generateErrorDescriptionForFiles(notUploadedFilesPaths, errors));
publishError(fileMessageId, "Could not upload any files");
return;
}
// save results to Realm and send message
MessageManager.getInstance().updateFileMessage(account, user, fileMessageId, uploadedFilesUrls, notUploadedFilesPaths);
publishCompleted(fileMessageId);
// if some files have errors move its to separate message
if (notUploadedFilesPaths.size() > 0) {
String messageId = MessageManager.getInstance().createFileMessage(account, user, notUploadedFiles);
setErrorForMessage(messageId, generateErrorDescriptionForFiles(notUploadedFilesPaths, errors));
}
}
Aggregations