diff options
Diffstat (limited to '')
7 files changed, 289 insertions, 345 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 85c35ecd..4eb081ce 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -31,7 +31,7 @@ import android.widget.LinearLayout; import android.widget.TextView; 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"; private Conversation conversation; 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 OnConversationUpdate onConvChanged = new OnConversationUpdate() { @Override public void onConversationUpdate() { @@ -66,7 +86,6 @@ public class ConferenceDetailsActivity extends XmppActivity { } }); } - }; @Override protected void onCreate(Bundle savedInstanceState) { @@ -156,7 +175,6 @@ public class ConferenceDetailsActivity extends XmppActivity { @Override void onBackendConnected() { - registerListener(); if (getIntent().getAction().equals(ACTION_VIEW_MUC)) { 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() { mAccountJid.setText(getString(R.string.using_account, conversation .getAccount().getJid().toBareJid())); diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index 7106fcdb..8cd68cff 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -1,9 +1,5 @@ package eu.siacs.conversations.ui; -import java.util.Iterator; - -import org.openintents.openpgp.util.OpenPgpUtils; - import android.app.AlertDialog; import android.app.PendingIntent; import android.content.Context; @@ -21,12 +17,17 @@ import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.CheckBox; -import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton; +import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.QuickContactBadge; import android.widget.TextView; + +import org.openintents.openpgp.util.OpenPgpUtils; + +import java.util.Iterator; + import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine; 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.Jid; -public class ContactDetailsActivity extends XmppActivity { +public class ContactDetailsActivity extends XmppActivity implements OnAccountUpdate, OnRosterUpdate { public static final String ACTION_VIEW_CONTACT = "view_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() { @Override @@ -63,61 +52,16 @@ public class ContactDetailsActivity extends XmppActivity { ContactDetailsActivity.this.finish(); } }; - - private DialogInterface.OnClickListener addToPhonebook = new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); - intent.setType(Contacts.CONTENT_ITEM_TYPE); - intent.putExtra(Intents.Insert.IM_HANDLE, contact.getJid().toString()); - intent.putExtra(Intents.Insert.IM_PROTOCOL, - CommonDataKinds.Im.PROTOCOL_JABBER); - intent.putExtra("finishActivityOnSaveCompleted", true); - ContactDetailsActivity.this.startActivityForResult(intent, 0); - } - }; - private OnClickListener onBadgeClick = new OnClickListener() { - - @Override - public void onClick(View v) { - AlertDialog.Builder builder = new AlertDialog.Builder( - ContactDetailsActivity.this); - builder.setTitle(getString(R.string.action_add_phone_book)); - builder.setMessage(getString(R.string.add_phone_book_text, - contact.getJid())); - builder.setNegativeButton(getString(R.string.cancel), null); - builder.setPositiveButton(getString(R.string.add), addToPhonebook); - builder.create().show(); - } - }; - - private LinearLayout keys; - - private OnRosterUpdate rosterUpdate = new OnRosterUpdate() { - - @Override - public void onRosterUpdate() { - runOnUiThread(new Runnable() { - - @Override - public void run() { - populateView(); - } - }); - } - }; - private OnCheckedChangeListener mOnSendCheckedChange = new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, - boolean isChecked) { + boolean isChecked) { if (isChecked) { if (contact .getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) { xmppConnectionService.sendPresencePacket(contact - .getAccount(), + .getAccount(), xmppConnectionService.getPresenceGenerator() .sendPresenceUpdatesTo(contact)); } else { @@ -131,12 +75,11 @@ public class ContactDetailsActivity extends XmppActivity { } } }; - private OnCheckedChangeListener mOnReceiveCheckedChange = new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, - boolean isChecked) { + boolean isChecked) { if (isChecked) { xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator() @@ -148,25 +91,70 @@ public class ContactDetailsActivity extends XmppActivity { } } }; - - private OnAccountUpdate accountUpdate = new OnAccountUpdate() { + 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() { @Override - public void onAccountUpdate() { - runOnUiThread(new Runnable() { + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); + intent.setType(Contacts.CONTENT_ITEM_TYPE); + intent.putExtra(Intents.Insert.IM_HANDLE, contact.getJid().toString()); + intent.putExtra(Intents.Insert.IM_PROTOCOL, + CommonDataKinds.Im.PROTOCOL_JABBER); + intent.putExtra("finishActivityOnSaveCompleted", true); + ContactDetailsActivity.this.startActivityForResult(intent, 0); + } + }; + private OnClickListener onBadgeClick = new OnClickListener() { - @Override - public void run() { - populateView(); - } - }); + @Override + public void onClick(View v) { + AlertDialog.Builder builder = new AlertDialog.Builder( + ContactDetailsActivity.this); + builder.setTitle(getString(R.string.action_add_phone_book)); + builder.setMessage(getString(R.string.add_phone_book_text, + contact.getJid())); + builder.setNegativeButton(getString(R.string.cancel), null); + builder.setPositiveButton(getString(R.string.add), addToPhonebook); + builder.create().show(); } }; + private LinearLayout keys; + + @Override + public void onRosterUpdate() { + runOnUiThread(new Runnable() { + + @Override + public void run() { + populateView(); + } + }); + } + + @Override + public void onAccountUpdate() { + runOnUiThread(new Runnable() { + + @Override + public void run() { + populateView(); + } + }); + } @Override protected String getShareableUri() { - if (contact!=null) { - return "xmpp:"+contact.getJid(); + if (contact != null) { + return "xmpp:" + contact.getJid(); } else { return ""; } @@ -176,15 +164,15 @@ public class ContactDetailsActivity extends XmppActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) { - try { - this.accountJid = Jid.fromString(getIntent().getExtras().getString("account")); - } catch (final InvalidJidException ignored) { - } - try { - this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact")); - } catch (final InvalidJidException ignored) { - } - } + try { + this.accountJid = Jid.fromString(getIntent().getExtras().getString("account")); + } catch (final InvalidJidException ignored) { + } + try { + this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact")); + } catch (final InvalidJidException ignored) { + } + } setContentView(R.layout.activity_contact_details); contactJidTv = (TextView) findViewById(R.id.details_contactjid); @@ -205,39 +193,39 @@ public class ContactDetailsActivity extends XmppActivity { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setNegativeButton(getString(R.string.cancel), null); switch (menuItem.getItemId()) { - case android.R.id.home: - finish(); - break; - case R.id.action_delete_contact: - builder.setTitle(getString(R.string.action_delete_contact)) - .setMessage( - getString(R.string.remove_contact_text, - contact.getJid())) - .setPositiveButton(getString(R.string.delete), - removeFromRoster).create().show(); - break; - case R.id.action_edit_contact: - if (contact.getSystemAccount() == null) { - quickEdit(contact.getDisplayName(), new OnValueEdited() { - - @Override - public void onValueEdited(String value) { - contact.setServerName(value); - ContactDetailsActivity.this.xmppConnectionService - .pushContactToServer(contact); - populateView(); - } - }); - } else { - Intent intent = new Intent(Intent.ACTION_EDIT); - String[] systemAccount = contact.getSystemAccount().split("#"); - long id = Long.parseLong(systemAccount[0]); - Uri uri = Contacts.getLookupUri(id, systemAccount[1]); - intent.setDataAndType(uri, Contacts.CONTENT_ITEM_TYPE); - intent.putExtra("finishActivityOnSaveCompleted", true); - startActivity(intent); - } - break; + case android.R.id.home: + finish(); + break; + case R.id.action_delete_contact: + builder.setTitle(getString(R.string.action_delete_contact)) + .setMessage( + getString(R.string.remove_contact_text, + contact.getJid())) + .setPositiveButton(getString(R.string.delete), + removeFromRoster).create().show(); + break; + case R.id.action_edit_contact: + if (contact.getSystemAccount() == null) { + quickEdit(contact.getDisplayName(), new OnValueEdited() { + + @Override + public void onValueEdited(String value) { + contact.setServerName(value); + ContactDetailsActivity.this.xmppConnectionService + .pushContactToServer(contact); + populateView(); + } + }); + } else { + Intent intent = new Intent(Intent.ACTION_EDIT); + String[] systemAccount = contact.getSystemAccount().split("#"); + long id = Long.parseLong(systemAccount[0]); + Uri uri = Contacts.getLookupUri(id, systemAccount[1]); + intent.setDataAndType(uri, Contacts.CONTENT_ITEM_TYPE); + intent.putExtra("finishActivityOnSaveCompleted", true); + startActivity(intent); + } + break; } return super.onOptionsItemSelected(menuItem); } @@ -293,34 +281,34 @@ public class ContactDetailsActivity extends XmppActivity { contact.lastseen.time)); switch (contact.getMostAvailableStatus()) { - case Presences.CHAT: - status.setText(R.string.contact_status_free_to_chat); - status.setTextColor(mColorGreen); - break; - case Presences.ONLINE: - status.setText(R.string.contact_status_online); - status.setTextColor(mColorGreen); - break; - case Presences.AWAY: - status.setText(R.string.contact_status_away); - status.setTextColor(mColorOrange); - break; - case Presences.XA: - status.setText(R.string.contact_status_extended_away); - status.setTextColor(mColorOrange); - break; - case Presences.DND: - status.setText(R.string.contact_status_do_not_disturb); - status.setTextColor(mColorRed); - break; - case Presences.OFFLINE: - status.setText(R.string.contact_status_offline); - status.setTextColor(mSecondaryTextColor); - break; - default: - status.setText(R.string.contact_status_offline); - status.setTextColor(mSecondaryTextColor); - break; + case Presences.CHAT: + status.setText(R.string.contact_status_free_to_chat); + status.setTextColor(mColorGreen); + break; + case Presences.ONLINE: + status.setText(R.string.contact_status_online); + status.setTextColor(mColorGreen); + break; + case Presences.AWAY: + status.setText(R.string.contact_status_away); + status.setTextColor(mColorOrange); + break; + case Presences.XA: + status.setText(R.string.contact_status_extended_away); + status.setTextColor(mColorOrange); + break; + case Presences.DND: + status.setText(R.string.contact_status_do_not_disturb); + status.setTextColor(mColorRed); + break; + case Presences.OFFLINE: + status.setText(R.string.contact_status_offline); + status.setTextColor(mSecondaryTextColor); + break; + default: + status.setText(R.string.contact_status_offline); + status.setTextColor(mSecondaryTextColor); + break; } if (contact.getPresences().size() > 1) { contactJidTv.setText(contact.getJid() + " (" @@ -339,7 +327,7 @@ public class ContactDetailsActivity extends XmppActivity { boolean hasKeys = false; LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (Iterator<String> iterator = contact.getOtrFingerprints() - .iterator(); iterator.hasNext();) { + .iterator(); iterator.hasNext(); ) { hasKeys = true; final String otrFingerprint = iterator.next(); View view = inflater.inflate(R.layout.contact_key, keys, false); @@ -427,9 +415,6 @@ public class ContactDetailsActivity extends XmppActivity { @Override public void onBackendConnected() { - xmppConnectionService.setOnRosterUpdateListener(this.rosterUpdate); - xmppConnectionService - .setOnAccountListChangedListener(this.accountUpdate); if ((accountJid != null) && (contactJid != null)) { Account account = xmppConnectionService .findAccountByJid(accountJid); @@ -440,12 +425,4 @@ public class ContactDetailsActivity extends XmppActivity { populateView(); } } - - @Override - protected void onStop() { - super.onStop(); - xmppConnectionService.removeOnRosterUpdateListener(); - xmppConnectionService.removeOnAccountListChangedListener(); - } - } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 8cb8a3aa..5d11bb59 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -634,18 +634,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 public void onSaveInstanceState(final Bundle savedInstanceState) { Conversation conversation = getSelectedConversation(); if (conversation != null) { @@ -662,9 +650,7 @@ public class ConversationActivity extends XmppActivity implements @Override void onBackendConnected() { - this.registerListener(); updateConversationList(); - if (xmppConnectionService.getAccounts().size() == 0) { startActivity(new Intent(this, EditAccountActivity.class)); } else if (conversationList.size() <= 0) { @@ -722,10 +708,10 @@ public class ConversationActivity extends XmppActivity implements } } - public void registerListener() { - xmppConnectionService.setOnConversationListChangedListener(this); - xmppConnectionService.setOnAccountListChangedListener(this); - xmppConnectionService.setOnRosterUpdateListener(this); + @Override + protected void unregisterListeners() { + super.unregisterListeners(); + xmppConnectionService.getNotificationService().setOpenConversation(null); } @Override diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 2344ee4b..b179c47b 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -33,7 +33,7 @@ import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.pep.Avatar; -public class EditAccountActivity extends XmppActivity { +public class EditAccountActivity extends XmppActivity implements OnAccountUpdate { private AutoCompleteTextView mAccountJid; private EditText mPassword; @@ -132,8 +132,6 @@ public class EditAccountActivity extends XmppActivity { finish(); } }; - private OnAccountUpdate mOnAccountUpdateListener = new OnAccountUpdate() { - @Override public void onAccountUpdate() { runOnUiThread(new Runnable() { @@ -162,7 +160,6 @@ public class EditAccountActivity extends XmppActivity { } }); } - }; private UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() { @Override @@ -350,20 +347,10 @@ public class EditAccountActivity extends XmppActivity { } @Override - protected void onStop() { - if (xmppConnectionServiceBound) { - xmppConnectionService.removeOnAccountListChangedListener(); - } - super.onStop(); - } - - @Override protected void onBackendConnected() { KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this, android.R.layout.simple_list_item_1, xmppConnectionService.getKnownHosts()); - this.xmppConnectionService - .setOnAccountListChangedListener(this.mOnAccountUpdateListener); if (this.jidToEdit != null) { this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit); updateAccountInformation(); diff --git a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java index 011ca0a9..906a16cc 100644 --- a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -22,15 +22,13 @@ import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; -public class ManageAccountActivity extends XmppActivity { +public class ManageAccountActivity extends XmppActivity implements OnAccountUpdate { protected Account selectedAccount = null; protected List<Account> accountList = new ArrayList<Account>(); protected ListView accountListView; protected AccountAdapter mAccountAdapter; - protected OnAccountUpdate accountChanged = new OnAccountUpdate() { - @Override public void onAccountUpdate() { accountList.clear(); @@ -43,7 +41,6 @@ public class ManageAccountActivity extends XmppActivity { } }); } - }; @Override protected void onCreate(Bundle savedInstanceState) { @@ -85,16 +82,7 @@ public class ManageAccountActivity extends XmppActivity { } @Override - protected void onStop() { - if (xmppConnectionServiceBound) { - xmppConnectionService.removeOnAccountListChangedListener(); - } - super.onStop(); - } - - @Override void onBackendConnected() { - xmppConnectionService.setOnAccountListChangedListener(accountChanged); this.accountList.clear(); this.accountList.addAll(xmppConnectionService.getAccounts()); mAccountAdapter.notifyDataSetChanged(); diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 2b357d0d..191e0b82 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -66,59 +66,25 @@ import eu.siacs.conversations.utils.Validator; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; -public class StartConversationActivity extends XmppActivity { +public class StartConversationActivity extends XmppActivity implements OnRosterUpdate { + public int conference_context_id; + public int contact_context_id; 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 contact_context_id; - - 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 MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() { @Override @@ -147,6 +113,31 @@ public class StartConversationActivity extends XmppActivity { 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() { @Override @@ -164,23 +155,21 @@ public class StartConversationActivity extends XmppActivity { int count) { } }; - private OnRosterUpdate onRosterUpdate = new OnRosterUpdate() { + private MenuItem mMenuSearchView; + private String mInitialJid; - @Override - public void onRosterUpdate() { - runOnUiThread(new Runnable() { + @Override + public void onRosterUpdate() { + runOnUiThread(new Runnable() { - @Override - public void run() { - if (mSearchEditText != null) { - filter(mSearchEditText.getText().toString()); - } + @Override + public void run() { + if (mSearchEditText != null) { + filter(mSearchEditText.getText().toString()); } - }); - } - }; - private MenuItem mMenuSearchView; - private String mInitialJid; + } + }); + } @Override public void onCreate(Bundle savedInstanceState) { @@ -243,12 +232,6 @@ public class StartConversationActivity extends XmppActivity { } - @Override - public void onStop() { - super.onStop(); - xmppConnectionService.removeOnRosterUpdateListener(); - } - protected void openConversationForContact(int position) { Contact contact = (Contact) contacts.get(position); Conversation conversation = xmppConnectionService @@ -361,20 +344,20 @@ public class StartConversationActivity extends XmppActivity { return; } if (Validator.isValidJid(jid.getText().toString())) { - final Jid accountJid; - try { - accountJid = Jid.fromString((String) spinner - .getSelectedItem()); - } catch (final InvalidJidException e) { - return; - } - final Jid contactJid; - try { - contactJid = Jid.fromString(jid.getText().toString()); - } catch (final InvalidJidException e) { - return; - } - Account account = xmppConnectionService + final Jid accountJid; + try { + accountJid = Jid.fromString((String) spinner + .getSelectedItem()); + } catch (final InvalidJidException e) { + return; + } + final Jid contactJid; + try { + contactJid = Jid.fromString(jid.getText().toString()); + } catch (final InvalidJidException e) { + return; + } + Account account = xmppConnectionService .findAccountByJid(accountJid); if (account == null) { dialog.dismiss(); @@ -427,19 +410,19 @@ public class StartConversationActivity extends XmppActivity { return; } if (Validator.isValidJid(jid.getText().toString())) { - final Jid accountJid; - try { - accountJid = Jid.fromString((String) spinner.getSelectedItem()); - } catch (final InvalidJidException e) { - return; - } - final Jid conferenceJid; - try { - conferenceJid = Jid.fromString(jid.getText().toString()); - } catch (final InvalidJidException e) { - return; // TODO: Do some error handling... - } - Account account = xmppConnectionService + final Jid accountJid; + try { + accountJid = Jid.fromString((String) spinner.getSelectedItem()); + } catch (final InvalidJidException e) { + return; + } + final Jid conferenceJid; + try { + conferenceJid = Jid.fromString(jid.getText().toString()); + } catch (final InvalidJidException e) { + return; // TODO: Do some error handling... + } + Account account = xmppConnectionService .findAccountByJid(accountJid); if (account == null) { dialog.dismiss(); @@ -570,7 +553,6 @@ public class StartConversationActivity extends XmppActivity { @Override protected void onBackendConnected() { - xmppConnectionService.setOnRosterUpdateListener(this.onRosterUpdate); this.mActivatedAccounts.clear(); for (Account account : xmppConnectionService.getAccounts()) { if (account.getStatus() != Account.STATUS_DISABLED) { @@ -611,20 +593,20 @@ public class StartConversationActivity extends XmppActivity { for (Parcelable message : getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) { if (message instanceof NdefMessage) { Log.d(Config.LOGTAG, "received message=" + message); - for (NdefRecord record : ((NdefMessage)message).getRecords()) { + for (NdefRecord record : ((NdefMessage) message).getRecords()) { switch (record.getTnf()) { - case NdefRecord.TNF_WELL_KNOWN: - if (Arrays.equals(record.getType(), NdefRecord.RTD_URI)) { - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - return getInviteJellyBean(record).invite(); - } else { - byte[] payload = record.getPayload(); - if (payload[0] == 0) { - return new Invite(Uri.parse(new String(Arrays.copyOfRange( - payload, 1, payload.length)))).invite(); + case NdefRecord.TNF_WELL_KNOWN: + if (Arrays.equals(record.getType(), NdefRecord.RTD_URI)) { + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + return getInviteJellyBean(record).invite(); + } else { + byte[] payload = record.getPayload(); + if (payload[0] == 0) { + return new Invite(Uri.parse(new String(Arrays.copyOfRange( + payload, 1, payload.length)))).invite(); + } } } - } } } } diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 2dafbd26..9d78e222 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -62,6 +62,7 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.Presences; import eu.siacs.conversations.services.AvatarService; import eu.siacs.conversations.services.XmppConnectionService; @@ -77,6 +78,7 @@ public abstract class XmppActivity extends Activity { public XmppConnectionService xmppConnectionService; public boolean xmppConnectionServiceBound = false; + protected boolean registeredListeners = false; protected int mPrimaryTextColor; protected int mSecondaryTextColor; @@ -105,11 +107,11 @@ public abstract class XmppActivity extends Activity { XmppConnectionBinder binder = (XmppConnectionBinder) service; xmppConnectionService = binder.getService(); xmppConnectionServiceBound = true; - if (!isFinishing() && !isDestroyed()) { - onBackendConnected(); - } else { - Log.d(Config.LOGTAG,"omitting call to onBackendConnected()"); + if (!registeredListeners) { + registerListeners(); + registeredListeners = true; } + onBackendConnected(); } @Override @@ -123,6 +125,12 @@ public abstract class XmppActivity extends Activity { super.onStart(); if (!xmppConnectionServiceBound) { connectToBackend(); + } else { + if (!registeredListeners) { + this.registerListeners(); + this.registeredListeners = true; + } + this.onBackendConnected(); } } @@ -137,6 +145,10 @@ public abstract class XmppActivity extends Activity { protected void onStop() { super.onStop(); if (xmppConnectionServiceBound) { + if (registeredListeners) { + this.unregisterListeners(); + this.registeredListeners = false; + } unbindService(mConnection); xmppConnectionServiceBound = false; } @@ -207,6 +219,36 @@ public abstract class XmppActivity extends Activity { 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) { switch (item.getItemId()) { case R.id.action_settings: |