Commit 41cbecc5 authored by Alexander Ivanov's avatar Alexander Ivanov

Remove unused ChatViewHolder.

parent 8dc9519f
...@@ -44,24 +44,31 @@ public class ChatViewerFragment { ...@@ -44,24 +44,31 @@ public class ChatViewerFragment {
private AbstractAvatarInflaterHelper avatarInflaterHelper; private AbstractAvatarInflaterHelper avatarInflaterHelper;
private Animation shake;
private boolean skipOnTextChanges; private boolean skipOnTextChanges;
private ChatViewHolder chatViewHolder; private TextView pageView;
private View titleView;
private EditText inputView;
private ListView listView;
private ChatMessageAdapter chatMessageAdapter;
/** /**
* Whether pages are shown. * Whether pages are shown.
*/ */
private boolean pagesShown; private boolean pagesShown;
private Handler handler;
/** /**
* Animation used to hide pages. * Animation used to hide pages.
*/ */
private Animation pagesHideAnimation; private Animation pagesHideAnimation;
/**
* Animation used for incoming message notification.
*/
private Animation shakeAnimation;
private Handler handler;
/** /**
* Runnable called to hide pages. * Runnable called to hide pages.
*/ */
...@@ -69,7 +76,7 @@ public class ChatViewerFragment { ...@@ -69,7 +76,7 @@ public class ChatViewerFragment {
@Override @Override
public void run() { public void run() {
handler.removeCallbacks(this); handler.removeCallbacks(this);
chatViewHolder.page.startAnimation(pagesHideAnimation); pageView.startAnimation(pagesHideAnimation);
} }
}; };
...@@ -105,7 +112,8 @@ public class ChatViewerFragment { ...@@ -105,7 +112,8 @@ public class ChatViewerFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
shake = AnimationUtils.loadAnimation(getActivity(), R.anim.shake); shakeAnimation = AnimationUtils.loadAnimation(getActivity(),
R.anim.shake);
pagesHideAnimation = AnimationUtils.loadAnimation(getActivity(), pagesHideAnimation = AnimationUtils.loadAnimation(getActivity(),
R.anim.chat_page_out); R.anim.chat_page_out);
pagesHideAnimation.setAnimationListener(new AnimationListener() { pagesHideAnimation.setAnimationListener(new AnimationListener() {
...@@ -116,7 +124,7 @@ public class ChatViewerFragment { ...@@ -116,7 +124,7 @@ public class ChatViewerFragment {
@Override @Override
public void onAnimationEnd(Animation animation) { public void onAnimationEnd(Animation animation) {
chatViewHolder.page.setVisibility(View.GONE); pageView.setVisibility(View.GONE);
} }
@Override @Override
...@@ -126,17 +134,20 @@ public class ChatViewerFragment { ...@@ -126,17 +134,20 @@ public class ChatViewerFragment {
}); });
View view = inflater.inflate(R.layout.chat_viewer_item, container, View view = inflater.inflate(R.layout.chat_viewer_item, container,
false); false);
ChatMessageAdapter chatMessageAdapter = new ChatMessageAdapter( chatMessageAdapter = new ChatMessageAdapter(getActivity());
getActivity()); pageView = (TextView) view.findViewById(R.id.chat_page);
chatViewHolder = new ChatViewHolder(view, chatMessageAdapter); titleView = view.findViewById(R.id.title);
chatViewHolder.list.setAdapter(chatViewHolder.chatMessageAdapter); inputView = (EditText) view.findViewById(R.id.chat_input);
chatViewHolder.send.setOnClickListener((OnClickListener) getActivity()); listView = (ListView) view.findViewById(android.R.id.list);
chatViewHolder.title
.setOnClickListener((OnClickListener) getActivity()); listView.setAdapter(chatMessageAdapter);
chatViewHolder.input.setOnKeyListener((OnKeyListener) getActivity()); view.findViewById(R.id.chat_send).setOnClickListener(
chatViewHolder.input (OnClickListener) getActivity());
titleView.setOnClickListener((OnClickListener) getActivity());
inputView.setOnKeyListener((OnKeyListener) getActivity());
inputView
.setOnEditorActionListener((OnEditorActionListener) getActivity()); .setOnEditorActionListener((OnEditorActionListener) getActivity());
chatViewHolder.input.addTextChangedListener(new TextWatcher() { inputView.addTextChangedListener(new TextWatcher() {
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, public void onTextChanged(CharSequence s, int start, int before,
...@@ -153,11 +164,11 @@ public class ChatViewerFragment { ...@@ -153,11 +164,11 @@ public class ChatViewerFragment {
if (skipOnTextChanges) if (skipOnTextChanges)
return; return;
((OnTextChangedListener) getActivity()).onTextChanged( ((OnTextChangedListener) getActivity()).onTextChanged(
chatViewHolder.input, s); inputView, s);
} }
}); });
chatViewHolder.list.setOnCreateContextMenuListener(getActivity()); listView.setOnCreateContextMenuListener(getActivity());
return view; return view;
} }
...@@ -166,73 +177,64 @@ public class ChatViewerFragment { ...@@ -166,73 +177,64 @@ public class ChatViewerFragment {
final String user = chat.getUser(); final String user = chat.getUser();
final AbstractContact abstractContact = RosterManager.getInstance() final AbstractContact abstractContact = RosterManager.getInstance()
.getBestContact(account, user); .getBestContact(account, user);
if (chat.equals(chatViewHolder.chatMessageAdapter.getAccount(), if (chat.equals(chatMessageAdapter.getAccount(),
chatViewHolder.chatMessageAdapter.getUser())) { chatMessageAdapter.getUser())) {
chatViewHolder.chatMessageAdapter.updateInfo(); chatMessageAdapter.updateInfo();
} else { } else {
if (chatViewHolder.chatMessageAdapter.getAccount() != null if (chatMessageAdapter.getAccount() != null
&& chatViewHolder.chatMessageAdapter.getUser() != null) && chatMessageAdapter.getUser() != null)
saveState(); saveState();
if (PageSwitcher.LOG) if (PageSwitcher.LOG)
LogManager.i( LogManager.i(this, "Load " + chatMessageAdapter.getUser()
this, + " in " + chatMessageAdapter.getAccount());
"Load "
+ chatViewHolder.chatMessageAdapter.getUser()
+ " in "
+ chatViewHolder.chatMessageAdapter
.getAccount());
skipOnTextChanges = true; skipOnTextChanges = true;
chatViewHolder.input.setText(ChatManager.getInstance() inputView.setText(ChatManager.getInstance().getTypedMessage(
.getTypedMessage(account, user)); account, user));
chatViewHolder.input.setSelection(ChatManager.getInstance() inputView.setSelection(
.getSelectionStart(account, user), ChatManager ChatManager.getInstance().getSelectionStart(account, user),
.getInstance().getSelectionEnd(account, user)); ChatManager.getInstance().getSelectionEnd(account, user));
skipOnTextChanges = false; skipOnTextChanges = false;
chatViewHolder.chatMessageAdapter.setChat(account, user); chatMessageAdapter.setChat(account, user);
chatViewHolder.list.setAdapter(chatViewHolder.list.getAdapter()); listView.setAdapter(listView.getAdapter());
} }
chatViewHolder.page pageView.setText(getString(
.setText(getString(R.string.chat_page, R.string.chat_page,
((ChatViewer) getActivity()).getChatPosition(account, ((ChatViewer) getActivity()).getChatPosition(account, user) + 1,
user) + 1, ((ChatViewer) getActivity()) ((ChatViewer) getActivity()).getChatCount()));
.getChatCount())); ContactTitleInflater.updateTitle(titleView, getActivity(),
ContactTitleInflater.updateTitle(chatViewHolder.title, getActivity(),
abstractContact); abstractContact);
avatarInflaterHelper.updateAvatar(chatViewHolder.avatar, avatarInflaterHelper.updateAvatar(
(ImageView) titleView.findViewById(R.id.avatar),
abstractContact); abstractContact);
SecurityLevel securityLevel = OTRManager.getInstance() SecurityLevel securityLevel = OTRManager.getInstance()
.getSecurityLevel(chat.getAccount(), chat.getUser()); .getSecurityLevel(chat.getAccount(), chat.getUser());
SecurityOtrMode securityOtrMode = SettingsManager.securityOtrMode(); SecurityOtrMode securityOtrMode = SettingsManager.securityOtrMode();
ImageView securityView = (ImageView) titleView
.findViewById(R.id.security);
if (securityLevel == SecurityLevel.plain if (securityLevel == SecurityLevel.plain
&& (securityOtrMode == SecurityOtrMode.disabled || securityOtrMode == SecurityOtrMode.manual)) { && (securityOtrMode == SecurityOtrMode.disabled || securityOtrMode == SecurityOtrMode.manual)) {
chatViewHolder.security.setVisibility(View.GONE); securityView.setVisibility(View.GONE);
} else { } else {
chatViewHolder.security.setVisibility(View.VISIBLE); securityView.setVisibility(View.VISIBLE);
chatViewHolder.security securityView.setImageLevel(securityLevel.getImageLevel());
.setImageLevel(securityLevel.getImageLevel());
} }
} }
public void saveState() { public void saveState() {
if (PageSwitcher.LOG) if (PageSwitcher.LOG)
LogManager.i( LogManager.i(this, "Save " + chatMessageAdapter.getUser() + " in "
this, + chatMessageAdapter.getAccount());
"Save " + chatViewHolder.chatMessageAdapter.getUser() ChatManager.getInstance().setTyped(chatMessageAdapter.getAccount(),
+ " in " chatMessageAdapter.getUser(), inputView.getText().toString(),
+ chatViewHolder.chatMessageAdapter.getAccount()); inputView.getSelectionStart(), inputView.getSelectionEnd());
ChatManager.getInstance().setTyped(
chatViewHolder.chatMessageAdapter.getAccount(),
chatViewHolder.chatMessageAdapter.getUser(),
chatViewHolder.input.getText().toString(),
chatViewHolder.input.getSelectionStart(),
chatViewHolder.input.getSelectionEnd());
} }
public void onChatChange(boolean incomingMessage) { public void onChatChange(boolean incomingMessage) {
if (incomingMessage) if (incomingMessage)
chatViewHolder.nameHolder.startAnimation(shake); titleView.findViewById(R.id.name_holder).startAnimation(
chatViewHolder.chatMessageAdapter.onChange(); shakeAnimation);
chatMessageAdapter.onChange();
} }
/** /**
...@@ -243,8 +245,8 @@ public class ChatViewerFragment { ...@@ -243,8 +245,8 @@ public class ChatViewerFragment {
return; return;
pagesShown = true; pagesShown = true;
handler.removeCallbacks(pagesHideRunnable); handler.removeCallbacks(pagesHideRunnable);
chatViewHolder.page.clearAnimation(); pageView.clearAnimation();
chatViewHolder.page.setVisibility(View.VISIBLE); pageView.setVisibility(View.VISIBLE);
} }
/** /**
...@@ -257,30 +259,4 @@ public class ChatViewerFragment { ...@@ -257,30 +259,4 @@ public class ChatViewerFragment {
handler.postDelayed(pagesHideRunnable, PAGES_HIDDER_DELAY); handler.postDelayed(pagesHideRunnable, PAGES_HIDDER_DELAY);
} }
private static class ChatViewHolder {
final TextView page;
final View title;
final View nameHolder;
final ImageView avatar;
final ImageView security;
final View send;
final EditText input;
final ListView list;
final ChatMessageAdapter chatMessageAdapter;
public ChatViewHolder(View view, ChatMessageAdapter chatMessageAdapter) {
page = (TextView) view.findViewById(R.id.chat_page);
title = view.findViewById(R.id.title);
nameHolder = title.findViewById(R.id.name_holder);
avatar = (ImageView) title.findViewById(R.id.avatar);
security = (ImageView) title.findViewById(R.id.security);
send = view.findViewById(R.id.chat_send);
input = (EditText) view.findViewById(R.id.chat_input);
list = (ListView) view.findViewById(android.R.id.list);
this.chatMessageAdapter = chatMessageAdapter;
}
}
} }
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