Commit 3e05f179 authored by Grigory Fedorov's avatar Grigory Fedorov

ChatViewerAdapter simplified: "intent" chat taken from ChatManager. No need to...

ChatViewerAdapter simplified: "intent" chat taken from ChatManager. No need to recreate adapter to open new chat.
parent cfeed485
...@@ -58,7 +58,6 @@ public class ChatViewer extends ChatScrollerActivity { ...@@ -58,7 +58,6 @@ public class ChatViewer extends ChatScrollerActivity {
LinearLayout chatScrollIndicatorLayout = (LinearLayout) findViewById(R.id.chat_scroll_indicator); LinearLayout chatScrollIndicatorLayout = (LinearLayout) findViewById(R.id.chat_scroll_indicator);
chatScroller.createView(viewPager, chatScrollIndicatorLayout); chatScroller.createView(viewPager, chatScrollIndicatorLayout);
chatScroller.initChats();
} }
@Override @Override
......
...@@ -155,7 +155,6 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL ...@@ -155,7 +155,6 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL
LinearLayout chatScrollIndicatorLayout = (LinearLayout) findViewById(R.id.chat_scroll_indicator); LinearLayout chatScrollIndicatorLayout = (LinearLayout) findViewById(R.id.chat_scroll_indicator);
chatScroller.createView(viewPager, chatScrollIndicatorLayout); chatScroller.createView(viewPager, chatScrollIndicatorLayout);
chatScroller.initChats();
} }
toolbar.setOnClickListener(this); toolbar.setOnClickListener(this);
...@@ -313,7 +312,11 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL ...@@ -313,7 +312,11 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL
case ACTION_ATTENTION: case ACTION_ATTENTION:
case ACTION_SHORTCUT: case ACTION_SHORTCUT:
action = null; action = null;
startChat(ChatManager.getInstance().getSelectedChat()); if (isDualPanelView) {
chatScroller.update();
} else {
startActivity(ChatViewer.createChatViewerIntent(this));
}
} }
} }
...@@ -429,7 +432,12 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL ...@@ -429,7 +432,12 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL
startActivity(ConferenceAdd.createIntent(this)); startActivity(ConferenceAdd.createIntent(this));
return true; return true;
case R.id.action_chat_list: case R.id.action_chat_list:
startChat(null); ChatManager.getInstance().setSelectedChat(null);
if (isDualPanelView) {
chatScroller.update();
} else {
startActivity(ChatViewer.createChatViewerIntent(this));
}
return true; return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
...@@ -482,7 +490,6 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL ...@@ -482,7 +490,6 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL
ChatManager.getInstance().setSelectedChat(null); ChatManager.getInstance().setSelectedChat(null);
if (isDualPanelView) { if (isDualPanelView) {
chatScroller.initChats();
chatScroller.update(); chatScroller.update();
} }
} }
...@@ -573,7 +580,6 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL ...@@ -573,7 +580,6 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL
ChatManager.getInstance().setInitialChat(abstractContact); ChatManager.getInstance().setInitialChat(abstractContact);
ChatManager.getInstance().setSelectedChat(abstractContact); ChatManager.getInstance().setSelectedChat(abstractContact);
if (isDualPanelView) { if (isDualPanelView) {
chatScroller.initChats();
chatScroller.update(); chatScroller.update();
} else { } else {
startActivity(ChatViewer.createChatViewerIntent(this)); startActivity(ChatViewer.createChatViewerIntent(this));
...@@ -624,7 +630,6 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL ...@@ -624,7 +630,6 @@ public class ContactList extends ChatIntentActivity implements OnAccountChangedL
if (ChatManager.getInstance().getInitialChat().equals(chat)) { if (ChatManager.getInstance().getInitialChat().equals(chat)) {
ChatManager.getInstance().setInitialChat(null); ChatManager.getInstance().setInitialChat(null);
chatScroller.initChats();
} }
chatScroller.update(); chatScroller.update();
......
...@@ -9,6 +9,7 @@ import android.view.ViewGroup; ...@@ -9,6 +9,7 @@ import android.view.ViewGroup;
import com.xabber.android.data.entity.BaseEntity; import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.message.AbstractChat; import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.MessageManager; import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.message.chat.ChatManager;
import com.xabber.android.ui.ChatViewerFragment; import com.xabber.android.ui.ChatViewerFragment;
import com.xabber.android.ui.RecentChatFragment; import com.xabber.android.ui.RecentChatFragment;
import com.xabber.xmpp.address.Jid; import com.xabber.xmpp.address.Jid;
...@@ -26,24 +27,12 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter { ...@@ -26,24 +27,12 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter {
/** /**
* Intent sent while opening chat activity. * Intent sent while opening chat activity.
*/ */
private final AbstractChat intent;
private ArrayList<AbstractChat> activeChats; private ArrayList<AbstractChat> activeChats;
private Fragment currentFragment; private Fragment currentFragment;
public ChatViewerAdapter(FragmentManager fragmentManager, BaseEntity chat) {
super(fragmentManager);
activeChats = new ArrayList<>(MessageManager.getInstance().getActiveChats());
intent = MessageManager.getInstance().getOrCreateChat(chat.getAccount(), Jid.getBareAddress(chat.getUser()));
updateChats();
}
public ChatViewerAdapter(FragmentManager fragmentManager) { public ChatViewerAdapter(FragmentManager fragmentManager) {
super(fragmentManager); super(fragmentManager);
activeChats = new ArrayList<>(MessageManager.getInstance().getActiveChats()); activeChats = new ArrayList<>(MessageManager.getInstance().getActiveChats());
intent = null;
updateChats(); updateChats();
} }
...@@ -72,6 +61,13 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter { ...@@ -72,6 +61,13 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter {
public boolean updateChats() { public boolean updateChats() {
ArrayList<AbstractChat> newChats = new ArrayList<>(MessageManager.getInstance().getActiveChats()); ArrayList<AbstractChat> newChats = new ArrayList<>(MessageManager.getInstance().getActiveChats());
BaseEntity initialChat = ChatManager.getInstance().getInitialChat();
AbstractChat intent = null;
if (initialChat != null) {
intent = MessageManager.getInstance().getOrCreateChat(initialChat.getAccount(), Jid.getBareAddress(initialChat.getUser()));
}
if (intent != null && !newChats.contains(intent)) { if (intent != null && !newChats.contains(intent)) {
newChats.add(intent); newChats.add(intent);
......
...@@ -63,20 +63,8 @@ public class ChatScroller implements ...@@ -63,20 +63,8 @@ public class ChatScroller implements
public void createView(ViewPager viewPager, LinearLayout chatScrollIndicatorLayout) { public void createView(ViewPager viewPager, LinearLayout chatScrollIndicatorLayout) {
this.viewPager = viewPager; this.viewPager = viewPager;
this.chatScrollIndicatorAdapter = new ChatScrollIndicatorAdapter(activity, chatScrollIndicatorLayout); this.chatScrollIndicatorAdapter = new ChatScrollIndicatorAdapter(activity, chatScrollIndicatorLayout);
}
public void onHide() {
MessageManager.getInstance().removeVisibleChat();
}
public void initChats() {
if (chatManager.getInitialChat() != null) {
chatViewerAdapter = new ChatViewerAdapter(activity.getFragmentManager(), chatManager.getInitialChat());
} else {
chatViewerAdapter = new ChatViewerAdapter(activity.getFragmentManager()); chatViewerAdapter = new ChatViewerAdapter(activity.getFragmentManager());
}
viewPager.setAdapter(chatViewerAdapter); viewPager.setAdapter(chatViewerAdapter);
viewPager.setOnPageChangeListener(this); viewPager.setOnPageChangeListener(this);
...@@ -87,6 +75,10 @@ public class ChatScroller implements ...@@ -87,6 +75,10 @@ public class ChatScroller implements
chatScrollIndicatorAdapter.update(chatViewerAdapter.getActiveChats()); chatScrollIndicatorAdapter.update(chatViewerAdapter.getActiveChats());
} }
public void onHide() {
MessageManager.getInstance().removeVisibleChat();
}
public void update() { public void update() {
if (!isInitialized()) { if (!isInitialized()) {
return; return;
......
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