use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class IncomingMessageVH method setUpAvatar.
private void setUpAvatar(Context context, GroupchatUser groupchatUser, MessageItem messageItem, boolean isMUC, String userName, boolean needTail) {
boolean needAvatar = isMUC ? SettingsManager.chatsShowAvatarsMUC() : SettingsManager.chatsShowAvatars();
// for new groupchats (0GGG)
if (groupchatUser != null && SettingsManager.chatsShowAvatarsMUC())
needAvatar = true;
if (!needAvatar) {
avatar.setVisibility(View.GONE);
avatarBackground.setVisibility(View.GONE);
return;
}
if (!needTail) {
avatar.setVisibility(View.INVISIBLE);
avatarBackground.setVisibility(View.INVISIBLE);
return;
}
avatar.setVisibility(View.VISIBLE);
avatarBackground.setVisibility(View.VISIBLE);
// groupchat avatar
if (groupchatUser != null) {
Drawable placeholder;
try {
UserJid userJid = UserJid.from(messageItem.getUser().getJid().toString() + "/" + groupchatUser.getNickname());
placeholder = AvatarManager.getInstance().getOccupantAvatar(userJid, groupchatUser.getNickname());
} catch (UserJid.UserJidCreateException e) {
placeholder = AvatarManager.getInstance().generateDefaultAvatar(groupchatUser.getNickname(), groupchatUser.getNickname());
}
Glide.with(context).load(groupchatUser.getAvatar()).centerCrop().placeholder(placeholder).error(placeholder).into(avatar);
return;
}
final UserJid user = messageItem.getUser();
final AccountJid account = messageItem.getAccount();
final Resourcepart resource = messageItem.getResource();
if (!isMUC)
avatar.setImageDrawable(AvatarManager.getInstance().getUserAvatarForContactList(user, userName));
else {
if ((MUCManager.getInstance().getNickname(account, user.getJid().asEntityBareJidIfPossible()).equals(resource))) {
avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
} else {
if (resource.equals(Resourcepart.EMPTY)) {
avatar.setImageDrawable(AvatarManager.getInstance().getRoomAvatarForContactList(user));
} else {
String nick = resource.toString();
UserJid userJid = null;
try {
userJid = UserJid.from(user.getJid().toString() + "/" + resource.toString());
avatar.setImageDrawable(AvatarManager.getInstance().getOccupantAvatar(userJid, nick));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
avatar.setImageDrawable(AvatarManager.getInstance().generateDefaultAvatar(nick, nick));
}
}
}
}
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class RecentChatFragment method onContactAvatarClick.
@Override
public void onContactAvatarClick(int adapterPosition) {
IFlexible item = adapter.getItem(adapterPosition);
if (item != null && item instanceof ContactVO) {
Intent intent;
AccountJid accountJid = ((ContactVO) item).getAccountJid();
UserJid userJid = ((ContactVO) item).getUserJid();
if (MUCManager.getInstance().hasRoom(accountJid, userJid)) {
intent = ContactActivity.createIntent(getActivity(), accountJid, userJid);
} else {
intent = ContactEditActivity.createIntent(getActivity(), accountJid, userJid);
}
getActivity().startActivity(intent);
}
}
use of com.xabber.android.data.entity.UserJid 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 com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class HttpFileUploadManager method uploadFile.
public void uploadFile(final AccountJid account, final UserJid user, final String filePath) {
final Jid uploadServerUrl = uploadServers.get(account);
if (uploadServerUrl == null) {
return;
}
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
return;
}
final File file = new File(filePath);
final com.xabber.xmpp.httpfileupload.Request httpFileUpload = new com.xabber.xmpp.httpfileupload.Request();
httpFileUpload.setFilename(file.getName());
httpFileUpload.setSize(String.valueOf(file.length()));
httpFileUpload.setTo(uploadServerUrl);
try {
accountItem.getConnection().sendIqWithResponseCallback(httpFileUpload, new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException {
if (!(packet instanceof Slot)) {
return;
}
uploadFileToSlot(account, (Slot) packet);
}
private void uploadFileToSlot(final AccountJid account, final Slot slot) {
SSLSocketFactory sslSocketFactory = null;
MemorizingTrustManager mtm = CertificateManager.getInstance().getNewFileUploadManager(account);
final SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new X509TrustManager[] { mtm }, new java.security.SecureRandom());
sslSocketFactory = sslContext.getSocketFactory();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
return;
}
OkHttpClient client = new OkHttpClient().newBuilder().sslSocketFactory(sslSocketFactory).hostnameVerifier(mtm.wrapHostnameVerifier(new org.apache.http.conn.ssl.StrictHostnameVerifier())).writeTimeout(5, TimeUnit.MINUTES).connectTimeout(5, TimeUnit.MINUTES).readTimeout(5, TimeUnit.MINUTES).build();
Request request = new Request.Builder().url(slot.getPutUrl()).put(RequestBody.create(CONTENT_TYPE, file)).build();
final String fileMessageId;
fileMessageId = MessageManager.getInstance().createFileMessage(account, user, file);
LogManager.i(HttpFileUploadManager.this, "starting upload file to " + slot.getPutUrl() + " size " + file.length());
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
LogManager.i(HttpFileUploadManager.this, "onFailure " + e.getMessage());
MessageManager.getInstance().updateMessageWithError(fileMessageId, e.toString());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
LogManager.i(HttpFileUploadManager.this, "onResponse " + response.isSuccessful() + " " + response.body().string());
if (response.isSuccessful()) {
MessageManager.getInstance().updateFileMessage(account, user, fileMessageId, slot.getGetUrl());
} else {
MessageManager.getInstance().updateMessageWithError(fileMessageId, response.message());
}
}
});
}
}, new ExceptionCallback() {
@Override
public void processException(Exception exception) {
LogManager.i(this, "On HTTP file upload slot error");
LogManager.exception(this, exception);
Application.getInstance().onError(R.string.http_file_upload_slot_error);
}
});
} catch (SmackException.NotConnectedException | InterruptedException e) {
LogManager.exception(this, e);
}
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class OccupantListFragment method onItemClick.
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
com.xabber.android.data.extension.muc.Occupant occupant = (com.xabber.android.data.extension.muc.Occupant) listAdapter.getItem(position);
LogManager.i(this, occupant.getNickname().toString());
UserJid occupantFullJid = null;
try {
occupantFullJid = UserJid.from(JidCreate.entityFullFrom(room, occupant.getNickname()));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
return;
}
final AbstractChat mucPrivateChat;
try {
mucPrivateChat = MessageManager.getInstance().getOrCreatePrivateMucChat(account, occupantFullJid.getJid().asFullJidIfPossible());
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
return;
}
mucPrivateChat.setIsPrivateMucChatAccepted(true);
startActivity(ChatActivity.createSpecificChatIntent(getActivity(), account, occupantFullJid));
}
Aggregations