Commit 1acecf64 authored by Grigory Fedorov's avatar Grigory Fedorov

ChatViewer: initial chat and selected chat stored separately - some chat selection bugs fixed.

parent 60fa6221
...@@ -27,6 +27,7 @@ import com.xabber.android.data.connection.ConnectionItem; ...@@ -27,6 +27,7 @@ import com.xabber.android.data.connection.ConnectionItem;
import com.xabber.android.data.connection.ConnectionManager; import com.xabber.android.data.connection.ConnectionManager;
import com.xabber.android.data.connection.ConnectionThread; import com.xabber.android.data.connection.ConnectionThread;
import com.xabber.android.data.connection.OnPacketListener; import com.xabber.android.data.connection.OnPacketListener;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.capability.CapabilitiesManager; import com.xabber.android.data.extension.capability.CapabilitiesManager;
import com.xabber.android.data.extension.capability.ClientInfo; import com.xabber.android.data.extension.capability.ClientInfo;
import com.xabber.android.data.message.AbstractChat; import com.xabber.android.data.message.AbstractChat;
...@@ -201,8 +202,8 @@ public class AttentionManager implements OnPacketListener, OnLoadListener { ...@@ -201,8 +202,8 @@ public class AttentionManager implements OnPacketListener, OnLoadListener {
chat.newAction(null, null, ChatAction.attention_called); chat.newAction(null, null, ChatAction.attention_called);
} }
public void removeAccountNotifications(String account, String user) { public void removeAccountNotifications(BaseEntity chat) {
attentionRequestProvider.remove(account, user); attentionRequestProvider.remove(chat.getAccount(), chat.getUser());
} }
} }
...@@ -289,15 +289,12 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco ...@@ -289,15 +289,12 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco
/** /**
* Sets currently visible chat. * Sets currently visible chat.
*
* @param account
* @param user
*/ */
public void setVisibleChat(String account, String user) { public void setVisibleChat(BaseEntity visibleChat) {
final boolean remove = !AccountManager.getInstance().getArchiveMode(account).saveLocally(); final boolean remove = !AccountManager.getInstance().getArchiveMode(visibleChat.getAccount()).saveLocally();
AbstractChat chat = getChat(account, user); AbstractChat chat = getChat(visibleChat.getAccount(), visibleChat.getUser());
if (chat == null) { if (chat == null) {
chat = createChat(account, user); chat = createChat(visibleChat.getAccount(), visibleChat.getUser());
} else { } else {
// Mark messages as read and them delete from db if necessary. // Mark messages as read and them delete from db if necessary.
final ArrayList<MessageItem> messageItems = new ArrayList<MessageItem>(); final ArrayList<MessageItem> messageItems = new ArrayList<MessageItem>();
......
...@@ -18,7 +18,6 @@ import android.app.Activity; ...@@ -18,7 +18,6 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
...@@ -62,11 +61,17 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -62,11 +61,17 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
*/ */
private static final String ACTION_ATTENTION = "com.xabber.android.data.ATTENTION"; private static final String ACTION_ATTENTION = "com.xabber.android.data.ATTENTION";
private static final String ACTION_RECENT_CHATS = "com.xabber.android.data.RECENT_CHATS"; private static final String ACTION_RECENT_CHATS = "com.xabber.android.data.RECENT_CHATS";
private static final String ACTION_SPECIFIC_CHAT = "com.xabber.android.data.ACTION_SPECIFIC_CHAT";
private static final String SAVED_INITIAL_ACCOUNT = "com.xabber.android.ui.ChatViewer.SAVED_INITIAL_ACCOUNT";
private static final String SAVED_INITIAL_USER = "com.xabber.android.ui.ChatViewer.SAVED_INITIAL_USER";
private static final String SAVED_ACCOUNT = "com.xabber.android.ui.ChatViewer.SAVED_ACCOUNT";
private static final String SAVED_USER = "com.xabber.android.ui.ChatViewer.SAVED_USER";
private static final String SAVED_EXIT_ON_SEND = "com.xabber.android.ui.ChatViewer.EXIT_ON_SEND";
private static final String SAVED_IS_RECENT_CHATS_SELECTED = "com.xabber.android.ui.ChatViewer.SAVED_IS_RECENT_CHATS_SELECTED"; private static final String SAVED_IS_RECENT_CHATS_SELECTED = "com.xabber.android.ui.ChatViewer.SAVED_IS_RECENT_CHATS_SELECTED";
private static final String SAVED_SELECTED_ACCOUNT = "com.xabber.android.ui.ChatViewer.SAVED_SELECTED_ACCOUNT";
private static final String SAVED_SELECTED_USER = "com.xabber.android.ui.ChatViewer.SAVED_SELECTED_USER";
private static final String SAVED_EXIT_ON_SEND = "com.xabber.android.ui.ChatViewer.EXIT_ON_SEND";
private boolean exitOnSend; private boolean exitOnSend;
...@@ -80,8 +85,8 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -80,8 +85,8 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
Collection<ChatViewerFragment> registeredChats = new HashSet<>(); Collection<ChatViewerFragment> registeredChats = new HashSet<>();
Collection<RecentChatFragment> recentChatFragments = new HashSet<>(); Collection<RecentChatFragment> recentChatFragments = new HashSet<>();
private String account = null; private BaseEntity initialChat = null;
private String user = null; private BaseEntity selectedChat = null;
private StatusBarPainter statusBarPainter; private StatusBarPainter statusBarPainter;
...@@ -95,40 +100,61 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -95,40 +100,61 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
return; return;
} }
getSelectedPageDataFromIntent();
setContentView(R.layout.activity_chat_viewer); setContentView(R.layout.activity_chat_viewer);
statusBarPainter = new StatusBarPainter(this); statusBarPainter = new StatusBarPainter(this);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
if (isRecentChatsSelected) { getInitialChatFromIntent();
chatViewerAdapter = new ChatViewerAdapter(getFragmentManager(), this); getSelectedPageDataFromIntent();
} else {
chatViewerAdapter = new ChatViewerAdapter(getFragmentManager(), account, user, this); if (savedInstanceState != null) {
restoreInstanceState(savedInstanceState);
} }
chatScrollIndicatorAdapter = new ChatScrollIndicatorAdapter(this, if (initialChat != null) {
(LinearLayout)findViewById(R.id.chat_scroll_indicator)); chatViewerAdapter = new ChatViewerAdapter(getFragmentManager(), initialChat, this);
chatScrollIndicatorAdapter.update(chatViewerAdapter.getActiveChats()); } else {
chatViewerAdapter = new ChatViewerAdapter(getFragmentManager(), this);
}
viewPager = (ViewPager) findViewById(R.id.pager); viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(chatViewerAdapter); viewPager.setAdapter(chatViewerAdapter);
viewPager.setOnPageChangeListener(this); viewPager.setOnPageChangeListener(this);
viewPager.getBackground().setAlpha(30); viewPager.getBackground().setAlpha(30);
chatScrollIndicatorAdapter = new ChatScrollIndicatorAdapter(this,
(LinearLayout)findViewById(R.id.chat_scroll_indicator));
chatScrollIndicatorAdapter.update(chatViewerAdapter.getActiveChats());
}
private void getInitialChatFromIntent() {
Intent intent = getIntent();
String account = getAccount(intent);
String user = getUser(intent);
if (account != null && user != null) {
initialChat = new BaseEntity(account, user);
}
} }
private void getSelectedPageDataFromIntent() { private void getSelectedPageDataFromIntent() {
Intent intent = getIntent(); Intent intent = getIntent();
if (intent.getAction() != null && intent.getAction().equals(ACTION_RECENT_CHATS)) {
isRecentChatsSelected = true; if (intent.getAction() == null) {
account = null; return;
user = null; }
} else {
isRecentChatsSelected = false; switch (intent.getAction()) {
account = getAccount(intent); case ACTION_RECENT_CHATS:
user = getUser(intent); isRecentChatsSelected = true;
selectedChat = null;
break;
case ACTION_SPECIFIC_CHAT:
case ACTION_ATTENTION:
case Intent.ACTION_SEND:
isRecentChatsSelected = false;
selectedChat = new BaseEntity(getAccount(intent), getUser(intent));
break;
} }
} }
...@@ -143,14 +169,22 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -143,14 +169,22 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
getSelectedPageDataFromIntent(); getSelectedPageDataFromIntent();
} }
@Override private void restoreInstanceState(Bundle savedInstanceState) {
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
account = savedInstanceState.getString(SAVED_ACCOUNT);
user = savedInstanceState.getString(SAVED_USER);
exitOnSend = savedInstanceState.getBoolean(SAVED_EXIT_ON_SEND);
isRecentChatsSelected = savedInstanceState.getBoolean(SAVED_IS_RECENT_CHATS_SELECTED); isRecentChatsSelected = savedInstanceState.getBoolean(SAVED_IS_RECENT_CHATS_SELECTED);
if (isRecentChatsSelected) {
selectedChat = null;
} else {
selectedChat = new BaseEntity(savedInstanceState.getString(SAVED_SELECTED_ACCOUNT),
savedInstanceState.getString(SAVED_SELECTED_USER));
}
exitOnSend = savedInstanceState.getBoolean(SAVED_EXIT_ON_SEND);
String initialAccount = savedInstanceState.getString(SAVED_INITIAL_ACCOUNT);
String initialUser = savedInstanceState.getString(SAVED_INITIAL_USER);
if (initialAccount != null && initialUser != null) {
initialChat = new BaseEntity(initialAccount, initialUser);
}
} }
@Override @Override
...@@ -167,7 +201,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -167,7 +201,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
Intent intent = getIntent(); Intent intent = getIntent();
if (hasAttention(intent)) { if (hasAttention(intent)) {
AttentionManager.getInstance().removeAccountNotifications(account, user); AttentionManager.getInstance().removeAccountNotifications(selectedChat);
} }
if (Intent.ACTION_SEND.equals(intent.getAction())) { if (Intent.ACTION_SEND.equals(intent.getAction())) {
...@@ -184,17 +218,22 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -184,17 +218,22 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
if (isRecentChatsSelected) { if (isRecentChatsSelected) {
selectRecentChatsPage(); selectRecentChatsPage();
} else { } else {
selectChatPage(account, user, false); selectChatPage(selectedChat, false);
} }
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putString(SAVED_ACCOUNT, account);
outState.putString(SAVED_USER, user);
outState.putBoolean(SAVED_EXIT_ON_SEND, exitOnSend);
outState.putBoolean(SAVED_IS_RECENT_CHATS_SELECTED, isRecentChatsSelected); outState.putBoolean(SAVED_IS_RECENT_CHATS_SELECTED, isRecentChatsSelected);
if (!isRecentChatsSelected) {
outState.putString(SAVED_SELECTED_ACCOUNT, selectedChat.getAccount());
outState.putString(SAVED_SELECTED_USER, selectedChat.getUser());
}
outState.putBoolean(SAVED_EXIT_ON_SEND, exitOnSend);
outState.putString(SAVED_INITIAL_ACCOUNT, initialChat.getAccount());
outState.putString(SAVED_INITIAL_USER, initialChat.getUser());
} }
@Override @Override
...@@ -206,12 +245,12 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -206,12 +245,12 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
MessageManager.getInstance().removeVisibleChat(); MessageManager.getInstance().removeVisibleChat();
} }
private void selectChatPage(String account, String user, boolean smothScroll) { private void selectChatPage(BaseEntity chat, boolean smoothScroll) {
selectPage(chatViewerAdapter.getPageNumber(account, user), smothScroll); selectPage(chatViewerAdapter.getPageNumber(chat), smoothScroll);
} }
private void selectRecentChatsPage() { private void selectRecentChatsPage() {
selectPage(chatViewerAdapter.getPageNumber(null, null), false); selectPage(chatViewerAdapter.getPageNumber(null), false);
} }
private void selectPage(int position, boolean smoothScroll) { private void selectPage(int position, boolean smoothScroll) {
...@@ -230,7 +269,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -230,7 +269,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
updateStatusBar(); updateStatusBar();
for (ChatViewerFragment chat : registeredChats) { for (ChatViewerFragment chat : registeredChats) {
if (chat.isEqual(account, user) && incoming) { if (chat.isEqual(selectedChat) && incoming) {
chat.playIncomingAnimation(); chat.playIncomingAnimation();
} }
} }
...@@ -261,24 +300,18 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -261,24 +300,18 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
hideKeyboard(this); hideKeyboard(this);
chatScrollIndicatorAdapter.select(chatViewerAdapter.getRealPagePosition(position)); chatScrollIndicatorAdapter.select(chatViewerAdapter.getRealPagePosition(position));
AbstractChat selectedChat = chatViewerAdapter.getChatByPageNumber(position); selectedChat = chatViewerAdapter.getChatByPageNumber(position);
isRecentChatsSelected = selectedChat == null; isRecentChatsSelected = selectedChat == null;
if (isRecentChatsSelected) { if (isRecentChatsSelected) {
account = null;
user = null;
MessageManager.getInstance().removeVisibleChat(); MessageManager.getInstance().removeVisibleChat();
} else { } else {
account = selectedChat.getAccount(); MessageManager.getInstance().setVisibleChat(selectedChat);
user = selectedChat.getUser();
MessageManager.getInstance().setVisibleChat(account, user);
MessageArchiveManager.getInstance().requestHistory(account, user, 0, MessageArchiveManager.getInstance().requestHistory(selectedChat.getAccount(), selectedChat.getUser(), 0,
MessageManager.getInstance().getChat(account, user).getRequiredMessageCount()); MessageManager.getInstance().getChat(selectedChat.getAccount(), selectedChat.getUser()).getRequiredMessageCount());
NotificationManager.getInstance().removeMessageNotification(account, user); NotificationManager.getInstance().removeMessageNotification(selectedChat.getAccount(), selectedChat.getUser());
} }
updateStatusBar(); updateStatusBar();
...@@ -288,7 +321,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -288,7 +321,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
if (isRecentChatsSelected) { if (isRecentChatsSelected) {
statusBarPainter.restore(); statusBarPainter.restore();
} else { } else {
statusBarPainter.updateWithAccountName(account); statusBarPainter.updateWithAccountName(selectedChat.getAccount());
} }
} }
...@@ -332,7 +365,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -332,7 +365,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
boolean isExtraTextInserted = false; boolean isExtraTextInserted = false;
for (ChatViewerFragment chat : registeredChats) { for (ChatViewerFragment chat : registeredChats) {
if (chat.isEqual(account, user)) { if (chat.isEqual(selectedChat)) {
chat.setInputText(extraText); chat.setInputText(extraText);
isExtraTextInserted = true; isExtraTextInserted = true;
} }
...@@ -345,7 +378,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -345,7 +378,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
@Override @Override
public void onChatSelected(AbstractChat chat) { public void onChatSelected(AbstractChat chat) {
selectChatPage(chat.getAccount(), chat.getUser(), true); selectChatPage(chat, true);
} }
public ChatViewerAdapter getChatViewerAdapter() { public ChatViewerAdapter getChatViewerAdapter() {
return chatViewerAdapter; return chatViewerAdapter;
...@@ -414,8 +447,10 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -414,8 +447,10 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
return ACTION_ATTENTION.equals(intent.getAction()); return ACTION_ATTENTION.equals(intent.getAction());
} }
public static Intent createIntent(Context context, String account, String user) { public static Intent createSpecificChatIntent(Context context, String account, String user) {
return new EntityIntentBuilder(context, ChatViewer.class).setAccount(account).setUser(user).build(); Intent intent = new EntityIntentBuilder(context, ChatViewer.class).setAccount(account).setUser(user).build();
intent.setAction(ACTION_SPECIFIC_CHAT);
return intent;
} }
public static Intent createRecentChatsIntent(Context context) { public static Intent createRecentChatsIntent(Context context) {
...@@ -425,7 +460,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -425,7 +460,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
} }
public static Intent createClearTopIntent(Context context, String account, String user) { public static Intent createClearTopIntent(Context context, String account, String user) {
Intent intent = createIntent(context, account, user); Intent intent = createSpecificChatIntent(context, account, user);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return intent; return intent;
} }
...@@ -443,7 +478,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -443,7 +478,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
* @return * @return
*/ */
public static Intent createSendIntent(Context context, String account, String user, String text) { public static Intent createSendIntent(Context context, String account, String user, String text) {
Intent intent = ChatViewer.createIntent(context, account, user); Intent intent = ChatViewer.createSpecificChatIntent(context, account, user);
intent.setAction(Intent.ACTION_SEND); intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra(Intent.EXTRA_TEXT, text);
return intent; return intent;
......
...@@ -28,10 +28,10 @@ import android.widget.ImageButton; ...@@ -28,10 +28,10 @@ import android.widget.ImageButton;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.NetworkException; import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.archive.MessageArchiveManager; import com.xabber.android.data.extension.archive.MessageArchiveManager;
import com.xabber.android.data.extension.attention.AttentionManager; import com.xabber.android.data.extension.attention.AttentionManager;
import com.xabber.android.data.extension.cs.ChatStateManager; import com.xabber.android.data.extension.cs.ChatStateManager;
...@@ -212,8 +212,6 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -212,8 +212,6 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
@Override @Override
public void afterTextChanged(Editable text) { public void afterTextChanged(Editable text) {
LogManager.i(this, "afterTextChanged");
setSendButtonColor(); setSendButtonColor();
if (!skipOnTextChanges) { if (!skipOnTextChanges) {
...@@ -426,8 +424,8 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem ...@@ -426,8 +424,8 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
securityButton.setImageLevel(securityLevel.getImageLevel()); securityButton.setImageLevel(securityLevel.getImageLevel());
} }
public boolean isEqual(String account, String user) { public boolean isEqual(BaseEntity chat) {
return this.account.equals(account) && this.user.equals(user); return chat != null && this.account.equals(chat.getAccount()) && this.user.equals(chat.getUser());
} }
public void setInputText(String additional) { public void setInputText(String additional) {
......
...@@ -442,7 +442,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList ...@@ -442,7 +442,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
@Override @Override
public void onContactClick(AbstractContact abstractContact) { public void onContactClick(AbstractContact abstractContact) {
if (action == null) { if (action == null) {
startActivity(ChatViewer.createIntent(this, startActivity(ChatViewer.createSpecificChatIntent(this,
abstractContact.getAccount(), abstractContact.getUser())); abstractContact.getAccount(), abstractContact.getUser()));
return; return;
} }
...@@ -474,7 +474,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList ...@@ -474,7 +474,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
break; break;
} }
default: default:
startActivity(ChatViewer.createIntent(this, startActivity(ChatViewer.createSpecificChatIntent(this,
abstractContact.getAccount(), abstractContact.getUser())); abstractContact.getAccount(), abstractContact.getUser()));
break; break;
} }
......
...@@ -6,6 +6,7 @@ import android.app.FragmentManager; ...@@ -6,6 +6,7 @@ import android.app.FragmentManager;
import android.support.v13.app.FragmentStatePagerAdapter; import android.support.v13.app.FragmentStatePagerAdapter;
import android.view.ViewGroup; import android.view.ViewGroup;
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.ui.ChatViewerFragment; import com.xabber.android.ui.ChatViewerFragment;
...@@ -34,16 +35,13 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter { ...@@ -34,16 +35,13 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter {
private Fragment currentFragment; private Fragment currentFragment;
public ChatViewerAdapter(FragmentManager fragmentManager, String account, String user, FinishUpdateListener finishUpdateListener) { public ChatViewerAdapter(FragmentManager fragmentManager, BaseEntity chat, FinishUpdateListener finishUpdateListener) {
super(fragmentManager); super(fragmentManager);
this.finishUpdateListener = finishUpdateListener; this.finishUpdateListener = finishUpdateListener;
activeChats = new ArrayList<>(MessageManager.getInstance().getActiveChats()); activeChats = new ArrayList<>(MessageManager.getInstance().getActiveChats());
intent = MessageManager.getInstance().getOrCreateChat(account, Jid.getBareAddress(user)); intent = MessageManager.getInstance().getOrCreateChat(chat.getAccount(), Jid.getBareAddress(chat.getUser()));
if (!activeChats.contains(intent)) {
intent.updateCreationTime();
}
updateChats(); updateChats();
} }
...@@ -121,11 +119,11 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter { ...@@ -121,11 +119,11 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter {
return true; return true;
} }
public int getPageNumber(String account, String user) { public int getPageNumber(BaseEntity chat) {
int realPosition = 0; int realPosition = 0;
for (int chatIndex = 0; chatIndex < activeChats.size(); chatIndex++) { for (int chatIndex = 0; chatIndex < activeChats.size(); chatIndex++) {
if (activeChats.get(chatIndex).equals(account, user)) { if (activeChats.get(chatIndex).equals(chat)) {
realPosition = chatIndex + 1; realPosition = chatIndex + 1;
break; break;
} }
......
...@@ -72,7 +72,7 @@ public class ContextMenuHelper { ...@@ -72,7 +72,7 @@ public class ContextMenuHelper {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
MessageManager.getInstance().openChat(account, user); MessageManager.getInstance().openChat(account, user);
activity.startActivity(ChatViewer.createIntent( activity.startActivity(ChatViewer.createSpecificChatIntent(
activity, account, user)); activity, account, user));
return true; return true;
} }
......
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