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,38 +498,53 @@ 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();
}
} else {
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.getAccount().equals(account)) {
listView.setSelection(position);
stopMovement();
break;
}
}
}
else
setSelectedAccount(account);
} else
scrollTo(account);
break;
}
}
/**
* 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
.getItemAtPosition(position);
if (baseEntity != null
&& baseEntity instanceof AccountConfiguration
&& baseEntity.getAccount().equals(account)) {
listView.setSelection(position);
stopMovement();
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();
}
/**
* Stop fling scrolling.
*/
......@@ -567,53 +582,7 @@ public class ContactList extends ManagedListActivity implements
if (object == null) {
// Account toggler
} else if (object instanceof AbstractContact) {
AbstractContact abstractContact = (AbstractContact) object;
if (ACTION_ROOM_INVITE.equals(action)) {
action = null;
Intent intent = getIntent();
String account = getRoomInviteAccount(intent);
String user = getRoomInviteUser(intent);
if (account != null && user != null)
try {
MUCManager.getInstance().invite(account, user,
abstractContact.getUser());
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
finish();
} else if (Intent.ACTION_SEND.equals(action)) {
action = null;
startActivity(ChatViewer.createSendIntent(this,
abstractContact.getAccount(),
abstractContact.getUser(), sendText));
finish();
} else if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
Intent intent = new Intent();
intent.putExtra(
Intent.EXTRA_SHORTCUT_INTENT,
ChatViewer.createClearTopIntent(this,
abstractContact.getAccount(),
abstractContact.getUser()));
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
abstractContact.getName());
Bitmap bitmap;
if (MUCManager.getInstance()
.hasRoom(abstractContact.getAccount(),
abstractContact.getUser()))
bitmap = AvatarManager.getInstance().getRoomBitmap(
abstractContact.getUser());
else
bitmap = AvatarManager.getInstance().getUserBitmap(
abstractContact.getUser());
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, AvatarManager
.getInstance().createShortcutBitmap(bitmap));
setResult(RESULT_OK, intent);
finish();
} else {
startActivity(ChatViewer
.createIntent(this, abstractContact.getAccount(),
abstractContact.getUser()));
}
onContactClick((AbstractContact) object);
} else if (object instanceof GroupConfiguration) {
GroupConfiguration groupConfiguration = (GroupConfiguration) object;
contactListAdapter.setExpanded(groupConfiguration.getAccount(),
......@@ -622,6 +591,53 @@ public class ContactList extends ManagedListActivity implements
}
}
private void onContactClick(AbstractContact abstractContact) {
if (ACTION_ROOM_INVITE.equals(action)) {
action = null;
Intent intent = getIntent();
String account = getRoomInviteAccount(intent);
String user = getRoomInviteUser(intent);
if (account != null && user != null)
try {
MUCManager.getInstance().invite(account, user,
abstractContact.getUser());
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
finish();
} else if (Intent.ACTION_SEND.equals(action)) {
action = null;
startActivity(ChatViewer.createSendIntent(this,
abstractContact.getAccount(), abstractContact.getUser(),
sendText));
finish();
} else if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
Intent intent = new Intent();
intent.putExtra(
Intent.EXTRA_SHORTCUT_INTENT,
ChatViewer.createClearTopIntent(this,
abstractContact.getAccount(),
abstractContact.getUser()));
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
abstractContact.getName());
Bitmap bitmap;
if (MUCManager.getInstance().hasRoom(abstractContact.getAccount(),
abstractContact.getUser()))
bitmap = AvatarManager.getInstance().getRoomBitmap(
abstractContact.getUser());
else
bitmap = AvatarManager.getInstance().getUserBitmap(
abstractContact.getUser());
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, AvatarManager
.getInstance().createShortcutBitmap(bitmap));
setResult(RESULT_OK, intent);
finish();
} else {
startActivity(ChatViewer.createIntent(this,
abstractContact.getAccount(), abstractContact.getUser()));
}
}
@Override
public void onContactsChanged(Collection<BaseEntity> addresses) {
contactListAdapter.refreshRequest();
......
......@@ -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