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