/soc/2012/michael/android: 0c93ea530151: Testclient conversation...

Michael Zangl michael at soc.pidgin.im
Wed Aug 15 06:14:15 EDT 2012


Changeset: 0c93ea530151f3b57f6a097a2b3d8808a88b3b24
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-08-11 11:08 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/0c93ea530151

Description:

Testclient conversation view: Implemented message listener and send button function

diffstat:

 android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/conversation/ConversationView.java |  39 +++++++++-
 1 files changed, 36 insertions(+), 3 deletions(-)

diffs (82 lines):

diff --git a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/conversation/ConversationView.java b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/conversation/ConversationView.java
--- a/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/conversation/ConversationView.java
+++ b/android/workspace/im.pidgin.libpurple.testclient/src/im/pidgin/libpurple/testclient/conversation/ConversationView.java
@@ -1,19 +1,24 @@
 package im.pidgin.libpurple.testclient.conversation;
 
 import im.pidgin.libpurple.buddy.PurpleBuddy;
+import im.pidgin.libpurple.conversation.ConversationListener;
+import im.pidgin.libpurple.conversation.PurpleConversation;
 import im.pidgin.libpurple.testclient.R;
 import im.pidgin.libpurple.testclient.core.TestClientView;
 import im.pidgin.libpurple.testclient.core.ViewController;
 import android.view.View;
+import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.TextView;
 
-public class ConversationView implements TestClientView {
+public class ConversationView implements TestClientView, ConversationListener {
 
 	private final ViewController viewController;
 	private final PurpleBuddy buddy;
 	private View view;
+	private PurpleConversation conversation;
+	private EditText messages;
 
 	public ConversationView(ViewController viewController, PurpleBuddy buddy) {
 		this.viewController = viewController;
@@ -23,22 +28,50 @@ public class ConversationView implements
 	@Override
 	public View createView() {
 		if (view == null) {
+			conversation = buddy.newConversation();
+			
 			view = viewController.getLayoutInflater().inflate(R.layout.conversation, null);
 			
 			TextView title = (TextView) view.findViewById(R.id.conversation_title);
 			title.setText(viewController.getResources().getString(R.string.conversation_title, buddy.getDisplayName()));
 			
-			EditText messages = (EditText) view.findViewById(R.id.conversation_messages);
-			EditText message = (EditText) view.findViewById(R.id.conversation_message);
+			messages = (EditText) view.findViewById(R.id.conversation_messages);
+			final EditText message = (EditText) view.findViewById(R.id.conversation_message);
 			Button sendbutton = (Button) view.findViewById(R.id.conversation_sendbutton);
+			sendbutton.setOnClickListener(new OnClickListener() {
+				@Override
+				public void onClick(View v) {
+					sendMessage(message);
+				}
+			});
+			conversation.addConversationListener(this);
 		}
 		return view;
 	}
 
+	protected void sendMessage(EditText message) {
+		String text = message.getText().toString();
+		
+		if (text != null) {
+			conversation.send(text);
+		}
+		message.setText("");
+	}
+
 	@Override
 	public void removed(View view) {
 		// TODO Auto-generated method stub
 
 	}
 
+	@Override
+	public void messageReceived(PurpleConversation purpleConversation,
+			String message) {
+		messages.append("\n" + message);
+	}
+
+	@Override
+	public void updateTypingState(PurpleConversation purpleConversation) {
+	}
+
 }



More information about the Commits mailing list