Commit ac7d67a5 authored by Grigory Fedorov's avatar Grigory Fedorov

ContactViewer options menu corrected or disabled for accounts, conferences.

parent cc9f3cfe
...@@ -30,13 +30,16 @@ import android.widget.EditText; ...@@ -30,13 +30,16 @@ import android.widget.EditText;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager; import com.xabber.android.data.LogManager;
import com.xabber.android.data.NetworkException; import com.xabber.android.data.NetworkException;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.OnAccountChangedListener; import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity; import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.extension.vcard.OnVCardListener; import com.xabber.android.data.extension.vcard.OnVCardListener;
import com.xabber.android.data.extension.vcard.VCardManager; import com.xabber.android.data.extension.vcard.VCardManager;
import com.xabber.android.data.intent.AccountIntentBuilder; import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.data.intent.EntityIntentBuilder; import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.roster.AbstractContact; import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.GroupManager;
import com.xabber.android.data.roster.OnContactChangedListener; import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.data.roster.RosterContact; import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
...@@ -133,6 +136,8 @@ public class ContactViewer extends ManagedActivity implements ...@@ -133,6 +136,8 @@ public class ContactViewer extends ManagedActivity implements
throw new IllegalStateException(); throw new IllegalStateException();
} }
private boolean isAccount = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -152,8 +157,7 @@ public class ContactViewer extends ManagedActivity implements ...@@ -152,8 +157,7 @@ public class ContactViewer extends ManagedActivity implements
} }
if (id != null) if (id != null)
// FIXME: Will be empty while application is loading // FIXME: Will be empty while application is loading
for (RosterContact rosterContact : RosterManager for (RosterContact rosterContact : RosterManager.getInstance().getContacts())
.getInstance().getContacts())
if (id.equals(rosterContact.getViewId())) { if (id.equals(rosterContact.getViewId())) {
account = rosterContact.getAccount(); account = rosterContact.getAccount();
bareAddress = rosterContact.getUser(); bareAddress = rosterContact.getUser();
...@@ -165,6 +169,12 @@ public class ContactViewer extends ManagedActivity implements ...@@ -165,6 +169,12 @@ public class ContactViewer extends ManagedActivity implements
account = getAccount(getIntent()); account = getAccount(getIntent());
bareAddress = Jid.getBareAddress(getUser(getIntent())); bareAddress = Jid.getBareAddress(getUser(getIntent()));
} }
if (bareAddress != null && bareAddress.equalsIgnoreCase(GroupManager.IS_ACCOUNT)) {
isAccount = true;
bareAddress = Jid.getBareAddress(AccountManager.getInstance().getAccount(account).getRealJid());
}
if (account == null || bareAddress == null) { if (account == null || bareAddress == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND); Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish(); finish();
...@@ -212,12 +222,11 @@ public class ContactViewer extends ManagedActivity implements ...@@ -212,12 +222,11 @@ public class ContactViewer extends ManagedActivity implements
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
Application.getInstance().addUIListener(OnVCardListener.class, this); Application.getInstance().addUIListener(OnVCardListener.class, this);
Application.getInstance().addUIListener(OnContactChangedListener.class, Application.getInstance().addUIListener(OnContactChangedListener.class, this);
this); Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
Application.getInstance().addUIListener(OnAccountChangedListener.class, if (vCard == null && !vCardError) {
this);
if (vCard == null && !vCardError)
VCardManager.getInstance().request(account, bareAddress, null); VCardManager.getInstance().request(account, bareAddress, null);
}
contactTitleExpandableToolbarInflater.onResume(); contactTitleExpandableToolbarInflater.onResume();
...@@ -229,9 +238,18 @@ public class ContactViewer extends ManagedActivity implements ...@@ -229,9 +238,18 @@ public class ContactViewer extends ManagedActivity implements
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater=getMenuInflater(); if (isAccount || MUCManager.getInstance().hasRoom(account, bareAddress)) {
return true;
}
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.contact_viewer, menu); inflater.inflate(R.menu.contact_viewer, menu);
RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, bareAddress);
if (rosterContact == null) {
menu.findItem(R.id.action_edit_alias).setVisible(false);
}
return true; return true;
} }
...@@ -242,7 +260,6 @@ public class ContactViewer extends ManagedActivity implements ...@@ -242,7 +260,6 @@ public class ContactViewer extends ManagedActivity implements
editAlias(); editAlias();
return true; return true;
case R.id.action_edit_groups: case R.id.action_edit_groups:
startActivity(GroupEditor.createIntent(this, account, bareAddress)); startActivity(GroupEditor.createIntent(this, account, bareAddress));
return true; return true;
...@@ -272,7 +289,7 @@ public class ContactViewer extends ManagedActivity implements ...@@ -272,7 +289,7 @@ public class ContactViewer extends ManagedActivity implements
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
try { try {
RosterManager.getInstance().setName(account, bareAddress, input.getText().toString()); RosterManager.getInstance().setName(account, bareAddress, input.getText().toString());
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance().onError(e); Application.getInstance().onError(e);
} }
...@@ -289,33 +306,31 @@ public class ContactViewer extends ManagedActivity implements ...@@ -289,33 +306,31 @@ public class ContactViewer extends ManagedActivity implements
} }
private ContactViewerFragment getFragment() { private ContactViewerFragment getFragment() {
return (ContactViewerFragment) getFragmentManager() return (ContactViewerFragment) getFragmentManager().findFragmentById(R.id.scrollable_container);
.findFragmentById(R.id.scrollable_container);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
Application.getInstance().removeUIListener(OnVCardListener.class, this); Application.getInstance().removeUIListener(OnVCardListener.class, this);
Application.getInstance().removeUIListener( Application.getInstance().removeUIListener(OnContactChangedListener.class, this);
OnContactChangedListener.class, this); Application.getInstance().removeUIListener(OnAccountChangedListener.class, this);
Application.getInstance().removeUIListener(
OnAccountChangedListener.class, this);
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putBoolean(SAVED_VCARD_ERROR, vCardError); outState.putBoolean(SAVED_VCARD_ERROR, vCardError);
if (vCard != null) if (vCard != null) {
outState.putString(SAVED_VCARD, vCard.getChildElementXML()); outState.putString(SAVED_VCARD, vCard.getChildElementXML());
}
} }
@Override @Override
public void onVCardReceived(String account, String bareAddress, VCard vCard) { public void onVCardReceived(String account, String bareAddress, VCard vCard) {
if (!this.account.equals(account) if (!this.account.equals(account) || !this.bareAddress.equals(bareAddress)) {
|| !this.bareAddress.equals(bareAddress))
return; return;
}
this.vCard = vCard; this.vCard = vCard;
this.vCardError = false; this.vCardError = false;
getFragment().updateVCard(vCard); getFragment().updateVCard(vCard);
...@@ -348,8 +363,7 @@ public class ContactViewer extends ManagedActivity implements ...@@ -348,8 +363,7 @@ public class ContactViewer extends ManagedActivity implements
} }
public static Intent createIntent(Context context, String account, public static Intent createIntent(Context context, String account, String user) {
String user) {
return new EntityIntentBuilder(context, ContactViewer.class) return new EntityIntentBuilder(context, ContactViewer.class)
.setAccount(account).setUser(user).build(); .setAccount(account).setUser(user).build();
} }
......
...@@ -264,12 +264,7 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat ...@@ -264,12 +264,7 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
viewHolder.avatar.setOnClickListener(new View.OnClickListener() { viewHolder.avatar.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
String user = AccountManager.getInstance().getAccount(account).getRealJid(); activity.startActivity(ContactViewer.createIntent(activity, account, GroupManager.IS_ACCOUNT));
if (user == null) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
} else {
activity.startActivity(ContactViewer.createIntent(activity, account, user));
}
} }
}); });
......
...@@ -285,12 +285,7 @@ public class ContextMenuHelper { ...@@ -285,12 +285,7 @@ public class ContextMenuHelper {
new MenuItem.OnMenuItemClickListener() { new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
String user = AccountManager.getInstance().getAccount(account).getRealJid(); activity.startActivity(ContactViewer.createIntent(activity, account, GroupManager.IS_ACCOUNT));
if (user == null) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
} else {
activity.startActivity(ContactViewer.createIntent(activity, account, user));
}
return true; return true;
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment