Commit cbfed8d2 authored by Grigory Fedorov's avatar Grigory Fedorov

ChatViewer: options menu moved from ChatViewerFragment.

Light refactoring.
parent 78d01152
...@@ -646,9 +646,8 @@ public abstract class AbstractChat extends BaseEntity { ...@@ -646,9 +646,8 @@ public abstract class AbstractChat extends BaseEntity {
int count = PRELOADED_MESSAGES int count = PRELOADED_MESSAGES
+ NotificationManager.getInstance() + NotificationManager.getInstance()
.getNotificationMessageCount(account, user); .getNotificationMessageCount(account, user);
Iterator<MessageItem> iterator = messages.iterator(); for (MessageItem message : messages)
while (iterator.hasNext()) if (message.isIncoming()) {
if (iterator.next().isIncoming()) {
count -= 1; count -= 1;
if (count <= 0) if (count <= 0)
return 0; return 0;
......
...@@ -22,6 +22,8 @@ import android.os.Bundle; ...@@ -22,6 +22,8 @@ import android.os.Bundle;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
...@@ -31,25 +33,32 @@ import android.widget.ImageView; ...@@ -31,25 +33,32 @@ import android.widget.ImageView;
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.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.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;
import com.xabber.android.data.extension.attention.AttentionManager; import com.xabber.android.data.extension.attention.AttentionManager;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.extension.muc.RoomChat;
import com.xabber.android.data.extension.muc.RoomState;
import com.xabber.android.data.extension.otr.OTRManager; import com.xabber.android.data.extension.otr.OTRManager;
import com.xabber.android.data.extension.otr.SecurityLevel; import com.xabber.android.data.extension.otr.SecurityLevel;
import com.xabber.android.data.intent.EntityIntentBuilder; import com.xabber.android.data.intent.EntityIntentBuilder;
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.OnChatChangedListener; import com.xabber.android.data.message.OnChatChangedListener;
import com.xabber.android.data.message.RegularChat;
import com.xabber.android.data.notification.NotificationManager; import com.xabber.android.data.notification.NotificationManager;
import com.xabber.android.data.roster.AbstractContact; import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.OnContactChangedListener; import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.adapter.ChatViewerAdapter; import com.xabber.android.ui.adapter.ChatViewerAdapter;
import com.xabber.android.ui.dialog.ChatExportDialogFragment;
import com.xabber.android.ui.helper.ContactTitleInflater; import com.xabber.android.ui.helper.ContactTitleInflater;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.preferences.ChatEditor;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import java.util.Collection; import java.util.Collection;
...@@ -63,8 +72,7 @@ import java.util.HashSet; ...@@ -63,8 +72,7 @@ import java.util.HashSet;
*/ */
public class ChatViewer extends ManagedActivity implements OnChatChangedListener, public class ChatViewer extends ManagedActivity implements OnChatChangedListener,
OnContactChangedListener, OnAccountChangedListener, ViewPager.OnPageChangeListener, OnContactChangedListener, OnAccountChangedListener, ViewPager.OnPageChangeListener,
ChatViewerAdapter.FinishUpdateListener, RecentChatFragment.RecentChatFragmentInteractionListener, ChatViewerAdapter.FinishUpdateListener, RecentChatFragment.RecentChatFragmentInteractionListener {
ChatViewerFragment.ChatViewerFragmentListener {
/** /**
* Attention request. * Attention request.
...@@ -75,6 +83,8 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -75,6 +83,8 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
private static final String SAVED_USER = "com.xabber.android.ui.ChatViewer.SAVED_USER"; 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_EXIT_ON_SEND = "com.xabber.android.ui.ChatViewer.EXIT_ON_SEND";
private static final int MINIMUM_MESSAGES_TO_LOAD = 10;
private boolean exitOnSend; private boolean exitOnSend;
private String extraText = null; private String extraText = null;
...@@ -96,6 +106,9 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -96,6 +106,9 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
private Animation shakeAnimation; private Animation shakeAnimation;
private boolean isChatSelected;
private Menu menu = null;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -142,19 +155,24 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -142,19 +155,24 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
actionBarView = LayoutInflater.from(this).inflate(R.layout.chat_viewer_action_bar, null); actionBarView = LayoutInflater.from(this).inflate(R.layout.chat_viewer_action_bar, null);
actionBarView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scrollChat();
}
});
actionBar.setCustomView(actionBarView, new ActionBar.LayoutParams( actionBar.setCustomView(actionBarView, new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT)); ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT));
setContentView(R.layout.activity_chat_viewer); setContentView(R.layout.activity_chat_viewer);
if (account != null && user != null) { if (account != null && user != null) {
chatViewerAdapter = new ChatViewerAdapter(getFragmentManager(), chatViewerAdapter = new ChatViewerAdapter(getFragmentManager(), account, user, this);
account, user, this); isChatSelected = true;
} else { } else {
chatViewerAdapter = new ChatViewerAdapter(getFragmentManager(), this); chatViewerAdapter = new ChatViewerAdapter(getFragmentManager(), this);
isChatSelected = false;
} }
viewPager = (ViewPager) findViewById(R.id.pager); viewPager = (ViewPager) findViewById(R.id.pager);
...@@ -164,6 +182,92 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -164,6 +182,92 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
selectPage(account, user, false); selectPage(account, user, false);
} }
private void scrollChat() {
if (!isChatSelected) {
return;
}
for (ChatViewerFragment chat : registeredChats) {
if (chat.isEqual(actionWithAccount, actionWithUser)) {
chat.scrollChat();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
this.menu = menu;
createOptionsMenu();
return true;
}
private void createOptionsMenu() {
if (menu == null) {
return;
}
menu.clear();
if (!isChatSelected) {
return;
}
getMenuInflater().inflate(R.menu.chat, menu);
final String account = actionWithAccount;
final String user = actionWithUser;
AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
if (abstractChat instanceof RoomChat) {
RoomState chatState = ((RoomChat) abstractChat).getState();
if (chatState == RoomState.available) {
menu.findItem(R.id.action_list_of_occupants).setVisible(true);
}
if (chatState == RoomState.unavailable) {
menu.findItem(R.id.action_join_conference).setVisible(true);
menu.findItem(R.id.action_close_chat).setVisible(true);
} else {
menu.findItem(R.id.action_invite_to_chat).setVisible(true);
if (chatState == RoomState.error) {
menu.findItem(R.id.action_authorization_settings).setVisible(true);
} else {
menu.findItem(R.id.action_leave_conference).setVisible(true);
}
}
}
if (abstractChat instanceof RegularChat) {
menu.findItem(R.id.action_edit_contact).setVisible(true);
SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
if (securityLevel == SecurityLevel.plain) {
menu.findItem(R.id.action_start_encryption).setVisible(true)
.setEnabled(SettingsManager.securityOtrMode() != SettingsManager.SecurityOtrMode.disabled);
} else {
menu.findItem(R.id.action_restart_encryption).setVisible(true);
}
boolean isEncrypted = securityLevel != SecurityLevel.plain;
menu.findItem(R.id.action_stop_encryption).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_fingerprint).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_question).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_shared_secret).setEnabled(isEncrypted);
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
createOptionsMenu();
return true;
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
...@@ -220,6 +324,163 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -220,6 +324,163 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
selectPage(account, user, false); selectPage(account, user, false);
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final String account = actionWithAccount;
final String user = actionWithUser;
switch (item.getItemId()) {
case R.id.action_edit_contact:
startActivity(ContactEditor.createIntent(this, account, user));
return true;
case R.id.action_chat_list:
selectRecentChatsPage();
return true;
case R.id.action_chat_settings:
startActivity(ChatEditor.createIntent(this, account, user));
return true;
case R.id.action_show_history:
showHistory(account, user);
return true;
case R.id.action_authorization_settings:
startActivity(MUCEditor.createIntent(this, account, user));
return true;
case R.id.action_close_chat:
closeChat(account, user);
return true;
case R.id.action_clear_text:
cleatInputText(account, user);
return true;
case R.id.action_clear_history:
clearHistory(account, user);
return true;
case R.id.action_export_chat:
ChatExportDialogFragment.newInstance(account, user).show(getFragmentManager(), "CHAT_EXPORT");
return true;
case R.id.action_call_attention:
callAttention(account, user);
return true;
/* conferences */
case R.id.action_join_conference:
MUCManager.getInstance().joinRoom(account, user, true);
return true;
case R.id.action_invite_to_chat:
startActivity(ContactList.createRoomInviteIntent(this, account, user));
return true;
case R.id.action_leave_conference:
leaveConference(account, user);
return true;
case R.id.action_list_of_occupants:
startActivity(OccupantList.createIntent(this, account, user));
return true;
/* encryption */
case R.id.action_start_encryption:
startEncryption(account, user);
return true;
case R.id.action_restart_encryption:
restartEncryption(account, user);
return true;
case R.id.action_stop_encryption:
stopEncryption(account, user);
return true;
case R.id.action_verify_with_fingerprint:
startActivity(FingerprintViewer.createIntent(this, account, user));
return true;
case R.id.action_verify_with_question:
startActivity(QuestionViewer.createIntent(this, account, user, true, false, null));
return true;
case R.id.action_verify_with_shared_secret:
startActivity(QuestionViewer.createIntent(this, account, user, false, false, null));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void cleatInputText(String account, String user) {
for (ChatViewerFragment chat : registeredChats) {
if (chat.isEqual(account, user)) {
chat.clearInputView();
}
}
}
private void stopEncryption(String account, String user) {
try {
OTRManager.getInstance().endSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void restartEncryption(String account, String user) {
try {
OTRManager.getInstance().refreshSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void startEncryption(String account, String user) {
try {
OTRManager.getInstance().startSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void callAttention(String account, String user) {
try {
AttentionManager.getInstance().sendAttention(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void clearHistory(String account, String user) {
MessageManager.getInstance().clearHistory(account, user);
updateRegisteredChats();
}
private void closeChat(String account, String user) {
MessageManager.getInstance().closeChat(account, user);
NotificationManager.getInstance().removeMessageNotification(account, user);
close();
}
private void leaveConference(String account, String user) {
MUCManager.getInstance().leaveRoom(account, user);
closeChat(account, user);
}
private void showHistory(String account, String user) {
MessageManager.getInstance().requestToLoadLocalHistory(account, user);
MessageArchiveManager.getInstance().requestHistory(account, user, MINIMUM_MESSAGES_TO_LOAD, 0);
updateRegisteredChats();
}
private void selectPage(String account, String user, boolean smoothScroll) { private void selectPage(String account, String user, boolean smoothScroll) {
int position = chatViewerAdapter.getPageNumber(account, user); int position = chatViewerAdapter.getPageNumber(account, user);
selectPage(position, smoothScroll); selectPage(position, smoothScroll);
...@@ -375,7 +636,19 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -375,7 +636,19 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
public void onPageSelected(int position) { public void onPageSelected(int position) {
AbstractChat selectedChat = chatViewerAdapter.getChatByPageNumber(position); AbstractChat selectedChat = chatViewerAdapter.getChatByPageNumber(position);
if (selectedChat == null) { isChatSelected = selectedChat != null;
if (isChatSelected) {
actionWithAccount = selectedChat.getAccount();
actionWithUser = selectedChat.getUser();
} else {
actionWithAccount = null;
actionWithUser = null;
}
createOptionsMenu();
if (!isChatSelected) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(defaultStatusBarColor); window.setStatusBarColor(defaultStatusBarColor);
} }
...@@ -387,21 +660,15 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -387,21 +660,15 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
return; return;
} }
String account = selectedChat.getAccount(); updateActionBar(actionWithAccount, actionWithUser);
String user = selectedChat.getUser();
updateActionBar(account, user);
MessageManager.getInstance().setVisibleChat(account, user); MessageManager.getInstance().setVisibleChat(actionWithAccount, actionWithUser);
MessageArchiveManager.getInstance().requestHistory( MessageArchiveManager.getInstance().requestHistory(
account, user, 0, actionWithAccount, actionWithUser, 0,
MessageManager.getInstance().getChat(account, user).getRequiredMessageCount()); MessageManager.getInstance().getChat(actionWithAccount, actionWithUser).getRequiredMessageCount());
NotificationManager.getInstance().removeMessageNotification(account, user); NotificationManager.getInstance().removeMessageNotification(actionWithAccount, actionWithUser);
actionWithAccount = account;
actionWithUser = user;
} }
private void updateActionBar(String account, String user) { private void updateActionBar(String account, String user) {
...@@ -497,8 +764,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -497,8 +764,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
selectPage(chat.getAccount(), chat.getUser(), true); selectPage(chat.getAccount(), chat.getUser(), true);
} }
@Override public void selectRecentChatsPage() {
public void onRecentChatsCalled() {
viewPager.setCurrentItem(chatViewerAdapter.getRecentChatsPosition(), true); viewPager.setCurrentItem(chatViewerAdapter.getRecentChatsPosition(), true);
} }
......
package com.xabber.android.ui; package com.xabber.android.ui;
import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
...@@ -11,7 +10,6 @@ import android.text.TextWatcher; ...@@ -11,7 +10,6 @@ import android.text.TextWatcher;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
...@@ -25,26 +23,12 @@ import android.widget.EditText; ...@@ -25,26 +23,12 @@ import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.extension.archive.MessageArchiveManager;
import com.xabber.android.data.extension.attention.AttentionManager;
import com.xabber.android.data.extension.cs.ChatStateManager; import com.xabber.android.data.extension.cs.ChatStateManager;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.extension.muc.RoomChat;
import com.xabber.android.data.extension.muc.RoomState;
import com.xabber.android.data.extension.otr.OTRManager;
import com.xabber.android.data.extension.otr.SecurityLevel;
import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.MessageItem; import com.xabber.android.data.message.MessageItem;
import com.xabber.android.data.message.MessageManager; import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.message.RegularChat;
import com.xabber.android.data.message.chat.ChatManager; import com.xabber.android.data.message.chat.ChatManager;
import com.xabber.android.data.notification.NotificationManager;
import com.xabber.android.ui.adapter.ChatMessageAdapter; import com.xabber.android.ui.adapter.ChatMessageAdapter;
import com.xabber.android.ui.dialog.ChatExportDialogFragment;
import com.xabber.android.ui.preferences.ChatEditor;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class ChatViewerFragment extends Fragment { public class ChatViewerFragment extends Fragment {
...@@ -52,8 +36,6 @@ public class ChatViewerFragment extends Fragment { ...@@ -52,8 +36,6 @@ public class ChatViewerFragment extends Fragment {
public static final String ARGUMENT_ACCOUNT = "ARGUMENT_ACCOUNT"; public static final String ARGUMENT_ACCOUNT = "ARGUMENT_ACCOUNT";
public static final String ARGUMENT_USER = "ARGUMENT_USER"; public static final String ARGUMENT_USER = "ARGUMENT_USER";
private static final int MINIMUM_MESSAGES_TO_LOAD = 10;
private TextView pageView; private TextView pageView;
private EditText inputView; private EditText inputView;
private ListView listView; private ListView listView;
...@@ -64,8 +46,6 @@ public class ChatViewerFragment extends Fragment { ...@@ -64,8 +46,6 @@ public class ChatViewerFragment extends Fragment {
private String account; private String account;
private String user; private String user;
private ChatViewerFragmentListener listener;
public static ChatViewerFragment newInstance(String account, String user) { public static ChatViewerFragment newInstance(String account, String user) {
ChatViewerFragment fragment = new ChatViewerFragment(); ChatViewerFragment fragment = new ChatViewerFragment();
...@@ -119,7 +99,6 @@ public class ChatViewerFragment extends Fragment { ...@@ -119,7 +99,6 @@ public class ChatViewerFragment extends Fragment {
listView.setAdapter(chatMessageAdapter); listView.setAdapter(chatMessageAdapter);
pageView = (TextView) view.findViewById(R.id.chat_page); pageView = (TextView) view.findViewById(R.id.chat_page);
// titleView = view.findViewById(R.id.title);
inputView = (EditText) view.findViewById(R.id.chat_input); inputView = (EditText) view.findViewById(R.id.chat_input);
view.findViewById(R.id.chat_send).setOnClickListener( view.findViewById(R.id.chat_send).setOnClickListener(
...@@ -131,16 +110,7 @@ public class ChatViewerFragment extends Fragment { ...@@ -131,16 +110,7 @@ public class ChatViewerFragment extends Fragment {
} }
}); });
// titleView.setOnClickListener(new View.OnClickListener() {
//
// @Override
// public void onClick(View v) {
// int size = listView.getCount();
// if (size > 0)
// listView.setSelection(size - 1);
// }
//
// });
inputView.setOnKeyListener(new View.OnKeyListener() { inputView.setOnKeyListener(new View.OnKeyListener() {
@Override @Override
...@@ -189,8 +159,6 @@ public class ChatViewerFragment extends Fragment { ...@@ -189,8 +159,6 @@ public class ChatViewerFragment extends Fragment {
}); });
setHasOptionsMenu(true);
updateView(); updateView();
chatMessageAdapter.onChange(); chatMessageAdapter.onChange();
...@@ -231,23 +199,6 @@ public class ChatViewerFragment extends Fragment { ...@@ -231,23 +199,6 @@ public class ChatViewerFragment extends Fragment {
unregisterForContextMenu(listView); unregisterForContextMenu(listView);
} }
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
listener = (ChatViewerFragmentListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement ChatViewerFragmentListener");
}
}
@Override
public void onDetach() {
listener = null;
super.onDetach();
}
public void saveInputState() { public void saveInputState() {
ChatManager.getInstance().setTyped(account, user, inputView.getText().toString(), ChatManager.getInstance().setTyped(account, user, inputView.getText().toString(),
inputView.getSelectionStart(), inputView.getSelectionEnd()); inputView.getSelectionStart(), inputView.getSelectionEnd());
...@@ -295,211 +246,6 @@ public class ChatViewerFragment extends Fragment { ...@@ -295,211 +246,6 @@ public class ChatViewerFragment extends Fragment {
chatMessageAdapter.onChange(); chatMessageAdapter.onChange();
} }
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
final String account = chatMessageAdapter.getAccount();
final String user = chatMessageAdapter.getUser();
AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
inflater.inflate(R.menu.chat, menu);
if (abstractChat != null && abstractChat instanceof RoomChat) {
if (((RoomChat) abstractChat).getState() == RoomState.unavailable) {
MenuItem item = menu.findItem(R.id.action_join_conference);
item.setVisible(true);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MUCManager.getInstance().joinRoom(account, user, true);
return true;
}
});
} else {
menu.findItem(R.id.action_invite_to_chat).setVisible(true)
.setIntent(ContactList.createRoomInviteIntent(getActivity(), account, user));
}
} else {
menu.findItem(R.id.action_edit_contact).setVisible(true)
.setIntent(ContactEditor.createIntent(getActivity(), account, user));
}
menu.findItem(R.id.action_chat_list).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
listener.onRecentChatsCalled();
return true;
}
});
menu.findItem(R.id.action_chat_settings)
.setIntent(ChatEditor.createIntent(getActivity(), account, user));
menu.findItem(R.id.action_show_history).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MessageManager.getInstance().requestToLoadLocalHistory(account, user);
MessageArchiveManager.getInstance()
.requestHistory(account, user, MINIMUM_MESSAGES_TO_LOAD, 0);
updateChat();
return true;
}
});
if (abstractChat != null && abstractChat instanceof RoomChat
&& ((RoomChat) abstractChat).getState() != RoomState.unavailable) {
if (((RoomChat) abstractChat).getState() == RoomState.error) {
menu.findItem(R.id.action_authorization_settings).setVisible(true)
.setIntent(MUCEditor.createIntent(getActivity(), account, user));
} else {
menu.findItem(R.id.action_leave_conference).setVisible(true).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MUCManager.getInstance().leaveRoom(account, user);
MessageManager.getInstance().closeChat(account, user);
NotificationManager.getInstance()
.removeMessageNotification(account, user);
((ChatViewer) getActivity()).close();
return true;
}
});
}
} else {
menu.findItem(R.id.action_close_chat).setVisible(true)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MessageManager.getInstance().closeChat(account, user);
NotificationManager.getInstance()
.removeMessageNotification(account, user);
((ChatViewer) getActivity()).close();
return true;
}
});
}
menu.findItem(R.id.action_clear_text).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
inputView.getText().clear();
return true;
}
});
menu.findItem(R.id.action_clear_history).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MessageManager.getInstance()
.clearHistory(account, user);
updateChat();
return false;
}
});
menu.findItem(R.id.action_export_chat).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ChatExportDialogFragment.newInstance(account, user).show(getActivity().getFragmentManager(), "CHAT_EXPORT");
return true;
}
});
if (abstractChat != null && abstractChat instanceof RegularChat) {
menu.findItem(R.id.action_call_attention).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
AttentionManager.getInstance().sendAttention(
account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
});
SecurityLevel securityLevel = OTRManager.getInstance()
.getSecurityLevel(abstractChat.getAccount(),
abstractChat.getUser());
if (securityLevel == SecurityLevel.plain) {
menu.findItem(R.id.action_start_encryption).setVisible(true)
.setEnabled(SettingsManager.securityOtrMode() != SettingsManager.SecurityOtrMode.disabled)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
OTRManager.getInstance().startSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
});
} else {
menu.findItem(R.id.action_restart_encryption).setVisible(true)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
OTRManager.getInstance().refreshSession(
account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
});
}
menu.findItem(R.id.action_stop_encryption)
.setEnabled(securityLevel != SecurityLevel.plain)
.setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
OTRManager.getInstance().endSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
return true;
}
});
menu.findItem(R.id.action_verify_with_fingerprint)
.setEnabled(securityLevel != SecurityLevel.plain)
.setIntent(FingerprintViewer.createIntent(getActivity(), account, user));
menu.findItem(R.id.action_verify_with_question)
.setEnabled(securityLevel != SecurityLevel.plain)
.setIntent(QuestionViewer
.createIntent(getActivity(), account, user, true, false, null));
menu.findItem(R.id.action_verify_with_shared_secret)
.setEnabled(securityLevel != SecurityLevel.plain)
.setIntent(QuestionViewer
.createIntent(getActivity(), account, user, false, false, null));
}
if (abstractChat != null && abstractChat instanceof RoomChat
&& ((RoomChat) abstractChat).getState() == RoomState.available)
menu.findItem(R.id.action_list_of_occupants).setVisible(true).setIntent(
OccupantList.createIntent(getActivity(), account, user));
}
@Override @Override
public void onCreateContextMenu(ContextMenu menu, View view, public void onCreateContextMenu(ContextMenu menu, View view,
ContextMenu.ContextMenuInfo menuInfo) { ContextMenu.ContextMenuInfo menuInfo) {
...@@ -585,7 +331,14 @@ public class ChatViewerFragment extends Fragment { ...@@ -585,7 +331,14 @@ public class ChatViewerFragment extends Fragment {
return user; return user;
} }
public interface ChatViewerFragmentListener { public void clearInputView() {
public void onRecentChatsCalled(); inputView.getText().clear();
}
public void scrollChat() {
int size = listView.getCount();
if (size > 0) {
listView.setSelection(size - 1);
}
} }
} }
...@@ -29,8 +29,6 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter { ...@@ -29,8 +29,6 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter {
private FinishUpdateListener finishUpdateListener; private FinishUpdateListener finishUpdateListener;
private Fragment currentFragment;
private static final int TOTAL_COUNT = 200; private static final int TOTAL_COUNT = 200;
private static final int OFFSET = TOTAL_COUNT / 2; private static final int OFFSET = TOTAL_COUNT / 2;
...@@ -165,15 +163,6 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter { ...@@ -165,15 +163,6 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter {
return realPosition - 1; return realPosition - 1;
} }
@Override
public void startUpdate(ViewGroup container) {
if (currentFragment instanceof ChatViewerFragment) {
((ChatViewerFragment)currentFragment).saveInputState();
}
super.startUpdate(container);
}
@Override @Override
public void finishUpdate(ViewGroup container) { public void finishUpdate(ViewGroup container) {
super.finishUpdate(container); super.finishUpdate(container);
......
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