Search in sources :

Example 96 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class SettingsActivity method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String name) {
    final List<String> resendPresence = Arrays.asList("confirm_messages", "xa_on_silent_mode", AWAY_WHEN_SCREEN_IS_OFF, "allow_message_correction", TREAT_VIBRATE_AS_SILENT, MANUALLY_CHANGE_PRESENCE, "last_activity");
    if (name.equals("resource")) {
        String resource = preferences.getString("resource", "mobile").toLowerCase(Locale.US);
        if (xmppConnectionServiceBound) {
            for (Account account : xmppConnectionService.getAccounts()) {
                if (account.setResource(resource)) {
                    if (!account.isOptionSet(Account.OPTION_DISABLED)) {
                        XmppConnection connection = account.getXmppConnection();
                        if (connection != null) {
                            connection.resetStreamId();
                        }
                        xmppConnectionService.reconnectAccountInBackground(account);
                    }
                }
            }
        }
    } else if (name.equals(KEEP_FOREGROUND_SERVICE)) {
        boolean foreground_service = preferences.getBoolean(KEEP_FOREGROUND_SERVICE, false);
        if (!foreground_service) {
            xmppConnectionService.clearStartTimeCounter();
        }
        xmppConnectionService.toggleForegroundService();
    } else if (resendPresence.contains(name)) {
        if (xmppConnectionServiceBound) {
            if (name.equals(AWAY_WHEN_SCREEN_IS_OFF) || name.equals(MANUALLY_CHANGE_PRESENCE)) {
                xmppConnectionService.toggleScreenEventReceiver();
            }
            if (name.equals(MANUALLY_CHANGE_PRESENCE) && !noAccountUsesPgp()) {
                Toast.makeText(this, R.string.republish_pgp_keys, Toast.LENGTH_LONG).show();
            }
            xmppConnectionService.refreshAllPresences();
        }
    } else if (name.equals("dont_trust_system_cas")) {
        xmppConnectionService.updateMemorizingTrustmanager();
        reconnectAccounts();
    } else if (name.equals("use_tor")) {
        reconnectAccounts();
    } else if (name.equals(AUTOMATIC_MESSAGE_DELETION)) {
        xmppConnectionService.expireOldMessages(true);
    }
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) Account(eu.siacs.conversations.entities.Account)

Example 97 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class StartConversationActivity method showJoinConferenceDialog.

@SuppressLint("InflateParams")
protected void showJoinConferenceDialog(final String prefilledJid) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.join_conference);
    final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
    final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
    final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
    final TextView jabberIdDesc = (TextView) dialogView.findViewById(R.id.jabber_id);
    jabberIdDesc.setText(R.string.conference_address);
    jid.setHint(R.string.conference_address_example);
    jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts));
    if (prefilledJid != null) {
        jid.append(prefilledJid);
    }
    populateAccountSpinner(this, mActivatedAccounts, spinner);
    final Checkable bookmarkCheckBox = (CheckBox) dialogView.findViewById(R.id.bookmark);
    builder.setView(dialogView);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.join, null);
    final AlertDialog dialog = builder.create();
    dialog.show();
    mCurrentDialog = dialog;
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            if (!xmppConnectionServiceBound) {
                return;
            }
            final Account account = getSelectedAccount(spinner);
            if (account == null) {
                return;
            }
            final Jid conferenceJid;
            try {
                conferenceJid = Jid.fromString(jid.getText().toString());
            } catch (final InvalidJidException e) {
                jid.setError(getString(R.string.invalid_jid));
                return;
            }
            if (bookmarkCheckBox.isChecked()) {
                if (account.hasBookmarkFor(conferenceJid)) {
                    jid.setError(getString(R.string.bookmark_already_exists));
                } else {
                    final Bookmark bookmark = new Bookmark(account, conferenceJid.toBareJid());
                    bookmark.setAutojoin(getPreferences().getBoolean("autojoin", true));
                    String nick = conferenceJid.getResourcepart();
                    if (nick != null && !nick.isEmpty()) {
                        bookmark.setNick(nick);
                    }
                    account.getBookmarks().add(bookmark);
                    xmppConnectionService.pushBookmarks(account);
                    final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true);
                    conversation.setBookmark(bookmark);
                    dialog.dismiss();
                    mCurrentDialog = null;
                    switchToConversation(conversation);
                }
            } else {
                final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true);
                dialog.dismiss();
                mCurrentDialog = null;
                switchToConversation(conversation);
            }
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) KnownHostsAdapter(eu.siacs.conversations.ui.adapter.KnownHostsAdapter) Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) Spinner(android.widget.Spinner) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation) SpannableString(android.text.SpannableString) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Bookmark(eu.siacs.conversations.entities.Bookmark) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Checkable(android.widget.Checkable) AutoCompleteTextView(android.widget.AutoCompleteTextView) SuppressLint(android.annotation.SuppressLint)

