Commit 5c67deb8 authored by Alexander Ivanov's avatar Alexander Ivanov

Process chat viewer events directly in activity.

parent b852d27b
...@@ -131,6 +131,8 @@ public class ChatViewer extends ManagedActivity implements ...@@ -131,6 +131,8 @@ public class ChatViewer extends ManagedActivity implements
private boolean isVisible; private boolean isVisible;
private boolean skipOnTextChanges;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -156,11 +158,6 @@ public class ChatViewer extends ManagedActivity implements ...@@ -156,11 +158,6 @@ public class ChatViewer extends ManagedActivity implements
setContentView(R.layout.chat_viewer); setContentView(R.layout.chat_viewer);
chatViewerAdapter = new ChatViewerAdapter(this, account, user); chatViewerAdapter = new ChatViewerAdapter(this, account, user);
chatViewerAdapter.setOnClickListener(this);
chatViewerAdapter.setOnKeyListener(this);
chatViewerAdapter.setOnEditorActionListener(this);
chatViewerAdapter.setOnCreateContextMenuListener(this);
chatViewerAdapter.setOnTextChangedListener(this);
pageSwitcher = (PageSwitcher) findViewById(R.id.switcher); pageSwitcher = (PageSwitcher) findViewById(R.id.switcher);
pageSwitcher.setAdapter(chatViewerAdapter); pageSwitcher.setAdapter(chatViewerAdapter);
pageSwitcher.setOnSelectListener(this); pageSwitcher.setOnSelectListener(this);
...@@ -582,6 +579,8 @@ public class ChatViewer extends ManagedActivity implements ...@@ -582,6 +579,8 @@ public class ChatViewer extends ManagedActivity implements
@Override @Override
public void onTextChanged(EditText editText, CharSequence text) { public void onTextChanged(EditText editText, CharSequence text) {
if (skipOnTextChanges)
return;
ChatStateManager.getInstance().onComposing(actionWithAccount, ChatStateManager.getInstance().onComposing(actionWithAccount,
actionWithUser, text); actionWithUser, text);
} }
...@@ -635,9 +634,9 @@ public class ChatViewer extends ManagedActivity implements ...@@ -635,9 +634,9 @@ public class ChatViewer extends ManagedActivity implements
text = text.substring(start, end); text = text.substring(start, end);
if ("".equals(text)) if ("".equals(text))
return; return;
chatViewerAdapter.setOnTextChangedListener(null); skipOnTextChanges = true;
editView.setText(""); editView.setText("");
chatViewerAdapter.setOnTextChangedListener(this); skipOnTextChanges = false;
sendMessage(text); sendMessage(text);
if (exitOnSend) if (exitOnSend)
close(); close();
......
...@@ -22,7 +22,6 @@ import android.text.Editable; ...@@ -22,7 +22,6 @@ import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener;
import android.view.View.OnKeyListener; import android.view.View.OnKeyListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.animation.Animation; import android.view.animation.Animation;
...@@ -74,35 +73,12 @@ public class ChatViewerAdapter extends BaseAdapter implements SaveStateAdapter, ...@@ -74,35 +73,12 @@ public class ChatViewerAdapter extends BaseAdapter implements SaveStateAdapter,
private ArrayList<AbstractChat> activeChats; private ArrayList<AbstractChat> activeChats;
/**
* Listener for click on title bar and send button.
*/
private OnClickListener onClickListener;
/**
* Listener for key press in edit view.
*/
private OnKeyListener onKeyListener;
/**
* Listener for actions in edit view.
*/
private OnEditorActionListener onEditorActionListener;
/**
* Listener for context menu in message list.
*/
private OnCreateContextMenuListener onCreateContextMenuListener;
/**
* Listen for text to be changed.
*/
private OnTextChangedListener onTextChangedListener;
private final AbstractAvatarInflaterHelper avatarInflaterHelper; private final AbstractAvatarInflaterHelper avatarInflaterHelper;
private final Animation shake; private final Animation shake;
private boolean skipOnTextChanges;
public ChatViewerAdapter(Activity activity, String account, String user) { public ChatViewerAdapter(Activity activity, String account, String user) {
this.activity = activity; this.activity = activity;
avatarInflaterHelper = AbstractAvatarInflaterHelper avatarInflaterHelper = AbstractAvatarInflaterHelper
...@@ -116,58 +92,10 @@ public class ChatViewerAdapter extends BaseAdapter implements SaveStateAdapter, ...@@ -116,58 +92,10 @@ public class ChatViewerAdapter extends BaseAdapter implements SaveStateAdapter,
intentPosition = -1; intentPosition = -1;
else else
intentPosition = activeChats.size(); intentPosition = activeChats.size();
onClickListener = null;
onKeyListener = null;
onEditorActionListener = null;
onCreateContextMenuListener = null;
onTextChangedListener = null;
shake = AnimationUtils.loadAnimation(activity, R.anim.shake); shake = AnimationUtils.loadAnimation(activity, R.anim.shake);
onChange(); onChange();
} }
public OnClickListener getOnClickListener() {
return onClickListener;
}
public void setOnClickListener(OnClickListener onClickListener) {
this.onClickListener = onClickListener;
}
public OnKeyListener getOnKeyListener() {
return onKeyListener;
}
public void setOnKeyListener(OnKeyListener onKeyListener) {
this.onKeyListener = onKeyListener;
}
public OnEditorActionListener getOnEditorActionListener() {
return onEditorActionListener;
}
public void setOnEditorActionListener(
OnEditorActionListener onEditorActionListener) {
this.onEditorActionListener = onEditorActionListener;
}
public OnCreateContextMenuListener getOnCreateContextMenuListener() {
return onCreateContextMenuListener;
}
public void setOnCreateContextMenuListener(
OnCreateContextMenuListener onCreateContextMenuListener) {
this.onCreateContextMenuListener = onCreateContextMenuListener;
}
public OnTextChangedListener getOnTextChangedListener() {
return onTextChangedListener;
}
public void setOnTextChangedListener(
OnTextChangedListener onTextChangedListener) {
this.onTextChangedListener = onTextChangedListener;
}
@Override @Override
public int getCount() { public int getCount() {
return activeChats.size(); return activeChats.size();
...@@ -195,11 +123,11 @@ public class ChatViewerAdapter extends BaseAdapter implements SaveStateAdapter, ...@@ -195,11 +123,11 @@ public class ChatViewerAdapter extends BaseAdapter implements SaveStateAdapter,
activity); activity);
chatViewHolder = new ChatViewHolder(view, chatMessageAdapter); chatViewHolder = new ChatViewHolder(view, chatMessageAdapter);
chatViewHolder.list.setAdapter(chatViewHolder.chatMessageAdapter); chatViewHolder.list.setAdapter(chatViewHolder.chatMessageAdapter);
chatViewHolder.send.setOnClickListener(onClickListener); chatViewHolder.send.setOnClickListener((OnClickListener) activity);
chatViewHolder.title.setOnClickListener(onClickListener); chatViewHolder.title.setOnClickListener((OnClickListener) activity);
chatViewHolder.input.setOnKeyListener(onKeyListener); chatViewHolder.input.setOnKeyListener((OnKeyListener) activity);
chatViewHolder.input chatViewHolder.input
.setOnEditorActionListener(onEditorActionListener); .setOnEditorActionListener((OnEditorActionListener) activity);
chatViewHolder.input.addTextChangedListener(new TextWatcher() { chatViewHolder.input.addTextChangedListener(new TextWatcher() {
@Override @Override
...@@ -214,14 +142,14 @@ public class ChatViewerAdapter extends BaseAdapter implements SaveStateAdapter, ...@@ -214,14 +142,14 @@ public class ChatViewerAdapter extends BaseAdapter implements SaveStateAdapter,
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if (onTextChangedListener != null) if (skipOnTextChanges)
onTextChangedListener.onTextChanged( return;
chatViewHolder.input, s); ((OnTextChangedListener) activity).onTextChanged(
chatViewHolder.input, s);
} }
}); });
chatViewHolder.list chatViewHolder.list.setOnCreateContextMenuListener(activity);
.setOnCreateContextMenuListener(onCreateContextMenuListener);
view.setTag(chatViewHolder); view.setTag(chatViewHolder);
} else { } else {
view = convertView; view = convertView;
...@@ -243,21 +171,21 @@ public class ChatViewerAdapter extends BaseAdapter implements SaveStateAdapter, ...@@ -243,21 +171,21 @@ public class ChatViewerAdapter extends BaseAdapter implements SaveStateAdapter,
LogManager.i(this, "Load " + view + " for " LogManager.i(this, "Load " + view + " for "
+ chatViewHolder.chatMessageAdapter.getUser() + " in " + chatViewHolder.chatMessageAdapter.getUser() + " in "
+ chatViewHolder.chatMessageAdapter.getAccount()); + chatViewHolder.chatMessageAdapter.getAccount());
OnTextChangedListener temp = onTextChangedListener; skipOnTextChanges = true;
onTextChangedListener = null;
chatViewHolder.input.setText(ChatManager.getInstance() chatViewHolder.input.setText(ChatManager.getInstance()
.getTypedMessage(account, user)); .getTypedMessage(account, user));
chatViewHolder.input.setSelection(ChatManager.getInstance() chatViewHolder.input.setSelection(ChatManager.getInstance()
.getSelectionStart(account, user), ChatManager .getSelectionStart(account, user), ChatManager
.getInstance().getSelectionEnd(account, user)); .getInstance().getSelectionEnd(account, user));
onTextChangedListener = temp; skipOnTextChanges = false;
chatViewHolder.chatMessageAdapter.setChat(account, user); chatViewHolder.chatMessageAdapter.setChat(account, user);
chatViewHolder.list.setAdapter(chatViewHolder.list.getAdapter()); chatViewHolder.list.setAdapter(chatViewHolder.list.getAdapter());
} }
chatViewHolder.page.setText(activity.getString(R.string.chat_page, chatViewHolder.page.setText(activity.getString(R.string.chat_page,
position + 1, getCount())); position + 1, getCount()));
ContactTitleInflater.updateTitle(chatViewHolder.title, activity, abstractContact); ContactTitleInflater.updateTitle(chatViewHolder.title, activity,
abstractContact);
avatarInflaterHelper.updateAvatar(chatViewHolder.avatar, avatarInflaterHelper.updateAvatar(chatViewHolder.avatar,
abstractContact); abstractContact);
SecurityLevel securityLevel = OTRManager.getInstance() SecurityLevel securityLevel = OTRManager.getInstance()
......
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