Search in sources :

Example 51 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class OTRManager method askForSecret.

@Override
public void askForSecret(SessionID sessionID, InstanceTag receiverTag, String question) {
    try {
        AccountJid accountJid = AccountJid.from(sessionID.getAccountID());
        UserJid userJid = UserJid.from(sessionID.getUserID());
        // set notify intent to chat
        setNotifyIntentToChat(QuestionActivity.createIntent(Application.getInstance(), accountJid, userJid, question != null, true, question), accountJid, userJid);
        // show android notification
        SMRequest request = new SMRequest(AccountJid.from(sessionID.getAccountID()), UserJid.from(sessionID.getUserID()), question);
        smRequestProvider.add(request, true);
        // send event of adding auth request to fragment
        EventBus.getDefault().post(new AuthAskEvent(accountJid, userJid));
    } catch (UserJid.UserJidCreateException | XmppStringprepException e) {
        LogManager.exception(this, e);
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 52 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class AccountManager method getSelectedAccount.

/**
 * @return Selected account to show contacts. <code>null</code> if
 * <ul>
 * <li>there is no selected account,</li>
 * <li>selected account does not exists or disabled,</li>
 * <li>Group by account is enabled.</li>
 * </ul>
 */
public AccountJid getSelectedAccount() {
    if (SettingsManager.contactsShowAccounts()) {
        return null;
    }
    if (TextUtils.isEmpty(SettingsManager.contactsSelectedAccount())) {
        return null;
    }
    AccountJid selected;
    try {
        selected = AccountJid.from(SettingsManager.contactsSelectedAccount());
    } catch (XmppStringprepException e) {
        LogManager.exception(this, e);
        return null;
    }
    AccountItem selectedAccountItem = accountItems.get(selected);
    if (selectedAccountItem != null && selectedAccountItem.isEnabled()) {
        return selected;
    }
    return null;
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 53 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class MessageDatabaseManager method copyDataFromSqliteToRealm.

void copyDataFromSqliteToRealm() {
    Realm realm = getNewBackgroundRealm();
    realm.beginTransaction();
    LogManager.i("DatabaseManager", "copying from sqlite to Reaml");
    long counter = 0;
    Cursor cursor = MessageTable.getInstance().getAllMessages();
    while (cursor.moveToNext()) {
        try {
            MessageItem messageItem = MessageTable.createMessageItem(cursor);
            realm.copyToRealm(messageItem);
        } catch (XmppStringprepException | UserJid.UserJidCreateException e) {
            LogManager.exception(this, e);
        }
        counter++;
    }
    cursor.close();
    LogManager.i("DatabaseManager", counter + " messages copied to Realm");
    LogManager.i("DatabaseManager", "onSuccess. removing messages from sqlite:");
    int removedMessages = MessageTable.getInstance().removeAllMessages();
    LogManager.i("DatabaseManager", removedMessages + " messages removed from sqlite");
    realm.commitTransaction();
    realm.close();
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Cursor(android.database.Cursor) ContactRealm(com.xabber.android.data.database.realm.ContactRealm) Realm(io.realm.Realm) DynamicRealm(io.realm.DynamicRealm)

Example 54 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class XMPPAccountAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    final XMPPAccountSettings account = items.get(position);
    XMPPAccountVH viewHolder = (XMPPAccountVH) holder;
    viewHolder.chkAccountSync.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            account.setSynchronization(isChecked);
        }
    });
    // set colors
    int colorId = ColorManager.getInstance().convertColorNameToId(account.getColor());
    // set username
    if (account.getUsername() != null && !account.getUsername().isEmpty())
        viewHolder.username.setText(account.getUsername());
    else
        viewHolder.username.setText(account.getJid());
    // set avatar
    try {
        AccountJid accountJid = AccountJid.from(account.getJid() + "/resource");
        viewHolder.avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatarForSync(accountJid, colorId));
    } catch (XmppStringprepException e) {
        e.printStackTrace();
    }
    if (account.isSynchronization() || isAllChecked) {
        if (account.getStatus() != null) {
            switch(account.getStatus()) {
                case local:
                    viewHolder.jid.setText(R.string.sync_status_local);
                    break;
                case remote:
                    viewHolder.jid.setText(R.string.sync_status_remote);
                    break;
                case localNewer:
                    viewHolder.jid.setText(R.string.sync_status_local);
                    break;
                case remoteNewer:
                    if (account.isDeleted()) {
                        viewHolder.jid.setText(R.string.sync_status_deleted);
                    } else {
                        viewHolder.jid.setText(R.string.sync_status_remote);
                    }
                    break;
                case localEqualsRemote:
                    viewHolder.jid.setText(R.string.sync_status_ok);
                    break;
                default:
                    break;
            }
        }
    } else {
        viewHolder.jid.setText(R.string.sync_status_no);
    }
    // set sync checkbox
    if (account.isSyncNotAllowed()) {
        viewHolder.jid.setText(R.string.sync_status_not_allowed);
        viewHolder.chkAccountSync.setEnabled(false);
    } else if (isAllChecked) {
        viewHolder.chkAccountSync.setEnabled(false);
        viewHolder.chkAccountSync.setChecked(true);
    } else {
        viewHolder.chkAccountSync.setEnabled(true);
        viewHolder.chkAccountSync.setChecked(account.isSynchronization());
    }
}
Also used : XMPPAccountSettings(com.xabber.android.data.xaccount.XMPPAccountSettings) AccountJid(com.xabber.android.data.entity.AccountJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) CompoundButton(android.widget.CompoundButton)

