Commit 23e3e407 authored by Alexander Ivanov's avatar Alexander Ivanov

Separate contact list, account toggler and intent methods.

parent 68a6c838
......@@ -162,7 +162,7 @@ public class ContactList extends ManagedListActivity implements
listView.setItemsCanFocus(true);
registerForContextMenu(listView);
contactListAdapter = new ContactListAdapter(this);
contactListAdapter = new ContactListAdapter(this, listView);
setListAdapter(contactListAdapter);
accountToggleAdapter = new AccountToggleAdapter(this, this,
(LinearLayout) findViewById(R.id.account_list));
......@@ -498,21 +498,24 @@ public class ContactList extends ManagedListActivity implements
String account = accountToggleAdapter.getItemForView(view);
if (account == null) // Check for tap on account in the title
break;
ListView listView = getListView();
if (!SettingsManager.contactsShowAccounts()) {
if (AccountManager.getInstance().getAccounts().size() < 2) {
if (AccountManager.getInstance().getAccounts().size() < 2)
scrollUp();
} else {
if (account.equals(AccountManager.getInstance()
.getSelectedAccount()))
SettingsManager.setContactsSelectedAccount("");
else
SettingsManager.setContactsSelectedAccount(account);
rebuildAccountToggler();
contactListAdapter.onChange();
stopMovement();
setSelectedAccount(account);
} else
scrollTo(account);
break;
}
} else {
}
/**
* Scroll contact list to specified account.
*
* @param account
*/
private void scrollTo(String account) {
ListView listView = getListView();
long count = listView.getCount();
for (int position = 0; position < (int) count; position++) {
BaseEntity baseEntity = (BaseEntity) listView
......@@ -526,8 +529,20 @@ public class ContactList extends ManagedListActivity implements
}
}
}
break;
}
/**
* Filter out contact list for selected account.
*
* @param account
*/
private void setSelectedAccount(String account) {
if (account.equals(AccountManager.getInstance().getSelectedAccount()))
SettingsManager.setContactsSelectedAccount("");
else
SettingsManager.setContactsSelectedAccount(account);
rebuildAccountToggler();
contactListAdapter.onChange();
stopMovement();
}
/**
......@@ -567,7 +582,16 @@ public class ContactList extends ManagedListActivity implements
if (object == null) {
// Account toggler
} else if (object instanceof AbstractContact) {
AbstractContact abstractContact = (AbstractContact) object;
onContactClick((AbstractContact) object);
} else if (object instanceof GroupConfiguration) {
GroupConfiguration groupConfiguration = (GroupConfiguration) object;
contactListAdapter.setExpanded(groupConfiguration.getAccount(),
groupConfiguration.getUser(),
!groupConfiguration.isExpanded());
}
}
private void onContactClick(AbstractContact abstractContact) {
if (ACTION_ROOM_INVITE.equals(action)) {
action = null;
Intent intent = getIntent();
......@@ -584,8 +608,8 @@ public class ContactList extends ManagedListActivity implements
} else if (Intent.ACTION_SEND.equals(action)) {
action = null;
startActivity(ChatViewer.createSendIntent(this,
abstractContact.getAccount(),
abstractContact.getUser(), sendText));
abstractContact.getAccount(), abstractContact.getUser(),
sendText));
finish();
} else if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
Intent intent = new Intent();
......@@ -597,8 +621,7 @@ public class ContactList extends ManagedListActivity implements
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
abstractContact.getName());
Bitmap bitmap;
if (MUCManager.getInstance()
.hasRoom(abstractContact.getAccount(),
if (MUCManager.getInstance().hasRoom(abstractContact.getAccount(),
abstractContact.getUser()))
bitmap = AvatarManager.getInstance().getRoomBitmap(
abstractContact.getUser());
......@@ -610,15 +633,8 @@ public class ContactList extends ManagedListActivity implements
setResult(RESULT_OK, intent);
finish();
} else {
startActivity(ChatViewer
.createIntent(this, abstractContact.getAccount(),
abstractContact.getUser()));
}
} else if (object instanceof GroupConfiguration) {
GroupConfiguration groupConfiguration = (GroupConfiguration) object;
contactListAdapter.setExpanded(groupConfiguration.getAccount(),
groupConfiguration.getUser(),
!groupConfiguration.isExpanded());
startActivity(ChatViewer.createIntent(this,
abstractContact.getAccount(), abstractContact.getUser()));
}
}
......
......@@ -22,12 +22,14 @@ import java.util.Date;
import java.util.Map.Entry;
import java.util.TreeMap;
import android.app.Activity;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import com.xabber.android.data.SettingsManager;
......@@ -47,7 +49,6 @@ import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.AccountAdd;
import com.xabber.android.ui.AccountList;
import com.xabber.android.ui.ContactAdd;
import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R;
/**
......@@ -120,9 +121,9 @@ public class ContactListAdapter extends
*/
private Date nextRefresh;
public ContactListAdapter(ManagedListActivity activity) {
super(activity, activity.getListView(), new ChatContactInflater(
activity), GroupManager.getInstance());
public ContactListAdapter(Activity activity, ListView listView) {
super(activity, listView, new ChatContactInflater(activity),
GroupManager.getInstance());
infoView = activity.findViewById(R.id.info);
if (infoView != null) {
connectedView = infoView.findViewById(R.id.connected);
......
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