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 ...@@ -162,7 +162,7 @@ public class ContactList extends ManagedListActivity implements
listView.setItemsCanFocus(true); listView.setItemsCanFocus(true);
registerForContextMenu(listView); registerForContextMenu(listView);
contactListAdapter = new ContactListAdapter(this); contactListAdapter = new ContactListAdapter(this, listView);
setListAdapter(contactListAdapter); setListAdapter(contactListAdapter);
accountToggleAdapter = new AccountToggleAdapter(this, this, accountToggleAdapter = new AccountToggleAdapter(this, this,
(LinearLayout) findViewById(R.id.account_list)); (LinearLayout) findViewById(R.id.account_list));
...@@ -498,38 +498,53 @@ public class ContactList extends ManagedListActivity implements ...@@ -498,38 +498,53 @@ public class ContactList extends ManagedListActivity implements
String account = accountToggleAdapter.getItemForView(view); 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; break;
ListView listView = getListView();
if (!SettingsManager.contactsShowAccounts()) { if (!SettingsManager.contactsShowAccounts()) {
if (AccountManager.getInstance().getAccounts().size() < 2) { if (AccountManager.getInstance().getAccounts().size() < 2)
scrollUp(); scrollUp();
} else { else
if (account.equals(AccountManager.getInstance() setSelectedAccount(account);
.getSelectedAccount())) } else
SettingsManager.setContactsSelectedAccount(""); scrollTo(account);
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;
}
}
}
break; 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. * Stop fling scrolling.
*/ */
...@@ -567,53 +582,7 @@ public class ContactList extends ManagedListActivity implements ...@@ -567,53 +582,7 @@ public class ContactList extends ManagedListActivity implements
if (object == null) { if (object == null) {
// Account toggler // Account toggler
} else if (object instanceof AbstractContact) { } else if (object instanceof AbstractContact) {
AbstractContact abstractContact = (AbstractContact) object; onContactClick((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()));
}
} else if (object instanceof GroupConfiguration) { } else if (object instanceof GroupConfiguration) {
GroupConfiguration groupConfiguration = (GroupConfiguration) object; GroupConfiguration groupConfiguration = (GroupConfiguration) object;
contactListAdapter.setExpanded(groupConfiguration.getAccount(), contactListAdapter.setExpanded(groupConfiguration.getAccount(),
...@@ -622,6 +591,53 @@ public class ContactList extends ManagedListActivity implements ...@@ -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 @Override
public void onContactsChanged(Collection<BaseEntity> addresses) { public void onContactsChanged(Collection<BaseEntity> addresses) {
contactListAdapter.refreshRequest(); contactListAdapter.refreshRequest();
......
...@@ -22,12 +22,14 @@ import java.util.Date; ...@@ -22,12 +22,14 @@ import java.util.Date;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap; import java.util.TreeMap;
import android.app.Activity;
import android.os.Handler; import android.os.Handler;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
...@@ -47,7 +49,6 @@ import com.xabber.android.data.roster.RosterManager; ...@@ -47,7 +49,6 @@ import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.AccountAdd; import com.xabber.android.ui.AccountAdd;
import com.xabber.android.ui.AccountList; import com.xabber.android.ui.AccountList;
import com.xabber.android.ui.ContactAdd; import com.xabber.android.ui.ContactAdd;
import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
/** /**
...@@ -120,9 +121,9 @@ public class ContactListAdapter extends ...@@ -120,9 +121,9 @@ public class ContactListAdapter extends
*/ */
private Date nextRefresh; private Date nextRefresh;
public ContactListAdapter(ManagedListActivity activity) { public ContactListAdapter(Activity activity, ListView listView) {
super(activity, activity.getListView(), new ChatContactInflater( super(activity, listView, new ChatContactInflater(activity),
activity), GroupManager.getInstance()); GroupManager.getInstance());
infoView = activity.findViewById(R.id.info); infoView = activity.findViewById(R.id.info);
if (infoView != null) { if (infoView != null) {
connectedView = infoView.findViewById(R.id.connected); 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