pidgin/android/android

Commented conversation classes
soc.2012.android
2012-08-20, Michael Zangl
0437d5133423
Parents f5645b56981a
Children ca24c4479a21
Commented conversation classes
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationListener.java Mon Aug 20 15:17:18 2012 +0200
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationListener.java Mon Aug 20 15:33:50 2012 +0200
@@ -1,8 +1,28 @@
package im.pidgin.libpurple.conversation;
+/**
+ * This interface allows you to listen to conversations
+ *
+ * @author michael
+ */
public interface ConversationListener {
- void messageReceived(PurpleConversation purpleConversation, PurpleMessage message);
+ /**
+ * Called when a message was received on a conversation.
+ *
+ * @param purpleConversation
+ * The conversation with that message.
+ * @param message
+ * The message that was received.
+ */
+ void messageReceived(PurpleConversation purpleConversation,
+ PurpleMessage message);
+ /**
+ * Called when the typing state of the buddy we are talking with changed.
+ *
+ * @param purpleConversation
+ * The conversation in which the buddy changed the typing state.
+ */
void updateTypingState(PurpleConversation purpleConversation);
}
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationManager.java Mon Aug 20 15:17:18 2012 +0200
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/ConversationManager.java Mon Aug 20 15:33:50 2012 +0200
@@ -9,10 +9,22 @@
import java.util.Date;
import java.util.Hashtable;
+/**
+ * This is the main conversation manager. It handles conversation object
+ * creation and destruction and event handling. This class is not accessible in
+ * the public API.
+ *
+ * @author michael
+ */
public class ConversationManager extends AbstractPurpleManaged implements
- PeerGenerator<PurpleConversation> {
+ PeerGenerator<PurpleConversation> {
- private final Hashtable<Long, PurpleConversation> conversations = new Hashtable<Long, PurpleConversation>();
+ /**
+ * A hashtable of conversations that we know of. TODO: We can use ui_data
+ * here.
+ */
+ private final Hashtable<Long, PurpleConversation> conversations =
+ new Hashtable<Long, PurpleConversation>();
public ConversationManager(CoreManager manager) {
super(manager);
@@ -27,34 +39,58 @@
private native void register_native();
+ /**
+ * Starts a new conversation with a buddy.
+ *
+ * @param buddy
+ * The buddy to start a conversation with.
+ * @return
+ */
public PurpleConversation newConversation(PurpleBuddy buddy) {
- PurpleConversation conversation = PurpleConversation.newConversation(
- buddy, getManager());
+ PurpleConversation conversation =
+ PurpleConversation.newConversation(buddy, getManager());
conversations.put(conversation.getNativePointer(), conversation);
return conversation;
}
-
- protected void createConversation(long conv) {
- //PurpleConversation conversation = getPeer(conv);
- //conversations.put(conversation.getNativePointer(), conversation);
+
+ /**
+ * Called on a conversation created event.
+ *
+ * @param conv
+ * The conversation that was created.
+ */
+ protected void createConversation(long conv) {
+ // PurpleConversation conversation = getPeer(conv);
+ // conversations.put(conversation.getNativePointer(), conversation);
}
- protected void destroyConversation(long conv) {
+ /**
+ * Called when a conversation was destroyed.
+ *
+ * @param conv
+ * The conversation that was destroyed.
+ */
+ protected void destroyConversation(long conv) {
PurpleConversation conversation = getPeer(conv);
+ conversation.nativeObjectFreed();
conversations.remove(conversation.getNativePointer());
conversation.nativeObjectFreed();
}
-
- protected void writeIm(long conv, String who, String message, int flags, long mtime) {
-
+
+ /* signal / ui ops callbacks */
+
+ protected void writeIm(long conv, String who, String message, int flags,
+ long mtime) {
+
Date time = new Date(mtime);
PurpleConversation conversation = getPeer(conv);
- conversation.notifyMessageReceived(new PurpleMessage(who, message, flags, time));
+ conversation.notifyMessageReceived(new PurpleMessage(who, message,
+ flags, time));
}
protected void updateBuddyTyping(long accountPointer, String who) {
- PurpleAccount account = getManager().getAccountList().getPeer(
- accountPointer);
+ PurpleAccount account =
+ getManager().getAccountList().getPeer(accountPointer);
PurpleConversation conversation = findImWithAccount(who, account);
if (conversation == null) {
return;
@@ -64,7 +100,7 @@
}
private PurpleConversation findImWithAccount(String who,
- PurpleAccount account) {
+ PurpleAccount account) {
long account_native = findImWithAccount_native(who, account);
if (account_native == 0) {
return null;
@@ -74,7 +110,7 @@
}
private native long findImWithAccount_native(String who,
- PurpleAccount account);
+ PurpleAccount account);
@Override
public PurpleConversation getPeer(long pointer) {
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleConversation.java Mon Aug 20 15:17:18 2012 +0200
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleConversation.java Mon Aug 20 15:33:50 2012 +0200
@@ -6,29 +6,63 @@
import java.util.LinkedList;
+/**
+ * This is a conversation with some buddy. Currently, this only represents an IM
+ * buddy.
+ *
+ * @author michael
+ */
public class PurpleConversation extends PeeredPurpleManaged {
+ /**
+ * Creates a new conversation.
+ *
+ * @param buddy
+ * The buddy to conversate with.
+ * @param manager
+ * The manager
+ * @return A new conversation that was just created.
+ */
protected static PurpleConversation newConversation(PurpleBuddy buddy,
- CoreManager manager) {
+ CoreManager manager) {
long nativePointer = newConversation_native(buddy);
return new PurpleConversation(nativePointer, manager);
}
private static native long newConversation_native(PurpleBuddy buddy);
- private final LinkedList<ConversationListener> conversationListeners = new LinkedList<ConversationListener>();
+ /**
+ * This is a list of listeners that listen to this conversation.
+ */
+ private final LinkedList<ConversationListener> conversationListeners =
+ new LinkedList<ConversationListener>();
+ /**
+ * The mutex to synchronize the conversation listeners.
+ */
private final Object conversationListenerMutex = new Object();
private PurpleConversation(long nativePointer, CoreManager manager) {
super(nativePointer, manager);
}
+ /**
+ * Adds a listener to this conversation.
+ *
+ * @param l
+ * The listener to add.
+ */
public void addConversationListener(ConversationListener l) {
synchronized (conversationListenerMutex) {
conversationListeners.add(l);
}
}
+ /**
+ * Removes a listener from this conversation if it was previously added.
+ *
+ * @param l
+ * The listener to remove.
+ */
public void removeConversationListener(ConversationListener l) {
synchronized (conversationListenerMutex) {
conversationListeners.remove(l);
@@ -51,6 +85,13 @@
}
}
+ /**
+ * Enables or disables logging for this conversation.
+ *
+ * @param logging
+ * <code>true</code> if logging should be enabled, or
+ * <code>false</code> otherwise.
+ */
public synchronized void setLogging(boolean logging) {
ensureNotDestroyed();
setLogging_native(logging);
@@ -58,6 +99,12 @@
private native void setLogging_native(boolean logging);
+ /**
+ * Returns whether or not logging is enabled for this conversation.
+ *
+ * @return <code>true</code> if logging is enabled, or <code>false</code>
+ * otherwise.
+ */
public synchronized boolean isLogging() {
ensureNotDestroyed();
return isLogging_native();
@@ -65,6 +112,12 @@
private native boolean isLogging_native();
+ /**
+ * Sends a message to the buddy in this conversation.
+ *
+ * @param message
+ * The message to send.
+ */
public synchronized void send(String message) {
ensureNotDestroyed();
send_native(message);
@@ -81,7 +134,12 @@
protected synchronized void nativeObjectFreed() {
super.nativeObjectFreed();
}
-
+
+ /**
+ * Gets the typing state of the opponent.
+ *
+ * @return true if the other buddy is typing. TODO: Change this to an enum.
+ */
public synchronized boolean getTypingState() {
ensureNotDestroyed();
return getTypingState_native();
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleMessage.java Mon Aug 20 15:17:18 2012 +0200
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/conversation/PurpleMessage.java Mon Aug 20 15:33:50 2012 +0200
@@ -4,6 +4,11 @@
import java.util.Date;
+/**
+ * This is a message that was sent on a conversation.
+ *
+ * @author michael
+ */
public class PurpleMessage {
private final String who;
@@ -11,33 +16,66 @@
private final int flags;
private final Date time;
- public PurpleMessage(String who, String message, int flags, Date time) {
+ /**
+ * Creates a new message object.
+ *
+ * @param who
+ * @param message
+ * @param flags
+ * @param time
+ */
+ protected PurpleMessage(String who, String message, int flags, Date time) {
this.who = who;
this.message = message;
this.flags = flags;
this.time = time;
}
-
+
+ /**
+ * Gets the user that wrote this message.
+ *
+ * @return The writer of the message
+ */
public String getWho() {
return who;
}
-
+
+ /**
+ * Gets the time the message was sent.
+ *
+ * @return That time as {@link Date} object.
+ */
public Date getTime() {
return time;
}
+ /**
+ * Gets the content of the message.
+ *
+ * @return The message.
+ */
public String getMessage() {
return message;
}
-
+
+ /**
+ * Checks whether the message was sent by us.
+ *
+ * @return <code>true</code> if and only if the message was sent by us.
+ */
public boolean isSend() {
return (flags & ConversationConstants.PURPLE_MESSAGE_SEND) != 0;
}
-
+
+ /**
+ * Checks whether the message was an incoming message
+ *
+ * @return <code>true</code> if and only if the message was received.
+ */
public boolean isReceived() {
return (flags & ConversationConstants.PURPLE_MESSAGE_RECV) != 0;
}
-
+
public boolean isSystem() {
return (flags & ConversationConstants.PURPLE_MESSAGE_SYSTEM) != 0;
}