diff options
author | Andrew Comminos <andrewcomminos@gmail.com> | 2013-12-14 07:53:50 +0400 |
---|---|---|
committer | Andrew Comminos <andrewcomminos@gmail.com> | 2013-12-14 07:53:50 +0400 |
commit | 115b08f93ea5c8b44c5f3c66ab6d971a3a61f940 (patch) | |
tree | fa573c0f433913c67ae18bfda69d905fb0c52560 /src/main/java | |
parent | 32906ccddb0ae0186928ea56692ae088c22525df (diff) |
Messaging and audio input updates.
Diffstat (limited to 'src/main/java')
4 files changed, 72 insertions, 40 deletions
diff --git a/src/main/java/com/morlunk/jumble/JumbleService.java b/src/main/java/com/morlunk/jumble/JumbleService.java index 1ec785d..487769a 100644 --- a/src/main/java/com/morlunk/jumble/JumbleService.java +++ b/src/main/java/com/morlunk/jumble/JumbleService.java @@ -172,6 +172,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon }; private int mPermissions; + private List<Message> mMessageLog = new ArrayList<Message>(); private boolean mReconnecting; private RemoteCallbackList<IJumbleObserver> mObservers = new RemoteCallbackList<IJumbleObserver>(); @@ -290,6 +291,16 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon } @Override + public List getMessageLog() throws RemoteException { + return mMessageLog; + } + + @Override + public void clearMessageLog() throws RemoteException { + mMessageLog.clear(); + } + + @Override public int getTransmitMode() throws RemoteException { return mTransmitMode; } @@ -413,22 +424,34 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon } @Override - public void sendUserTextMessage(int session, String message) throws RemoteException { + public Message sendUserTextMessage(int session, String message) throws RemoteException { Mumble.TextMessage.Builder tmb = Mumble.TextMessage.newBuilder(); tmb.addSession(session); tmb.setMessage(message); mConnection.sendTCPMessage(tmb.build(), JumbleTCPMessageType.TextMessage); + + User user = getUser(session); + List<User> users = new ArrayList<User>(1); + users.add(user); + Message logMessage = new Message(getSession(), new ArrayList<Channel>(0), new ArrayList<Channel>(0), users, message); + mMessageLog.add(logMessage); + return logMessage; } @Override - public void sendChannelTextMessage(int channel, String message, boolean tree) throws RemoteException { + public Message sendChannelTextMessage(int channel, String message, boolean tree) throws RemoteException { Mumble.TextMessage.Builder tmb = Mumble.TextMessage.newBuilder(); - if(tree) - tmb.addTreeId(channel); - else - tmb.addChannelId(channel); + if(tree) tmb.addTreeId(channel); + else tmb.addChannelId(channel); tmb.setMessage(message); mConnection.sendTCPMessage(tmb.build(), JumbleTCPMessageType.TextMessage); + + Channel targetChannel = getChannel(channel); + List<Channel> targetChannels = new ArrayList<Channel>(); + targetChannels.add(targetChannel); + Message logMessage = new Message(getSession(), targetChannels, tree ? targetChannels : new ArrayList<Channel>(0), new ArrayList<User>(0), message); + mMessageLog.add(logMessage); + return logMessage; } @Override @@ -627,6 +650,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon mChannelHandler = null; mUserHandler = null; + mMessageLog.clear(); } @Override @@ -686,12 +710,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon */ public void logWarning(final String warning) { final Message message = new Message(Message.Type.WARNING, warning); - notifyObservers(new ObserverRunnable() { - @Override - public void run(IJumbleObserver observer) throws RemoteException { - observer.onMessageLogged(message); - } - }); + logMessage(message); } /** @@ -703,12 +722,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon return; // Don't log messages while synchronizing. final Message message = new Message(Message.Type.INFO, info); - notifyObservers(new ObserverRunnable() { - @Override - public void run(IJumbleObserver observer) throws RemoteException { - observer.onMessageLogged(message); - } - }); + logMessage(message); } /** @@ -716,6 +730,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon * @param message A message to log to the client. */ public void logMessage(final Message message) { + mMessageLog.add(message); notifyObservers(new ObserverRunnable() { @Override public void run(IJumbleObserver observer) throws RemoteException { diff --git a/src/main/java/com/morlunk/jumble/audio/AudioInput.java b/src/main/java/com/morlunk/jumble/audio/AudioInput.java index 21bef55..b199dda 100644 --- a/src/main/java/com/morlunk/jumble/audio/AudioInput.java +++ b/src/main/java/com/morlunk/jumble/audio/AudioInput.java @@ -256,7 +256,7 @@ public class AudioInput extends ProtocolHandler implements Runnable { synchronized (mRecordLock) { mRecording = false; try { - mRecordThread.join(); + mRecordLock.wait(); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/src/main/java/com/morlunk/jumble/model/Message.java b/src/main/java/com/morlunk/jumble/model/Message.java index 40f7ee1..b3b3467 100644 --- a/src/main/java/com/morlunk/jumble/model/Message.java +++ b/src/main/java/com/morlunk/jumble/model/Message.java @@ -51,9 +51,9 @@ public class Message implements Parcelable { private Message.Type mType; private int mActor = -1; - private List<Integer> mChannelIds; - private List<Integer> mTreeIds; - private List<Integer> mUserIds; + private List<Channel> mChannels; + private List<Channel> mTrees; + private List<User> mUsers; private String mMessage; private Time mReceivedTime; @@ -68,12 +68,12 @@ public class Message implements Parcelable { mReceivedTime.setToNow(); } - public Message(int actor, List<Integer> channelIds, List<Integer> treeIds, List<Integer> userIds, String message) { + public Message(int actor, List<Channel> channels, List<Channel> trees, List<User> users, String message) { this(Type.TEXT_MESSAGE, message); mActor = actor; - mChannelIds = channelIds; - mTreeIds = treeIds; - mUserIds = userIds; + mChannels = channels; + mTrees = trees; + mUsers = users; } public Message(Parcel parcel) { @@ -83,9 +83,9 @@ public class Message implements Parcelable { public void readFromParcel(Parcel in) { mType = Type.values()[in.readInt()]; mActor = in.readInt(); - mChannelIds = in.readArrayList(null); - mTreeIds = in.readArrayList(null); - mUserIds = in.readArrayList(null); + mChannels = in.readArrayList(null); + mTrees = in.readArrayList(null); + mUsers = in.readArrayList(null); mMessage = in.readString(); mReceivedTime = new Time(); mReceivedTime.set(in.readLong()); @@ -95,16 +95,16 @@ public class Message implements Parcelable { return mActor; } - public List<Integer> getChannelIds() { - return mChannelIds; + public List<Channel> getChannels() { + return mChannels; } - public List<Integer> getTreeIds() { - return mTreeIds; + public List<Channel> getTrees() { + return mTrees; } - public List<Integer> getUserIds() { - return mUserIds; + public List<User> getUsers() { + return mUsers; } public String getMessage() { @@ -128,9 +128,9 @@ public class Message implements Parcelable { public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mType.ordinal()); dest.writeInt(mActor); - dest.writeList(mChannelIds); - dest.writeList(mTreeIds); - dest.writeList(mUserIds); + dest.writeList(mChannels); + dest.writeList(mTrees); + dest.writeList(mUsers); dest.writeString(mMessage); dest.writeLong(mReceivedTime.toMillis(false)); } diff --git a/src/main/java/com/morlunk/jumble/protocol/TextMessageHandler.java b/src/main/java/com/morlunk/jumble/protocol/TextMessageHandler.java index 8a80360..d60c1dd 100644 --- a/src/main/java/com/morlunk/jumble/protocol/TextMessageHandler.java +++ b/src/main/java/com/morlunk/jumble/protocol/TextMessageHandler.java @@ -16,12 +16,18 @@ package com.morlunk.jumble.protocol; +import android.os.RemoteException; + import com.morlunk.jumble.JumbleService; +import com.morlunk.jumble.model.Channel; import com.morlunk.jumble.model.Message; import com.morlunk.jumble.model.User; import com.morlunk.jumble.protobuf.Mumble; import com.morlunk.jumble.util.MessageFormatter; +import java.util.ArrayList; +import java.util.List; + /** * Handles receiving text messages. * Created by andrew on 27/07/13. @@ -39,7 +45,18 @@ public class TextMessageHandler extends ProtocolHandler { if(sender != null && sender.isLocalIgnored()) return; - Message message = new Message(msg.getActor(), msg.getChannelIdList(), msg.getTreeIdList(), msg.getSessionList(), msg.getMessage()); - getService().logMessage(message); + try { + List<Channel> channels = new ArrayList<Channel>(msg.getChannelIdCount()); + for(int channelId : msg.getChannelIdList()) channels.add(getService().getBinder().getChannel(channelId)); + List<Channel> trees = new ArrayList<Channel>(msg.getTreeIdCount()); + for(int treeId : msg.getTreeIdList()) trees.add(getService().getBinder().getChannel(treeId)); + List<User> users = new ArrayList<User>(msg.getSessionCount()); + for(int userId : msg.getSessionList()) users.add(getService().getBinder().getUser(userId)); + + Message message = new Message(msg.getActor(), channels, trees, users, msg.getMessage()); + getService().logMessage(message); + } catch (RemoteException e) { + e.printStackTrace(); + } } } |