Example 55 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.

the class FillableForm method setAnswer.

public void setAnswer(String fieldName, CharSequence answer) {
    FormField blankField = getFieldOrThrow(fieldName);
    FormField.Type type = blankField.getType();
    FormField filledFormField;
    switch(type) {
        case list_multi:
        case jid_multi:
            throw new IllegalArgumentException("Can not answer fields of type '" + type + "' with a CharSequence");
        case fixed:
            throw new IllegalArgumentException("Fields of type 'fixed' are not answerable");
        case list_single:
        case text_private:
        case text_single:
        case hidden:
            filledFormField = createSingleKindFieldBuilder(fieldName, type).setValue(answer).build();
            break;
        case bool:
            filledFormField = FormField.booleanBuilder(fieldName).setValue(answer).build();
            break;
        case jid_single:
            Jid jid;
            try {
                jid = JidCreate.from(answer);
            } catch (XmppStringprepException e) {
                throw new IllegalArgumentException(e);
            }
            filledFormField = FormField.jidSingleBuilder(fieldName).setValue(jid).build();
            break;
        case text_multi:
            filledFormField = createMultiKindFieldbuilder(fieldName, type).addValue(answer).build();
            break;
        default:
            throw new AssertionError();
    }
    write(filledFormField);
}
Also used : Jid(org.jxmpp.jid.Jid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) AbstractSingleStringValueFormField(org.jivesoftware.smackx.xdata.AbstractSingleStringValueFormField) AbstractMultiFormField(org.jivesoftware.smackx.xdata.AbstractMultiFormField) FormField(org.jivesoftware.smackx.xdata.FormField)

Aggregations

XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)76 DomainBareJid (org.jxmpp.jid.DomainBareJid)20 SmackException (org.jivesoftware.smack.SmackException)18 Jid (org.jxmpp.jid.Jid)18 EntityBareJid (org.jxmpp.jid.EntityBareJid)16 AccountJid (com.xabber.android.data.entity.AccountJid)12 XMPPException (org.jivesoftware.smack.XMPPException)12 UserJid (com.xabber.android.data.entity.UserJid)11 BareJid (org.jxmpp.jid.BareJid)9 Resourcepart (org.jxmpp.jid.parts.Resourcepart)9 ArrayList (java.util.ArrayList)8 Localpart (org.jxmpp.jid.parts.Localpart)8 Cursor (android.database.Cursor)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 HashMap (java.util.HashMap)5 SwingWorker (org.jivesoftware.spark.util.SwingWorker)5 IOException (java.io.IOException)4 KeyManagementException (java.security.KeyManagementException)4 NetworkException (com.xabber.android.data.NetworkException)3 InetAddress (java.net.InetAddress)3