Commit 3871a0d0 authored by Grigory Fedorov's avatar Grigory Fedorov

Recent chats fragment update implemented.

parent 23408a81
...@@ -22,7 +22,6 @@ import android.support.v4.view.ViewPager; ...@@ -22,7 +22,6 @@ import android.support.v4.view.ViewPager;
import com.xabber.android.data.ActivityManager; import com.xabber.android.data.ActivityManager;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.account.OnAccountChangedListener; import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity; import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.archive.MessageArchiveManager; import com.xabber.android.data.extension.archive.MessageArchiveManager;
...@@ -71,6 +70,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -71,6 +70,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
ViewPager viewPager; ViewPager viewPager;
Collection<ChatViewerFragment> registeredChats = new HashSet<>(); Collection<ChatViewerFragment> registeredChats = new HashSet<>();
Collection<RecentChatFragment> recentChatFragments = new HashSet<>();
private String actionWithAccount = null; private String actionWithAccount = null;
private String actionWithUser = null; private String actionWithUser = null;
...@@ -167,8 +167,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -167,8 +167,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
return; return;
} }
LogManager.i(this, "onNewIntent account: " + account + ", user: " + user);
selectPage(account, user, false); selectPage(account, user, false);
} }
...@@ -244,30 +242,29 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -244,30 +242,29 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
@Override @Override
public void onChatChanged(final String account, final String user, public void onChatChanged(final String account, final String user,
final boolean incoming) { final boolean incoming) {
LogManager.i(this, "onChatChanged " + user);
for (ChatViewerFragment chat : registeredChats) { for (ChatViewerFragment chat : registeredChats) {
if (chat.isEqual(account, user)) { if (chat.isEqual(account, user)) {
chat.updateChat(incoming); chat.updateChat(incoming);
} }
} }
updateRegisteredRecentChatsFragments();
} }
@Override @Override
public void onContactsChanged(Collection<BaseEntity> entities) { public void onContactsChanged(Collection<BaseEntity> entities) {
LogManager.i(this, "onContactsChanged");
chatViewerAdapter.onChange(); chatViewerAdapter.onChange();
updateRegisteredChats(); updateRegisteredChats();
updateRegisteredRecentChatsFragments();
} }
@Override @Override
public void onAccountsChanged(Collection<String> accounts) { public void onAccountsChanged(Collection<String> accounts) {
LogManager.i(this, "onAccountsChanged");
chatViewerAdapter.onChange(); chatViewerAdapter.onChange();
updateRegisteredChats(); updateRegisteredChats();
updateRegisteredRecentChatsFragments();
} }
void onSent() { void onSent() {
...@@ -325,6 +322,12 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -325,6 +322,12 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
} }
} }
private void updateRegisteredRecentChatsFragments() {
for (RecentChatFragment recentChatFragment : recentChatFragments) {
recentChatFragment.updateChats(chatViewerAdapter.getActiveChats());
}
}
@Override @Override
public void onPageScrollStateChanged(int state) { public void onPageScrollStateChanged(int state) {
} }
...@@ -338,9 +341,17 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -338,9 +341,17 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
registeredChats.remove(chat); registeredChats.remove(chat);
} }
public void registerRecentChatsList(RecentChatFragment recentChatFragment) {
recentChatFragments.add(recentChatFragment);
}
public void unregisterRecentChatsList(RecentChatFragment recentChatFragment) {
recentChatFragments.remove(recentChatFragment);
}
@Override @Override
public void onChatViewAdapterFinishUpdate() { public void onChatViewAdapterFinishUpdate() {
LogManager.i(this, "onChatViewAdapterFinishUpdate position: user: " + actionWithUser);
insertExtraText(); insertExtraText();
Fragment currentFragment = chatViewerAdapter.getCurrentFragment(); Fragment currentFragment = chatViewerAdapter.getCurrentFragment();
......
...@@ -73,6 +73,20 @@ public class RecentChatFragment extends ListFragment { ...@@ -73,6 +73,20 @@ public class RecentChatFragment extends ListFragment {
return inflater.inflate(R.layout.list, container, false); return inflater.inflate(R.layout.list, container, false);
} }
@Override
public void onResume() {
super.onResume();
((ChatViewer)getActivity()).registerRecentChatsList(this);
}
@Override
public void onPause() {
super.onPause();
((ChatViewer)getActivity()).unregisterRecentChatsList(this);
}
@Override @Override
public void onDetach() { public void onDetach() {
listener = null; listener = null;
...@@ -93,4 +107,7 @@ public class RecentChatFragment extends ListFragment { ...@@ -93,4 +107,7 @@ public class RecentChatFragment extends ListFragment {
public void onRecentChatSelected(AbstractChat chat); public void onRecentChatSelected(AbstractChat chat);
} }
public void updateChats(List<AbstractChat> chats) {
((ChatListAdapter) getListAdapter()).updateChats(chats);
}
} }
...@@ -152,4 +152,8 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter implements Upda ...@@ -152,4 +152,8 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter implements Upda
public Fragment getCurrentFragment() { public Fragment getCurrentFragment() {
return currentFragment; return currentFragment;
} }
public ArrayList<AbstractChat> getActiveChats() {
return activeChats;
}
} }
\ No newline at end of file
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