Commit 67ff3d03 authored by Grigory Fedorov's avatar Grigory Fedorov

Light code formatting.

parent cfffc807
......@@ -45,7 +45,6 @@ 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.OnAccountChangedListener;
import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.android.data.extension.muc.MUCManager;
......@@ -76,9 +75,8 @@ import java.util.Collection;
*
* @author alexander.ivanov
*/
public class ContactList extends ManagedActivity implements
OnAccountChangedListener, View.OnClickListener,
OnChoosedListener, OnContactClickListener {
public class ContactList extends ManagedActivity implements OnAccountChangedListener,
View.OnClickListener, OnChoosedListener, OnContactClickListener {
/**
* Select contact to be invited to the room was requested.
......@@ -121,6 +119,7 @@ public class ContactList extends ManagedActivity implements
ActivityManager.getInstance().startNewTask(this);
}
super.onCreate(savedInstanceState);
if (isFinishing()) {
return;
}
......@@ -233,7 +232,6 @@ public class ContactList extends ManagedActivity implements
@Override
protected void onResume() {
super.onResume();
updateStatusBar();
rebuildAccountToggle();
Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
......@@ -281,9 +279,9 @@ public class ContactList extends ManagedActivity implements
}
}
}
if (Application.getInstance().doNotify()) {
if (SettingsManager.bootCount() > 2
&& !SettingsManager.connectionStartAtBoot()
if (SettingsManager.bootCount() > 2 && !SettingsManager.connectionStartAtBoot()
&& !SettingsManager.startAtBootSuggested()) {
StartAtBootDialogFragment.newInstance().show(getFragmentManager(), "START_AT_BOOT");
}
......@@ -458,8 +456,9 @@ public class ContactList extends ManagedActivity implements
break;
default:
String account = accountToggleAdapter.getItemForView(view);
if (account == null) // Check for tap on account in the title
if (account == null) { // Check for tap on account in the title
break;
}
if (!SettingsManager.contactsShowAccounts()) {
if (AccountManager.getInstance().getAccounts().size() < 2) {
getContactListFragment().scrollUp();
......@@ -538,7 +537,6 @@ public class ContactList extends ManagedActivity implements
}
private void rebuildAccountToggle() {
updateStatusBar();
accountToggleAdapter.rebuild();
if (SettingsManager.contactsShowPanel() && accountToggleAdapter.getCount() > 0) {
actionBarView.setVisibility(View.VISIBLE);
......@@ -547,14 +545,6 @@ public class ContactList extends ManagedActivity implements
}
}
private void updateStatusBar() {
String statusText = SettingsManager.statusText();
StatusMode statusMode = SettingsManager.statusMode();
if ("".equals(statusText)) {
statusText = getString(statusMode.getStringID());
}
}
public static Intent createPersistentIntent(Context context) {
Intent intent = new Intent(context, ContactList.class);
intent.setAction("android.intent.action.MAIN");
......@@ -567,8 +557,7 @@ public class ContactList extends ManagedActivity implements
return new Intent(context, ContactList.class);
}
public static Intent createRoomInviteIntent(Context context,
String account, String room) {
public static Intent createRoomInviteIntent(Context context, String account, String room) {
Intent intent = new EntityIntentBuilder(context, ContactList.class)
.setAccount(account).setUser(room).build();
intent.setAction(ACTION_ROOM_INVITE);
......
......@@ -43,9 +43,8 @@ import com.xabber.androiddev.R;
import java.util.Collection;
public class ContactListFragment extends Fragment implements
OnAccountChangedListener, OnContactChangedListener,
OnChatChangedListener, OnItemClickListener,
public class ContactListFragment extends Fragment implements OnAccountChangedListener,
OnContactChangedListener, OnChatChangedListener, OnItemClickListener,
OnContactListChangedListener {
private ContactListAdapter adapter;
......@@ -85,8 +84,7 @@ public class ContactListFragment extends Fragment implements
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.contact_list_fragment, container,
false);
View view = inflater.inflate(R.layout.contact_list_fragment, container, false);
listView = (ListView) view.findViewById(android.R.id.list);
listView.setOnItemClickListener(this);
listView.setItemsCanFocus(true);
......@@ -98,20 +96,16 @@ public class ContactListFragment extends Fragment implements
disconnectedView = infoView.findViewById(R.id.disconnected);
textView = (TextView) infoView.findViewById(R.id.text);
buttonView = (Button) infoView.findViewById(R.id.button);
animation = AnimationUtils.loadAnimation(getActivity(),
R.anim.connection);
animation = AnimationUtils.loadAnimation(getActivity(), R.anim.connection);
return view;
}
@Override
public void onResume() {
super.onResume();
Application.getInstance().addUIListener(OnAccountChangedListener.class,
this);
Application.getInstance().addUIListener(OnContactChangedListener.class,
this);
Application.getInstance().addUIListener(OnChatChangedListener.class,
this);
Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
Application.getInstance().addUIListener(OnContactChangedListener.class, this);
Application.getInstance().addUIListener(OnChatChangedListener.class, this);
adapter.onChange();
}
......@@ -122,39 +116,36 @@ public class ContactListFragment extends Fragment implements
}
@Override
public void onCreateContextMenu(ContextMenu menu, View view,
ContextMenuInfo menuInfo) {
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
BaseEntity baseEntity = (BaseEntity) listView
.getItemAtPosition(info.position);
BaseEntity baseEntity = (BaseEntity) listView.getItemAtPosition(info.position);
if (baseEntity instanceof AbstractContact) {
ContextMenuHelper.createContactContextMenu(getActivity(), adapter,
(AbstractContact) baseEntity, menu);
ContextMenuHelper.createContactContextMenu(
getActivity(), adapter, (AbstractContact) baseEntity, menu);
} else if (baseEntity instanceof AccountConfiguration) {
ContextMenuHelper.createAccountContextMenu(getActivity(), adapter,
baseEntity.getAccount(), menu);
ContextMenuHelper.createAccountContextMenu(
getActivity(), adapter, baseEntity.getAccount(), menu);
} else if (baseEntity instanceof GroupConfiguration) {
ContextMenuHelper.createGroupContextMenu(getActivity(), adapter,
baseEntity.getAccount(), baseEntity.getUser(), menu);
} else
} else {
throw new IllegalStateException();
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
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);
((OnContactClickListener) getActivity()).onContactClick((AbstractContact) object);
} else if (object instanceof GroupConfiguration) {
GroupConfiguration groupConfiguration = (GroupConfiguration) object;
adapter.setExpanded(groupConfiguration.getAccount(),
groupConfiguration.getUser(),
adapter.setExpanded(groupConfiguration.getAccount(), groupConfiguration.getUser(),
!groupConfiguration.isExpanded());
} else
} else {
throw new IllegalStateException();
}
}
@Override
public void onContactsChanged(Collection<BaseEntity> addresses) {
......@@ -168,14 +159,14 @@ public class ContactListFragment extends Fragment implements
@Override
public void onChatChanged(String account, String user, boolean incoming) {
if (incoming)
if (incoming) {
adapter.refreshRequest();
}
}
@Override
public void onContactListChanged(CommonState commonState,
boolean hasContacts, boolean hasVisibleContacts,
boolean isFilterEnabled) {
public void onContactListChanged(CommonState commonState, boolean hasContacts,
boolean hasVisibleContacts, boolean isFilterEnabled) {
if (hasVisibleContacts) {
infoView.setVisibility(View.GONE);
disconnectedView.clearAnimation();
......@@ -187,13 +178,13 @@ public class ContactListFragment extends Fragment implements
final ContactListState state;
final OnClickListener listener;
if (isFilterEnabled) {
if (commonState == CommonState.online)
if (commonState == CommonState.online) {
state = ContactListState.online;
else if (commonState == CommonState.roster
|| commonState == CommonState.connecting)
} else if (commonState == CommonState.roster || commonState == CommonState.connecting) {
state = ContactListState.connecting;
else
} else {
state = ContactListState.offline;
}
text = R.string.application_state_no_online;
button = 0;
listener = null;
......@@ -202,25 +193,21 @@ public class ContactListFragment extends Fragment implements
text = R.string.application_state_no_online;
button = R.string.application_action_no_online;
listener = new OnClickListener() {
@Override
public void onClick(View view) {
SettingsManager.setContactsShowOffline(true);
adapter.onChange();
}
};
} else if (commonState == CommonState.online) {
state = ContactListState.online;
text = R.string.application_state_no_contacts;
button = R.string.application_action_no_contacts;
listener = new OnClickListener() {
@Override
public void onClick(View view) {
startActivity(ContactAdd.createIntent(getActivity()));
}
};
} else if (commonState == CommonState.roster) {
state = ContactListState.connecting;
......@@ -237,49 +224,41 @@ public class ContactListFragment extends Fragment implements
text = R.string.application_state_waiting;
button = R.string.application_action_waiting;
listener = new OnClickListener() {
@Override
public void onClick(View view) {
ConnectionManager.getInstance().updateConnections(true);
}
};
} else if (commonState == CommonState.offline) {
state = ContactListState.offline;
text = R.string.application_state_offline;
button = R.string.application_action_offline;
listener = new OnClickListener() {
@Override
public void onClick(View view) {
AccountManager.getInstance().setStatus(
StatusMode.available, null);
}
};
} else if (commonState == CommonState.disabled) {
state = ContactListState.offline;
text = R.string.application_state_disabled;
button = R.string.application_action_disabled;
listener = new OnClickListener() {
@Override
public void onClick(View view) {
startActivity(AccountList.createIntent(getActivity()));
}
};
} else if (commonState == CommonState.empty) {
state = ContactListState.offline;
text = R.string.application_state_empty;
button = R.string.application_action_empty;
listener = new OnClickListener() {
@Override
public void onClick(View view) {
startActivity(AccountAdd.createIntent(getActivity()));
}
};
} else {
throw new IllegalStateException();
......@@ -291,9 +270,10 @@ public class ContactListFragment extends Fragment implements
} else if (state == ContactListState.connecting) {
connectedView.setVisibility(View.VISIBLE);
disconnectedView.setVisibility(View.VISIBLE);
if (disconnectedView.getAnimation() == null)
if (disconnectedView.getAnimation() == null) {
disconnectedView.startAnimation(animation);
} else if (state == ContactListState.online) {
}
} else {
connectedView.setVisibility(View.VISIBLE);
disconnectedView.setVisibility(View.INVISIBLE);
disconnectedView.clearAnimation();
......@@ -312,12 +292,9 @@ public class ContactListFragment extends Fragment implements
* Force stop contact list updates before pause or application close.
*/
void unregisterListeners() {
Application.getInstance().removeUIListener(
OnAccountChangedListener.class, this);
Application.getInstance().removeUIListener(
OnContactChangedListener.class, this);
Application.getInstance().removeUIListener(OnChatChangedListener.class,
this);
Application.getInstance().removeUIListener(OnAccountChangedListener.class, this);
Application.getInstance().removeUIListener(OnContactChangedListener.class, this);
Application.getInstance().removeUIListener(OnChatChangedListener.class, this);
adapter.removeRefreshRequests();
}
......@@ -337,10 +314,8 @@ public class ContactListFragment extends Fragment implements
void scrollTo(String account) {
long count = listView.getCount();
for (int position = 0; position < (int) count; position++) {
BaseEntity baseEntity = (BaseEntity) listView
.getItemAtPosition(position);
if (baseEntity != null
&& baseEntity instanceof AccountConfiguration
BaseEntity baseEntity = (BaseEntity) listView.getItemAtPosition(position);
if (baseEntity != null && baseEntity instanceof AccountConfiguration
&& baseEntity.getAccount().equals(account)) {
stopMovement();
listView.setSelection(position);
......@@ -355,10 +330,11 @@ public class ContactListFragment extends Fragment implements
* @param account
*/
void setSelectedAccount(String account) {
if (account.equals(AccountManager.getInstance().getSelectedAccount()))
if (account.equals(AccountManager.getInstance().getSelectedAccount())) {
SettingsManager.setContactsSelectedAccount("");
else
} else {
SettingsManager.setContactsSelectedAccount(account);
}
stopMovement();
adapter.onChange();
}
......@@ -367,8 +343,9 @@ public class ContactListFragment extends Fragment implements
* Scroll to the top of contact list.
*/
void scrollUp() {
if (listView.getCount() > 0)
if (listView.getCount() > 0) {
listView.setSelection(0);
}
stopMovement();
}
......@@ -383,9 +360,7 @@ public class ContactListFragment extends Fragment implements
}
public interface OnContactClickListener {
void onContactClick(AbstractContact contact);
}
}
......@@ -14,9 +14,6 @@
*/
package com.xabber.android.ui.adapter;
import java.util.ArrayList;
import java.util.Locale;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
......@@ -27,6 +24,9 @@ import android.widget.Filterable;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.roster.AbstractContact;
import java.util.ArrayList;
import java.util.Locale;
/**
* Base adapter for the list of contacts.
*
......@@ -62,20 +62,13 @@ public abstract class BaseContactAdapter<Inflater extends BaseContactInflater>
public BaseContactAdapter(Activity activity, Inflater inflater) {
this.activity = activity;
this.locale = Locale.getDefault();
this.baseEntities = new ArrayList<BaseEntity>();
this.baseEntities = new ArrayList<>();
this.inflater = inflater;
inflater.setAdapter(this);
contactFilter = null;
filterString = null;
}
/**
* @return View inflater.
*/
public Inflater getInflater() {
return inflater;
}
@Override
public void onChange() {
notifyDataSetChanged();
......@@ -111,8 +104,9 @@ public abstract class BaseContactAdapter<Inflater extends BaseContactInflater>
@Override
public Filter getFilter() {
if (contactFilter == null)
if (contactFilter == null) {
contactFilter = new ContactFilter();
}
return contactFilter;
}
......@@ -126,10 +120,11 @@ public abstract class BaseContactAdapter<Inflater extends BaseContactInflater>
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
if (constraint == null || constraint.length() == 0)
if (constraint == null || constraint.length() == 0) {
filterString = null;
else
} else {
filterString = constraint.toString().toLowerCase(locale);
}
onChange();
}
......
......@@ -59,14 +59,11 @@ public abstract class BaseContactInflater {
public BaseContactInflater(Activity activity) {
this.activity = activity;
layoutInflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
avatarInflaterHelper = AbstractAvatarInflaterHelper
.createAbstractContactInflaterHelper();
Bitmap bitmap = BitmapFactory.decodeResource(activity.getResources(),
R.drawable.shadow);
shadowDrawable = new BitmapDrawable(bitmap);
layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
avatarInflaterHelper = AbstractAvatarInflaterHelper.createAbstractContactInflaterHelper();
Bitmap bitmap = BitmapFactory.decodeResource(activity.getResources(), R.drawable.shadow);
shadowDrawable = new BitmapDrawable(activity.getResources(), bitmap);
shadowDrawable.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
}
......@@ -115,19 +112,18 @@ public abstract class BaseContactInflater {
*/
public void getView(View view, AbstractContact abstractContact) {
final ViewHolder viewHolder = (ViewHolder) view.getTag();
if (abstractContact.isConnected())
if (abstractContact.isConnected()) {
viewHolder.shadow.setVisibility(View.GONE);
else
} else {
viewHolder.shadow.setVisibility(View.VISIBLE);
}
viewHolder.color.setImageLevel(abstractContact.getColorLevel());
if (SettingsManager.contactsShowAvatars()) {
viewHolder.avatar.setVisibility(View.VISIBLE);
viewHolder.avatar.setImageDrawable(abstractContact
.getAvatarForContactList());
avatarInflaterHelper.updateAvatar(viewHolder.avatar,
abstractContact);
viewHolder.avatar.setImageDrawable(abstractContact.getAvatarForContactList());
avatarInflaterHelper.updateAvatar(viewHolder.avatar, abstractContact);
((RelativeLayout.LayoutParams) viewHolder.panel.getLayoutParams())
.addRule(RelativeLayout.RIGHT_OF, R.id.avatar);
} else {
......@@ -140,14 +136,12 @@ public abstract class BaseContactInflater {
final String statusText = getStatusText(abstractContact);
if ("".equals(statusText)) {
viewHolder.name.getLayoutParams().height = activity.getResources()
.getDimensionPixelSize(
R.dimen.contact_name_height_hide_status);
.getDimensionPixelSize(R.dimen.contact_name_height_hide_status);
viewHolder.name.setGravity(Gravity.CENTER_VERTICAL);
viewHolder.status.setVisibility(View.GONE);
} else {
viewHolder.name.getLayoutParams().height = activity.getResources()
.getDimensionPixelSize(
R.dimen.contact_name_height_show_status);
.getDimensionPixelSize(R.dimen.contact_name_height_show_status);
viewHolder.name.setGravity(Gravity.BOTTOM);
viewHolder.status.setText(statusText);
viewHolder.status.setVisibility(View.VISIBLE);
......
......@@ -14,14 +14,6 @@
*/
package com.xabber.android.ui.adapter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Map.Entry;
import java.util.TreeMap;
import android.app.Activity;
import android.os.Handler;
import android.widget.ListView;
......@@ -39,14 +31,21 @@ import com.xabber.android.data.roster.GroupManager;
import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Map.Entry;
import java.util.TreeMap;
/**
* Adapter for contact list in the main activity.
*
* @author alexander.ivanov
*/
public class ContactListAdapter extends
GroupedContactAdapter<ChatContactInflater, GroupManager> implements
Runnable {
public class ContactListAdapter extends GroupedContactAdapter<ChatContactInflater, GroupManager>
implements Runnable {
/**
* Number of milliseconds between lazy refreshes.
......@@ -71,7 +70,7 @@ public class ContactListAdapter extends
/**
* Whether refresh is in progress.
*/
private boolean refreshInProgess;
private boolean refreshInProgress;
/**
* Minimal time when next refresh can be executed.
......@@ -80,15 +79,14 @@ public class ContactListAdapter extends
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) {
super(activity, listView, new ChatContactInflater(activity), GroupManager.getInstance());
this.listener = listener;
handler = new Handler();
refreshLock = new Object();
refreshRequested = false;
refreshInProgess = false;
refreshInProgress = false;
nextRefresh = new Date();
}
......@@ -97,11 +95,12 @@ public class ContactListAdapter extends
*/
public void refreshRequest() {
synchronized (refreshLock) {
if (refreshRequested)
if (refreshRequested) {
return;
if (refreshInProgess)
}
if (refreshInProgress) {
refreshRequested = true;
else {
} else {
long delay = nextRefresh.getTime() - new Date().getTime();
handler.postDelayed(this, delay > 0 ? delay : 0);
}
......@@ -114,7 +113,7 @@ public class ContactListAdapter extends
public void removeRefreshRequests() {
synchronized (refreshLock) {
refreshRequested = false;
refreshInProgess = false;
refreshInProgress = false;
handler.removeCallbacks(this);
}
}
......@@ -123,32 +122,25 @@ public class ContactListAdapter extends
public void onChange() {
synchronized (refreshLock) {
refreshRequested = false;
refreshInProgess = true;
refreshInProgress = true;
handler.removeCallbacks(this);
}
final Collection<RosterContact> rosterContacts = RosterManager
.getInstance().getContacts();
final Collection<RosterContact> rosterContacts = RosterManager.getInstance().getContacts();
final boolean showOffline = SettingsManager.contactsShowOffline();
final boolean showGroups = SettingsManager.contactsShowGroups();
final boolean showEmptyGroups = SettingsManager
.contactsShowEmptyGroups();
final boolean showActiveChats = SettingsManager
.contactsShowActiveChats();
final boolean stayActiveChats = SettingsManager
.contactsStayActiveChats();
final boolean showEmptyGroups = SettingsManager.contactsShowEmptyGroups();
final boolean showActiveChats = SettingsManager.contactsShowActiveChats();
final boolean stayActiveChats = SettingsManager.contactsStayActiveChats();
final boolean showAccounts = SettingsManager.contactsShowAccounts();
final Comparator<AbstractContact> comparator = SettingsManager
.contactsOrder();
final CommonState commonState = AccountManager.getInstance()
.getCommonState();
final String selectedAccount = AccountManager.getInstance()
.getSelectedAccount();
final Comparator<AbstractContact> comparator = SettingsManager.contactsOrder();
final CommonState commonState = AccountManager.getInstance().getCommonState();
final String selectedAccount = AccountManager.getInstance().getSelectedAccount();
/**
* Accounts.
*/
final TreeMap<String, AccountConfiguration> accounts = new TreeMap<String, AccountConfiguration>();
final TreeMap<String, AccountConfiguration> accounts = new TreeMap<>();
/**
* Groups.
......@@ -168,7 +160,7 @@ public class ContactListAdapter extends
/**
* List of rooms and active chats grouped by users inside accounts.
*/
final TreeMap<String, TreeMap<String, AbstractChat>> abstractChats = new TreeMap<String, TreeMap<String, AbstractChat>>();
final TreeMap<String, TreeMap<String, AbstractChat>> abstractChats = new TreeMap<>();
/**
* Whether there is at least one contact.
......@@ -180,18 +172,17 @@ public class ContactListAdapter extends
*/
boolean hasVisibleContacts = false;
for (String account : AccountManager.getInstance().getAccounts())
for (String account : AccountManager.getInstance().getAccounts()) {
accounts.put(account, null);
}
for (AbstractChat abstractChat : MessageManager.getInstance()
.getChats()) {
for (AbstractChat abstractChat : MessageManager.getInstance().getChats()) {
if ((abstractChat instanceof RoomChat || abstractChat.isActive())
&& accounts.containsKey(abstractChat.getAccount())) {
final String account = abstractChat.getAccount();
TreeMap<String, AbstractChat> users = abstractChats
.get(account);
TreeMap<String, AbstractChat> users = abstractChats.get(account);
if (users == null) {
users = new TreeMap<String, AbstractChat>();
users = new TreeMap<>();
abstractChats.put(account, users);
}
users.put(abstractChat.getUser(), abstractChat);
......@@ -203,77 +194,82 @@ public class ContactListAdapter extends
if (showAccounts) {
groups = null;
contacts = null;
for (Entry<String, AccountConfiguration> entry : accounts
.entrySet()) {
for (Entry<String, AccountConfiguration> entry : accounts.entrySet()) {
entry.setValue(new AccountConfiguration(entry.getKey(),
GroupManager.IS_ACCOUNT, groupStateProvider));
}
} else {
if (showGroups) {
groups = new TreeMap<String, GroupConfiguration>();
groups = new TreeMap<>();
contacts = null;
} else {
groups = null;
contacts = new ArrayList<AbstractContact>();
contacts = new ArrayList<>();
}
}
if (showActiveChats)
if (showActiveChats) {
activeChats = new GroupConfiguration(GroupManager.NO_ACCOUNT,
GroupManager.ACTIVE_CHATS, groupStateProvider);
else
} else {
activeChats = null;
}
// Build structure.
for (RosterContact rosterContact : rosterContacts) {
if (!rosterContact.isEnabled())
if (!rosterContact.isEnabled()) {
continue;
}
hasContacts = true;
final boolean online = rosterContact.getStatusMode().isOnline();
final String account = rosterContact.getAccount();
final TreeMap<String, AbstractChat> users = abstractChats
.get(account);
final TreeMap<String, AbstractChat> users = abstractChats.get(account);
final AbstractChat abstractChat;
if (users == null)
if (users == null) {
abstractChat = null;
else
} else {
abstractChat = users.remove(rosterContact.getUser());
if (showActiveChats && abstractChat != null
&& abstractChat.isActive()) {
}
if (showActiveChats && abstractChat != null && abstractChat.isActive()) {
activeChats.setNotEmpty();
hasVisibleContacts = true;
if (activeChats.isExpanded())
if (activeChats.isExpanded()) {
activeChats.addAbstractContact(rosterContact);
}
activeChats.increment(online);
if (!stayActiveChats || (!showAccounts && !showGroups))
if (!stayActiveChats || (!showAccounts && !showGroups)) {
continue;
}
if (selectedAccount != null && !selectedAccount.equals(account))
}
if (selectedAccount != null && !selectedAccount.equals(account)) {
continue;
}
if (addContact(rosterContact, online, accounts, groups,
contacts, showAccounts, showGroups, showOffline))
contacts, showAccounts, showGroups, showOffline)) {
hasVisibleContacts = true;
}
for (TreeMap<String, AbstractChat> users : abstractChats.values())
}
for (TreeMap<String, AbstractChat> users : abstractChats.values()) {
for (AbstractChat abstractChat : users.values()) {
final AbstractContact abstractContact;
if (abstractChat instanceof RoomChat)
abstractContact = new RoomContact(
(RoomChat) abstractChat);
else
if (abstractChat instanceof RoomChat) {
abstractContact = new RoomContact((RoomChat) abstractChat);
} else {
abstractContact = new ChatContact(abstractChat);
}
if (showActiveChats && abstractChat.isActive()) {
activeChats.setNotEmpty();
hasVisibleContacts = true;
if (activeChats.isExpanded())
if (activeChats.isExpanded()) {
activeChats.addAbstractContact(abstractContact);
}
activeChats.increment(false);
if (!stayActiveChats || (!showAccounts && !showGroups))
if (!stayActiveChats || (!showAccounts && !showGroups)) {
continue;
}
if (selectedAccount != null
&& !selectedAccount.equals(abstractChat
.getAccount()))
}
if (selectedAccount != null && !selectedAccount.equals(abstractChat.getAccount())) {
continue;
}
final String group;
final boolean online;
if (abstractChat instanceof RoomChat) {
......@@ -284,8 +280,9 @@ public class ContactListAdapter extends
online = false;
}
hasVisibleContacts = true;
addContact(abstractContact, group, online, accounts,
groups, contacts, showAccounts, showGroups);
addContact(abstractContact, group, online, accounts, groups, contacts,
showAccounts, showGroups);
}
}
// Remove empty groups, sort and apply structure.
......@@ -293,10 +290,10 @@ public class ContactListAdapter extends
if (hasVisibleContacts) {
if (showActiveChats) {
if (!activeChats.isEmpty()) {
if (showAccounts || showGroups)
if (showAccounts || showGroups) {
baseEntities.add(activeChats);
activeChats
.sortAbstractContacts(ComparatorByChat.COMPARATOR_BY_CHAT);
}
activeChats.sortAbstractContacts(ComparatorByChat.COMPARATOR_BY_CHAT);
baseEntities.addAll(activeChats.getAbstractContacts());
}
}
......@@ -304,34 +301,29 @@ public class ContactListAdapter extends
for (AccountConfiguration rosterAccount : accounts.values()) {
baseEntities.add(rosterAccount);
if (showGroups) {
if (rosterAccount.isExpanded())
if (rosterAccount.isExpanded()) {
for (GroupConfiguration rosterConfiguration : rosterAccount
.getSortedGroupConfigurations())
if (showEmptyGroups
|| !rosterConfiguration.isEmpty()) {
.getSortedGroupConfigurations()) {
if (showEmptyGroups || !rosterConfiguration.isEmpty()) {
baseEntities.add(rosterConfiguration);
rosterConfiguration
.sortAbstractContacts(comparator);
baseEntities.addAll(rosterConfiguration
.getAbstractContacts());
rosterConfiguration.sortAbstractContacts(comparator);
baseEntities.addAll(rosterConfiguration.getAbstractContacts());
}
}
}
} else {
rosterAccount.sortAbstractContacts(comparator);
baseEntities.addAll(rosterAccount
.getAbstractContacts());
baseEntities.addAll(rosterAccount.getAbstractContacts());
}
}
} else {
if (showGroups) {
for (GroupConfiguration rosterConfiguration : groups
.values())
if (showEmptyGroups
|| !rosterConfiguration.isEmpty()) {
for (GroupConfiguration rosterConfiguration : groups.values()) {
if (showEmptyGroups || !rosterConfiguration.isEmpty()) {
baseEntities.add(rosterConfiguration);
rosterConfiguration
.sortAbstractContacts(comparator);
baseEntities.addAll(rosterConfiguration
.getAbstractContacts());
rosterConfiguration.sortAbstractContacts(comparator);
baseEntities.addAll(rosterConfiguration.getAbstractContacts());
}
}
} else {
Collections.sort(contacts, comparator);
......@@ -340,33 +332,35 @@ public class ContactListAdapter extends
}
}
} else { // Search
final ArrayList<AbstractContact> baseEntities = new ArrayList<AbstractContact>();
final ArrayList<AbstractContact> baseEntities = new ArrayList<>();
// Build structure.
for (RosterContact rosterContact : rosterContacts) {
if (!rosterContact.isEnabled())
if (!rosterContact.isEnabled()) {
continue;
}
final String account = rosterContact.getAccount();
final TreeMap<String, AbstractChat> users = abstractChats
.get(account);
if (users != null)
final TreeMap<String, AbstractChat> users = abstractChats.get(account);
if (users != null) {
users.remove(rosterContact.getUser());
if (rosterContact.getName().toLowerCase(locale)
.contains(filterString))
}
if (rosterContact.getName().toLowerCase(locale).contains(filterString)) {
baseEntities.add(rosterContact);
}
for (TreeMap<String, AbstractChat> users : abstractChats.values())
}
for (TreeMap<String, AbstractChat> users : abstractChats.values()) {
for (AbstractChat abstractChat : users.values()) {
final AbstractContact abstractContact;
if (abstractChat instanceof RoomChat)
abstractContact = new RoomContact(
(RoomChat) abstractChat);
else
if (abstractChat instanceof RoomChat) {
abstractContact = new RoomContact((RoomChat) abstractChat);
} else {
abstractContact = new ChatContact(abstractChat);
if (abstractContact.getName().toLowerCase(locale)
.contains(filterString))
}
if (abstractContact.getName().toLowerCase(locale).contains(filterString)) {
baseEntities.add(abstractContact);
}
}
}
Collections.sort(baseEntities, comparator);
this.baseEntities.clear();
this.baseEntities.addAll(baseEntities);
......@@ -379,12 +373,13 @@ public class ContactListAdapter extends
synchronized (refreshLock) {
nextRefresh = new Date(new Date().getTime() + REFRESH_INTERVAL);
refreshInProgess = false;
refreshInProgress = false;
handler.removeCallbacks(this); // Just to be sure.
if (refreshRequested)
if (refreshRequested) {
handler.postDelayed(this, REFRESH_INTERVAL);
}
}
}
@Override
public void run() {
......
......@@ -14,11 +14,6 @@
*/
package com.xabber.android.ui.adapter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.TreeMap;
import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
......@@ -38,6 +33,11 @@ import com.xabber.android.data.roster.GroupStateProvider;
import com.xabber.android.data.roster.ShowOfflineMode;
import com.xabber.androiddev.R;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.TreeMap;
/**
* Provide grouping implementation for the list of contacts.
*
......@@ -62,7 +62,7 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
static final int TYPE_GROUP = 1;
static {
Collection<Group> groups = new ArrayList<Group>(1);
Collection<Group> groups = new ArrayList<>(1);
groups.add(new Group() {
@Override
public String getName() {
......@@ -95,28 +95,15 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
public GroupedContactAdapter(Activity activity, ListView listView,
Inflater inflater, StateProvider groupStateProvider) {
super(activity, listView, inflater);
layoutInflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.groupStateProvider = groupStateProvider;
TypedArray typedArray;
typedArray = activity.getTheme().obtainStyledAttributes(
R.styleable.ContactList);
expanderAccountTextColor = typedArray
.getColorStateList(R.styleable.ContactList_expanderAccountColor);
expanderGroupTextColor = typedArray
.getColorStateList(R.styleable.ContactList_expanderGroupColor);
typedArray = activity.getTheme().obtainStyledAttributes(R.styleable.ContactList);
expanderAccountTextColor = typedArray.getColorStateList(R.styleable.ContactList_expanderAccountColor);
expanderGroupTextColor = typedArray.getColorStateList(R.styleable.ContactList_expanderGroupColor);
typedArray.recycle();
}
/**
* Returns group state provider.
*
* @return
*/
public StateProvider getGroupStateProvider() {
return groupStateProvider;
}
@Override
public int getViewTypeCount() {
return 2;
......@@ -125,13 +112,14 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
@Override
public int getItemViewType(int position) {
Object object = getItem(position);
if (object instanceof AbstractContact)
if (object instanceof AbstractContact) {
return TYPE_CONTACT;
else if (object instanceof GroupConfiguration)
} else if (object instanceof GroupConfiguration) {
return TYPE_GROUP;
else
} else {
throw new IllegalStateException();
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
......@@ -141,15 +129,12 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
final View view;
final GroupViewHolder viewHolder;
if (convertView == null) {
view = layoutInflater.inflate(R.layout.base_group_item, parent,
false);
TypedArray typedArray = activity
.obtainStyledAttributes(R.styleable.ContactList);
view.setBackgroundDrawable(typedArray
.getDrawable(R.styleable.ContactList_expanderBackground));
((ImageView) view.findViewById(R.id.indicator))
.setImageDrawable(typedArray
.getDrawable(R.styleable.ContactList_expanderIndicator));
view = layoutInflater.inflate(R.layout.base_group_item, parent, false);
TypedArray typedArray = activity.obtainStyledAttributes(R.styleable.ContactList);
view.setBackgroundDrawable(
typedArray.getDrawable(R.styleable.ContactList_expanderBackground));
((ImageView) view.findViewById(R.id.indicator)).setImageDrawable(
typedArray.getDrawable(R.styleable.ContactList_expanderIndicator));
typedArray.recycle();
viewHolder = new GroupViewHolder(view);
......@@ -161,26 +146,24 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
final GroupConfiguration configuration = (GroupConfiguration) getItem(position);
final int level;
if (configuration instanceof AccountConfiguration) {
level = AccountManager.getInstance().getColorLevel(
configuration.getAccount());
level = AccountManager.getInstance().getColorLevel(configuration.getAccount());
viewHolder.name.setTextColor(expanderAccountTextColor);
} else {
level = AccountManager.getInstance().getColorCount();
viewHolder.name.setTextColor(expanderGroupTextColor);
}
view.getBackground().setLevel(level);
viewHolder.name.getBackground().setLevel(
configuration.getShowOfflineMode().ordinal());
viewHolder.name.getBackground().setLevel(configuration.getShowOfflineMode().ordinal());
final String name = GroupManager.getInstance().getGroupName(
configuration.getAccount(), configuration.getUser());
viewHolder.name.setText(name + " (" + configuration.getOnline()
+ "/" + configuration.getTotal() + ")");
viewHolder.indicator.setImageLevel(configuration.isExpanded() ? 1
: 0);
viewHolder.indicator.setImageLevel(configuration.isExpanded() ? 1 : 0);
return view;
} else
} else {
throw new IllegalStateException();
}
}
/**
* Gets or creates roster group in roster account.
......@@ -191,10 +174,10 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
*/
protected GroupConfiguration getGroupConfiguration(
AccountConfiguration accountConfiguration, String name) {
GroupConfiguration groupConfiguration = accountConfiguration
.getGroupConfiguration(name);
if (groupConfiguration != null)
GroupConfiguration groupConfiguration = accountConfiguration.getGroupConfiguration(name);
if (groupConfiguration != null) {
return groupConfiguration;
}
groupConfiguration = new GroupConfiguration(
accountConfiguration.getAccount(), name, groupStateProvider);
accountConfiguration.addGroupConfiguration(groupConfiguration);
......@@ -211,10 +194,10 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
protected GroupConfiguration getGroupConfiguration(
TreeMap<String, GroupConfiguration> groups, String name) {
GroupConfiguration groupConfiguration = groups.get(name);
if (groupConfiguration != null)
if (groupConfiguration != null) {
return groupConfiguration;
groupConfiguration = new GroupConfiguration(GroupManager.NO_ACCOUNT,
name, groupStateProvider);
}
groupConfiguration = new GroupConfiguration(GroupManager.NO_ACCOUNT, name, groupStateProvider);
groups.put(name, groupConfiguration);
return groupConfiguration;
}
......@@ -231,38 +214,39 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
* @param showAccounts
* @param showGroups
*/
protected void addContact(AbstractContact abstractContact, String group,
boolean online, TreeMap<String, AccountConfiguration> accounts,
TreeMap<String, GroupConfiguration> groups,
ArrayList<AbstractContact> contacts, boolean showAccounts,
boolean showGroups) {
protected void addContact(AbstractContact abstractContact, String group, boolean online,
TreeMap<String, AccountConfiguration> accounts, TreeMap<String, GroupConfiguration> groups,
ArrayList<AbstractContact> contacts, boolean showAccounts, boolean showGroups) {
if (showAccounts) {
final String account = abstractContact.getAccount();
final AccountConfiguration accountConfiguration;
accountConfiguration = accounts.get(account);
if (accountConfiguration == null)
if (accountConfiguration == null) {
return;
}
if (showGroups) {
GroupConfiguration groupConfiguration = getGroupConfiguration(
accountConfiguration, group);
GroupConfiguration groupConfiguration
= getGroupConfiguration(accountConfiguration, group);
if (accountConfiguration.isExpanded()) {
groupConfiguration.setNotEmpty();
if (groupConfiguration.isExpanded())
if (groupConfiguration.isExpanded()) {
groupConfiguration.addAbstractContact(abstractContact);
}
}
groupConfiguration.increment(online);
} else {
if (accountConfiguration.isExpanded())
if (accountConfiguration.isExpanded()) {
accountConfiguration.addAbstractContact(abstractContact);
}
}
accountConfiguration.increment(online);
} else {
if (showGroups) {
GroupConfiguration groupConfiguration = getGroupConfiguration(
groups, group);
GroupConfiguration groupConfiguration = getGroupConfiguration(groups, group);
groupConfiguration.setNotEmpty();
if (groupConfiguration.isExpanded())
if (groupConfiguration.isExpanded()) {
groupConfiguration.addAbstractContact(abstractContact);
}
groupConfiguration.increment(online);
} else {
contacts.add(abstractContact);
......@@ -292,13 +276,14 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
if (showAccounts) {
final AccountConfiguration accountConfiguration;
accountConfiguration = accounts.get(abstractContact.getAccount());
if (accountConfiguration == null)
return hasVisible;
if (accountConfiguration == null) {
return false;
}
if (showGroups) {
Collection<? extends Group> abstractGroups = abstractContact
.getGroups();
if (abstractGroups.size() == 0)
Collection<? extends Group> abstractGroups = abstractContact.getGroups();
if (abstractGroups.size() == 0) {
abstractGroups = NO_GROUP_LIST;
}
for (Group abstractGroup : abstractGroups) {
GroupConfiguration groupConfiguration = getGroupConfiguration(
accountConfiguration, abstractGroup.getName());
......@@ -316,41 +301,39 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
hasVisible = true;
if (accountConfiguration.isExpanded()) {
groupConfiguration.setNotEmpty();
if (groupConfiguration.isExpanded())
groupConfiguration
.addAbstractContact(abstractContact);
if (groupConfiguration.isExpanded()) {
groupConfiguration.addAbstractContact(abstractContact);
}
}
}
groupConfiguration.increment(online);
}
} else {
if (online
|| (accountConfiguration.getShowOfflineMode() == ShowOfflineMode.always)
if (online || (accountConfiguration.getShowOfflineMode() == ShowOfflineMode.always)
|| (accountConfiguration.getShowOfflineMode() == ShowOfflineMode.normal && showOffline)) {
hasVisible = true;
if (accountConfiguration.isExpanded())
accountConfiguration
.addAbstractContact(abstractContact);
if (accountConfiguration.isExpanded()) {
accountConfiguration.addAbstractContact(abstractContact);
}
}
}
accountConfiguration.increment(online);
} else {
if (showGroups) {
Collection<? extends Group> abstractGroups = abstractContact
.getGroups();
if (abstractGroups.size() == 0)
Collection<? extends Group> abstractGroups = abstractContact.getGroups();
if (abstractGroups.size() == 0) {
abstractGroups = NO_GROUP_LIST;
}
for (Group abstractGroup : abstractGroups) {
GroupConfiguration groupConfiguration = getGroupConfiguration(
groups, abstractGroup.getName());
if (online
|| (groupConfiguration.getShowOfflineMode() == ShowOfflineMode.always)
GroupConfiguration groupConfiguration
= getGroupConfiguration(groups, abstractGroup.getName());
if (online || (groupConfiguration.getShowOfflineMode() == ShowOfflineMode.always)
|| (groupConfiguration.getShowOfflineMode() == ShowOfflineMode.normal && showOffline)) {
groupConfiguration.setNotEmpty();
hasVisible = true;
if (groupConfiguration.isExpanded())
groupConfiguration
.addAbstractContact(abstractContact);
if (groupConfiguration.isExpanded()) {
groupConfiguration.addAbstractContact(abstractContact);
}
}
groupConfiguration.increment(online);
}
......
......@@ -36,8 +36,7 @@ public abstract class SmoothContactAdapter<Inflater extends BaseContactInflater>
*/
ListView listView;
public SmoothContactAdapter(Activity activity, ListView listView,
Inflater inflater) {
public SmoothContactAdapter(Activity activity, ListView listView, Inflater inflater) {
super(activity, inflater);
this.listView = listView;
}
......
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