Search in sources :

Example 51 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class QuestionViewer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isFinishing()) {
        return;
    }
    Intent intent = getIntent();
    account = QuestionViewer.getAccount(intent);
    user = QuestionViewer.getUser(intent);
    if (AccountManager.getInstance().getAccount(account) == null || user == null) {
        Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
        finish();
        return;
    }
    if (intent.getBooleanExtra(EXTRA_FIELD_CANCEL, false)) {
        try {
            OTRManager.getInstance().abortSmp(account, user);
        } catch (NetworkException e) {
            Application.getInstance().onError(e);
        }
        finish();
        return;
    }
    showQuestion = intent.getBooleanExtra(EXTRA_FIELD_SHOW_QUESTION, true);
    answerRequest = intent.getBooleanExtra(EXTRA_FIELD_ANSWER_REQUEST, false);
    if (showQuestion) {
        setContentView(R.layout.question_viewer);
        questionView = (EditText) findViewById(R.id.question);
        questionView.setEnabled(!answerRequest);
        if (answerRequest) {
            questionView.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
        } else {
            findViewById(R.id.cancel).setVisibility(View.GONE);
        }
    } else {
        setContentView(R.layout.secret_viewer);
    }
    findViewById(R.id.cancel).setOnClickListener(this);
    findViewById(R.id.send).setOnClickListener(this);
    contactTitleActionBarInflater = new ContactTitleActionBarInflater(this, (Toolbar) findViewById(R.id.toolbar_default));
    contactTitleActionBarInflater.setUpActionBarView();
}
Also used : ContactTitleActionBarInflater(com.xabber.android.ui.helper.ContactTitleActionBarInflater) Intent(android.content.Intent) NetworkException(com.xabber.android.data.NetworkException) Toolbar(android.support.v7.widget.Toolbar)

Example 52 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class SSNManager method sendFeature.

