use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class AccountListActivity method updateAccountOrder.
public void updateAccountOrder() {
if (accountListAdapter != null) {
int order = 1;
for (AccountItem account : accountListAdapter.getItems()) AccountManager.getInstance().setOrder(account.getAccount(), order++);
XabberAccountManager.getInstance().setLastOrderChangeTimestampIsNow();
if (XabberAccountManager.getInstance().getAccount() != null)
XabberAccountManager.getInstance().updateAccountSettings();
}
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class AccountListActivity method update.
private void update() {
List<AccountItem> accountItems = new ArrayList<>();
for (AccountItem accountItem : AccountManager.getInstance().getAllAccountItems()) {
accountItems.add(accountItem);
}
accountListAdapter.setAccountItems(accountItems);
barPainter.setDefaultColor();
// set margin for textView
int height = 52 * (accountItems.size() + 1) + 16;
final float scale = getResources().getDisplayMetrics().density;
int pixels = (int) (height * scale + 0.5f);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(16, pixels, 16, 0);
tvSummary.setLayoutParams(params);
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class ConnectionThread method connectAndLogin.
@SuppressWarnings("WeakerAccess")
void connectAndLogin() {
AndroidLoggingHandler.reset(new AndroidLoggingHandler());
java.util.logging.Logger.getLogger(XMPPTCPConnection.class.getName()).setLevel(Level.FINEST);
java.util.logging.Logger.getLogger(AbstractDNSClient.class.getName()).setLevel(Level.FINEST);
java.util.logging.Logger.getLogger(AbstractXMPPConnection.class.getName()).setLevel(Level.FINEST);
java.util.logging.Logger.getLogger(DNSUtil.class.getName()).setLevel(Level.FINEST);
if (connection.getConfiguration().getPassword().isEmpty()) {
AccountErrorEvent accountErrorEvent = new AccountErrorEvent(connectionItem.getAccount(), AccountErrorEvent.Type.PASS_REQUIRED, "");
// com.xabber.android.data.account.AccountManager.getInstance().addAccountError(accountErrorEvent);
com.xabber.android.data.account.AccountManager.getInstance().setEnabled(connectionItem.getAccount(), false);
EventBus.getDefault().postSticky(accountErrorEvent);
return;
}
// switch (SettingsManager.connectionDnsResolver()) {
// case dnsJavaResolver:
// LogManager.i(this, "Use DNS Java resolver");
// ExtDNSJavaResolver.setup();
// break;
// case miniDnsResolver:
// LogManager.i(this, "Use Mini DNS resolver");
// MiniDnsResolver.setup();
// break;
// }
LogManager.i(this, "Use DNS Java resolver");
ExtDNSJavaResolver.setup();
ProviderManager.addExtensionProvider(DataForm.ELEMENT, DataForm.NAMESPACE, new CustomDataProvider());
ProviderManager.addExtensionProvider(ForwardComment.ELEMENT, ForwardComment.NAMESPACE, new ForwardCommentProvider());
ProviderManager.addExtensionProvider(ReferenceElement.ELEMENT, ReferenceElement.NAMESPACE, new ReferencesProvider());
ProviderManager.addIQProvider(XTokenIQ.ELEMENT, XTokenIQ.NAMESPACE, new XTokenProvider());
ProviderManager.addIQProvider(SessionsIQ.ELEMENT, SessionsIQ.NAMESPACE, new SessionsProvider());
try {
LogManager.i(this, "Trying to connect and login...");
if (!connection.isConnected()) {
connectionItem.updateState(ConnectionState.connecting);
connection.connect();
} else {
LogManager.i(this, "Already connected");
}
if (!connection.isAuthenticated()) {
ProviderManager.addIQProvider(HttpConfirmIq.ELEMENT, HttpConfirmIq.NAMESPACE, new HttpConfirmIqProvider());
connection.login();
} else {
LogManager.i(this, "Already authenticated");
}
} catch (SASLErrorException e) {
LogManager.exception(this, e);
if (e.getMechanism().equals(SASLXTOKENMechanism.NAME)) {
LogManager.d(this, "Authorization error with x-token: " + e.toString());
AccountManager.getInstance().removeXToken(connectionItem.getAccount());
}
AccountErrorEvent accountErrorEvent = new AccountErrorEvent(connectionItem.getAccount(), AccountErrorEvent.Type.AUTHORIZATION, e.getMessage());
// com.xabber.android.data.account.AccountManager.getInstance().addAccountError(accountErrorEvent);
com.xabber.android.data.account.AccountManager.getInstance().setEnabled(connectionItem.getAccount(), false);
EventBus.getDefault().postSticky(accountErrorEvent);
// catching RuntimeExceptions seems to be strange, but we got a lot of error coming from
// Smack or mini DSN client inside of Smack.
} catch (XMPPException | SmackException | IOException | RuntimeException e) {
LogManager.exception(this, e);
if (!((AccountItem) connectionItem).isSuccessfulConnectionHappened()) {
LogManager.i(this, "There was no successful connection, disabling account");
AccountErrorEvent accountErrorEvent = new AccountErrorEvent(connectionItem.getAccount(), AccountErrorEvent.Type.CONNECTION, Log.getStackTraceString(e));
com.xabber.android.data.account.AccountManager.getInstance().addAccountError(accountErrorEvent);
com.xabber.android.data.account.AccountManager.getInstance().setEnabled(connectionItem.getAccount(), false);
EventBus.getDefault().postSticky(accountErrorEvent);
}
} catch (InterruptedException e) {
LogManager.exception(this, e);
}
LogManager.i(this, "Connection thread finished");
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class RecentChatFragment method updateChats.
public void updateChats() {
Collection<AbstractChat> chats = MessageManager.getInstance().getChats();
List<AbstractChat> recentChats = new ArrayList<>();
for (AbstractChat abstractChat : chats) {
MessageItem lastMessage = abstractChat.getLastMessage();
if (lastMessage != null) {
AccountItem accountItem = AccountManager.getInstance().getAccount(abstractChat.getAccount());
if (accountItem != null && accountItem.isEnabled()) {
recentChats.add(abstractChat);
}
}
}
// crowdfunding chat
int unreadCount = CrowdfundingManager.getInstance().getUnreadMessageCount();
CrowdfundingMessage message = CrowdfundingManager.getInstance().getLastNotDelayedMessageFromRealm();
if (message != null)
recentChats.add(CrowdfundingChat.createCrowdfundingChat(unreadCount, message));
Collections.sort(recentChats, ChatComparator.CHAT_COMPARATOR);
final List<AbstractContact> newContacts = new ArrayList<>();
for (AbstractChat chat : recentChats) {
if (chat instanceof CrowdfundingChat)
newContacts.add(new CrowdfundingContact((CrowdfundingChat) chat));
else if (!chat.isArchived() || ((ChatActivity) getActivity()).isShowArchived())
newContacts.add(RosterManager.getInstance().getBestContact(chat.getAccount(), chat.getUser()));
}
updateItems(newContacts);
}
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