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

Remove unused ChatViewHolder.

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