Commit eebd5b6f authored by Grigory Fedorov's avatar Grigory Fedorov

Contact list: account menu via xml, offline contact dialog, on status icon pop up menu.

Accounts and groups drawn in lighter colors.
parent 3faf53ce
...@@ -22,9 +22,9 @@ package com.xabber.android.data.roster; ...@@ -22,9 +22,9 @@ package com.xabber.android.data.roster;
public enum ShowOfflineMode { public enum ShowOfflineMode {
/** /**
* Never show offline contacts. * Always show offline contacts.
*/ */
never, always,
/** /**
* Show offline contacts according to global settings. * Show offline contacts according to global settings.
...@@ -32,8 +32,7 @@ public enum ShowOfflineMode { ...@@ -32,8 +32,7 @@ public enum ShowOfflineMode {
normal, normal,
/** /**
* Always show offline contacts. * Never show offline contacts.
*/ */
always; never
} }
\ No newline at end of file
...@@ -19,6 +19,7 @@ import android.widget.Button; ...@@ -19,6 +19,7 @@ import android.widget.Button;
import android.widget.Filterable; import android.widget.Filterable;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView; import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView; import android.widget.TextView;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
...@@ -32,12 +33,13 @@ import com.xabber.android.data.entity.BaseEntity; ...@@ -32,12 +33,13 @@ import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.message.OnChatChangedListener; import com.xabber.android.data.message.OnChatChangedListener;
import com.xabber.android.data.roster.AbstractContact; import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.OnContactChangedListener; import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.ui.adapter.AccountConfiguration;
import com.xabber.android.ui.adapter.AccountActionButtonsAdapter; import com.xabber.android.ui.adapter.AccountActionButtonsAdapter;
import com.xabber.android.ui.adapter.AccountConfiguration;
import com.xabber.android.ui.adapter.ContactListAdapter; import com.xabber.android.ui.adapter.ContactListAdapter;
import com.xabber.android.ui.adapter.ContactListAdapter.OnContactListChangedListener; import com.xabber.android.ui.adapter.ContactListAdapter.OnContactListChangedListener;
import com.xabber.android.ui.adapter.ContactListState; import com.xabber.android.ui.adapter.ContactListState;
import com.xabber.android.ui.adapter.GroupConfiguration; import com.xabber.android.ui.adapter.GroupConfiguration;
import com.xabber.android.ui.adapter.GroupedContactAdapter;
import com.xabber.android.ui.adapter.UpdatableAdapter; import com.xabber.android.ui.adapter.UpdatableAdapter;
import com.xabber.android.ui.helper.ContextMenuHelper; import com.xabber.android.ui.helper.ContextMenuHelper;
import com.xabber.android.ui.preferences.AccountList; import com.xabber.android.ui.preferences.AccountList;
...@@ -47,7 +49,7 @@ import java.util.Collection; ...@@ -47,7 +49,7 @@ import java.util.Collection;
public class ContactListFragment extends Fragment implements OnAccountChangedListener, public class ContactListFragment extends Fragment implements OnAccountChangedListener,
OnContactChangedListener, OnChatChangedListener, OnItemClickListener, OnContactChangedListener, OnChatChangedListener, OnItemClickListener,
OnContactListChangedListener, OnClickListener { OnContactListChangedListener, OnClickListener, GroupedContactAdapter.OnAccountClickListener {
private ContactListAdapter adapter; private ContactListAdapter adapter;
...@@ -91,7 +93,7 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis ...@@ -91,7 +93,7 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
listView.setOnItemClickListener(this); listView.setOnItemClickListener(this);
listView.setItemsCanFocus(true); listView.setItemsCanFocus(true);
registerForContextMenu(listView); registerForContextMenu(listView);
adapter = new ContactListAdapter(getActivity(), listView, this); adapter = new ContactListAdapter(getActivity(), listView, this, this);
listView.setAdapter(adapter); listView.setAdapter(adapter);
infoView = view.findViewById(R.id.info); infoView = view.findViewById(R.id.info);
connectedView = infoView.findViewById(R.id.connected); connectedView = infoView.findViewById(R.id.connected);
...@@ -400,6 +402,14 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis ...@@ -400,6 +402,14 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
accountActionButtonsAdapter.rebuild(); accountActionButtonsAdapter.rebuild();
} }
@Override
public void onAccountClick(View view, final String account) {
PopupMenu popup = new PopupMenu(getActivity(), view);
popup.inflate(R.menu.account);
ContextMenuHelper.setUpAccountMenu(getActivity(), adapter, account, popup.getMenu());
popup.show();
}
public interface OnContactClickListener { public interface OnContactClickListener {
void onContactClick(AbstractContact contact); void onContactClick(AbstractContact contact);
} }
......
...@@ -16,6 +16,7 @@ package com.xabber.android.ui.adapter; ...@@ -16,6 +16,7 @@ package com.xabber.android.ui.adapter;
import android.app.Activity; import android.app.Activity;
import android.os.Handler; import android.os.Handler;
import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
...@@ -79,9 +80,9 @@ public class ContactListAdapter extends GroupedContactAdapter<ChatContactInflate ...@@ -79,9 +80,9 @@ public class ContactListAdapter extends GroupedContactAdapter<ChatContactInflate
private final OnContactListChangedListener listener; private final OnContactListChangedListener listener;
public ContactListAdapter( public ContactListAdapter(Activity activity, ListView listView, OnContactListChangedListener listener,
Activity activity, ListView listView, OnContactListChangedListener listener) { GroupedContactAdapter.OnAccountClickListener onAccountClickListener) {
super(activity, listView, new ChatContactInflater(activity), GroupManager.getInstance()); super(activity, listView, new ChatContactInflater(activity), GroupManager.getInstance(), onAccountClickListener);
this.listener = listener; this.listener = listener;
handler = new Handler(); handler = new Handler();
refreshLock = new Object(); refreshLock = new Object();
......
...@@ -95,21 +95,24 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater ...@@ -95,21 +95,24 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
private final int accountGroupElevation; private final int accountGroupElevation;
private final int accountSubgroupElevation; private final int accountSubgroupElevation;
private final int activeChatsColor; private final int activeChatsColor;
private final OnAccountClickListener onAccountClickListener;
public GroupedContactAdapter(Activity activity, ListView listView, public GroupedContactAdapter(Activity activity, ListView listView,
Inflater inflater, StateProvider groupStateProvider) { Inflater inflater, StateProvider groupStateProvider, OnAccountClickListener onAccountClickListener) {
super(activity, listView, inflater); super(activity, listView, inflater);
layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.groupStateProvider = groupStateProvider; this.groupStateProvider = groupStateProvider;
Resources resources = activity.getResources(); Resources resources = activity.getResources();
accountColors = resources.getIntArray(R.array.account_action_bar); accountColors = resources.getIntArray(R.array.account_200);
accountSubgroupColors = resources.getIntArray(R.array.account_background); accountSubgroupColors = resources.getIntArray(R.array.account_50);
activeChatsColor = resources.getColor(R.color.color_primary_light); activeChatsColor = resources.getColor(R.color.color_primary_light);
accountGroupElevation = resources.getDimensionPixelSize(R.dimen.account_group_elevation); accountGroupElevation = resources.getDimensionPixelSize(R.dimen.account_group_elevation);
accountSubgroupElevation = resources.getDimensionPixelSize(R.dimen.account_subgroup_elevation); accountSubgroupElevation = resources.getDimensionPixelSize(R.dimen.account_subgroup_elevation);
this.onAccountClickListener = onAccountClickListener;
} }
@Override @Override
...@@ -212,6 +215,14 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater ...@@ -212,6 +215,14 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
final AccountConfiguration configuration = (AccountConfiguration) getItem(position); final AccountConfiguration configuration = (AccountConfiguration) getItem(position);
viewHolder.statusIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onAccountClickListener.onAccountClick(v, configuration.getAccount());
}
});
final int level = AccountManager.getInstance().getColorLevel(configuration.getAccount()); final int level = AccountManager.getInstance().getColorLevel(configuration.getAccount());
view.setBackgroundDrawable(new ColorDrawable(accountColors[level])); view.setBackgroundDrawable(new ColorDrawable(accountColors[level]));
...@@ -469,5 +480,8 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater ...@@ -469,5 +480,8 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
} }
} }
public interface OnAccountClickListener {
void onAccountClick(View view, String account);
}
} }
...@@ -14,10 +14,13 @@ ...@@ -14,10 +14,13 @@
*/ */
package com.xabber.android.ui.helper; package com.xabber.android.ui.helper;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.SubMenu;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException; import com.xabber.android.data.NetworkException;
...@@ -34,6 +37,7 @@ import com.xabber.android.data.roster.GroupManager; ...@@ -34,6 +37,7 @@ import com.xabber.android.data.roster.GroupManager;
import com.xabber.android.data.roster.PresenceManager; import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.ShowOfflineMode; import com.xabber.android.data.roster.ShowOfflineMode;
import com.xabber.android.ui.ContactAdd; import com.xabber.android.ui.ContactAdd;
import com.xabber.android.ui.ContactViewer;
import com.xabber.android.ui.GroupEditor; import com.xabber.android.ui.GroupEditor;
import com.xabber.android.ui.MUCEditor; import com.xabber.android.ui.MUCEditor;
import com.xabber.android.ui.StatusEditor; import com.xabber.android.ui.StatusEditor;
...@@ -43,7 +47,6 @@ import com.xabber.android.ui.dialog.GroupDeleteDialogFragment; ...@@ -43,7 +47,6 @@ import com.xabber.android.ui.dialog.GroupDeleteDialogFragment;
import com.xabber.android.ui.dialog.GroupRenameDialogFragment; import com.xabber.android.ui.dialog.GroupRenameDialogFragment;
import com.xabber.android.ui.dialog.MUCDeleteDialogFragment; import com.xabber.android.ui.dialog.MUCDeleteDialogFragment;
import com.xabber.android.ui.preferences.AccountEditor; import com.xabber.android.ui.preferences.AccountEditor;
import com.xabber.android.ui.ContactViewer;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
/** /**
...@@ -189,7 +192,7 @@ public class ContextMenuHelper { ...@@ -189,7 +192,7 @@ public class ContextMenuHelper {
} }
public static void createGroupContextMenu(final FragmentActivity activity, public static void createGroupContextMenu(final FragmentActivity activity,
UpdatableAdapter adapter, final String account, final String group, ContextMenu menu) { final UpdatableAdapter adapter, final String account, final String group, ContextMenu menu) {
menu.setHeaderTitle(GroupManager.getInstance().getGroupName(account, group)); menu.setHeaderTitle(GroupManager.getInstance().getGroupName(account, group));
if (!group.equals(GroupManager.ACTIVE_CHATS) && !group.equals(GroupManager.IS_ROOM)) { if (!group.equals(GroupManager.ACTIVE_CHATS) && !group.equals(GroupManager.IS_ROOM)) {
menu.add(R.string.group_rename).setOnMenuItemClickListener( menu.add(R.string.group_rename).setOnMenuItemClickListener(
...@@ -220,34 +223,47 @@ public class ContextMenuHelper { ...@@ -220,34 +223,47 @@ public class ContextMenuHelper {
} }
} }
if (!group.equals(GroupManager.ACTIVE_CHATS)) { if (!group.equals(GroupManager.ACTIVE_CHATS)) {
createOfflineModeContextMenu(adapter, account, group, menu); menu.add(R.string.show_offline_settings).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
createOfflineContactsDialog(activity, adapter, account, group).show();
return true;
}
});
} }
} }
public static void createAccountContextMenu( final FragmentActivity activity, UpdatableAdapter adapter, public static void createAccountContextMenu( final FragmentActivity activity, final UpdatableAdapter adapter,
final String account, ContextMenu menu) { final String account, ContextMenu menu) {
activity.getMenuInflater().inflate(R.menu.account, menu);
menu.setHeaderTitle(AccountManager.getInstance().getVerboseName(account)); menu.setHeaderTitle(AccountManager.getInstance().getVerboseName(account));
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
setUpAccountMenu(activity, adapter, account, menu);
}
public static void setUpAccountMenu(final FragmentActivity activity, final UpdatableAdapter adapter, final String account, Menu menu) {
final AccountItem accountItem = AccountManager.getInstance().getAccount(account);
ConnectionState state = accountItem.getState(); ConnectionState state = accountItem.getState();
if (state == ConnectionState.waiting) { if (state == ConnectionState.waiting) {
menu.add(R.string.account_reconnect).setOnMenuItemClickListener( menu.findItem(R.id.action_reconnect_account).setVisible(true).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() { new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
if (AccountManager.getInstance() if (accountItem.updateConnection(true))
.getAccount(account).updateConnection(true)) AccountManager.getInstance().onAccountChanged(account);
AccountManager.getInstance().onAccountChanged(
account);
return true; return true;
} }
}); });
} }
menu.add(R.string.status_editor).setIntent(StatusEditor.createIntent(activity, account));
menu.add(R.string.account_editor).setIntent(AccountEditor.createIntent(activity, account)); menu.findItem(R.id.action_edit_account_status).setIntent(StatusEditor.createIntent(activity, account));
menu.findItem(R.id.action_edit_account).setIntent(AccountEditor.createIntent(activity, account));
if (state.isConnected()) { if (state.isConnected()) {
menu.add(R.string.contact_viewer).setOnMenuItemClickListener( menu.findItem(R.id.action_contact_info).setVisible(true).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() { new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
...@@ -260,62 +276,37 @@ public class ContextMenuHelper { ...@@ -260,62 +276,37 @@ public class ContextMenuHelper {
return true; return true;
} }
}); });
menu.add(R.string.contact_add).setIntent(ContactAdd.createIntent(activity, account)); menu.findItem(R.id.action_add_contact).setVisible(true).setIntent(ContactAdd.createIntent(activity, account));
}
if (SettingsManager.contactsShowAccounts()) {
createOfflineModeContextMenu(adapter, account, null, menu);
} }
}
private static void createOfflineModeContextMenu(UpdatableAdapter adapter, if (SettingsManager.contactsShowAccounts()) {
String account, String group, ContextMenu menu) { menu.findItem(R.id.action_set_up_offline_contacts).setVisible(true)
SubMenu mapMode = menu.addSubMenu(R.string.show_offline_settings); .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
mapMode.setHeaderTitle(R.string.show_offline_settings); @Override
MenuItem always = mapMode.add(R.string.show_offline_settings, 0, 0, R.string.show_offline_always) public boolean onMenuItemClick(MenuItem item) {
.setOnMenuItemClickListener( ContextMenuHelper.createOfflineContactsDialog(activity, adapter,
new OfflineModeClickListener(adapter, account, group, ShowOfflineMode.always)); account, GroupManager.IS_ACCOUNT).show();
MenuItem normal = mapMode.add(R.string.show_offline_settings, 0, 0, R.string.show_offline_normal).setOnMenuItemClickListener( return true;
new OfflineModeClickListener(adapter, account, group, ShowOfflineMode.normal)); }
MenuItem never = mapMode.add(R.string.show_offline_settings, 0, 0, R.string.show_offline_never).setOnMenuItemClickListener( });
new OfflineModeClickListener(adapter, account, group, ShowOfflineMode.never));
mapMode.setGroupCheckable(R.string.show_offline_settings, true, true);
ShowOfflineMode showOfflineMode = GroupManager.getInstance().getShowOfflineMode(account,
group == null ? GroupManager.IS_ACCOUNT : group);
if (showOfflineMode == ShowOfflineMode.always) {
always.setChecked(true);
} else if (showOfflineMode == ShowOfflineMode.normal) {
normal.setChecked(true);
} else if (showOfflineMode == ShowOfflineMode.never) {
never.setChecked(true);
} else {
throw new IllegalStateException();
} }
} }
private static class OfflineModeClickListener implements MenuItem.OnMenuItemClickListener { public static AlertDialog createOfflineContactsDialog(Context context, final UpdatableAdapter adapter,
final String account, final String group) {
private final UpdatableAdapter adapter; return new AlertDialog.Builder(context)
private final String account; .setTitle(R.string.show_offline_settings)
private final String group; .setSingleChoiceItems(
private final ShowOfflineMode mode; R.array.offline_contacts_show_option,
GroupManager.getInstance().getShowOfflineMode(account, group).ordinal(),
public OfflineModeClickListener(UpdatableAdapter adapter, new DialogInterface.OnClickListener() {
String account, String group, ShowOfflineMode mode) { @Override
super(); public void onClick(DialogInterface dialog, int which) {
this.adapter = adapter; GroupManager.getInstance().setShowOfflineMode(account,
this.account = account; group, ShowOfflineMode.values()[which]);
this.group = group; adapter.onChange();
this.mode = mode; dialog.dismiss();
} }
}).create();
@Override
public boolean onMenuItemClick(MenuItem item) {
GroupManager.getInstance().setShowOfflineMode(account,
group == null ? GroupManager.IS_ACCOUNT : group, mode);
adapter.onChange();
return true;
}
} }
} }
...@@ -14,15 +14,17 @@ ...@@ -14,15 +14,17 @@
--> -->
<level-list xmlns:android="http://schemas.android.com/apk/res/android"> <level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item <item
android:drawable="@drawable/ic_show_offline_never_18dp" android:drawable="@drawable/ic_show_offline_always_18dp"
android:minLevel="0" android:minLevel="0"
android:maxLevel="0" /> android:maxLevel="0" />
<item <item
android:drawable="@android:color/transparent" android:drawable="@android:color/transparent"
android:minLevel="1" android:minLevel="1"
android:maxLevel="1" /> android:maxLevel="1" />
<item <item
android:drawable="@drawable/ic_show_offline_always_18dp" android:drawable="@drawable/ic_show_offline_never_18dp"
android:minLevel="2" android:minLevel="2"
android:maxLevel="2" /> android:maxLevel="2" />
</level-list> </level-list>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_reconnect_account"
android:visible="false"
android:title="@string/account_reconnect" />
<item android:id="@+id/action_edit_account_status"
android:title="@string/status_editor" />
<item android:id="@+id/action_edit_account"
android:title="@string/account_editor" />
<item android:id="@+id/action_contact_info"
android:visible="false"
android:title="@string/contact_viewer" />
<item android:id="@+id/action_add_contact"
android:visible="false"
android:title="@string/contact_add" />
<item android:id="@+id/action_set_up_offline_contacts"
android:visible="false"
android:title="@string/show_offline_settings" />
</menu>
\ No newline at end of file
...@@ -34,6 +34,17 @@ ...@@ -34,6 +34,17 @@
<item>@color/teal_700</item> <item>@color/teal_700</item>
</array> </array>
<array name="account_200">
<item>@color/green_200</item>
<item>@color/orange_200</item>
<item>@color/red_200</item>
<item>@color/blue_200</item>
<item>@color/indigo_200</item>
<item>@color/blue_grey_200</item>
<item>@color/cyan_200</item>
<item>@color/teal_200</item>
</array>
<array name="account_background"> <array name="account_background">
<item>@color/green_100</item> <item>@color/green_100</item>
<item>@color/orange_100</item> <item>@color/orange_100</item>
...@@ -45,6 +56,17 @@ ...@@ -45,6 +56,17 @@
<item>@color/teal_100</item> <item>@color/teal_100</item>
</array> </array>
<array name="account_50">
<item>@color/green_50</item>
<item>@color/orange_50</item>
<item>@color/red_50</item>
<item>@color/blue_50</item>
<item>@color/indigo_50</item>
<item>@color/blue_grey_50</item>
<item>@color/cyan_50</item>
<item>@color/teal_50</item>
</array>
<color name="color_primary_light">@color/red_100</color> <color name="color_primary_light">@color/red_100</color>
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="offline_contacts_show_option">
<item>@string/show_offline_always</item>
<item>@string/show_offline_normal</item>
<item>@string/show_offline_never</item>
</string-array>
</resources>
\ No newline at end of file
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