Example 98 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class StartConversationActivity method filterContacts.

protected void filterContacts(String needle) {
    this.contacts.clear();
    for (Account account : xmppConnectionService.getAccounts()) {
        if (account.getStatus() != Account.State.DISABLED) {
            for (Contact contact : account.getRoster().getContacts()) {
                Presence.Status s = contact.getShownStatus();
                if (contact.showInRoster() && contact.match(this, needle) && (!this.mHideOfflineContacts || (needle != null && !needle.trim().isEmpty()) || s.compareTo(Presence.Status.OFFLINE) < 0)) {
                    this.contacts.add(contact);
                }
            }
        }
    }
    Collections.sort(this.contacts);
    mContactsAdapter.notifyDataSetChanged();
}
Also used : Account(eu.siacs.conversations.entities.Account) Presence(eu.siacs.conversations.entities.Presence) Contact(eu.siacs.conversations.entities.Contact)

Example 99 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class StartConversationActivity method deleteConference.

protected void deleteConference() {
    int position = conference_context_id;
    final Bookmark bookmark = (Bookmark) conferences.get(position);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setTitle(R.string.delete_bookmark);
    builder.setMessage(getString(R.string.remove_bookmark_text, bookmark.getJid()));
    builder.setPositiveButton(R.string.delete, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            bookmark.unregisterConversation();
            Account account = bookmark.getAccount();
            account.getBookmarks().remove(bookmark);
            xmppConnectionService.pushBookmarks(account);
            filter(mSearchEditText.getText().toString());
        }
    });
    builder.create().show();
}
Also used : AlertDialog(android.app.AlertDialog) Account(eu.siacs.conversations.entities.Account) Bookmark(eu.siacs.conversations.entities.Bookmark) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) SuppressLint(android.annotation.SuppressLint)

Example 100 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class StartConversationActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if ((requestCode & 0xFFFF) == IntentIntegrator.REQUEST_CODE) {
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        if (scanResult != null && scanResult.getFormatName() != null) {
            String data = scanResult.getContents();
            Invite invite = new Invite(data);
            if (xmppConnectionServiceBound) {
                invite.invite();
            } else if (invite.getJid() != null) {
                this.mPendingInvite = invite;
            } else {
                this.mPendingInvite = null;
            }
        }
    } else if (resultCode == RESULT_OK) {
        if (xmppConnectionServiceBound) {
            this.mPostponedActivityResult = null;
            if (requestCode == REQUEST_CREATE_CONFERENCE) {
                Account account = extractAccount(intent);
                final String subject = intent.getStringExtra("subject");
                List<Jid> jids = new ArrayList<>();
                if (intent.getBooleanExtra("multiple", false)) {
                    String[] toAdd = intent.getStringArrayExtra("contacts");
                    for (String item : toAdd) {
                        try {
                            jids.add(Jid.fromString(item));
                        } catch (InvalidJidException e) {
                        //ignored
                        }
                    }
                } else {
                    try {
                        jids.add(Jid.fromString(intent.getStringExtra("contact")));
                    } catch (Exception e) {
                    //ignored
                    }
                }
                if (account != null && jids.size() > 0) {
                    if (xmppConnectionService.createAdhocConference(account, subject, jids, mAdhocConferenceCallback)) {
                        mToast = Toast.makeText(this, R.string.creating_conference, Toast.LENGTH_LONG);
                        mToast.show();
                    }
                }
            }
        } else {
            this.mPostponedActivityResult = new Pair<>(requestCode, intent);
        }
    }
    super.onActivityResult(requestCode, requestCode, intent);
}
Also used : Account(eu.siacs.conversations.entities.Account) IntentResult(com.google.zxing.integration.android.IntentResult) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) List(java.util.List) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) ActivityNotFoundException(android.content.ActivityNotFoundException) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Pair(android.util.Pair)

Aggregations

Account (eu.siacs.conversations.entities.Account)100 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)41 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 Jid (eu.siacs.conversations.xmpp.jid.Jid)22 Element (eu.siacs.conversations.xml.Element)21 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)17 Conversation (eu.siacs.conversations.entities.Conversation)16 Contact (eu.siacs.conversations.entities.Contact)9 Message (eu.siacs.conversations.entities.Message)9 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)7 Intent (android.content.Intent)7 Bookmark (eu.siacs.conversations.entities.Bookmark)7 SuppressLint (android.annotation.SuppressLint)6 AlertDialog (android.app.AlertDialog)6 TextView (android.widget.TextView)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 FileNotFoundException (java.io.FileNotFoundException)6 DialogInterface (android.content.DialogInterface)5 View (android.view.View)5