use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.
the class XmppActivity method selectPresence.
public void selectPresence(final Conversation conversation, final PresenceSelector.OnPresenceSelected listener) {
final Contact contact = conversation.getContact();
if (conversation.hasValidOtrSession()) {
SessionID id = conversation.getOtrSession().getSessionID();
Jid jid;
try {
jid = Jid.fromString(id.getAccountID() + "/" + id.getUserID());
} catch (InvalidJidException e) {
jid = null;
}
conversation.setNextCounterpart(jid);
listener.onPresenceSelected();
} else if (!contact.showInRoster()) {
showAddToRosterDialog(conversation);
} else {
final Presences presences = contact.getPresences();
if (presences.size() == 0) {
if (!contact.getOption(Contact.Options.TO) && !contact.getOption(Contact.Options.ASKING) && contact.getAccount().getStatus() == Account.State.ONLINE) {
showAskForPresenceDialog(contact);
} else if (!contact.getOption(Contact.Options.TO) || !contact.getOption(Contact.Options.FROM)) {
PresenceSelector.warnMutualPresenceSubscription(this, conversation, listener);
} else {
conversation.setNextCounterpart(null);
listener.onPresenceSelected();
}
} else if (presences.size() == 1) {
String presence = presences.toResourceArray()[0];
try {
conversation.setNextCounterpart(Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), presence));
} catch (InvalidJidException e) {
conversation.setNextCounterpart(null);
}
listener.onPresenceSelected();
} else {
PresenceSelector.showPresenceSelectionDialog(this, conversation, listener);
}
}
}
use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.
the class XmppActivity method showPresenceSelectionDialog.
private void showPresenceSelectionDialog(Presences presences, final Conversation conversation, final OnPresenceSelected listener) {
final Contact contact = conversation.getContact();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.choose_presence));
final String[] resourceArray = presences.toResourceArray();
Pair<Map<String, String>, Map<String, String>> typeAndName = presences.toTypeAndNameMap();
final Map<String, String> resourceTypeMap = typeAndName.first;
final Map<String, String> resourceNameMap = typeAndName.second;
final String[] readableIdentities = new String[resourceArray.length];
final AtomicInteger selectedResource = new AtomicInteger(0);
for (int i = 0; i < resourceArray.length; ++i) {
String resource = resourceArray[i];
if (resource.equals(contact.getLastResource())) {
selectedResource.set(i);
}
String type = resourceTypeMap.get(resource);
String name = resourceNameMap.get(resource);
if (type != null) {
if (Collections.frequency(resourceTypeMap.values(), type) == 1) {
readableIdentities[i] = PresenceSelector.translateType(this, type);
} else if (name != null) {
if (Collections.frequency(resourceNameMap.values(), name) == 1 || CryptoHelper.UUID_PATTERN.matcher(resource).matches()) {
readableIdentities[i] = PresenceSelector.translateType(this, type) + " (" + name + ")";
} else {
readableIdentities[i] = PresenceSelector.translateType(this, type) + " (" + name + " / " + resource + ")";
}
} else {
readableIdentities[i] = PresenceSelector.translateType(this, type) + " (" + resource + ")";
}
} else {
readableIdentities[i] = resource;
}
}
builder.setSingleChoiceItems(readableIdentities, selectedResource.get(), (dialog, which) -> selectedResource.set(which));
builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.ok, (dialog, which) -> {
try {
Jid next = Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), resourceArray[selectedResource.get()]);
conversation.setNextCounterpart(next);
} catch (InvalidJidException e) {
conversation.setNextCounterpart(null);
}
listener.onPresenceSelected();
});
builder.create().show();
}
use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.
the class ShareViaAccountActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manage_accounts);
accountListView = findViewById(R.id.account_list);
this.mAccountAdapter = new AccountAdapter(this, accountList);
accountListView.setAdapter(this.mAccountAdapter);
accountListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
final Account account = accountList.get(position);
final String body = getIntent().getStringExtra(EXTRA_BODY);
try {
final Jid contact = Jid.fromString(getIntent().getStringExtra(EXTRA_CONTACT));
final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contact, false, false);
switchToConversation(conversation, body, false);
} catch (InvalidJidException e) {
// ignore error
}
finish();
}
});
}
use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.
the class StartConversationActivity method openConversationsForBookmark.
protected void openConversationsForBookmark(Bookmark bookmark) {
Jid jid = bookmark.getJid();
if (jid == null) {
Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
return;
}
Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), jid, true, true, true);
bookmark.setConversation(conversation);
if (!bookmark.autojoin() && getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin))) {
bookmark.setAutojoin(true);
xmppConnectionService.pushBookmarks(bookmark.getAccount());
}
switchToConversation(conversation);
}
use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.
the class SettingsActivity method deleteOmemoIdentities.
private boolean deleteOmemoIdentities() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.pref_delete_omemo_identities);
final List<CharSequence> accounts = new ArrayList<>();
for (Account account : xmppConnectionService.getAccounts()) {
if (account.isEnabled()) {
accounts.add(account.getJid().toBareJid().toString());
}
}
final boolean[] checkedItems = new boolean[accounts.size()];
builder.setMultiChoiceItems(accounts.toArray(new CharSequence[accounts.size()]), checkedItems, (dialog, which, isChecked) -> {
checkedItems[which] = isChecked;
final AlertDialog alertDialog = (AlertDialog) dialog;
for (boolean item : checkedItems) {
if (item) {
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
return;
}
}
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
});
builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.delete_selected_keys, (dialog, which) -> {
for (int i = 0; i < checkedItems.length; ++i) {
if (checkedItems[i]) {
try {
Jid jid = Jid.fromString(accounts.get(i).toString());
Account account = xmppConnectionService.findAccountByJid(jid);
if (account != null) {
account.getAxolotlService().regenerateKeys(true);
}
} catch (InvalidJidException e) {
//
}
}
}
});
AlertDialog dialog = builder.create();
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
return true;
}
Aggregations