mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-23 09:22:19 -05:00
Merge branch 'master' into optimization
Conflicts: src/org/yaaic/activity/ConversationActivity.java src/org/yaaic/irc/IRCService.java
This commit is contained in:
commit
60f4412096
@ -22,18 +22,21 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.yaaic"
|
package="org.yaaic"
|
||||||
android:versionCode="2"
|
android:versionCode="2"
|
||||||
android:versionName="@string/app_version">
|
android:versionName="0.2">
|
||||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
<application
|
||||||
|
android:icon="@drawable/icon"
|
||||||
|
android:label="Yaaic">
|
||||||
<activity
|
<activity
|
||||||
android:name=".view.ServersActivity"
|
android:name=".activity.ServersActivity"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name"
|
||||||
|
android:launchMode="singleTask">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".view.AddServerActivity"
|
android:name=".activity.AddServerActivity"
|
||||||
android:label="@string/add_server_label">
|
android:label="@string/add_server_label">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
@ -43,20 +46,20 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".view.ConversationActivity"
|
android:name=".activity.ConversationActivity"
|
||||||
android:windowSoftInputMode="adjustResize|stateHidden">
|
android:windowSoftInputMode="adjustResize|stateHidden">
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".view.AboutActivity"
|
android:name=".activity.AboutActivity"
|
||||||
android:label="@string/about_label"
|
android:label="@string/about_label"
|
||||||
android:theme="@android:style/Theme.Dialog">
|
android:theme="@android:style/Theme.Dialog">
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".view.SettingsActivity"
|
android:name=".activity.SettingsActivity"
|
||||||
android:label="@string/settings_label">
|
android:label="@string/settings_label">
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".view.JoinActivity"
|
android:name=".activity.JoinActivity"
|
||||||
android:label="@string/join_label"
|
android:label="@string/join_label"
|
||||||
android:theme="@android:style/Theme.Dialog">
|
android:theme="@android:style/Theme.Dialog">
|
||||||
</activity>
|
</activity>
|
||||||
|
@ -24,8 +24,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.yaaic.db.Database;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global Master Class :)
|
* Global Master Class :)
|
||||||
*
|
*
|
||||||
@ -36,6 +39,7 @@ public class Yaaic
|
|||||||
public static Yaaic instance;
|
public static Yaaic instance;
|
||||||
|
|
||||||
private HashMap<Integer, Server> servers;
|
private HashMap<Integer, Server> servers;
|
||||||
|
private boolean serversLoaded = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private constructor, you may want to use static getInstance()
|
* Private constructor, you may want to use static getInstance()
|
||||||
@ -45,6 +49,23 @@ public class Yaaic
|
|||||||
servers = new HashMap<Integer, Server>();
|
servers = new HashMap<Integer, Server>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load servers from database
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
public void loadServers(Context context)
|
||||||
|
{
|
||||||
|
if (!serversLoaded) {
|
||||||
|
Database db = new Database(context);
|
||||||
|
servers = db.getServers();
|
||||||
|
db.close();
|
||||||
|
|
||||||
|
//context.sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
|
||||||
|
serversLoaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get global Yaaic instance
|
* Get global Yaaic instance
|
||||||
*
|
*
|
||||||
|
@ -18,7 +18,7 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.view;
|
package org.yaaic.activity;
|
||||||
|
|
||||||
import org.yaaic.R;
|
import org.yaaic.R;
|
||||||
|
|
@ -18,7 +18,7 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.view;
|
package org.yaaic.activity;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ import org.yaaic.R;
|
|||||||
import org.yaaic.Yaaic;
|
import org.yaaic.Yaaic;
|
||||||
import org.yaaic.db.Database;
|
import org.yaaic.db.Database;
|
||||||
import org.yaaic.exception.ValidationException;
|
import org.yaaic.exception.ValidationException;
|
||||||
import org.yaaic.model.Broadcast;
|
import org.yaaic.model.Extra;
|
||||||
import org.yaaic.model.Identity;
|
import org.yaaic.model.Identity;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
import org.yaaic.model.Status;
|
import org.yaaic.model.Status;
|
||||||
@ -63,10 +63,10 @@ public class AddServerActivity extends Activity implements OnClickListener
|
|||||||
((Button) findViewById(R.id.cancel)).setOnClickListener(this);
|
((Button) findViewById(R.id.cancel)).setOnClickListener(this);
|
||||||
|
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
if (extras != null && extras.containsKey(Broadcast.EXTRA_SERVER)) {
|
if (extras != null && extras.containsKey(Extra.SERVER)) {
|
||||||
// Request to edit an existing server
|
// Request to edit an existing server
|
||||||
Database db = new Database(this);
|
Database db = new Database(this);
|
||||||
this.server = db.getServerById(extras.getInt(Broadcast.EXTRA_SERVER));
|
this.server = db.getServerById(extras.getInt(Extra.SERVER));
|
||||||
db.close();
|
db.close();
|
||||||
|
|
||||||
// Set server values
|
// Set server values
|
@ -18,7 +18,7 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.view;
|
package org.yaaic.activity;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@ -63,6 +63,7 @@ import org.yaaic.model.Server;
|
|||||||
import org.yaaic.model.Status;
|
import org.yaaic.model.Status;
|
||||||
import org.yaaic.receiver.ConversationReceiver;
|
import org.yaaic.receiver.ConversationReceiver;
|
||||||
import org.yaaic.receiver.ServerReceiver;
|
import org.yaaic.receiver.ServerReceiver;
|
||||||
|
import org.yaaic.view.MessageListView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The server view with a scrollable list of all channels
|
* The server view with a scrollable list of all channels
|
||||||
@ -125,7 +126,11 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
|||||||
|
|
||||||
((ImageView) findViewById(R.id.status)).setImageResource(server.getStatusIcon());
|
((ImageView) findViewById(R.id.status)).setImageResource(server.getStatusIcon());
|
||||||
|
|
||||||
bindService(new Intent(this, IRCService.class), this, 0);
|
// Start service
|
||||||
|
Intent intent = new Intent(this, IRCService.class);
|
||||||
|
intent.setAction(IRCService.ACTION_FOREGROUND);
|
||||||
|
startService(intent);
|
||||||
|
bindService(intent, this, 0);
|
||||||
|
|
||||||
channelReceiver = new ConversationReceiver(server.getId(), this);
|
channelReceiver = new ConversationReceiver(server.getId(), this);
|
||||||
registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_MESSAGE));
|
registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_MESSAGE));
|
||||||
@ -163,6 +168,15 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
|||||||
{
|
{
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
|
binder.getService().checkServiceStatus();
|
||||||
|
|
||||||
|
/*if (!binder.getService().hasConnections()) {
|
||||||
|
Log.d("Yaaic", "Stopping service");
|
||||||
|
//binder.getService().stopSelf();
|
||||||
|
} else {
|
||||||
|
Log.d("Yaaic", "Unbinding service");
|
||||||
|
}*/
|
||||||
|
|
||||||
unbindService(this);
|
unbindService(this);
|
||||||
unregisterReceiver(channelReceiver);
|
unregisterReceiver(channelReceiver);
|
||||||
unregisterReceiver(serverReceiver);
|
unregisterReceiver(serverReceiver);
|
||||||
@ -214,10 +228,12 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
|||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.disconnect:
|
case R.id.disconnect:
|
||||||
binder.getService().getConnection(serverId).quitServer();
|
binder.getService().getConnection(serverId).quitServer();
|
||||||
|
server.setStatus(Status.DISCONNECTED);
|
||||||
server.clearConversations();
|
server.clearConversations();
|
||||||
setResult(RESULT_OK);
|
setResult(RESULT_OK);
|
||||||
finish();
|
finish();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.join:
|
case R.id.join:
|
||||||
startActivityForResult(new Intent(this, JoinActivity.class), 0);
|
startActivityForResult(new Intent(this, JoinActivity.class), 0);
|
||||||
break;
|
break;
|
||||||
@ -276,7 +292,9 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
|||||||
deckAdapter.removeItem(target);
|
deckAdapter.removeItem(target);
|
||||||
|
|
||||||
if (deckAdapter.isSwitched()) {
|
if (deckAdapter.isSwitched()) {
|
||||||
onBackPressed();
|
switcher.showNext();
|
||||||
|
switcher.removeView(deckAdapter.getSwitchedView());
|
||||||
|
deckAdapter.setSwitched(null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,31 +333,20 @@ public class ConversationActivity extends Activity implements ServiceConnection,
|
|||||||
/**
|
/**
|
||||||
* On key down
|
* On key down
|
||||||
*
|
*
|
||||||
* This is glue code to call onBackPressed() which
|
* XXX: As we only track the back key: Android >= 2.0 will call a method called onBackPressed()
|
||||||
* will be automatically called by later android releases
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||||
{
|
{
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
|
||||||
onBackPressed();
|
if (deckAdapter.isSwitched()) {
|
||||||
return true;
|
switcher.showNext();
|
||||||
}
|
switcher.removeView(deckAdapter.getSwitchedView());
|
||||||
return false;
|
deckAdapter.setSwitched(null, null);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* On back key pressed
|
|
||||||
*/
|
|
||||||
public void onBackPressed()
|
|
||||||
{
|
|
||||||
if (deckAdapter.isSwitched()) {
|
|
||||||
switcher.showNext();
|
|
||||||
switcher.removeView(deckAdapter.getSwitchedView());
|
|
||||||
deckAdapter.setSwitched(null, null);
|
|
||||||
} else {
|
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -18,7 +18,7 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.view;
|
package org.yaaic.activity;
|
||||||
|
|
||||||
import org.yaaic.R;
|
import org.yaaic.R;
|
||||||
|
|
@ -18,7 +18,7 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.view;
|
package org.yaaic.activity;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
@ -47,6 +47,7 @@ import org.yaaic.irc.IRCService;
|
|||||||
import org.yaaic.layout.NonScalingBackgroundDrawable;
|
import org.yaaic.layout.NonScalingBackgroundDrawable;
|
||||||
import org.yaaic.listener.ServerListener;
|
import org.yaaic.listener.ServerListener;
|
||||||
import org.yaaic.model.Broadcast;
|
import org.yaaic.model.Broadcast;
|
||||||
|
import org.yaaic.model.Extra;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
import org.yaaic.model.Status;
|
import org.yaaic.model.Status;
|
||||||
import org.yaaic.receiver.ServerReceiver;
|
import org.yaaic.receiver.ServerReceiver;
|
||||||
@ -87,6 +88,7 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
|||||||
|
|
||||||
// Start and connect to service
|
// Start and connect to service
|
||||||
Intent intent = new Intent(this, IRCService.class);
|
Intent intent = new Intent(this, IRCService.class);
|
||||||
|
intent.setAction(IRCService.ACTION_BACKGROUND);
|
||||||
startService(intent);
|
startService(intent);
|
||||||
bindService(intent, this, 0);
|
bindService(intent, this, 0);
|
||||||
|
|
||||||
@ -199,7 +201,7 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Intent intent = new Intent(this, AddServerActivity.class);
|
Intent intent = new Intent(this, AddServerActivity.class);
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, serverId);
|
intent.putExtra(Extra.SERVER, serverId);
|
||||||
startActivityForResult(intent, 0);
|
startActivityForResult(intent, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.view;
|
package org.yaaic.activity;
|
||||||
|
|
||||||
import org.yaaic.R;
|
import org.yaaic.R;
|
||||||
|
|
@ -22,6 +22,8 @@ package org.yaaic.command;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
import org.yaaic.command.handler.CloseHandler;
|
import org.yaaic.command.handler.CloseHandler;
|
||||||
import org.yaaic.command.handler.DCCHandler;
|
import org.yaaic.command.handler.DCCHandler;
|
||||||
import org.yaaic.command.handler.DeopHandler;
|
import org.yaaic.command.handler.DeopHandler;
|
||||||
@ -47,8 +49,6 @@ import org.yaaic.model.Conversation;
|
|||||||
import org.yaaic.model.Message;
|
import org.yaaic.model.Message;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parser for commands
|
* Parser for commands
|
||||||
*
|
*
|
||||||
@ -59,6 +59,14 @@ public class CommandParser
|
|||||||
private HashMap<String, BaseHandler> commands;
|
private HashMap<String, BaseHandler> commands;
|
||||||
private static CommandParser instance;
|
private static CommandParser instance;
|
||||||
|
|
||||||
|
private final static String[] serverCommands = {
|
||||||
|
"admin", "motd", "version", "away", "knock", "rules",
|
||||||
|
"vhost", "credits", "license", "setname", "watch", "pong",
|
||||||
|
"cycle", "links", "silence", "who", "dalinfo", "userhost",
|
||||||
|
"list", "stats", "whois", "invite", "lusers", "ping",
|
||||||
|
"time", "whowas", "ison", "map",
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new CommandParser instance
|
* Create a new CommandParser instance
|
||||||
*/
|
*/
|
||||||
@ -106,14 +114,112 @@ public class CommandParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the given command a valid command?
|
* Is the given command a valid client command?
|
||||||
*
|
*
|
||||||
* @param command
|
* @param command The (client) command to check (/command)
|
||||||
* @return
|
* @return true if the command can be handled by the client, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean isCommand(String command)
|
public boolean isClientCommand(String command)
|
||||||
{
|
{
|
||||||
return commands.containsKey(command);
|
return commands.containsKey(command.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the given command a valid server command?
|
||||||
|
*
|
||||||
|
* @param command The (server) command to check (/command)
|
||||||
|
* @return true if the command can be handled by a server, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean isServerCommand(String command)
|
||||||
|
{
|
||||||
|
command = command.toLowerCase();
|
||||||
|
for (String validCommand : serverCommands) {
|
||||||
|
if (validCommand.equals(command)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a client command
|
||||||
|
*
|
||||||
|
* @param type Type of the command (/type param1 param2 ..)
|
||||||
|
* @param params The parameters of the command (0 is the command itself)
|
||||||
|
* @param server The current server
|
||||||
|
* @param conversation The selected conversation
|
||||||
|
* @param service The service handling the connections
|
||||||
|
*/
|
||||||
|
public void handleClientCommand(String type, String[] params, Server server, Conversation conversation, IRCService service)
|
||||||
|
{
|
||||||
|
BaseHandler command = commands.get(type);
|
||||||
|
try {
|
||||||
|
command.execute(params, server, conversation, service);
|
||||||
|
} catch(CommandException e) {
|
||||||
|
// Command could not be executed
|
||||||
|
if (conversation != null) {
|
||||||
|
Message errorMessage = new Message(type + ": " + e.getMessage());
|
||||||
|
errorMessage.setColor(Message.COLOR_RED);
|
||||||
|
conversation.addMessage(errorMessage);
|
||||||
|
|
||||||
|
Message usageMessage = new Message("Syntax: " + command.getUsage());
|
||||||
|
conversation.addMessage(usageMessage);
|
||||||
|
|
||||||
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
|
server.getId(),
|
||||||
|
conversation.getName()
|
||||||
|
);
|
||||||
|
|
||||||
|
service.sendBroadcast(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a server command
|
||||||
|
*
|
||||||
|
* @param type Type of the command (/type param1 param2 ..)
|
||||||
|
* @param params The parameters of the command (0 is the command itself)
|
||||||
|
* @param server The current server
|
||||||
|
* @param conversation The selected conversation
|
||||||
|
* @param service The service handling the connections
|
||||||
|
*/
|
||||||
|
public void handleServerCommand(String type, String[] params, Server server, Conversation conversation, IRCService service)
|
||||||
|
{
|
||||||
|
if (params.length > 1) {
|
||||||
|
service.getConnection(server.getId()).sendRawLineViaQueue(
|
||||||
|
type.toUpperCase() + " " + BaseHandler.mergeParams(params)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
service.getConnection(server.getId()).sendRawLineViaQueue(type.toUpperCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an unknown command
|
||||||
|
*
|
||||||
|
* @param type Type of the command (/type param1 param2 ..)
|
||||||
|
* @param server The current server
|
||||||
|
* @param conversation The selected conversation
|
||||||
|
* @param service The service handling the connections
|
||||||
|
*/
|
||||||
|
public void handleUnknownCommand(String type, Server server, Conversation conversation, IRCService service)
|
||||||
|
{
|
||||||
|
if (conversation != null) {
|
||||||
|
Message message = new Message("Unknown command: " + type);
|
||||||
|
message.setColor(Message.COLOR_RED);
|
||||||
|
conversation.addMessage(message);
|
||||||
|
|
||||||
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
|
server.getId(),
|
||||||
|
conversation.getName()
|
||||||
|
);
|
||||||
|
|
||||||
|
service.sendBroadcast(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,45 +233,12 @@ public class CommandParser
|
|||||||
String[] params = line.split(" ");
|
String[] params = line.split(" ");
|
||||||
String type = params[0];
|
String type = params[0];
|
||||||
|
|
||||||
if (isCommand(type)) {
|
if (isClientCommand(type)) {
|
||||||
BaseHandler command = commands.get(type);
|
handleClientCommand(type, params, server, conversation, service);
|
||||||
try {
|
} else if (isServerCommand(type)) {
|
||||||
command.execute(params, server, conversation, service);
|
handleServerCommand(type, params, server, conversation, service);
|
||||||
} catch(CommandException e) {
|
|
||||||
// Wrong number of params
|
|
||||||
if (conversation != null) {
|
|
||||||
Message errorMessage = new Message(type + ": " + e.getMessage());
|
|
||||||
errorMessage.setColor(Message.COLOR_RED);
|
|
||||||
conversation.addMessage(errorMessage);
|
|
||||||
|
|
||||||
Message usageMessage = new Message("Syntax: " + command.getUsage());
|
|
||||||
conversation.addMessage(usageMessage);
|
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
|
|
||||||
service.sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Unknown command
|
handleUnknownCommand(type, server, conversation, service);
|
||||||
if (params.length > 1) {
|
|
||||||
// Send command to server
|
|
||||||
service.getConnection(server.getId()).sendRawLineViaQueue(
|
|
||||||
params[0].toUpperCase() + " " + BaseHandler.mergeParams(params)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
if (conversation != null) {
|
|
||||||
Message message = new Message("Unknown command: " + type);
|
|
||||||
message.setColor(Message.COLOR_RED);
|
|
||||||
conversation.addMessage(message);
|
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
|
|
||||||
service.sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,9 +55,11 @@ public class CloseHandler extends BaseHandler
|
|||||||
if (conversation.getType() == Conversation.TYPE_QUERY) {
|
if (conversation.getType() == Conversation.TYPE_QUERY) {
|
||||||
server.removeConversation(conversation.getName());
|
server.removeConversation(conversation.getName());
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_REMOVE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_REMOVE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
|
server.getId(),
|
||||||
|
conversation.getName()
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,11 @@ public class EchoHandler extends BaseHandler
|
|||||||
Message message = new Message(BaseHandler.mergeParams(params));
|
Message message = new Message(BaseHandler.mergeParams(params));
|
||||||
conversation.addMessage(message);
|
conversation.addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
|
server.getId(),
|
||||||
|
conversation.getName()
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
} else {
|
} else {
|
||||||
throw new CommandException("Text is missing");
|
throw new CommandException("Text is missing");
|
||||||
|
@ -56,9 +56,11 @@ public class MeHandler extends BaseHandler
|
|||||||
message.setIcon(R.drawable.action);
|
message.setIcon(R.drawable.action);
|
||||||
server.getConversation(conversation.getName()).addMessage(message);
|
server.getConversation(conversation.getName()).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
|
server.getId(),
|
||||||
|
conversation.getName()
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
|
|
||||||
service.getConnection(server.getId()).sendAction(conversation.getName(), action);
|
service.getConnection(server.getId()).sendAction(conversation.getName(), action);
|
||||||
|
@ -63,9 +63,11 @@ public class NamesHandler extends BaseHandler
|
|||||||
message.setColor(Message.COLOR_YELLOW);
|
message.setColor(Message.COLOR_YELLOW);
|
||||||
conversation.addMessage(message);
|
conversation.addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
|
server.getId(),
|
||||||
|
conversation.getName()
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,9 +53,11 @@ public class NoticeHandler extends BaseHandler
|
|||||||
message.setIcon(R.drawable.info);
|
message.setIcon(R.drawable.info);
|
||||||
conversation.addMessage(message);
|
conversation.addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
|
server.getId(),
|
||||||
|
conversation.getName()
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
|
|
||||||
service.getConnection(server.getId()).sendNotice(params[1], text);
|
service.getConnection(server.getId()).sendNotice(params[1], text);
|
||||||
|
@ -59,9 +59,11 @@ public class QueryHandler extends BaseHandler
|
|||||||
|
|
||||||
server.addConversationl(new Query(params[1]));
|
server.addConversationl(new Query(params[1]));
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_NEW);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, params[1]);
|
server.getId(),
|
||||||
|
conversation.getName()
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
} else {
|
} else {
|
||||||
throw new CommandException("Invalid number of params");
|
throw new CommandException("Invalid number of params");
|
||||||
|
@ -77,8 +77,8 @@ public class IRCBinder extends Binder
|
|||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
server.setStatus(Status.DISCONNECTED);
|
server.setStatus(Status.DISCONNECTED);
|
||||||
Intent sIntent = new Intent(Broadcast.SERVER_UPDATE);
|
|
||||||
sIntent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Intent sIntent = Broadcast.createServerIntent(Broadcast.SERVER_UPDATE, server.getId());
|
||||||
service.sendBroadcast(sIntent);
|
service.sendBroadcast(sIntent);
|
||||||
|
|
||||||
IRCConnection connection = getService().getConnection(server.getId());
|
IRCConnection connection = getService().getConnection(server.getId());
|
||||||
@ -97,9 +97,11 @@ public class IRCBinder extends Binder
|
|||||||
message.setIcon(R.drawable.error);
|
message.setIcon(R.drawable.error);
|
||||||
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
||||||
|
|
||||||
Intent cIntent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent cIntent = Broadcast.createConversationIntent(
|
||||||
cIntent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
cIntent.putExtra(Broadcast.EXTRA_CONVERSATION, ServerInfo.DEFAULT_NAME);
|
server.getId(),
|
||||||
|
ServerInfo.DEFAULT_NAME
|
||||||
|
);
|
||||||
service.sendBroadcast(cIntent);
|
service.sendBroadcast(cIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,9 +133,12 @@ public class IRCConnection extends PircBot
|
|||||||
message.setColor(Message.COLOR_GREEN);
|
message.setColor(Message.COLOR_GREEN);
|
||||||
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, ServerInfo.DEFAULT_NAME);
|
server.getId(),
|
||||||
|
ServerInfo.DEFAULT_NAME
|
||||||
|
);
|
||||||
|
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,23 +168,29 @@ public class IRCConnection extends PircBot
|
|||||||
server.addConversationl(conversation);
|
server.addConversationl(conversation);
|
||||||
conversation.addMessage(message);
|
conversation.addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_NEW);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, sender);
|
Broadcast.CONVERSATION_NEW,
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
server.getId(),
|
||||||
|
sender
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, sender);
|
server.getId(),
|
||||||
|
sender
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// A action in a channel
|
// A action in a channel
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,9 +214,12 @@ public class IRCConnection extends PircBot
|
|||||||
message.setColor(Message.COLOR_BLUE);
|
message.setColor(Message.COLOR_BLUE);
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
|
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,9 +234,12 @@ public class IRCConnection extends PircBot
|
|||||||
message.setIcon(R.drawable.voice);
|
message.setIcon(R.drawable.voice);
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
|
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,18 +254,22 @@ public class IRCConnection extends PircBot
|
|||||||
Message message = new Message(sourceNick + " invites you into " + target);
|
Message message = new Message(sourceNick + " invites you into " + target);
|
||||||
server.getConversation(server.getSelectedConversation()).addMessage(message);
|
server.getConversation(server.getSelectedConversation()).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, server.getSelectedConversation());
|
server.getId(),
|
||||||
|
server.getSelectedConversation()
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
} else {
|
} else {
|
||||||
// Someone is invited
|
// Someone is invited
|
||||||
Message message = new Message(sourceNick + " invites " + targetNick + " into " + target);
|
Message message = new Message(sourceNick + " invites " + targetNick + " into " + target);
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,9 +284,11 @@ public class IRCConnection extends PircBot
|
|||||||
// We joined a new channel
|
// We joined a new channel
|
||||||
server.addConversationl(new Channel(target));
|
server.addConversationl(new Channel(target));
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_NEW);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
Broadcast.CONVERSATION_NEW,
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
} else {
|
} else {
|
||||||
Message message = new Message(sender + " joins");
|
Message message = new Message(sender + " joins");
|
||||||
@ -275,9 +296,11 @@ public class IRCConnection extends PircBot
|
|||||||
message.setColor(Message.COLOR_GREEN);
|
message.setColor(Message.COLOR_GREEN);
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,18 +315,22 @@ public class IRCConnection extends PircBot
|
|||||||
// We are kicked
|
// We are kicked
|
||||||
server.removeConversation(target);
|
server.removeConversation(target);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_REMOVE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_REMOVE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
} else {
|
} else {
|
||||||
Message message = new Message(kickerNick + " kicks " + recipientNick);
|
Message message = new Message(kickerNick + " kicks " + recipientNick);
|
||||||
message.setColor(Message.COLOR_GREEN);
|
message.setColor(Message.COLOR_GREEN);
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -326,9 +353,11 @@ public class IRCConnection extends PircBot
|
|||||||
|
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,9 +390,11 @@ public class IRCConnection extends PircBot
|
|||||||
message.setColor(Message.COLOR_GREEN);
|
message.setColor(Message.COLOR_GREEN);
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -389,9 +420,11 @@ public class IRCConnection extends PircBot
|
|||||||
message.setIcon(R.drawable.info);
|
message.setIcon(R.drawable.info);
|
||||||
conversation.addMessage(message);
|
conversation.addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
|
server.getId(),
|
||||||
|
conversation.getName()
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,9 +439,11 @@ public class IRCConnection extends PircBot
|
|||||||
message.setIcon(R.drawable.op);
|
message.setIcon(R.drawable.op);
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,9 +457,11 @@ public class IRCConnection extends PircBot
|
|||||||
// We parted a channel
|
// We parted a channel
|
||||||
server.removeConversation(target);
|
server.removeConversation(target);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_REMOVE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_REMOVE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
} else {
|
} else {
|
||||||
Message message = new Message(sender + " parts");
|
Message message = new Message(sender + " parts");
|
||||||
@ -432,9 +469,11 @@ public class IRCConnection extends PircBot
|
|||||||
message.setIcon(R.drawable.part);
|
message.setIcon(R.drawable.part);
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -462,16 +501,20 @@ public class IRCConnection extends PircBot
|
|||||||
conversation.addMessage(message);
|
conversation.addMessage(message);
|
||||||
server.addConversationl(conversation);
|
server.addConversationl(conversation);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_NEW);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, sender);
|
Broadcast.CONVERSATION_NEW,
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
server.getId(),
|
||||||
|
sender
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
} else {
|
} else {
|
||||||
conversation.addMessage(message);
|
conversation.addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, sender);
|
server.getId(),
|
||||||
|
sender
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -490,9 +533,11 @@ public class IRCConnection extends PircBot
|
|||||||
message.setIcon(R.drawable.quit);
|
message.setIcon(R.drawable.quit);
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,9 +550,11 @@ public class IRCConnection extends PircBot
|
|||||||
message.setIcon(R.drawable.quit);
|
message.setIcon(R.drawable.quit);
|
||||||
conversation.addMessage(message);
|
conversation.addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversation.getName());
|
server.getId(),
|
||||||
|
conversation.getName()
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,9 +585,11 @@ public class IRCConnection extends PircBot
|
|||||||
// remember channel's topic
|
// remember channel's topic
|
||||||
((Channel) server.getConversation(target)).setTopic(topic);
|
((Channel) server.getConversation(target)).setTopic(topic);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,9 +613,11 @@ public class IRCConnection extends PircBot
|
|||||||
message.setColor(Message.COLOR_BLUE);
|
message.setColor(Message.COLOR_BLUE);
|
||||||
server.getConversation(target).addMessage(message);
|
server.getConversation(target).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, target);
|
server.getId(),
|
||||||
|
target
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -851,9 +902,11 @@ public class IRCConnection extends PircBot
|
|||||||
message.setColor(Message.COLOR_GREY);
|
message.setColor(Message.COLOR_GREY);
|
||||||
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, ServerInfo.DEFAULT_NAME);
|
server.getId(),
|
||||||
|
ServerInfo.DEFAULT_NAME
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -887,9 +940,11 @@ public class IRCConnection extends PircBot
|
|||||||
message.setColor(Message.COLOR_GREY);
|
message.setColor(Message.COLOR_GREY);
|
||||||
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent intent = Broadcast.createConversationIntent(
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, ServerInfo.DEFAULT_NAME);
|
server.getId(),
|
||||||
|
ServerInfo.DEFAULT_NAME
|
||||||
|
);
|
||||||
service.sendBroadcast(intent);
|
service.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -900,8 +955,8 @@ public class IRCConnection extends PircBot
|
|||||||
public void onDisconnect()
|
public void onDisconnect()
|
||||||
{
|
{
|
||||||
server.setStatus(Status.DISCONNECTED);
|
server.setStatus(Status.DISCONNECTED);
|
||||||
Intent sIntent = new Intent(Broadcast.SERVER_UPDATE);
|
|
||||||
sIntent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Intent sIntent = Broadcast.createServerIntent(Broadcast.SERVER_UPDATE, server.getId());
|
||||||
service.sendBroadcast(sIntent);
|
service.sendBroadcast(sIntent);
|
||||||
|
|
||||||
Message message = new Message("Disconnected");
|
Message message = new Message("Disconnected");
|
||||||
@ -909,9 +964,11 @@ public class IRCConnection extends PircBot
|
|||||||
message.setColor(Message.COLOR_RED);
|
message.setColor(Message.COLOR_RED);
|
||||||
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message);
|
||||||
|
|
||||||
Intent cIntent = new Intent(Broadcast.CONVERSATION_MESSAGE);
|
Intent cIntent = Broadcast.createConversationIntent(
|
||||||
cIntent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
|
Broadcast.CONVERSATION_MESSAGE,
|
||||||
cIntent.putExtra(Broadcast.EXTRA_CONVERSATION, ServerInfo.DEFAULT_NAME);
|
server.getId(),
|
||||||
|
ServerInfo.DEFAULT_NAME
|
||||||
|
);
|
||||||
service.sendBroadcast(cIntent);
|
service.sendBroadcast(cIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -945,6 +1002,10 @@ public class IRCConnection extends PircBot
|
|||||||
@Override
|
@Override
|
||||||
public void quitServer()
|
public void quitServer()
|
||||||
{
|
{
|
||||||
quitServer("Yaaic - Yet another Android IRC client - http://www.yaaic.org");
|
new Thread() {
|
||||||
|
public void run() {
|
||||||
|
quitServer("Yaaic - Yet another Android IRC client - http://www.yaaic.org");
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,21 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
package org.yaaic.irc;
|
package org.yaaic.irc;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.yaaic.R;
|
||||||
import org.yaaic.Yaaic;
|
import org.yaaic.Yaaic;
|
||||||
import org.yaaic.db.Database;
|
import org.yaaic.db.Database;
|
||||||
import org.yaaic.model.Broadcast;
|
import org.yaaic.model.Broadcast;
|
||||||
|
import org.yaaic.model.Server;
|
||||||
|
import org.yaaic.activity.ServersActivity;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
@ -38,6 +47,21 @@ public class IRCService extends Service
|
|||||||
{
|
{
|
||||||
private IRCBinder binder;
|
private IRCBinder binder;
|
||||||
private HashMap<Integer, IRCConnection> connections;
|
private HashMap<Integer, IRCConnection> connections;
|
||||||
|
private boolean foreground = false;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static final Class[] mStartForegroundSignature = new Class[] { int.class, Notification.class };
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static final Class[] mStopForegroundSignature = new Class[] { boolean.class };
|
||||||
|
|
||||||
|
public static final String ACTION_FOREGROUND = "org.yaaic.service.foreground";
|
||||||
|
public static final String ACTION_BACKGROUND = "org.yaaic.service.background";
|
||||||
|
|
||||||
|
private NotificationManager mNM;
|
||||||
|
private Method mStartForeground;
|
||||||
|
private Method mStopForeground;
|
||||||
|
private Object[] mStartForegroundArgs = new Object[2];
|
||||||
|
private Object[] mStopForegroundArgs = new Object[1];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new service
|
* Create new service
|
||||||
@ -50,13 +74,25 @@ public class IRCService extends Service
|
|||||||
this.binder = new IRCBinder(this);
|
this.binder = new IRCBinder(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On create
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate()
|
public void onCreate()
|
||||||
{
|
{
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
try {
|
||||||
|
mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature);
|
||||||
|
mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
// Running on an older platform.
|
||||||
|
mStartForeground = mStopForeground = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Load servers from Database
|
// Load servers from Database
|
||||||
Database db = new Database(this);
|
Database db = new Database(this);
|
||||||
Yaaic.getInstance().setServers(db.getServers());
|
Yaaic.getInstance().setServers(db.getServers());
|
||||||
db.close();
|
db.close();
|
||||||
|
|
||||||
@ -64,12 +100,111 @@ public class IRCService extends Service
|
|||||||
sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
|
sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On start (will be called on pre-2.0 platform. On 2.0 or later onStartCommand()
|
||||||
|
* will be called)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onStart(Intent intent, int startId)
|
public void onStart(Intent intent, int startId)
|
||||||
{
|
{
|
||||||
super.onStart(intent, startId);
|
super.onStart(intent, startId);
|
||||||
|
handleCommand(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On start command (Android >= 2.0)
|
||||||
|
*
|
||||||
|
* @param intent
|
||||||
|
* @param flags
|
||||||
|
* @param startId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int onStartCommand(Intent intent, int flags, int startId)
|
||||||
|
{
|
||||||
|
handleCommand(intent);
|
||||||
|
|
||||||
|
// We want this service to continue running until it is explicitly
|
||||||
|
// stopped, so return sticky.
|
||||||
|
//return START_STICKY;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle command
|
||||||
|
*
|
||||||
|
* @param intent
|
||||||
|
*/
|
||||||
|
private void handleCommand(Intent intent)
|
||||||
|
{
|
||||||
|
if (ACTION_FOREGROUND.equals(intent.getAction())) {
|
||||||
|
foreground = true;
|
||||||
|
|
||||||
|
// Set the icon, scrolling text and timestamp
|
||||||
|
Notification notification = new Notification(R.drawable.icon, "Connected", System.currentTimeMillis());
|
||||||
|
|
||||||
|
// The PendingIntent to launch our activity if the user selects this notification
|
||||||
|
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ServersActivity.class), 0);
|
||||||
|
|
||||||
|
// Set the info for the views that show in the notification panel.
|
||||||
|
notification.setLatestEventInfo(this, getText(R.string.app_name), "Connected", contentIntent);
|
||||||
|
|
||||||
|
startForegroundCompat(R.string.app_name, notification);
|
||||||
|
} else if (ACTION_BACKGROUND.equals(intent.getAction()) && !foreground) {
|
||||||
|
stopForegroundCompat(R.string.app_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a wrapper around the new startForeground method, using the older
|
||||||
|
* APIs if it is not available.
|
||||||
|
*/
|
||||||
|
private void startForegroundCompat(int id, Notification notification)
|
||||||
|
{
|
||||||
|
// If we have the new startForeground API, then use it.
|
||||||
|
if (mStartForeground != null) {
|
||||||
|
mStartForegroundArgs[0] = Integer.valueOf(id);
|
||||||
|
mStartForegroundArgs[1] = notification;
|
||||||
|
try {
|
||||||
|
mStartForeground.invoke(this, mStartForegroundArgs);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
// Should not happen.
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// Should not happen.
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fall back on the old API.
|
||||||
|
setForeground(true);
|
||||||
|
mNM.notify(id, notification);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a wrapper around the new stopForeground method, using the older
|
||||||
|
* APIs if it is not available.
|
||||||
|
*/
|
||||||
|
private void stopForegroundCompat(int id)
|
||||||
|
{
|
||||||
|
// If we have the new stopForeground API, then use it.
|
||||||
|
if (mStopForeground != null) {
|
||||||
|
mStopForegroundArgs[0] = Boolean.TRUE;
|
||||||
|
try {
|
||||||
|
mStopForeground.invoke(this, mStopForegroundArgs);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
// Should not happen.
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// Should not happen.
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fall back on the old API. Note to cancel BEFORE changing the
|
||||||
|
// foreground state, since we could be killed at that point.
|
||||||
|
mNM.cancel(id);
|
||||||
|
setForeground(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get connection for given server
|
* Get connection for given server
|
||||||
*
|
*
|
||||||
@ -88,6 +223,42 @@ public class IRCService extends Service
|
|||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check status of service
|
||||||
|
*/
|
||||||
|
public void checkServiceStatus()
|
||||||
|
{
|
||||||
|
boolean shutDown = true;
|
||||||
|
ArrayList<Server> mServers = Yaaic.getInstance().getServersAsArrayList();
|
||||||
|
int mSize = mServers.size();
|
||||||
|
Server server;
|
||||||
|
|
||||||
|
for (int i = 0; i < mSize; i++) {
|
||||||
|
server = mServers.get(i);
|
||||||
|
if (server.isDisconnected()) {
|
||||||
|
connections.remove(server.getId());
|
||||||
|
} else {
|
||||||
|
shutDown = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shutDown) {
|
||||||
|
foreground = false;
|
||||||
|
stopSelf();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On Destroy
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onDestroy()
|
||||||
|
{
|
||||||
|
// Make sure our notification is gone.
|
||||||
|
stopForegroundCompat(R.string.app_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On Activity binding to this service
|
* On Activity binding to this service
|
||||||
*
|
*
|
||||||
|
@ -35,23 +35,36 @@ public abstract class Broadcast
|
|||||||
public static final String CONVERSATION_NEW = "org.yaaic.conversation.new";
|
public static final String CONVERSATION_NEW = "org.yaaic.conversation.new";
|
||||||
public static final String CONVERSATION_REMOVE = "org.yaaic.conversation.remove";
|
public static final String CONVERSATION_REMOVE = "org.yaaic.conversation.remove";
|
||||||
|
|
||||||
public static final String EXTRA_SERVER = "server";
|
|
||||||
public static final String EXTRA_CONVERSATION = "conversation";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an intent for conversation broadcasting
|
* Create an Intent for conversation broadcasting
|
||||||
*
|
*
|
||||||
* @param broadcastType The type of the broadcast, some constant of Broadcast.*
|
* @param broadcastType The type of the broadcast, some constant of Broadcast.*
|
||||||
* @param serverId The id of the server
|
* @param serverId The id of the server
|
||||||
* @param conversationName The unique name of the conversation
|
* @param conversationName The unique name of the conversation
|
||||||
* @return
|
* @return The created Intent
|
||||||
*/
|
*/
|
||||||
public static Intent createConversationIntent(String broadcastType, int serverId, String conversationName)
|
public static Intent createConversationIntent(String broadcastType, int serverId, String conversationName)
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(broadcastType);
|
Intent intent = new Intent(broadcastType);
|
||||||
|
|
||||||
intent.putExtra(Broadcast.EXTRA_SERVER, serverId);
|
intent.putExtra(Extra.SERVER, serverId);
|
||||||
intent.putExtra(Broadcast.EXTRA_CONVERSATION, conversationName);
|
intent.putExtra(Extra.CONVERSATION, conversationName);
|
||||||
|
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an Intent for server broadcasting
|
||||||
|
*
|
||||||
|
* @param broadcastType The typo of the broadcast, some constant of Broadcast.*
|
||||||
|
* @param serverId The id of the server
|
||||||
|
* @return The created Intent
|
||||||
|
*/
|
||||||
|
public static Intent createServerIntent(String broadcastType, int serverId)
|
||||||
|
{
|
||||||
|
Intent intent = new Intent(broadcastType);
|
||||||
|
|
||||||
|
intent.putExtra(Extra.SERVER, serverId);
|
||||||
|
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
32
src/org/yaaic/model/Extra.java
Normal file
32
src/org/yaaic/model/Extra.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
Yaaic - Yet Another Android IRC Client
|
||||||
|
|
||||||
|
Copyright 2009-2010 Sebastian Kaspari
|
||||||
|
|
||||||
|
This file is part of Yaaic.
|
||||||
|
|
||||||
|
Yaaic is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Yaaic is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.yaaic.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class for constants used for bundle params (extras)
|
||||||
|
*
|
||||||
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
|
*/
|
||||||
|
public class Extra
|
||||||
|
{
|
||||||
|
public static final String SERVER = "server";
|
||||||
|
public static final String CONVERSATION = "conversation";
|
||||||
|
}
|
@ -26,6 +26,7 @@ import android.content.Intent;
|
|||||||
|
|
||||||
import org.yaaic.listener.ConversationListener;
|
import org.yaaic.listener.ConversationListener;
|
||||||
import org.yaaic.model.Broadcast;
|
import org.yaaic.model.Broadcast;
|
||||||
|
import org.yaaic.model.Extra;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A channel receiver for receiving channel updates
|
* A channel receiver for receiving channel updates
|
||||||
@ -58,7 +59,7 @@ public class ConversationReceiver extends BroadcastReceiver
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent)
|
public void onReceive(Context context, Intent intent)
|
||||||
{
|
{
|
||||||
int serverId = intent.getExtras().getInt(Broadcast.EXTRA_SERVER);
|
int serverId = intent.getExtras().getInt(Extra.SERVER);
|
||||||
if (serverId != this.serverId) {
|
if (serverId != this.serverId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -66,11 +67,11 @@ public class ConversationReceiver extends BroadcastReceiver
|
|||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
|
||||||
if (action.equals(Broadcast.CONVERSATION_MESSAGE)) {
|
if (action.equals(Broadcast.CONVERSATION_MESSAGE)) {
|
||||||
listener.onConversationMessage(intent.getExtras().getString(Broadcast.EXTRA_CONVERSATION));
|
listener.onConversationMessage(intent.getExtras().getString(Extra.CONVERSATION));
|
||||||
} else if (action.equals(Broadcast.CONVERSATION_NEW)) {
|
} else if (action.equals(Broadcast.CONVERSATION_NEW)) {
|
||||||
listener.onNewConversation(intent.getExtras().getString(Broadcast.EXTRA_CONVERSATION));
|
listener.onNewConversation(intent.getExtras().getString(Extra.CONVERSATION));
|
||||||
} else if (action.equals(Broadcast.CONVERSATION_REMOVE)) {
|
} else if (action.equals(Broadcast.CONVERSATION_REMOVE)) {
|
||||||
listener.onRemoveConversation(intent.getExtras().getString(Broadcast.EXTRA_CONVERSATION));
|
listener.onRemoveConversation(intent.getExtras().getString(Extra.CONVERSATION));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user