mirror of
https://github.com/moparisthebest/Yaaic
synced 2025-02-16 15:00:14 -05:00
ServerActivity: Only handle broadcasts for the assigned server
This commit is contained in:
parent
38fe74fcc9
commit
c8772cea66
@ -20,25 +20,38 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.yaaic.receiver;
|
||||
|
||||
import org.yaaic.listener.ChannelListener;
|
||||
import org.yaaic.model.Broadcast;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.yaaic.listener.ChannelListener;
|
||||
import org.yaaic.model.Broadcast;
|
||||
|
||||
public class ChannelReceiver extends BroadcastReceiver
|
||||
{
|
||||
private ChannelListener listener;
|
||||
private int serverId;
|
||||
|
||||
public ChannelReceiver(ChannelListener listener)
|
||||
/**
|
||||
* Create a new channel reciever
|
||||
*
|
||||
* @param serverId Only listen on channels of this server
|
||||
* @param listener
|
||||
*/
|
||||
public ChannelReceiver(int serverId, ChannelListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
this.serverId = serverId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
int serverId = intent.getExtras().getInt(Broadcast.EXTRA_SERVER);
|
||||
if (serverId != this.serverId) {
|
||||
return;
|
||||
}
|
||||
|
||||
String action = intent.getAction();
|
||||
|
||||
if (action.equals(Broadcast.CHANNEL_MESSAGE)) {
|
||||
|
@ -111,7 +111,7 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann
|
||||
Intent intent = new Intent(this, IRCService.class);
|
||||
bindService(intent, this, 0);
|
||||
|
||||
receiver = new ChannelReceiver(this);
|
||||
receiver = new ChannelReceiver(server.getId(), this);
|
||||
registerReceiver(receiver, new IntentFilter(Broadcast.CHANNEL_MESSAGE));
|
||||
registerReceiver(receiver, new IntentFilter(Broadcast.CHANNEL_NEW));
|
||||
registerReceiver(receiver, new IntentFilter(Broadcast.CHANNEL_REMOVE));
|
||||
@ -177,6 +177,16 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get server object assigned to this activity
|
||||
*
|
||||
* @return the server object
|
||||
*/
|
||||
public Server getServer()
|
||||
{
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* On channel message
|
||||
|
Loading…
Reference in New Issue
Block a user