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);
}
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);
}
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();
}
}
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);
}
}
});
}
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();
}
}
Aggregations