make presence selector work with empty resources (bare jid)

This commit is contained in:
Daniel Gultsch 2020-06-13 09:59:39 +02:00
parent 0dba9f560c
commit fda9e7b51c
2 changed files with 902 additions and 897 deletions

View File

@ -205,7 +205,7 @@ public abstract class XmppActivity extends ActionBarActivity {
super.onStart(); super.onStart();
if (!xmppConnectionServiceBound) { if (!xmppConnectionServiceBound) {
if (this.mSkipBackgroundBinding) { if (this.mSkipBackgroundBinding) {
Log.d(Config.LOGTAG,"skipping background binding"); Log.d(Config.LOGTAG, "skipping background binding");
} else { } else {
connectToBackend(); connectToBackend();
} }
@ -223,7 +223,7 @@ public abstract class XmppActivity extends ActionBarActivity {
try { try {
startService(intent); startService(intent);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Log.w(Config.LOGTAG,"unable to start service from "+getClass().getSimpleName()); Log.w(Config.LOGTAG, "unable to start service from " + getClass().getSimpleName());
} }
bindService(intent, mConnection, Context.BIND_AUTO_CREATE); bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
} }
@ -385,12 +385,8 @@ public abstract class XmppActivity extends ActionBarActivity {
listener.onPresenceSelected(); listener.onPresenceSelected();
} }
} else if (presences.size() == 1) { } else if (presences.size() == 1) {
String presence = presences.toResourceArray()[0]; final String presence = presences.toResourceArray()[0];
try { conversation.setNextCounterpart(PresenceSelector.getNextCounterpart(contact, presence));
conversation.setNextCounterpart(Jid.of(contact.getJid().getLocal(), contact.getJid().getDomain(), presence));
} catch (IllegalArgumentException e) {
conversation.setNextCounterpart(null);
}
listener.onPresenceSelected(); listener.onPresenceSelected();
} else { } else {
PresenceSelector.showPresenceSelectionDialog(this, conversation, listener); PresenceSelector.showPresenceSelectionDialog(this, conversation, listener);
@ -560,12 +556,12 @@ public abstract class XmppActivity extends ActionBarActivity {
try { try {
startService(intent); startService(intent);
} catch (Exception e) { } catch (Exception e) {
Log.e(Config.LOGTAG,"unable to delegate uri permission",e); Log.e(Config.LOGTAG, "unable to delegate uri permission", e);
} }
} }
protected void inviteToConversation(Conversation conversation) { protected void inviteToConversation(Conversation conversation) {
startActivityForResult(ChooseContactActivity.create(this,conversation), REQUEST_INVITE_TO_CONVERSATION); startActivityForResult(ChooseContactActivity.create(this, conversation), REQUEST_INVITE_TO_CONVERSATION);
} }
protected void announcePgp(final Account account, final Conversation conversation, Intent intent, final Runnable onSuccess) { protected void announcePgp(final Account account, final Conversation conversation, Intent intent, final Runnable onSuccess) {
@ -669,7 +665,7 @@ public abstract class XmppActivity extends ActionBarActivity {
builder.setTitle(contact.getJid().toString()); builder.setTitle(contact.getJid().toString());
builder.setMessage(getString(R.string.not_in_roster)); builder.setMessage(getString(R.string.not_in_roster));
builder.setNegativeButton(getString(R.string.cancel), null); builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.add_contact), (dialog, which) -> xmppConnectionService.createContact(contact,true)); builder.setPositiveButton(getString(R.string.add_contact), (dialog, which) -> xmppConnectionService.createContact(contact, true));
builder.create().show(); builder.create().show();
} }
@ -709,7 +705,7 @@ public abstract class XmppActivity extends ActionBarActivity {
boolean password, boolean password,
boolean permitEmpty) { boolean permitEmpty) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
DialogQuickeditBinding binding = DataBindingUtil.inflate(getLayoutInflater(),R.layout.dialog_quickedit, null, false); DialogQuickeditBinding binding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.dialog_quickedit, null, false);
if (password) { if (password) {
binding.inputEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); binding.inputEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
} }
@ -841,7 +837,7 @@ public abstract class XmppActivity extends ActionBarActivity {
@Override @Override
public boolean onMenuOpened(int id, Menu menu) { public boolean onMenuOpened(int id, Menu menu) {
if(id == AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR && menu != null) { if (id == AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR && menu != null) {
MenuDoubleTabUtil.recordMenuOpen(); MenuDoubleTabUtil.recordMenuOpen();
} }
return super.onMenuOpened(id, menu); return super.onMenuOpened(id, menu);
@ -1006,7 +1002,7 @@ public abstract class XmppActivity extends ActionBarActivity {
if (context instanceof XmppActivity) { if (context instanceof XmppActivity) {
return (XmppActivity) context; return (XmppActivity) context;
} }
context = ((ContextWrapper)context).getBaseContext(); context = ((ContextWrapper) context).getBaseContext();
} }
return null; return null;
} }

View File

@ -106,12 +106,21 @@ public class PresenceSelector {
builder.setPositiveButton( builder.setPositiveButton(
R.string.ok, R.string.ok,
(dialog, which) -> onFullJidSelected.onFullJidSelected( (dialog, which) -> onFullJidSelected.onFullJidSelected(
Jid.of(contact.getJid().getLocal(), contact.getJid().getDomain(), resourceArray[selectedResource.get()]) getNextCounterpart(contact, resourceArray[selectedResource.get()])
) )
); );
builder.create().show(); builder.create().show();
} }
public static Jid getNextCounterpart(final Contact contact, final String resource) {
if (resource.isEmpty()) {
return contact.getJid().asBareJid();
} else {
return contact.getJid().withResource(resource);
}
}
public static void warnMutualPresenceSubscription(Activity activity, final Conversation conversation, final OnPresenceSelected listener) { public static void warnMutualPresenceSubscription(Activity activity, final Conversation conversation, final OnPresenceSelected listener) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(conversation.getContact().getJid().toString()); builder.setTitle(conversation.getContact().getJid().toString());