private void sendFeature(String account, String user, String session, Feature feature) {
    Message message = new Message(user, Message.Type.normal);
    message.setThread(session);
    message.addExtension(feature);
    try {
        ConnectionManager.getInstance().sendStanza(account, message);
    } catch (NetworkException e) {
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) NetworkException(com.xabber.android.data.NetworkException)

Example 53 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class TimeManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    String account = ((AccountItem) connection).getAccount();
    if (!(packet instanceof Time))
        return;
    Time time = (Time) packet;
    if (time.getType() == Type.get) {
        Time result = new Time();
        result.setType(Type.result);
        result.setPacketID(time.getPacketID());
        result.setFrom(time.getTo());
        result.setTo(time.getFrom());
        Calendar calendar = Calendar.getInstance();
        result.setTzo((calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / 60000);
        result.setUtc(calendar.getTime());
        try {
            ConnectionManager.getInstance().sendStanza(account, result);
        } catch (NetworkException e) {
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Calendar(java.util.Calendar) Time(com.xabber.xmpp.time.Time) NetworkException(com.xabber.android.data.NetworkException)

Example 54 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class VCardManager method onVCardReceived.

private void onVCardReceived(final String account, final String bareAddress, final VCard vCard) {
    final StructuredName name;
    if (vCard.getType() == Type.error) {
        onVCardFailed(account, bareAddress);
        if (names.containsKey(bareAddress)) {
            return;
        }
        name = EMPTY_STRUCTURED_NAME;
    } else {
        for (OnVCardListener listener : Application.getInstance().getUIListeners(OnVCardListener.class)) {
            listener.onVCardReceived(account, bareAddress, vCard);
        }
        String hash = vCard.getAvatarHash();
        AvatarManager.getInstance().onAvatarReceived(bareAddress, hash, vCard.getAvatar());
        name = new StructuredName(vCard.getNickName(), vCard.getField(VCardProperty.FN.name()), vCard.getFirstName(), vCard.getMiddleName(), vCard.getLastName());
        Application.getInstance().runInBackground(new Runnable() {

            @Override
            public void run() {
                try {
                    if (Jid.getBareAddress(account).equals(bareAddress)) {
                        PresenceManager.getInstance().resendPresence(account);
                    }
                } catch (NetworkException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    names.put(bareAddress, name);
    for (RosterContact rosterContact : RosterManager.getInstance().getContacts()) {
        if (rosterContact.getUser().equals(bareAddress)) {
            for (OnRosterChangedListener listener : Application.getInstance().getManagers(OnRosterChangedListener.class)) {
                listener.onContactStructuredInfoChanged(rosterContact, name);
            }
        }
    }
    Application.getInstance().runInBackground(new Runnable() {

        @Override
        public void run() {
            VCardTable.getInstance().write(bareAddress, name);
        }
    });
    if (vCard.getFrom() == null) {
        // account it self
        AccountManager.getInstance().onAccountChanged(account);
    } else {
        RosterManager.getInstance().onContactChanged(account, bareAddress);
    }
}
Also used : OnRosterChangedListener(com.xabber.android.data.roster.OnRosterChangedListener) RosterContact(com.xabber.android.data.roster.RosterContact) StructuredName(com.xabber.android.data.roster.StructuredName) NetworkException(com.xabber.android.data.NetworkException)

Example 55 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class VCardManager method saveVCard.

public void saveVCard(final String account, final VCard vCard) {
    ConnectionThread connectionThread = AccountManager.getInstance().getAccount(account).getConnectionThread();
    if (connectionThread == null) {
        onVCardSaveFailed(account);
        return;
    }
    final AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
    final org.jivesoftware.smackx.vcardtemp.VCardManager vCardManager = org.jivesoftware.smackx.vcardtemp.VCardManager.getInstanceFor(xmppConnection);
    final Thread thread = new Thread("Save vCard for account " + account) {

        @Override
        public void run() {
            boolean isSuccess = true;
            xmppConnection.setPacketReplyTimeout(120000);
            vCardSaveRequests.add(account);
            try {
                vCardManager.saveVCard(vCard);
                String avatarHash = vCard.getAvatarHash();
                if (avatarHash == null) {
                    avatarHash = AvatarManager.EMPTY_HASH;
                }
                PresenceManager.getInstance().sendVCardUpdatePresence(account, avatarHash);
            } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | NetworkException e) {
                LogManager.w(this, "Error saving vCard: " + e.getMessage());
                isSuccess = false;
            }
            vCardSaveRequests.remove(account);
            xmppConnection.setPacketReplyTimeout(ConnectionManager.PACKET_REPLY_TIMEOUT);
            final boolean finalIsSuccess = isSuccess;
            Application.getInstance().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (finalIsSuccess) {
                        onVCardSaveSuccess(account);
                    } else {
                        onVCardSaveFailed(account);
                    }
                }
            });
        }
    };
    thread.start();
}
Also used : ConnectionThread(com.xabber.android.data.connection.ConnectionThread) ConnectionThread(com.xabber.android.data.connection.ConnectionThread) NetworkException(com.xabber.android.data.NetworkException) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Aggregations

NetworkException (com.xabber.android.data.NetworkException)63 Message (org.jivesoftware.smack.packet.Message)13 OtrException (net.java.otr4j.OtrException)11 AccountItem (com.xabber.android.data.account.AccountItem)10 AbstractChat (com.xabber.android.data.message.AbstractChat)10 AccountJid (com.xabber.android.data.entity.AccountJid)9 OnResponseListener (com.xabber.android.data.connection.OnResponseListener)6 Date (java.util.Date)6 IQ (org.jivesoftware.smack.packet.IQ)6 UserJid (com.xabber.android.data.entity.UserJid)5 Presence (org.jivesoftware.smack.packet.Presence)4 Intent (android.content.Intent)3 Set (com.xabber.xmpp.rsm.Set)3 File (java.io.File)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)2 Captcha (com.xabber.android.data.extension.captcha.Captcha)2 RoomChat (com.xabber.android.data.extension.muc.RoomChat)2 NotificationState (com.xabber.android.data.message.NotificationState)2 RegularChat (com.xabber.android.data.message.RegularChat)2 OnRosterChangedListener (com.xabber.android.data.roster.OnRosterChangedListener)2