Commit 91e9bc2d authored by Grigory Fedorov's avatar Grigory Fedorov

ChatViewerFragment: send button color is set according to text input readiness.

parent 89532e64
...@@ -45,6 +45,9 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -45,6 +45,9 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
private String account; private String account;
private String user; private String user;
boolean isInputEmpty = true;
private ImageButton sendButton;
public static ChatViewerFragment newInstance(String account, String user) { public static ChatViewerFragment newInstance(String account, String user) {
ChatViewerFragment fragment = new ChatViewerFragment(); ChatViewerFragment fragment = new ChatViewerFragment();
...@@ -70,8 +73,8 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -70,8 +73,8 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
View view = inflater.inflate(R.layout.chat_viewer_item, container, false); View view = inflater.inflate(R.layout.chat_viewer_item, container, false);
((ImageButton)view.findViewById(R.id.button_send_message)) sendButton = (ImageButton) view.findViewById(R.id.button_send_message);
.setImageLevel(AccountManager.getInstance().getColorLevel(account)); sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp);
chatMessageAdapter = new ChatMessageAdapter(getActivity(), account, user); chatMessageAdapter = new ChatMessageAdapter(getActivity(), account, user);
...@@ -135,7 +138,9 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -135,7 +138,9 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
return; return;
} }
ChatStateManager.getInstance().onComposing(account, user, text); ChatStateManager.getInstance().onComposing(account, user, text);
}
setSendButtonColor();
}
}); });
...@@ -144,6 +149,22 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -144,6 +149,22 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
} }
private void setSendButtonColor() {
boolean empty = inputView.getText().toString().isEmpty();
if (empty != isInputEmpty) {
isInputEmpty = empty;
if (isInputEmpty) {
sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp);
} else {
sendButton.setImageResource(R.drawable.ic_button_send);
sendButton.setImageLevel(AccountManager.getInstance().getColorLevel(account));
}
}
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
...@@ -157,6 +178,7 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -157,6 +178,7 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
inputView.setText(ChatManager.getInstance().getTypedMessage(account, user)); inputView.setText(ChatManager.getInstance().getTypedMessage(account, user));
inputView.setSelection(ChatManager.getInstance().getSelectionStart(account, user), inputView.setSelection(ChatManager.getInstance().getSelectionStart(account, user),
ChatManager.getInstance().getSelectionEnd(account, user)); ChatManager.getInstance().getSelectionEnd(account, user));
setSendButtonColor();
skipOnTextChanges = false; skipOnTextChanges = false;
...@@ -198,6 +220,7 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -198,6 +220,7 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
skipOnTextChanges = true; skipOnTextChanges = true;
inputView.getText().clear(); inputView.getText().clear();
setSendButtonColor();
skipOnTextChanges = false; skipOnTextChanges = false;
sendMessage(text); sendMessage(text);
...@@ -291,6 +314,8 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -291,6 +314,8 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
} }
inputView.setText(before + additional + after); inputView.setText(before + additional + after);
inputView.setSelection(selection + additional.length()); inputView.setSelection(selection + additional.length());
setSendButtonColor();
} }
public String getAccount() { public String getAccount() {
......
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