Search in sources :

Example 6 with Bookmark

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

the class XmppConnectionService method saveConversationAsBookmark.

public void saveConversationAsBookmark(Conversation conversation, String name) {
    Account account = conversation.getAccount();
    Bookmark bookmark = new Bookmark(account, conversation.getJid().toBareJid());
    if (!conversation.getJid().isBareJid()) {
        bookmark.setNick(conversation.getJid().getResourcepart());
    }
    if (name != null && !name.trim().isEmpty()) {
        bookmark.setBookmarkName(name.trim());
    }
    bookmark.setAutojoin(getPreferences().getBoolean("autojoin", true));
    account.getBookmarks().add(bookmark);
    pushBookmarks(account);
    conversation.setBookmark(bookmark);
}
Also used : Account(eu.siacs.conversations.entities.Account) Bookmark(eu.siacs.conversations.entities.Bookmark)

Example 7 with Bookmark

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

the class XmppConnectionService method pushBookmarks.

public void pushBookmarks(Account account) {
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": pushing bookmarks");
    IqPacket iqPacket = new IqPacket(IqPacket.TYPE.SET);
    Element query = iqPacket.query("jabber:iq:private");
    Element storage = query.addChild("storage", "storage:bookmarks");
    for (Bookmark bookmark : account.getBookmarks()) {
        storage.addChild(bookmark);
    }
    sendIqPacket(account, iqPacket, mDefaultIqHandler);
}
Also used : Bookmark(eu.siacs.conversations.entities.Bookmark) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 8 with Bookmark

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

the class XmppConnectionService method archiveConversation.

public void archiveConversation(Conversation conversation) {
    getNotificationService().clear(conversation);
    conversation.setStatus(Conversation.STATUS_ARCHIVED);
    synchronized (this.conversations) {
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            if (conversation.getAccount().getStatus() == Account.State.ONLINE) {
                Bookmark bookmark = conversation.getBookmark();
                if (bookmark != null && bookmark.autojoin() && respectAutojoin()) {
                    bookmark.setAutojoin(false);
                    pushBookmarks(bookmark.getAccount());
                }
            }
            leaveMuc(conversation);
        } else {
            conversation.endOtrIfNeeded();
            if (conversation.getContact().getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
                Log.d(Config.LOGTAG, "Canceling presence request from " + conversation.getJid().toString());
                sendPresencePacket(conversation.getAccount(), mPresenceGenerator.stopPresenceUpdatesTo(conversation.getContact()));
            }
        }
        updateConversation(conversation);
        this.conversations.remove(conversation);
        updateConversationUi();
    }
}
Also used : Bookmark(eu.siacs.conversations.entities.Bookmark)

Example 9 with Bookmark

use of eu.siacs.conversations.entities.Bookmark 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 10 with Bookmark

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

the class StartConversationActivity method shareBookmarkUri.

protected void shareBookmarkUri(int position) {
    Bookmark bookmark = (Bookmark) conferences.get(position);
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + bookmark.getJid().toBareJid().toString() + "?join");
    shareIntent.setType("text/plain");
    try {
        startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with)));
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, R.string.no_application_to_share_uri, Toast.LENGTH_SHORT).show();
    }
}
Also used : Bookmark(eu.siacs.conversations.entities.Bookmark) ActivityNotFoundException(android.content.ActivityNotFoundException) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Aggregations

Bookmark (eu.siacs.conversations.entities.Bookmark)12 Account (eu.siacs.conversations.entities.Account)7 Jid (eu.siacs.conversations.xmpp.jid.Jid)4 Conversation (eu.siacs.conversations.entities.Conversation)3 Element (eu.siacs.conversations.xml.Element)3 SuppressLint (android.annotation.SuppressLint)2 AlertDialog (android.app.AlertDialog)2 MucOptions (eu.siacs.conversations.entities.MucOptions)2 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)2 PendingIntent (android.app.PendingIntent)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Intent (android.content.Intent)1 SpannableString (android.text.SpannableString)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 CheckBox (android.widget.CheckBox)1 Checkable (android.widget.Checkable)1