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