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;
import com.xabber.android.data.connection.ConnectionManager;
import com.xabber.android.data.connection.ConnectionThread;
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.ClientInfo;
import com.xabber.android.data.message.AbstractChat;
......@@ -201,8 +202,8 @@ public class AttentionManager implements OnPacketListener, OnLoadListener {
chat.newAction(null, null, ChatAction.attention_called);
}
public void removeAccountNotifications(String account, String user) {
attentionRequestProvider.remove(account, user);
public void removeAccountNotifications(BaseEntity chat) {
attentionRequestProvider.remove(chat.getAccount(), chat.getUser());
}
}
......@@ -289,15 +289,12 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco
/**
* Sets currently visible chat.
*
* @param account
* @param user
*/
public void setVisibleChat(String account, String user) {
final boolean remove = !AccountManager.getInstance().getArchiveMode(account).saveLocally();
AbstractChat chat = getChat(account, user);
public void setVisibleChat(BaseEntity visibleChat) {
final boolean remove = !AccountManager.getInstance().getArchiveMode(visibleChat.getAccount()).saveLocally();
AbstractChat chat = getChat(visibleChat.getAccount(), visibleChat.getUser());
if (chat == null) {
chat = createChat(account, user);
chat = createChat(visibleChat.getAccount(), visibleChat.getUser());
} else {
// Mark messages as read and them delete from db if necessary.
final ArrayList<MessageItem> messageItems = new ArrayList<MessageItem>();
......
......@@ -28,10 +28,10 @@ import android.widget.ImageButton;
import android.widget.PopupMenu;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager;
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.attention.AttentionManager;
import com.xabber.android.data.extension.cs.ChatStateManager;
......@@ -212,8 +212,6 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
@Override
public void afterTextChanged(Editable text) {
LogManager.i(this, "afterTextChanged");
setSendButtonColor();
if (!skipOnTextChanges) {
......@@ -426,8 +424,8 @@ public class ChatViewerFragment extends Fragment implements PopupMenu.OnMenuItem
securityButton.setImageLevel(securityLevel.getImageLevel());
}
public boolean isEqual(String account, String user) {
return this.account.equals(account) && this.user.equals(user);
public boolean isEqual(BaseEntity chat) {
return chat != null && this.account.equals(chat.getAccount()) && this.user.equals(chat.getUser());
}
public void setInputText(String additional) {
......
......@@ -442,7 +442,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
@Override
public void onContactClick(AbstractContact abstractContact) {
if (action == null) {
startActivity(ChatViewer.createIntent(this,
startActivity(ChatViewer.createSpecificChatIntent(this,
abstractContact.getAccount(), abstractContact.getUser()));
return;
}
......@@ -474,7 +474,7 @@ public class ContactList extends ManagedActivity implements OnAccountChangedList
break;
}
default:
startActivity(ChatViewer.createIntent(this,
startActivity(ChatViewer.createSpecificChatIntent(this,
abstractContact.getAccount(), abstractContact.getUser()));
break;
}
......
......@@ -6,6 +6,7 @@ import android.app.FragmentManager;
import android.support.v13.app.FragmentStatePagerAdapter;
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.ui.ChatViewerFragment;
......@@ -34,16 +35,13 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter {
private Fragment currentFragment;
public ChatViewerAdapter(FragmentManager fragmentManager, String account, String user, FinishUpdateListener finishUpdateListener) {
public ChatViewerAdapter(FragmentManager fragmentManager, BaseEntity chat, FinishUpdateListener finishUpdateListener) {
super(fragmentManager);
this.finishUpdateListener = finishUpdateListener;
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();
}
......@@ -121,11 +119,11 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter {
return true;
}
public int getPageNumber(String account, String user) {
public int getPageNumber(BaseEntity chat) {
int realPosition = 0;
for (int chatIndex = 0; chatIndex < activeChats.size(); chatIndex++) {
if (activeChats.get(chatIndex).equals(account, user)) {
if (activeChats.get(chatIndex).equals(chat)) {
realPosition = chatIndex + 1;
break;
}
......
......@@ -72,7 +72,7 @@ public class ContextMenuHelper {
@Override
public boolean onMenuItemClick(MenuItem item) {
MessageManager.getInstance().openChat(account, user);
activity.startActivity(ChatViewer.createIntent(
activity.startActivity(ChatViewer.createSpecificChatIntent(
activity, account, user));
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