Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update all broadcast sending to use LocalBroadcastManager. #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions application/src/org/yaaic/Yaaic.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
import org.yaaic.model.Server;

import android.content.Context;
import android.support.v4.content.LocalBroadcastManager;

/**
* Global Master Class :)
*
*
* @author Sebastian Kaspari <[email protected]>
*/
public class Yaaic
Expand All @@ -51,7 +52,7 @@ private Yaaic()

/**
* Load servers from database
*
*
* @param context
*/
public void loadServers(Context context)
Expand All @@ -61,14 +62,14 @@ public void loadServers(Context context)
servers = db.getServers();
db.close();

// context.sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
// LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
serversLoaded = true;
}
}

/**
* Get global Yaaic instance
*
*
* @return the global Yaaic instance
*/
public static Yaaic getInstance()
Expand All @@ -82,7 +83,7 @@ public static Yaaic getInstance()

/**
* Get server by id
*
*
* @return Server object with given unique id
*/
public Server getServerById(int serverId)
Expand All @@ -92,7 +93,7 @@ public Server getServerById(int serverId)

/**
* Remove server with given unique id from list
*
*
* @param serverId
*/
public void removeServerById(int serverId)
Expand All @@ -102,7 +103,7 @@ public void removeServerById(int serverId)

/**
* Set servers
*
*
* @param servers
*/
public void setServers(HashMap<Integer, Server> servers)
Expand Down Expand Up @@ -130,7 +131,7 @@ public void updateServer(Server server)

/**
* Get list of servers
*
*
* @return list of servers
*/
public ArrayList<Server> getServersAsArrayList()
Expand Down
12 changes: 7 additions & 5 deletions application/src/org/yaaic/activity/ConversationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import android.os.Handler;
import android.os.IBinder;
import android.speech.RecognizerIntent;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.ViewPager;
import android.text.InputType;
import android.text.method.TextKeyListener;
Expand Down Expand Up @@ -715,11 +716,12 @@ public void run() {
server.addConversation(query);

Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_NEW,
server.getId(),
nicknameWithoutPrefix
);
binder.getService().sendBroadcast(intent);
Broadcast.CONVERSATION_NEW,
server.getId(),
nicknameWithoutPrefix
);

LocalBroadcastManager.getInstance(binder.getService()).sendBroadcast(intent);
}
break;
case User.ACTION_OP:
Expand Down
3 changes: 2 additions & 1 deletion application/src/org/yaaic/command/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.yaaic.model.Server;

import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

/**
* Parser for commands
Expand Down Expand Up @@ -195,7 +196,7 @@ public void handleClientCommand(String type, String[] params, Server server, Con
conversation.getName()
);

service.sendBroadcast(intent);
LocalBroadcastManager.getInstance(service).sendBroadcast(intent);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion application/src/org/yaaic/command/handler/AMsgHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

/**
* Command: /amsg <message>
Expand Down Expand Up @@ -65,7 +66,7 @@ public void execute(String[] params, Server server, Conversation conversation, I
currentConversation.getName()
);

service.sendBroadcast(intent);
LocalBroadcastManager.getInstance(service).sendBroadcast(intent);

service.getConnection(server.getId()).sendMessage(currentConversation.getName(), text);
}
Expand Down
8 changes: 5 additions & 3 deletions application/src/org/yaaic/command/handler/CloseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

/**
* Command: /close
*
*
* Closes the current window
*
*
* @author Sebastian Kaspari <[email protected]>
*/
public class CloseHandler extends BaseHandler
Expand All @@ -62,7 +63,8 @@ public void execute(String[] params, Server server, Conversation conversation, I
server.getId(),
conversation.getName()
);
service.sendBroadcast(intent);

LocalBroadcastManager.getInstance(service).sendBroadcast(intent);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion application/src/org/yaaic/command/handler/DCCHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.yaaic.model.Server;

import android.content.Context;
import android.support.v4.content.LocalBroadcastManager;

