Skip to content
This repository has been archived by the owner on Jan 25, 2018. It is now read-only.

Commit

Permalink
fixed the tab view interaction between buddy and chat list
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Apr 21, 2011
1 parent 03ce9ec commit 2137177
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1,091 deletions.
93 changes: 32 additions & 61 deletions src/info/guardianproject/otr/app/im/app/ActiveChatListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package info.guardianproject.otr.app.im.app;

import info.guardianproject.otr.app.im.IChatSession;
import info.guardianproject.otr.app.im.IChatSessionListener;
import info.guardianproject.otr.app.im.IChatSessionManager;
import info.guardianproject.otr.app.im.IContactListListener;
import info.guardianproject.otr.app.im.IContactListManager;
import info.guardianproject.otr.app.im.IImConnection;
import info.guardianproject.otr.app.im.ISubscriptionListener;
import info.guardianproject.otr.app.im.R;
import info.guardianproject.otr.app.im.app.adapter.ChatSessionListenerAdapter;
import info.guardianproject.otr.app.im.app.adapter.ContactListListenerAdapter;
import info.guardianproject.otr.app.im.engine.Contact;
import info.guardianproject.otr.app.im.engine.ContactListManager;
Expand Down Expand Up @@ -56,57 +58,43 @@ public class ActiveChatListView extends LinearLayout {
IImConnection mConn;
SimpleAlertHandler mHandler;
Context mContext;
private final IContactListListener mChatListListener;
private final IChatSessionListener mChatListListener;

UserPresenceView mPresenceView;
ListView mChatList;

private ChatListTreeAdapter mAdapter;//ChatListAdapter
private boolean mHideOfflineContacts;
private SavedState mSavedState;
private SavedState mSavedState;
private ChatListAdapter mAdapter;//ChatListAdapter
private boolean mAutoRefresh = true;

public ActiveChatListView(Context screen, AttributeSet attrs) {
super(screen, attrs);
mContext = screen;
mScreen = (Activity)screen;
mHandler = new SimpleAlertHandler(mScreen);
mChatListListener = new MyContactListListener(mHandler);
mChatListListener = new MyChatSessionListener(mHandler);
}

private class MyContactListListener extends ContactListListenerAdapter {
public MyContactListListener(SimpleAlertHandler handler) {
super(handler);
private class MyChatSessionListener extends ChatSessionListenerAdapter {
public MyChatSessionListener(SimpleAlertHandler handler) {
super();
}

@Override
public void onAllContactListsLoaded() {
if (mAdapter != null) {
mAdapter.startAutoRequery();
}
}
}

private final ISubscriptionListener.Stub mSubscriptionListener = new ISubscriptionListener.Stub() {

public void onSubScriptionRequest(Contact from) {
querySubscription();
}
@Override
public void onChatSessionCreated(IChatSession session) {

super.onChatSessionCreated(session);
mAdapter.startAutoRequery();
}

public void onSubscriptionApproved(String contact) {
querySubscription();
}
@Override
public void onChatSessionCreateError(String name, ImErrorInfo error) {
super.onChatSessionCreateError(name, error);
}

public void onSubscriptionDeclined(String contact) {
querySubscription();
}

}

private void querySubscription() {
if (mAdapter != null) {
mAdapter.startQuerySubscriptions();
}
}
};

@Override
protected void onFinishInflate() {
Expand All @@ -132,29 +120,18 @@ public void setConnection(IImConnection conn) {
mPresenceView.setConnection(conn);

if (mAdapter == null) {
mAdapter = new ChatListTreeAdapter(conn, mScreen);
mAdapter.setHideOfflineContacts(mHideOfflineContacts);
mAdapter = new ChatListAdapter(conn, mScreen);
mChatList.setAdapter(mAdapter);
mChatList.setOnScrollListener(mAdapter);

/*
if (mSavedState != null) {
int[] expandedGroups = mSavedState.mExpandedGroups;
if(expandedGroups != null) {
for (int group : expandedGroups) {
mChatList.expandGroup(group);
}
}
}*/

} else {
mAdapter.changeConnection(conn);
}
try {
IContactListManager listMgr = conn.getContactListManager();
if (listMgr.getState() == ContactListManager.LISTS_LOADED) {
mAdapter.startAutoRequery();
}
IChatSessionManager listMgr = conn.getChatSessionManager();
mAdapter.startAutoRequery();

} catch (RemoteException e) {
Log.e(ImApp.LOG_TAG, "Service died!");
}
Expand All @@ -164,13 +141,6 @@ public void setConnection(IImConnection conn) {
}
}

public void setHideOfflineContacts(boolean hide) {
if (mAdapter != null) {
mAdapter.setHideOfflineContacts(hide);
} else {
mHideOfflineContacts = hide;
}
}

/*
public void startChat() {
Expand Down Expand Up @@ -411,19 +381,20 @@ public String getSelectedContactList() {

private void registerListeners() {
try{
IContactListManager listManager = mConn.getContactListManager();
listManager.registerContactListListener(mChatListListener);
listManager.registerSubscriptionListener(mSubscriptionListener);
IChatSessionManager chatManager = mConn.getChatSessionManager();

chatManager.registerChatSessionListener(mChatListListener);

}catch(RemoteException e) {
mHandler.showServiceErrorAlert();
}
}

private void unregisterListeners() {
try{
IContactListManager listManager = mConn.getContactListManager();
listManager.unregisterContactListListener(mChatListListener);
listManager.unregisterSubscriptionListener(mSubscriptionListener);
IChatSessionManager chatManager = mConn.getChatSessionManager();
chatManager.unregisterChatSessionListener(mChatListListener);
}catch(RemoteException e) {
mHandler.showServiceErrorAlert();
}
Expand Down
4 changes: 0 additions & 4 deletions src/info/guardianproject/otr/app/im/app/ChatListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ public void run() {
finish();
} else {
mActiveChatListView.setConnection(mConn);
mActiveChatListView.setHideOfflineContacts(
mSettingMap.getHideOfflineContacts());
}
}
}
Expand All @@ -146,8 +144,6 @@ public void run() {
mSettingMap.addObserver(new Observer() {
public void update(Observable observed, Object updateData) {
if (!mDestroyed) {
mActiveChatListView.setHideOfflineContacts(
mSettingMap.getHideOfflineContacts());
}
}
});
Expand Down
Loading

0 comments on commit 2137177

Please sign in to comment.