auto register/unregister listeners
This commit is contained in:
parent
fce78abb1c
commit
e555fe4b03
|
@ -31,7 +31,7 @@ import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class ConferenceDetailsActivity extends XmppActivity {
|
public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnRenameListener {
|
||||||
public static final String ACTION_VIEW_MUC = "view_muc";
|
public static final String ACTION_VIEW_MUC = "view_muc";
|
||||||
private Conversation conversation;
|
private Conversation conversation;
|
||||||
private TextView mYourNick;
|
private TextView mYourNick;
|
||||||
|
@ -53,8 +53,28 @@ public class ConferenceDetailsActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRename(final boolean success) {
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
populateView();
|
||||||
|
if (success) {
|
||||||
|
Toast.makeText(
|
||||||
|
ConferenceDetailsActivity.this,
|
||||||
|
getString(R.string.your_nick_has_been_changed),
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(ConferenceDetailsActivity.this,
|
||||||
|
getString(R.string.nick_in_use),
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private List<User> users = new ArrayList<>();
|
private List<User> users = new ArrayList<>();
|
||||||
private OnConversationUpdate onConvChanged = new OnConversationUpdate() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConversationUpdate() {
|
public void onConversationUpdate() {
|
||||||
|
@ -66,7 +86,6 @@ public class ConferenceDetailsActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -156,7 +175,6 @@ public class ConferenceDetailsActivity extends XmppActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onBackendConnected() {
|
void onBackendConnected() {
|
||||||
registerListener();
|
|
||||||
if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {
|
if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {
|
||||||
this.uuid = getIntent().getExtras().getString("uuid");
|
this.uuid = getIntent().getExtras().getString("uuid");
|
||||||
}
|
}
|
||||||
|
@ -169,42 +187,6 @@ public class ConferenceDetailsActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
if (xmppConnectionServiceBound) {
|
|
||||||
xmppConnectionService.removeOnConversationListChangedListener();
|
|
||||||
}
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void registerListener() {
|
|
||||||
xmppConnectionService
|
|
||||||
.setOnConversationListChangedListener(this.onConvChanged);
|
|
||||||
xmppConnectionService.setOnRenameListener(new OnRenameListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRename(final boolean success) {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
populateView();
|
|
||||||
if (success) {
|
|
||||||
Toast.makeText(
|
|
||||||
ConferenceDetailsActivity.this,
|
|
||||||
getString(R.string.your_nick_has_been_changed),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
} else {
|
|
||||||
Toast.makeText(ConferenceDetailsActivity.this,
|
|
||||||
getString(R.string.nick_in_use),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void populateView() {
|
private void populateView() {
|
||||||
mAccountJid.setText(getString(R.string.using_account, conversation
|
mAccountJid.setText(getString(R.string.using_account, conversation
|
||||||
.getAccount().getJid().toBareJid()));
|
.getAccount().getJid().toBareJid()));
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -21,12 +17,17 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.QuickContactBadge;
|
import android.widget.QuickContactBadge;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.openintents.openpgp.util.OpenPgpUtils;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.crypto.PgpEngine;
|
import eu.siacs.conversations.crypto.PgpEngine;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
|
@ -38,22 +39,10 @@ import eu.siacs.conversations.utils.UIHelper;
|
||||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
|
|
||||||
public class ContactDetailsActivity extends XmppActivity {
|
public class ContactDetailsActivity extends XmppActivity implements OnAccountUpdate, OnRosterUpdate {
|
||||||
public static final String ACTION_VIEW_CONTACT = "view_contact";
|
public static final String ACTION_VIEW_CONTACT = "view_contact";
|
||||||
|
|
||||||
private Contact contact;
|
private Contact contact;
|
||||||
|
|
||||||
private Jid accountJid;
|
|
||||||
private Jid contactJid;
|
|
||||||
|
|
||||||
private TextView contactJidTv;
|
|
||||||
private TextView accountJidTv;
|
|
||||||
private TextView status;
|
|
||||||
private TextView lastseen;
|
|
||||||
private CheckBox send;
|
|
||||||
private CheckBox receive;
|
|
||||||
private QuickContactBadge badge;
|
|
||||||
|
|
||||||
private DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() {
|
private DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,7 +52,54 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
ContactDetailsActivity.this.finish();
|
ContactDetailsActivity.this.finish();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private OnCheckedChangeListener mOnSendCheckedChange = new OnCheckedChangeListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView,
|
||||||
|
boolean isChecked) {
|
||||||
|
if (isChecked) {
|
||||||
|
if (contact
|
||||||
|
.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
||||||
|
xmppConnectionService.sendPresencePacket(contact
|
||||||
|
.getAccount(),
|
||||||
|
xmppConnectionService.getPresenceGenerator()
|
||||||
|
.sendPresenceUpdatesTo(contact));
|
||||||
|
} else {
|
||||||
|
contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
||||||
|
xmppConnectionService.sendPresencePacket(contact.getAccount(),
|
||||||
|
xmppConnectionService.getPresenceGenerator()
|
||||||
|
.stopPresenceUpdatesTo(contact));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private OnCheckedChangeListener mOnReceiveCheckedChange = new OnCheckedChangeListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView,
|
||||||
|
boolean isChecked) {
|
||||||
|
if (isChecked) {
|
||||||
|
xmppConnectionService.sendPresencePacket(contact.getAccount(),
|
||||||
|
xmppConnectionService.getPresenceGenerator()
|
||||||
|
.requestPresenceUpdatesFrom(contact));
|
||||||
|
} else {
|
||||||
|
xmppConnectionService.sendPresencePacket(contact.getAccount(),
|
||||||
|
xmppConnectionService.getPresenceGenerator()
|
||||||
|
.stopPresenceUpdatesFrom(contact));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private Jid accountJid;
|
||||||
|
private Jid contactJid;
|
||||||
|
private TextView contactJidTv;
|
||||||
|
private TextView accountJidTv;
|
||||||
|
private TextView status;
|
||||||
|
private TextView lastseen;
|
||||||
|
private CheckBox send;
|
||||||
|
private CheckBox receive;
|
||||||
|
private QuickContactBadge badge;
|
||||||
private DialogInterface.OnClickListener addToPhonebook = new DialogInterface.OnClickListener() {
|
private DialogInterface.OnClickListener addToPhonebook = new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -91,82 +127,34 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private LinearLayout keys;
|
private LinearLayout keys;
|
||||||
|
|
||||||
private OnRosterUpdate rosterUpdate = new OnRosterUpdate() {
|
@Override
|
||||||
|
public void onRosterUpdate() {
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRosterUpdate() {
|
public void run() {
|
||||||
runOnUiThread(new Runnable() {
|
populateView();
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
populateView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private OnCheckedChangeListener mOnSendCheckedChange = new OnCheckedChangeListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView,
|
|
||||||
boolean isChecked) {
|
|
||||||
if (isChecked) {
|
|
||||||
if (contact
|
|
||||||
.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
|
||||||
xmppConnectionService.sendPresencePacket(contact
|
|
||||||
.getAccount(),
|
|
||||||
xmppConnectionService.getPresenceGenerator()
|
|
||||||
.sendPresenceUpdatesTo(contact));
|
|
||||||
} else {
|
|
||||||
contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
|
||||||
xmppConnectionService.sendPresencePacket(contact.getAccount(),
|
|
||||||
xmppConnectionService.getPresenceGenerator()
|
|
||||||
.stopPresenceUpdatesTo(contact));
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
private OnCheckedChangeListener mOnReceiveCheckedChange = new OnCheckedChangeListener() {
|
@Override
|
||||||
|
public void onAccountUpdate() {
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView,
|
public void run() {
|
||||||
boolean isChecked) {
|
populateView();
|
||||||
if (isChecked) {
|
|
||||||
xmppConnectionService.sendPresencePacket(contact.getAccount(),
|
|
||||||
xmppConnectionService.getPresenceGenerator()
|
|
||||||
.requestPresenceUpdatesFrom(contact));
|
|
||||||
} else {
|
|
||||||
xmppConnectionService.sendPresencePacket(contact.getAccount(),
|
|
||||||
xmppConnectionService.getPresenceGenerator()
|
|
||||||
.stopPresenceUpdatesFrom(contact));
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
private OnAccountUpdate accountUpdate = new OnAccountUpdate() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAccountUpdate() {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
populateView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getShareableUri() {
|
protected String getShareableUri() {
|
||||||
if (contact!=null) {
|
if (contact != null) {
|
||||||
return "xmpp:"+contact.getJid();
|
return "xmpp:" + contact.getJid();
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -176,15 +164,15 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
|
if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
|
||||||
try {
|
try {
|
||||||
this.accountJid = Jid.fromString(getIntent().getExtras().getString("account"));
|
this.accountJid = Jid.fromString(getIntent().getExtras().getString("account"));
|
||||||
} catch (final InvalidJidException ignored) {
|
} catch (final InvalidJidException ignored) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact"));
|
this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact"));
|
||||||
} catch (final InvalidJidException ignored) {
|
} catch (final InvalidJidException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setContentView(R.layout.activity_contact_details);
|
setContentView(R.layout.activity_contact_details);
|
||||||
|
|
||||||
contactJidTv = (TextView) findViewById(R.id.details_contactjid);
|
contactJidTv = (TextView) findViewById(R.id.details_contactjid);
|
||||||
|
@ -205,39 +193,39 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setNegativeButton(getString(R.string.cancel), null);
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
finish();
|
finish();
|
||||||
break;
|
break;
|
||||||
case R.id.action_delete_contact:
|
case R.id.action_delete_contact:
|
||||||
builder.setTitle(getString(R.string.action_delete_contact))
|
builder.setTitle(getString(R.string.action_delete_contact))
|
||||||
.setMessage(
|
.setMessage(
|
||||||
getString(R.string.remove_contact_text,
|
getString(R.string.remove_contact_text,
|
||||||
contact.getJid()))
|
contact.getJid()))
|
||||||
.setPositiveButton(getString(R.string.delete),
|
.setPositiveButton(getString(R.string.delete),
|
||||||
removeFromRoster).create().show();
|
removeFromRoster).create().show();
|
||||||
break;
|
break;
|
||||||
case R.id.action_edit_contact:
|
case R.id.action_edit_contact:
|
||||||
if (contact.getSystemAccount() == null) {
|
if (contact.getSystemAccount() == null) {
|
||||||
quickEdit(contact.getDisplayName(), new OnValueEdited() {
|
quickEdit(contact.getDisplayName(), new OnValueEdited() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onValueEdited(String value) {
|
public void onValueEdited(String value) {
|
||||||
contact.setServerName(value);
|
contact.setServerName(value);
|
||||||
ContactDetailsActivity.this.xmppConnectionService
|
ContactDetailsActivity.this.xmppConnectionService
|
||||||
.pushContactToServer(contact);
|
.pushContactToServer(contact);
|
||||||
populateView();
|
populateView();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(Intent.ACTION_EDIT);
|
Intent intent = new Intent(Intent.ACTION_EDIT);
|
||||||
String[] systemAccount = contact.getSystemAccount().split("#");
|
String[] systemAccount = contact.getSystemAccount().split("#");
|
||||||
long id = Long.parseLong(systemAccount[0]);
|
long id = Long.parseLong(systemAccount[0]);
|
||||||
Uri uri = Contacts.getLookupUri(id, systemAccount[1]);
|
Uri uri = Contacts.getLookupUri(id, systemAccount[1]);
|
||||||
intent.setDataAndType(uri, Contacts.CONTENT_ITEM_TYPE);
|
intent.setDataAndType(uri, Contacts.CONTENT_ITEM_TYPE);
|
||||||
intent.putExtra("finishActivityOnSaveCompleted", true);
|
intent.putExtra("finishActivityOnSaveCompleted", true);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(menuItem);
|
return super.onOptionsItemSelected(menuItem);
|
||||||
}
|
}
|
||||||
|
@ -293,34 +281,34 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
contact.lastseen.time));
|
contact.lastseen.time));
|
||||||
|
|
||||||
switch (contact.getMostAvailableStatus()) {
|
switch (contact.getMostAvailableStatus()) {
|
||||||
case Presences.CHAT:
|
case Presences.CHAT:
|
||||||
status.setText(R.string.contact_status_free_to_chat);
|
status.setText(R.string.contact_status_free_to_chat);
|
||||||
status.setTextColor(mColorGreen);
|
status.setTextColor(mColorGreen);
|
||||||
break;
|
break;
|
||||||
case Presences.ONLINE:
|
case Presences.ONLINE:
|
||||||
status.setText(R.string.contact_status_online);
|
status.setText(R.string.contact_status_online);
|
||||||
status.setTextColor(mColorGreen);
|
status.setTextColor(mColorGreen);
|
||||||
break;
|
break;
|
||||||
case Presences.AWAY:
|
case Presences.AWAY:
|
||||||
status.setText(R.string.contact_status_away);
|
status.setText(R.string.contact_status_away);
|
||||||
status.setTextColor(mColorOrange);
|
status.setTextColor(mColorOrange);
|
||||||
break;
|
break;
|
||||||
case Presences.XA:
|
case Presences.XA:
|
||||||
status.setText(R.string.contact_status_extended_away);
|
status.setText(R.string.contact_status_extended_away);
|
||||||
status.setTextColor(mColorOrange);
|
status.setTextColor(mColorOrange);
|
||||||
break;
|
break;
|
||||||
case Presences.DND:
|
case Presences.DND:
|
||||||
status.setText(R.string.contact_status_do_not_disturb);
|
status.setText(R.string.contact_status_do_not_disturb);
|
||||||
status.setTextColor(mColorRed);
|
status.setTextColor(mColorRed);
|
||||||
break;
|
break;
|
||||||
case Presences.OFFLINE:
|
case Presences.OFFLINE:
|
||||||
status.setText(R.string.contact_status_offline);
|
status.setText(R.string.contact_status_offline);
|
||||||
status.setTextColor(mSecondaryTextColor);
|
status.setTextColor(mSecondaryTextColor);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
status.setText(R.string.contact_status_offline);
|
status.setText(R.string.contact_status_offline);
|
||||||
status.setTextColor(mSecondaryTextColor);
|
status.setTextColor(mSecondaryTextColor);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (contact.getPresences().size() > 1) {
|
if (contact.getPresences().size() > 1) {
|
||||||
contactJidTv.setText(contact.getJid() + " ("
|
contactJidTv.setText(contact.getJid() + " ("
|
||||||
|
@ -339,7 +327,7 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
boolean hasKeys = false;
|
boolean hasKeys = false;
|
||||||
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
for (Iterator<String> iterator = contact.getOtrFingerprints()
|
for (Iterator<String> iterator = contact.getOtrFingerprints()
|
||||||
.iterator(); iterator.hasNext();) {
|
.iterator(); iterator.hasNext(); ) {
|
||||||
hasKeys = true;
|
hasKeys = true;
|
||||||
final String otrFingerprint = iterator.next();
|
final String otrFingerprint = iterator.next();
|
||||||
View view = inflater.inflate(R.layout.contact_key, keys, false);
|
View view = inflater.inflate(R.layout.contact_key, keys, false);
|
||||||
|
@ -427,9 +415,6 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackendConnected() {
|
public void onBackendConnected() {
|
||||||
xmppConnectionService.setOnRosterUpdateListener(this.rosterUpdate);
|
|
||||||
xmppConnectionService
|
|
||||||
.setOnAccountListChangedListener(this.accountUpdate);
|
|
||||||
if ((accountJid != null) && (contactJid != null)) {
|
if ((accountJid != null) && (contactJid != null)) {
|
||||||
Account account = xmppConnectionService
|
Account account = xmppConnectionService
|
||||||
.findAccountByJid(accountJid);
|
.findAccountByJid(accountJid);
|
||||||
|
@ -440,12 +425,4 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
populateView();
|
populateView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
xmppConnectionService.removeOnRosterUpdateListener();
|
|
||||||
xmppConnectionService.removeOnAccountListChangedListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -633,18 +633,6 @@ public class ConversationActivity extends XmppActivity implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
if (xmppConnectionServiceBound) {
|
|
||||||
xmppConnectionService.removeOnConversationListChangedListener();
|
|
||||||
xmppConnectionService.removeOnAccountListChangedListener();
|
|
||||||
xmppConnectionService.removeOnRosterUpdateListener();
|
|
||||||
xmppConnectionService.getNotificationService().setOpenConversation(
|
|
||||||
null);
|
|
||||||
}
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(final Bundle savedInstanceState) {
|
public void onSaveInstanceState(final Bundle savedInstanceState) {
|
||||||
Conversation conversation = getSelectedConversation();
|
Conversation conversation = getSelectedConversation();
|
||||||
|
@ -662,9 +650,7 @@ public class ConversationActivity extends XmppActivity implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onBackendConnected() {
|
void onBackendConnected() {
|
||||||
this.registerListener();
|
|
||||||
updateConversationList();
|
updateConversationList();
|
||||||
|
|
||||||
if (xmppConnectionService.getAccounts().size() == 0) {
|
if (xmppConnectionService.getAccounts().size() == 0) {
|
||||||
startActivity(new Intent(this, EditAccountActivity.class));
|
startActivity(new Intent(this, EditAccountActivity.class));
|
||||||
} else if (conversationList.size() <= 0) {
|
} else if (conversationList.size() <= 0) {
|
||||||
|
@ -722,10 +708,10 @@ public class ConversationActivity extends XmppActivity implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerListener() {
|
@Override
|
||||||
xmppConnectionService.setOnConversationListChangedListener(this);
|
protected void unregisterListeners() {
|
||||||
xmppConnectionService.setOnAccountListChangedListener(this);
|
super.unregisterListeners();
|
||||||
xmppConnectionService.setOnRosterUpdateListener(this);
|
xmppConnectionService.getNotificationService().setOpenConversation(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -33,7 +33,7 @@ import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
import eu.siacs.conversations.xmpp.pep.Avatar;
|
import eu.siacs.conversations.xmpp.pep.Avatar;
|
||||||
|
|
||||||
public class EditAccountActivity extends XmppActivity {
|
public class EditAccountActivity extends XmppActivity implements OnAccountUpdate {
|
||||||
|
|
||||||
private AutoCompleteTextView mAccountJid;
|
private AutoCompleteTextView mAccountJid;
|
||||||
private EditText mPassword;
|
private EditText mPassword;
|
||||||
|
@ -132,8 +132,6 @@ public class EditAccountActivity extends XmppActivity {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private OnAccountUpdate mOnAccountUpdateListener = new OnAccountUpdate() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccountUpdate() {
|
public void onAccountUpdate() {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
|
@ -162,7 +160,6 @@ public class EditAccountActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
private UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() {
|
private UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -349,21 +346,11 @@ public class EditAccountActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
if (xmppConnectionServiceBound) {
|
|
||||||
xmppConnectionService.removeOnAccountListChangedListener();
|
|
||||||
}
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBackendConnected() {
|
protected void onBackendConnected() {
|
||||||
KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
|
KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
|
||||||
android.R.layout.simple_list_item_1,
|
android.R.layout.simple_list_item_1,
|
||||||
xmppConnectionService.getKnownHosts());
|
xmppConnectionService.getKnownHosts());
|
||||||
this.xmppConnectionService
|
|
||||||
.setOnAccountListChangedListener(this.mOnAccountUpdateListener);
|
|
||||||
if (this.jidToEdit != null) {
|
if (this.jidToEdit != null) {
|
||||||
this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
|
this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
|
||||||
updateAccountInformation();
|
updateAccountInformation();
|
||||||
|
|
|
@ -22,15 +22,13 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
public class ManageAccountActivity extends XmppActivity {
|
public class ManageAccountActivity extends XmppActivity implements OnAccountUpdate {
|
||||||
|
|
||||||
protected Account selectedAccount = null;
|
protected Account selectedAccount = null;
|
||||||
|
|
||||||
protected List<Account> accountList = new ArrayList<Account>();
|
protected List<Account> accountList = new ArrayList<Account>();
|
||||||
protected ListView accountListView;
|
protected ListView accountListView;
|
||||||
protected AccountAdapter mAccountAdapter;
|
protected AccountAdapter mAccountAdapter;
|
||||||
protected OnAccountUpdate accountChanged = new OnAccountUpdate() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccountUpdate() {
|
public void onAccountUpdate() {
|
||||||
accountList.clear();
|
accountList.clear();
|
||||||
|
@ -43,7 +41,6 @@ public class ManageAccountActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -84,17 +81,8 @@ public class ManageAccountActivity extends XmppActivity {
|
||||||
menu.setHeaderTitle(this.selectedAccount.getJid().toBareJid().toString());
|
menu.setHeaderTitle(this.selectedAccount.getJid().toBareJid().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
if (xmppConnectionServiceBound) {
|
|
||||||
xmppConnectionService.removeOnAccountListChangedListener();
|
|
||||||
}
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onBackendConnected() {
|
void onBackendConnected() {
|
||||||
xmppConnectionService.setOnAccountListChangedListener(accountChanged);
|
|
||||||
this.accountList.clear();
|
this.accountList.clear();
|
||||||
this.accountList.addAll(xmppConnectionService.getAccounts());
|
this.accountList.addAll(xmppConnectionService.getAccounts());
|
||||||
mAccountAdapter.notifyDataSetChanged();
|
mAccountAdapter.notifyDataSetChanged();
|
||||||
|
|
|
@ -66,59 +66,25 @@ import eu.siacs.conversations.utils.Validator;
|
||||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
|
|
||||||
public class StartConversationActivity extends XmppActivity {
|
public class StartConversationActivity extends XmppActivity implements OnRosterUpdate {
|
||||||
|
|
||||||
private Tab mContactsTab;
|
|
||||||
private Tab mConferencesTab;
|
|
||||||
private ViewPager mViewPager;
|
|
||||||
|
|
||||||
private MyListFragment mContactsListFragment = new MyListFragment();
|
|
||||||
private List<ListItem> contacts = new ArrayList<>();
|
|
||||||
private ArrayAdapter<ListItem> mContactsAdapter;
|
|
||||||
|
|
||||||
private MyListFragment mConferenceListFragment = new MyListFragment();
|
|
||||||
private List<ListItem> conferences = new ArrayList<ListItem>();
|
|
||||||
private ArrayAdapter<ListItem> mConferenceAdapter;
|
|
||||||
|
|
||||||
private List<String> mActivatedAccounts = new ArrayList<String>();
|
|
||||||
private List<String> mKnownHosts;
|
|
||||||
private List<String> mKnownConferenceHosts;
|
|
||||||
|
|
||||||
private Invite mPendingInvite = null;
|
|
||||||
|
|
||||||
private Menu mOptionsMenu;
|
|
||||||
private EditText mSearchEditText;
|
|
||||||
|
|
||||||
public int conference_context_id;
|
public int conference_context_id;
|
||||||
public int contact_context_id;
|
public int contact_context_id;
|
||||||
|
private Tab mContactsTab;
|
||||||
private TabListener mTabListener = new TabListener() {
|
private Tab mConferencesTab;
|
||||||
|
private ViewPager mViewPager;
|
||||||
@Override
|
private MyListFragment mContactsListFragment = new MyListFragment();
|
||||||
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
|
private List<ListItem> contacts = new ArrayList<>();
|
||||||
return;
|
private ArrayAdapter<ListItem> mContactsAdapter;
|
||||||
}
|
private MyListFragment mConferenceListFragment = new MyListFragment();
|
||||||
|
private List<ListItem> conferences = new ArrayList<ListItem>();
|
||||||
@Override
|
private ArrayAdapter<ListItem> mConferenceAdapter;
|
||||||
public void onTabSelected(Tab tab, FragmentTransaction ft) {
|
private List<String> mActivatedAccounts = new ArrayList<String>();
|
||||||
mViewPager.setCurrentItem(tab.getPosition());
|
private List<String> mKnownHosts;
|
||||||
onTabChanged();
|
private List<String> mKnownConferenceHosts;
|
||||||
}
|
private Invite mPendingInvite = null;
|
||||||
|
private Menu mOptionsMenu;
|
||||||
@Override
|
private EditText mSearchEditText;
|
||||||
public void onTabReselected(Tab tab, FragmentTransaction ft) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private ViewPager.SimpleOnPageChangeListener mOnPageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onPageSelected(int position) {
|
|
||||||
getActionBar().setSelectedNavigationItem(position);
|
|
||||||
onTabChanged();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
|
private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -147,6 +113,31 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private TabListener mTabListener = new TabListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabSelected(Tab tab, FragmentTransaction ft) {
|
||||||
|
mViewPager.setCurrentItem(tab.getPosition());
|
||||||
|
onTabChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabReselected(Tab tab, FragmentTransaction ft) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private ViewPager.SimpleOnPageChangeListener mOnPageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {
|
||||||
|
getActionBar().setSelectedNavigationItem(position);
|
||||||
|
onTabChanged();
|
||||||
|
}
|
||||||
|
};
|
||||||
private TextWatcher mSearchTextWatcher = new TextWatcher() {
|
private TextWatcher mSearchTextWatcher = new TextWatcher() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -164,24 +155,22 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
int count) {
|
int count) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private OnRosterUpdate onRosterUpdate = new OnRosterUpdate() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRosterUpdate() {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (mSearchEditText != null) {
|
|
||||||
filter(mSearchEditText.getText().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private MenuItem mMenuSearchView;
|
private MenuItem mMenuSearchView;
|
||||||
private String mInitialJid;
|
private String mInitialJid;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRosterUpdate() {
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (mSearchEditText != null) {
|
||||||
|
filter(mSearchEditText.getText().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -243,12 +232,6 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
xmppConnectionService.removeOnRosterUpdateListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void openConversationForContact(int position) {
|
protected void openConversationForContact(int position) {
|
||||||
Contact contact = (Contact) contacts.get(position);
|
Contact contact = (Contact) contacts.get(position);
|
||||||
Conversation conversation = xmppConnectionService
|
Conversation conversation = xmppConnectionService
|
||||||
|
@ -361,20 +344,20 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Validator.isValidJid(jid.getText().toString())) {
|
if (Validator.isValidJid(jid.getText().toString())) {
|
||||||
final Jid accountJid;
|
final Jid accountJid;
|
||||||
try {
|
try {
|
||||||
accountJid = Jid.fromString((String) spinner
|
accountJid = Jid.fromString((String) spinner
|
||||||
.getSelectedItem());
|
.getSelectedItem());
|
||||||
} catch (final InvalidJidException e) {
|
} catch (final InvalidJidException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Jid contactJid;
|
final Jid contactJid;
|
||||||
try {
|
try {
|
||||||
contactJid = Jid.fromString(jid.getText().toString());
|
contactJid = Jid.fromString(jid.getText().toString());
|
||||||
} catch (final InvalidJidException e) {
|
} catch (final InvalidJidException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Account account = xmppConnectionService
|
Account account = xmppConnectionService
|
||||||
.findAccountByJid(accountJid);
|
.findAccountByJid(accountJid);
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
@ -427,19 +410,19 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Validator.isValidJid(jid.getText().toString())) {
|
if (Validator.isValidJid(jid.getText().toString())) {
|
||||||
final Jid accountJid;
|
final Jid accountJid;
|
||||||
try {
|
try {
|
||||||
accountJid = Jid.fromString((String) spinner.getSelectedItem());
|
accountJid = Jid.fromString((String) spinner.getSelectedItem());
|
||||||
} catch (final InvalidJidException e) {
|
} catch (final InvalidJidException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Jid conferenceJid;
|
final Jid conferenceJid;
|
||||||
try {
|
try {
|
||||||
conferenceJid = Jid.fromString(jid.getText().toString());
|
conferenceJid = Jid.fromString(jid.getText().toString());
|
||||||
} catch (final InvalidJidException e) {
|
} catch (final InvalidJidException e) {
|
||||||
return; // TODO: Do some error handling...
|
return; // TODO: Do some error handling...
|
||||||
}
|
}
|
||||||
Account account = xmppConnectionService
|
Account account = xmppConnectionService
|
||||||
.findAccountByJid(accountJid);
|
.findAccountByJid(accountJid);
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
@ -570,7 +553,6 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBackendConnected() {
|
protected void onBackendConnected() {
|
||||||
xmppConnectionService.setOnRosterUpdateListener(this.onRosterUpdate);
|
|
||||||
this.mActivatedAccounts.clear();
|
this.mActivatedAccounts.clear();
|
||||||
for (Account account : xmppConnectionService.getAccounts()) {
|
for (Account account : xmppConnectionService.getAccounts()) {
|
||||||
if (account.getStatus() != Account.STATUS_DISABLED) {
|
if (account.getStatus() != Account.STATUS_DISABLED) {
|
||||||
|
@ -611,20 +593,20 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
for (Parcelable message : getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) {
|
for (Parcelable message : getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) {
|
||||||
if (message instanceof NdefMessage) {
|
if (message instanceof NdefMessage) {
|
||||||
Log.d(Config.LOGTAG, "received message=" + message);
|
Log.d(Config.LOGTAG, "received message=" + message);
|
||||||
for (NdefRecord record : ((NdefMessage)message).getRecords()) {
|
for (NdefRecord record : ((NdefMessage) message).getRecords()) {
|
||||||
switch (record.getTnf()) {
|
switch (record.getTnf()) {
|
||||||
case NdefRecord.TNF_WELL_KNOWN:
|
case NdefRecord.TNF_WELL_KNOWN:
|
||||||
if (Arrays.equals(record.getType(), NdefRecord.RTD_URI)) {
|
if (Arrays.equals(record.getType(), NdefRecord.RTD_URI)) {
|
||||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
return getInviteJellyBean(record).invite();
|
return getInviteJellyBean(record).invite();
|
||||||
} else {
|
} else {
|
||||||
byte[] payload = record.getPayload();
|
byte[] payload = record.getPayload();
|
||||||
if (payload[0] == 0) {
|
if (payload[0] == 0) {
|
||||||
return new Invite(Uri.parse(new String(Arrays.copyOfRange(
|
return new Invite(Uri.parse(new String(Arrays.copyOfRange(
|
||||||
payload, 1, payload.length)))).invite();
|
payload, 1, payload.length)))).invite();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
|
import eu.siacs.conversations.entities.MucOptions;
|
||||||
import eu.siacs.conversations.entities.Presences;
|
import eu.siacs.conversations.entities.Presences;
|
||||||
import eu.siacs.conversations.services.AvatarService;
|
import eu.siacs.conversations.services.AvatarService;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
|
@ -77,6 +78,7 @@ public abstract class XmppActivity extends Activity {
|
||||||
|
|
||||||
public XmppConnectionService xmppConnectionService;
|
public XmppConnectionService xmppConnectionService;
|
||||||
public boolean xmppConnectionServiceBound = false;
|
public boolean xmppConnectionServiceBound = false;
|
||||||
|
protected boolean registeredListeners = false;
|
||||||
|
|
||||||
protected int mPrimaryTextColor;
|
protected int mPrimaryTextColor;
|
||||||
protected int mSecondaryTextColor;
|
protected int mSecondaryTextColor;
|
||||||
|
@ -105,11 +107,11 @@ public abstract class XmppActivity extends Activity {
|
||||||
XmppConnectionBinder binder = (XmppConnectionBinder) service;
|
XmppConnectionBinder binder = (XmppConnectionBinder) service;
|
||||||
xmppConnectionService = binder.getService();
|
xmppConnectionService = binder.getService();
|
||||||
xmppConnectionServiceBound = true;
|
xmppConnectionServiceBound = true;
|
||||||
if (!isFinishing() && !isDestroyed()) {
|
if (!registeredListeners) {
|
||||||
onBackendConnected();
|
registerListeners();
|
||||||
} else {
|
registeredListeners = true;
|
||||||
Log.d(Config.LOGTAG,"omitting call to onBackendConnected()");
|
|
||||||
}
|
}
|
||||||
|
onBackendConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,6 +125,12 @@ public abstract class XmppActivity extends Activity {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
if (!xmppConnectionServiceBound) {
|
if (!xmppConnectionServiceBound) {
|
||||||
connectToBackend();
|
connectToBackend();
|
||||||
|
} else {
|
||||||
|
if (!registeredListeners) {
|
||||||
|
this.registerListeners();
|
||||||
|
this.registeredListeners = true;
|
||||||
|
}
|
||||||
|
this.onBackendConnected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +145,10 @@ public abstract class XmppActivity extends Activity {
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
if (xmppConnectionServiceBound) {
|
if (xmppConnectionServiceBound) {
|
||||||
|
if (registeredListeners) {
|
||||||
|
this.unregisterListeners();
|
||||||
|
this.registeredListeners = false;
|
||||||
|
}
|
||||||
unbindService(mConnection);
|
unbindService(mConnection);
|
||||||
xmppConnectionServiceBound = false;
|
xmppConnectionServiceBound = false;
|
||||||
}
|
}
|
||||||
|
@ -207,6 +219,36 @@ public abstract class XmppActivity extends Activity {
|
||||||
|
|
||||||
abstract void onBackendConnected();
|
abstract void onBackendConnected();
|
||||||
|
|
||||||
|
protected void registerListeners() {
|
||||||
|
if (this instanceof XmppConnectionService.OnConversationUpdate) {
|
||||||
|
this.xmppConnectionService.setOnConversationListChangedListener((XmppConnectionService.OnConversationUpdate) this);
|
||||||
|
}
|
||||||
|
if (this instanceof XmppConnectionService.OnAccountUpdate) {
|
||||||
|
this.xmppConnectionService.setOnAccountListChangedListener((XmppConnectionService.OnAccountUpdate) this);
|
||||||
|
}
|
||||||
|
if (this instanceof XmppConnectionService.OnRosterUpdate) {
|
||||||
|
this.xmppConnectionService.setOnRosterUpdateListener((XmppConnectionService.OnRosterUpdate) this);
|
||||||
|
}
|
||||||
|
if (this instanceof MucOptions.OnRenameListener) {
|
||||||
|
this.xmppConnectionService.setOnRenameListener((MucOptions.OnRenameListener) this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unregisterListeners() {
|
||||||
|
if (this instanceof XmppConnectionService.OnConversationUpdate) {
|
||||||
|
this.xmppConnectionService.removeOnConversationListChangedListener();
|
||||||
|
}
|
||||||
|
if (this instanceof XmppConnectionService.OnAccountUpdate) {
|
||||||
|
this.xmppConnectionService.removeOnAccountListChangedListener();
|
||||||
|
}
|
||||||
|
if (this instanceof XmppConnectionService.OnRosterUpdate) {
|
||||||
|
this.xmppConnectionService.removeOnRosterUpdateListener();
|
||||||
|
}
|
||||||
|
if (this instanceof MucOptions.OnRenameListener) {
|
||||||
|
this.xmppConnectionService.setOnRenameListener(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_settings:
|
case R.id.action_settings:
|
||||||
|
|
Loading…
Reference in New Issue