use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.
the class ConferenceAddFragment method addConference.
public void addConference() {
Resourcepart nick;
try {
nick = Resourcepart.from(nickView.getText().toString().trim());
} catch (XmppStringprepException e) {
LogManager.exception(this, e);
Toast.makeText(getActivity(), getString(R.string.EMPTY_NICK_NAME), Toast.LENGTH_LONG).show();
return;
}
String password = passwordView.getText().toString();
final boolean join = true;
MUCManager.getInstance().createRoom(account, conferenceJid, nick, password, join);
// add conference to bookmarks
BookmarksManager.getInstance().addConferenceToBookmarks(account, conferenceJid.getLocalpart().toString(), conferenceJid, nick);
try {
startActivity(ChatActivity.createSpecificChatIntent(getActivity(), account, UserJid.from(conferenceJid)));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.
the class ContactAddFragment method addContact.
@Override
public void addContact() {
final AccountJid account = (AccountJid) accountView.getSelectedItem();
if (account == null || getAccount() == null) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_ACCOUNT), Toast.LENGTH_LONG).show();
return;
}
String contactString = userView.getText().toString();
contactString = contactString.trim();
if (contactString.contains(" ")) {
userView.setError(getString(R.string.INCORRECT_USER_NAME));
return;
}
if (TextUtils.isEmpty(contactString)) {
userView.setError(getString(R.string.EMPTY_USER_NAME));
return;
}
final UserJid user;
try {
EntityBareJid entityFullJid = JidCreate.entityBareFrom(contactString);
user = UserJid.from(entityFullJid);
} catch (XmppStringprepException | UserJid.UserJidCreateException e) {
e.printStackTrace();
userView.setError(getString(R.string.INCORRECT_USER_NAME));
return;
}
if (listenerActivity != null)
listenerActivity.showProgress(true);
final String name = nameView.getText().toString();
final ArrayList<String> groups = getSelected();
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
try {
RosterManager.getInstance().createContact(account, user, name, groups);
PresenceManager.getInstance().requestSubscription(account, user);
} catch (SmackException.NotLoggedInException | SmackException.NotConnectedException e) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
stopAddContactProcess(false);
} catch (XMPPException.XMPPErrorException e) {
Application.getInstance().onError(R.string.XMPP_EXCEPTION);
stopAddContactProcess(false);
} catch (SmackException.NoResponseException e) {
Application.getInstance().onError(R.string.CONNECTION_FAILED);
stopAddContactProcess(false);
} catch (NetworkException e) {
Application.getInstance().onError(e);
stopAddContactProcess(false);
} catch (InterruptedException e) {
LogManager.exception(this, e);
stopAddContactProcess(false);
}
stopAddContactProcess(true);
}
});
}
use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.
the class ConferenceSelectFragment method onNextClick.
private void onNextClick() {
if (account == null) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_ACCOUNT), Toast.LENGTH_SHORT).show();
return;
}
DomainBareJid server;
try {
server = JidCreate.domainBareFrom(serverView.getText().toString());
} catch (XmppStringprepException e) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_SERVER_NAME), Toast.LENGTH_SHORT).show();
return;
}
Localpart room;
try {
room = Localpart.from(roomView.getText().toString());
} catch (XmppStringprepException e) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_ROOM_NAME), Toast.LENGTH_LONG).show();
return;
}
UserJid roomJid = null;
try {
roomJid = UserJid.from(JidCreate.entityBareFrom(room, server));
startActivity(ConferenceAddActivity.createIntent(getActivity(), account, roomJid));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.
the class XMPPAuthManager method addContactToRoster.
private void addContactToRoster(String apiJid, String clientJid) {
UserJid user;
AccountJid account;
try {
user = UserJid.from(apiJid);
account = AccountJid.from(clientJid);
RosterManager.getInstance().createContact(account, user, "xabber", Collections.EMPTY_LIST);
PresenceManager.getInstance().requestSubscription(account, user, false);
} catch (UserJid.UserJidCreateException | XmppStringprepException | InterruptedException | SmackException | NetworkException | XMPPException.XMPPErrorException e) {
LogManager.exception(this, e);
return;
}
}
use of org.jxmpp.stringprep.XmppStringprepException 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