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;
public enum ShowOfflineMode {
/**
* Never show offline contacts.
* Always show offline contacts.
*/
never,
always,
/**
* Show offline contacts according to global settings.
......@@ -32,8 +32,7 @@ public enum ShowOfflineMode {
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;
import android.widget.Filterable;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import com.xabber.android.data.Application;
......@@ -32,12 +33,13 @@ import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.message.OnChatChangedListener;
import com.xabber.android.data.roster.AbstractContact;
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.AccountConfiguration;
import com.xabber.android.ui.adapter.ContactListAdapter;
import com.xabber.android.ui.adapter.ContactListAdapter.OnContactListChangedListener;
import com.xabber.android.ui.adapter.ContactListState;
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.helper.ContextMenuHelper;
import com.xabber.android.ui.preferences.AccountList;
......@@ -47,7 +49,7 @@ import java.util.Collection;
public class ContactListFragment extends Fragment implements OnAccountChangedListener,
OnContactChangedListener, OnChatChangedListener, OnItemClickListener,
OnContactListChangedListener, OnClickListener {
OnContactListChangedListener, OnClickListener, GroupedContactAdapter.OnAccountClickListener {
private ContactListAdapter adapter;
......@@ -91,7 +93,7 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
listView.setOnItemClickListener(this);
listView.setItemsCanFocus(true);
registerForContextMenu(listView);
adapter = new ContactListAdapter(getActivity(), listView, this);
adapter = new ContactListAdapter(getActivity(), listView, this, this);
listView.setAdapter(adapter);
infoView = view.findViewById(R.id.info);
connectedView = infoView.findViewById(R.id.connected);
......@@ -400,6 +402,14 @@ public class ContactListFragment extends Fragment implements OnAccountChangedLis
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 {
void onContactClick(AbstractContact contact);
}
......
......@@ -16,6 +16,7 @@ package com.xabber.android.ui.adapter;
import android.app.Activity;
import android.os.Handler;
import android.view.View;
import android.widget.ListView;
import com.xabber.android.data.SettingsManager;
......@@ -79,9 +80,9 @@ public class ContactListAdapter extends GroupedContactAdapter<ChatContactInflate
private final OnContactListChangedListener listener;
public ContactListAdapter(
Activity activity, ListView listView, OnContactListChangedListener listener) {
super(activity, listView, new ChatContactInflater(activity), GroupManager.getInstance());
public ContactListAdapter(Activity activity, ListView listView, OnContactListChangedListener listener,
GroupedContactAdapter.OnAccountClickListener onAccountClickListener) {
super(activity, listView, new ChatContactInflater(activity), GroupManager.getInstance(), onAccountClickListener);
this.listener = listener;
handler = new Handler();
refreshLock = new Object();
......
......@@ -95,21 +95,24 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
private final int accountGroupElevation;
private final int accountSubgroupElevation;
private final int activeChatsColor;
private final OnAccountClickListener onAccountClickListener;
public GroupedContactAdapter(Activity activity, ListView listView,
Inflater inflater, StateProvider groupStateProvider) {
Inflater inflater, StateProvider groupStateProvider, OnAccountClickListener onAccountClickListener) {
super(activity, listView, inflater);
layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.groupStateProvider = groupStateProvider;
Resources resources = activity.getResources();
accountColors = resources.getIntArray(R.array.account_action_bar);
accountSubgroupColors = resources.getIntArray(R.array.account_background);
accountColors = resources.getIntArray(R.array.account_200);
accountSubgroupColors = resources.getIntArray(R.array.account_50);
activeChatsColor = resources.getColor(R.color.color_primary_light);
accountGroupElevation = resources.getDimensionPixelSize(R.dimen.account_group_elevation);
accountSubgroupElevation = resources.getDimensionPixelSize(R.dimen.account_subgroup_elevation);
this.onAccountClickListener = onAccountClickListener;
}
@Override
......@@ -212,6 +215,14 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
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());
view.setBackgroundDrawable(new ColorDrawable(accountColors[level]));
......@@ -469,5 +480,8 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
}
}
public interface OnAccountClickListener {
void onAccountClick(View view, String account);
}
}
......@@ -14,10 +14,13 @@
*/
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.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
......@@ -34,6 +37,7 @@ import com.xabber.android.data.roster.GroupManager;
import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.ShowOfflineMode;
import com.xabber.android.ui.ContactAdd;
import com.xabber.android.ui.ContactViewer;
import com.xabber.android.ui.GroupEditor;
import com.xabber.android.ui.MUCEditor;
import com.xabber.android.ui.StatusEditor;
......@@ -43,7 +47,6 @@ import com.xabber.android.ui.dialog.GroupDeleteDialogFragment;
import com.xabber.android.ui.dialog.GroupRenameDialogFragment;
import com.xabber.android.ui.dialog.MUCDeleteDialogFragment;
import com.xabber.android.ui.preferences.AccountEditor;
import com.xabber.android.ui.ContactViewer;
import com.xabber.androiddev.R;
/**
......@@ -189,7 +192,7 @@ public class ContextMenuHelper {
}
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));
if (!group.equals(GroupManager.ACTIVE_CHATS) && !group.equals(GroupManager.IS_ROOM)) {
menu.add(R.string.group_rename).setOnMenuItemClickListener(
......@@ -220,34 +223,47 @@ public class ContextMenuHelper {
}
}
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) {
activity.getMenuInflater().inflate(R.menu.account, menu);
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();
if (state == ConnectionState.waiting) {
menu.add(R.string.account_reconnect).setOnMenuItemClickListener(
menu.findItem(R.id.action_reconnect_account).setVisible(true).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (AccountManager.getInstance()
.getAccount(account).updateConnection(true))
AccountManager.getInstance().onAccountChanged(
account);
if (accountItem.updateConnection(true))
AccountManager.getInstance().onAccountChanged(account);
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()) {
menu.add(R.string.contact_viewer).setOnMenuItemClickListener(
menu.findItem(R.id.action_contact_info).setVisible(true).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
......@@ -260,62 +276,37 @@ public class ContextMenuHelper {
return true;
}
});
menu.add(R.string.contact_add).setIntent(ContactAdd.createIntent(activity, account));
}
if (SettingsManager.contactsShowAccounts()) {
createOfflineModeContextMenu(adapter, account, null, menu);
menu.findItem(R.id.action_add_contact).setVisible(true).setIntent(ContactAdd.createIntent(activity, account));
}
}
private static void createOfflineModeContextMenu(UpdatableAdapter adapter,
String account, String group, ContextMenu menu) {
SubMenu mapMode = menu.addSubMenu(R.string.show_offline_settings);
mapMode.setHeaderTitle(R.string.show_offline_settings);
MenuItem always = mapMode.add(R.string.show_offline_settings, 0, 0, R.string.show_offline_always)
.setOnMenuItemClickListener(
new OfflineModeClickListener(adapter, account, group, ShowOfflineMode.always));
MenuItem normal = mapMode.add(R.string.show_offline_settings, 0, 0, R.string.show_offline_normal).setOnMenuItemClickListener(
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();
if (SettingsManager.contactsShowAccounts()) {
menu.findItem(R.id.action_set_up_offline_contacts).setVisible(true)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ContextMenuHelper.createOfflineContactsDialog(activity, adapter,
account, GroupManager.IS_ACCOUNT).show();
return true;
}
});
}
}
private static class OfflineModeClickListener implements MenuItem.OnMenuItemClickListener {
private final UpdatableAdapter adapter;
private final String account;
private final String group;
private final ShowOfflineMode mode;
public OfflineModeClickListener(UpdatableAdapter adapter,
String account, String group, ShowOfflineMode mode) {
super();
this.adapter = adapter;
this.account = account;
this.group = group;
this.mode = mode;
}
@Override
public boolean onMenuItemClick(MenuItem item) {
GroupManager.getInstance().setShowOfflineMode(account,
group == null ? GroupManager.IS_ACCOUNT : group, mode);
adapter.onChange();
return true;
}
public static AlertDialog createOfflineContactsDialog(Context context, final UpdatableAdapter adapter,
final String account, final String group) {
return new AlertDialog.Builder(context)
.setTitle(R.string.show_offline_settings)
.setSingleChoiceItems(
R.array.offline_contacts_show_option,
GroupManager.getInstance().getShowOfflineMode(account, group).ordinal(),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
GroupManager.getInstance().setShowOfflineMode(account,
group, ShowOfflineMode.values()[which]);
adapter.onChange();
dialog.dismiss();
}
}).create();
}
}
......@@ -14,15 +14,17 @@
-->
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/ic_show_offline_never_18dp"
android:drawable="@drawable/ic_show_offline_always_18dp"
android:minLevel="0"
android:maxLevel="0" />
<item
android:drawable="@android:color/transparent"
android:minLevel="1"
android:maxLevel="1" />
<item
android:drawable="@drawable/ic_show_offline_always_18dp"
android:drawable="@drawable/ic_show_offline_never_18dp"
android:minLevel="2"
android:maxLevel="2" />
</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 @@
<item>@color/teal_700</item>
</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">
<item>@color/green_100</item>
<item>@color/orange_100</item>
......@@ -45,6 +56,17 @@
<item>@color/teal_100</item>
</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>
......
<?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