Commit a7e4a25f authored by Grigory Fedorov's avatar Grigory Fedorov

ContactList options menu get hidden when there are no active accounts.

parent 0f98f208
......@@ -46,6 +46,7 @@ import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.CommonState;
import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.avatar.AvatarManager;
......@@ -57,7 +58,7 @@ import com.xabber.android.data.notification.NotificationManager;
import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.ContactListFragment.OnContactClickListener;
import com.xabber.android.ui.ContactListFragment.ContactListFragmentListener;
import com.xabber.android.ui.dialog.AccountChooseDialogFragment;
import com.xabber.android.ui.dialog.AccountChooseDialogFragment.OnChoosedListener;
import com.xabber.android.ui.dialog.ContactIntegrationDialogFragment;
......@@ -81,7 +82,7 @@ import java.util.Locale;
* @author alexander.ivanov
*/
public class ContactList extends ManagedActivity implements OnAccountChangedListener,
View.OnClickListener, OnChoosedListener, OnContactClickListener, ContactListDrawerFragment.ContactListDrawerListener, Toolbar.OnMenuItemClickListener {
View.OnClickListener, OnChoosedListener, ContactListFragmentListener, ContactListDrawerFragment.ContactListDrawerListener, Toolbar.OnMenuItemClickListener {
/**
* Select contact to be invited to the room was requested.
......@@ -111,6 +112,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
private BarPainter barPainter;
private ActionBarDrawerToggle drawerToggle;
private DrawerLayout drawerLayout;
private Menu optionsMenu;
public static Intent createPersistentIntent(Context context) {
Intent intent = new Intent(context, ContactList.class);
......@@ -162,7 +164,8 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
drawerLayout.setDrawerListener(drawerToggle);
toolbar.inflateMenu(R.menu.contact_list);
setUpSearchView(toolbar.getMenu());
optionsMenu = toolbar.getMenu();
setUpSearchView(optionsMenu);
toolbar.setOnMenuItemClickListener(this);
barPainter = new BarPainter(this, toolbar);
......@@ -558,6 +561,30 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
}
}
@Override
public void onContactListChange(CommonState commonState) {
switch (commonState) {
case empty:
case disabled:
for (int i = 0; i < optionsMenu.size(); i++) {
optionsMenu.getItem(i).setVisible(false);
}
break;
case offline:
case waiting:
case connecting:
case roster:
case online:
for (int i = 0; i < optionsMenu.size(); i++) {
optionsMenu.getItem(i).setVisible(true);
}
break;
}
}
private void createShortcut(AbstractContact abstractContact) {
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, ChatViewer.createShortCutIntent(this,
......
package com.xabber.android.ui;
import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.Fragment;
......@@ -91,6 +92,15 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
private FloatingActionButton scrollToChatsActionButton;
private AccountPainter accountPainter;
private ContactListFragmentListener contactListFragmentListener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
contactListFragmentListener = (ContactListFragmentListener) activity;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.contact_list_fragment, container, false);
......@@ -149,6 +159,12 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
unregisterListeners();
}
@Override
public void onDetach() {
super.onDetach();
contactListFragmentListener = null;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
......@@ -171,7 +187,7 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Object object = parent.getAdapter().getItem(position);
if (object instanceof AbstractContact) {
((OnContactClickListener) getActivity()).onContactClick((AbstractContact) object);
contactListFragmentListener.onContactClick((AbstractContact) object);
} else if (object instanceof GroupConfiguration) {
GroupConfiguration groupConfiguration = (GroupConfiguration) object;
adapter.setExpanded(groupConfiguration.getAccount(), groupConfiguration.getUser(),
......@@ -328,7 +344,7 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
}
buttonView.setOnClickListener(listener);
contactListFragmentListener.onContactListChange(commonState);
}
......@@ -443,8 +459,11 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
popup.show();
}
public interface OnContactClickListener {
public interface ContactListFragmentListener {
void onContactClick(AbstractContact contact);
void onContactListChange(CommonState commonState);
}
}
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