Search in sources :

Example 26 with UserJid

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));
                }
            }
        }
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) Drawable(android.graphics.drawable.Drawable) UserJid(com.xabber.android.data.entity.UserJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 27 with UserJid

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);
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) IFlexible(eu.davidea.flexibleadapter.items.IFlexible) ContactVO(com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO) UserJid(com.xabber.android.data.entity.UserJid) Intent(android.content.Intent)

Example 28 with UserJid

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);
    }
}
Also used : Localpart(org.jxmpp.jid.parts.Localpart) UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 29 with UserJid

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);
    }
}
Also used : OkHttpClient(okhttp3.OkHttpClient) AccountItem(com.xabber.android.data.account.AccountItem) StanzaListener(org.jivesoftware.smack.StanzaListener) AccountJid(com.xabber.android.data.entity.AccountJid) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Call(okhttp3.Call) UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) DomainBareJid(org.jxmpp.jid.DomainBareJid) Jid(org.jxmpp.jid.Jid) Stanza(org.jivesoftware.smack.packet.Stanza) Request(okhttp3.Request) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) ExceptionCallback(org.jivesoftware.smack.ExceptionCallback) SmackException(org.jivesoftware.smack.SmackException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XMPPException(org.jivesoftware.smack.XMPPException) MemorizingTrustManager(de.duenndns.ssl.MemorizingTrustManager) Response(okhttp3.Response) Callback(okhttp3.Callback) ExceptionCallback(org.jivesoftware.smack.ExceptionCallback) X509TrustManager(javax.net.ssl.X509TrustManager) Slot(com.xabber.xmpp.httpfileupload.Slot) File(java.io.File)

Example 30 with UserJid

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));
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) UserJid(com.xabber.android.data.entity.UserJid)

Aggregations

UserJid (com.xabber.android.data.entity.UserJid)67 AccountJid (com.xabber.android.data.entity.AccountJid)43 AbstractChat (com.xabber.android.data.message.AbstractChat)15 ArrayList (java.util.ArrayList)15 Intent (android.content.Intent)9 Jid (org.jxmpp.jid.Jid)9 Presence (org.jivesoftware.smack.packet.Presence)8 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)8 AccountItem (com.xabber.android.data.account.AccountItem)7 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 Message (org.jivesoftware.smack.packet.Message)6 Resourcepart (org.jxmpp.jid.parts.Resourcepart)6 NetworkException (com.xabber.android.data.NetworkException)5 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)5 SmackException (org.jivesoftware.smack.SmackException)5 Uri (android.net.Uri)4 ContactVO (com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO)4 DomainBareJid (org.jxmpp.jid.DomainBareJid)4 TextView (android.widget.TextView)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)3