aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2015-02-21 11:06:52 +0100
committeriNPUTmice <daniel@gultsch.de>2015-02-21 11:06:52 +0100
commit7ee5e959597cfded524c7179b663138aca781ad8 (patch)
tree29a97c63d690a4d419a5500b1bb5a1c10f1f078b /src/main/java/eu/siacs/conversations/ui
parent3f248e0d89af977e7f602102663be9729430f1ed (diff)
added typing notifications through XEP-0085. fixed #210
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java91
-rw-r--r--src/main/java/eu/siacs/conversations/ui/EditMessage.java59
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java4
3 files changed, 117 insertions, 37 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index 35599946..3e0668be 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
@@ -40,6 +40,7 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentLinkedQueue;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Account;
@@ -52,15 +53,15 @@ import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.services.XmppConnectionService;
-import eu.siacs.conversations.ui.EditMessage.OnEnterPressed;
import eu.siacs.conversations.ui.XmppActivity.OnPresenceSelected;
import eu.siacs.conversations.ui.XmppActivity.OnValueEdited;
import eu.siacs.conversations.ui.adapter.MessageAdapter;
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked;
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked;
+import eu.siacs.conversations.xmpp.chatstate.ChatState;
import eu.siacs.conversations.xmpp.jid.Jid;
-public class ConversationFragment extends Fragment {
+public class ConversationFragment extends Fragment implements EditMessage.KeyboardListener {
protected Conversation conversation;
private OnClickListener leaveMuc = new OnClickListener() {
@@ -327,18 +328,6 @@ public class ConversationFragment extends Fragment {
}
});
mEditMessage.setOnEditorActionListener(mEditorActionListener);
- mEditMessage.setOnEnterPressedListener(new OnEnterPressed() {
-
- @Override
- public boolean onEnterPressed() {
- if (activity.enterIsSend()) {
- sendMessage();
- return true;
- } else {
- return false;
- }
- }
- });
mSendButton = (ImageButton) view.findViewById(R.id.textSendButton);
mSendButton.setOnClickListener(this.mSendButtonListener);
@@ -558,7 +547,17 @@ public class ConversationFragment extends Fragment {
mDecryptJobRunning = false;
super.onStop();
if (this.conversation != null) {
- this.conversation.setNextMessage(mEditMessage.getText().toString());
+ final String msg = mEditMessage.getText().toString();
+ this.conversation.setNextMessage(msg);
+ updateChatState(this.conversation,msg);
+ }
+ }
+
+ private void updateChatState(final Conversation conversation, final String msg) {
+ ChatState state = msg.length() == 0 ? Config.DEFAULT_CHATSTATE : ChatState.PAUSED;
+ Account.State status = conversation.getAccount().getStatus();
+ if (status == Account.State.ONLINE && conversation.setOutgoingChatState(state)) {
+ activity.xmppConnectionService.sendChatState(conversation);
}
}
@@ -566,11 +565,18 @@ public class ConversationFragment extends Fragment {
if (conversation == null) {
return;
}
+
+ this.activity = (ConversationActivity) getActivity();
+
if (this.conversation != null) {
- this.conversation.setNextMessage(mEditMessage.getText().toString());
+ final String msg = mEditMessage.getText().toString();
+ this.conversation.setNextMessage(msg);
+ if (this.conversation != conversation) {
+ updateChatState(this.conversation,msg);
+ }
this.conversation.trim();
}
- this.activity = (ConversationActivity) getActivity();
+
this.askForPassphraseIntent = null;
this.conversation = conversation;
this.mDecryptJobRunning = false;
@@ -578,8 +584,10 @@ public class ConversationFragment extends Fragment {
if (this.conversation.getMode() == Conversation.MODE_MULTI) {
this.conversation.setNextCounterpart(null);
}
+ this.mEditMessage.setKeyboardListener(null);
this.mEditMessage.setText("");
this.mEditMessage.append(this.conversation.getNextMessage());
+ this.mEditMessage.setKeyboardListener(this);
this.messagesView.setAdapter(messageListAdapter);
updateMessages();
this.messagesLoaded = true;
@@ -834,13 +842,21 @@ public class ConversationFragment extends Fragment {
protected void updateStatusMessages() {
synchronized (this.messageList) {
if (conversation.getMode() == Conversation.MODE_SINGLE) {
- for (int i = this.messageList.size() - 1; i >= 0; --i) {
- if (this.messageList.get(i).getStatus() == Message.STATUS_RECEIVED) {
- return;
- } else {
- if (this.messageList.get(i).getStatus() == Message.STATUS_SEND_DISPLAYED) {
- this.messageList.add(i + 1,Message.createStatusMessage(conversation));
+ ChatState state = conversation.getIncomingChatState();
+ if (state == ChatState.COMPOSING) {
+ this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_is_typing, conversation.getName())));
+ } else if (state == ChatState.PAUSED) {
+ this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_has_stopped_typing, conversation.getName())));
+ } else {
+ for (int i = this.messageList.size() - 1; i >= 0; --i) {
+ if (this.messageList.get(i).getStatus() == Message.STATUS_RECEIVED) {
return;
+ } else {
+ if (this.messageList.get(i).getStatus() == Message.STATUS_SEND_DISPLAYED) {
+ this.messageList.add(i + 1,
+ Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, conversation.getName())));
+ return;
+ }
}
}
}
@@ -995,4 +1011,33 @@ public class ConversationFragment extends Fragment {
this.mEditMessage.append(text);
}
+ @Override
+ public void onEnterPressed() {
+ sendMessage();
+ }
+
+ @Override
+ public void onTypingStarted() {
+ Account.State status = conversation.getAccount().getStatus();
+ if (status == Account.State.ONLINE && conversation.setOutgoingChatState(ChatState.COMPOSING)) {
+ activity.xmppConnectionService.sendChatState(conversation);
+ }
+ }
+
+ @Override
+ public void onTypingStopped() {
+ Account.State status = conversation.getAccount().getStatus();
+ if (status == Account.State.ONLINE && conversation.setOutgoingChatState(ChatState.PAUSED)) {
+ activity.xmppConnectionService.sendChatState(conversation);
+ }
+ }
+
+ @Override
+ public void onTextDeleted() {
+ Account.State status = conversation.getAccount().getStatus();
+ if (status == Account.State.ONLINE && conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
+ activity.xmppConnectionService.sendChatState(conversation);
+ }
+ }
+
}
diff --git a/src/main/java/eu/siacs/conversations/ui/EditMessage.java b/src/main/java/eu/siacs/conversations/ui/EditMessage.java
index 5090bbf5..57fa7285 100644
--- a/src/main/java/eu/siacs/conversations/ui/EditMessage.java
+++ b/src/main/java/eu/siacs/conversations/ui/EditMessage.java
@@ -1,10 +1,13 @@
package eu.siacs.conversations.ui;
import android.content.Context;
+import android.os.Handler;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.EditText;
+import eu.siacs.conversations.Config;
+
public class EditMessage extends EditText {
public EditMessage(Context context, AttributeSet attrs) {
@@ -15,28 +18,62 @@ public class EditMessage extends EditText {
super(context);
}
- protected OnEnterPressed mOnEnterPressed;
+ protected Handler mTypingHandler = new Handler();
+
+ protected Runnable mTypingTimeout = new Runnable() {
+ @Override
+ public void run() {
+ if (isUserTyping && keyboardListener != null) {
+ keyboardListener.onTypingStopped();
+ isUserTyping = false;
+ }
+ }
+ };
+
+ private boolean isUserTyping = false;
+
+ protected KeyboardListener keyboardListener;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
- if (mOnEnterPressed != null) {
- if (mOnEnterPressed.onEnterPressed()) {
- return true;
- } else {
- return super.onKeyDown(keyCode, event);
- }
+ if (keyboardListener != null) {
+ keyboardListener.onEnterPressed();
}
+ return true;
}
return super.onKeyDown(keyCode, event);
}
- public void setOnEnterPressedListener(OnEnterPressed listener) {
- this.mOnEnterPressed = listener;
+ @Override
+ public void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
+ super.onTextChanged(text,start,lengthBefore,lengthAfter);
+ if (this.mTypingHandler != null && this.keyboardListener != null) {
+ this.mTypingHandler.removeCallbacks(mTypingTimeout);
+ this.mTypingHandler.postDelayed(mTypingTimeout, Config.TYPING_TIMEOUT * 1000);
+ final int length = text.length();
+ if (!isUserTyping && length > 0) {
+ this.isUserTyping = true;
+ this.keyboardListener.onTypingStarted();
+ } else if (length == 0) {
+ this.isUserTyping = false;
+ this.keyboardListener.onTextDeleted();
+ }
+ }
+ }
+
+ public void setKeyboardListener(KeyboardListener listener) {
+ this.keyboardListener = listener;
+ if (listener != null) {
+ this.isUserTyping = false;
+ }
}
- public interface OnEnterPressed {
- public boolean onEnterPressed();
+ public interface KeyboardListener {
+ public void onEnterPressed();
+ public void onTypingStarted();
+ public void onTypingStopped();
+ public void onTextDeleted();
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index 442c6ecf..58713534 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -410,9 +410,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
.avatarService().get(conversation.getContact(),
activity.getPixel(32)));
viewHolder.contact_picture.setAlpha(0.5f);
- viewHolder.status_message.setText(
- activity.getString(R.string.contact_has_read_up_to_this_point, conversation.getName()));
-
+ viewHolder.status_message.setText(message.getBody());
}
return view;
} else if (type == NULL) {