/**
* Command: /dcc SEND <nickname> <file>
Expand Down Expand Up @@ -63,7 +64,7 @@ public void execute(String[] params, Server server, Conversation conversation, I
message.setColor(Message.COLOR_GREY);
conversation.addMessage(message);

service.sendBroadcast(
LocalBroadcastManager.getInstance(service).sendBroadcast(
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), conversation.getName())
);
} else {
Expand Down
3 changes: 2 additions & 1 deletion application/src/org/yaaic/command/handler/EchoHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

/**
* Command: /echo <text>
Expand All @@ -54,7 +55,7 @@ public void execute(String[] params, Server server, Conversation conversation, I
server.getId(),
conversation.getName()
);
service.sendBroadcast(intent);
LocalBroadcastManager.getInstance(service).sendBroadcast(intent);
} else {
throw new CommandException(service.getString(R.string.text_missing));
}
Expand Down
11 changes: 6 additions & 5 deletions application/src/org/yaaic/command/handler/HelpHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

/**
* Command: /help
*
*
* @author Karol Gliniecki <[email protected]>
* @author Sebastian Kaspari <[email protected]>
*/
Expand All @@ -61,7 +62,7 @@ public void execute(String[] params, Server server, Conversation conversation, I

/**
* Show all available commands
*
*
* @param conversation
* @param server
* @param service
Expand Down Expand Up @@ -100,12 +101,12 @@ private void showAllCommands(IRCService service, Server server, Conversation con
conversation.getName()
);

service.sendBroadcast(intent);
LocalBroadcastManager.getInstance(service).sendBroadcast(intent);
}

/**
* Show details of a single command
*
*
* @param conversation
* @param server
* @param service
Expand All @@ -129,7 +130,7 @@ private void showCommandDetails(IRCService service, Server server, Conversation
conversation.getName()
);

service.sendBroadcast(intent);
LocalBroadcastManager.getInstance(service).sendBroadcast(intent);
} else {
throw new CommandException(service.getString(R.string.unknown_command, command));
}
Expand Down
3 changes: 2 additions & 1 deletion application/src/org/yaaic/command/handler/MeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

/**
* Command: /me <action>
Expand Down Expand Up @@ -62,7 +63,7 @@ public void execute(String[] params, Server server, Conversation conversation, I
server.getId(),
conversation.getName()
);
service.sendBroadcast(intent);
LocalBroadcastManager.getInstance(service).sendBroadcast(intent);

service.getConnection(server.getId()).sendAction(conversation.getName(), action);
} else {
Expand Down
3 changes: 2 additions & 1 deletion application/src/org/yaaic/command/handler/MsgHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

/**
* Command: /msg <target> <message>
Expand Down Expand Up @@ -63,7 +64,7 @@ public void execute(String[] params, Server server, Conversation conversation, I
targetConversation.getName()
);

service.sendBroadcast(intent);
LocalBroadcastManager.getInstance(service).sendBroadcast(intent);
}
} else {
throw new CommandException(service.getString(R.string.invalid_number_of_params));
Expand Down
3 changes: 2 additions & 1 deletion application/src/org/yaaic/command/handler/NamesHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

/**
* Command: /names
Expand Down Expand Up @@ -70,7 +71,7 @@ public void execute(String[] params, Server server, Conversation conversation, I
server.getId(),
conversation.getName()
);
service.sendBroadcast(intent);
LocalBroadcastManager.getInstance(service).sendBroadcast(intent);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion application/src/org/yaaic/command/handler/NoticeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

/**
* Command: /notice <nickname> <message>
Expand Down Expand Up @@ -59,7 +60,7 @@ public void execute(String[] params, Server server, Conversation conversation, I
server.getId(),
conversation.getName()
);
service.sendBroadcast(intent);
LocalBroadcastManager.getInstance(service).sendBroadcast(intent);

service.getConnection(server.getId()).sendNotice(params[1], text);
} else {
Expand Down
3 changes: 2 additions & 1 deletion application/src/org/yaaic/command/handler/QueryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;

/**
* Command: /query <nickname>
Expand Down Expand Up @@ -68,7 +69,7 @@ public void execute(String[] params, Server server, Conversation conversation, I
server.getId(),
query.getName()
);
service.sendBroadcast(intent);
LocalBroadcastManager.getInstance(service).sendBroadcast(intent);
} else {
throw new CommandException(service.getString(R.string.invalid_number_of_params));
}
Expand Down
Loading