diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d6ea206..72ea0dd 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -68,6 +68,10 @@ along with Yaaic. If not, see .
android:label="@string/users"
android:theme="@android:style/Theme.Dialog">
+
+
@@ -85,7 +89,8 @@ along with Yaaic. If not, see .
android:theme="@android:style/Theme.Dialog">
-
+
+
diff --git a/res/layout/aliasadd.xml b/res/layout/aliasadd.xml
new file mode 100644
index 0000000..12958b0
--- /dev/null
+++ b/res/layout/aliasadd.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/aliasitem.xml b/res/layout/aliasitem.xml
new file mode 100644
index 0000000..2548570
--- /dev/null
+++ b/res/layout/aliasitem.xml
@@ -0,0 +1,8 @@
+
+
diff --git a/res/layout/serveradd.xml b/res/layout/serveradd.xml
index 8d417b6..e2ad489 100644
--- a/res/layout/serveradd.xml
+++ b/res/layout/serveradd.xml
@@ -108,6 +108,11 @@ along with Yaaic. If not, see .
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
+
Add server
Select a charset
Nickname
+ Aliases
Ident
Real Name
@@ -48,6 +49,7 @@
Cancel
No
+ These aliases will be used if the main nickname is unavailable.
These channels will be automatically joined after connect.
These commands will be executed after connect.
diff --git a/src/org/jibble/pircbot/PircBot.java b/src/org/jibble/pircbot/PircBot.java
index cdf1817..bca96f9 100644
--- a/src/org/jibble/pircbot/PircBot.java
+++ b/src/org/jibble/pircbot/PircBot.java
@@ -2333,7 +2333,7 @@ public abstract class PircBot implements ReplyConstants {
_name = name;
}
- protected final void setAliases(Collection aliases) {
+ public final void setAliases(Collection aliases) {
_aliases.clear();
_aliases.addAll(aliases);
}
diff --git a/src/org/yaaic/activity/AddAliasActivity.java b/src/org/yaaic/activity/AddAliasActivity.java
new file mode 100644
index 0000000..9b0a003
--- /dev/null
+++ b/src/org/yaaic/activity/AddAliasActivity.java
@@ -0,0 +1,112 @@
+package org.yaaic.activity;
+
+import java.util.ArrayList;
+
+import org.yaaic.R;
+import org.yaaic.model.Extra;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.Window;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ListView;
+import android.widget.AdapterView.OnItemClickListener;
+
+public class AddAliasActivity extends Activity implements OnClickListener, OnItemClickListener
+{
+ private EditText aliasInput;
+ private ArrayAdapter adapter;
+ private ArrayList aliases;
+ private Button okButton;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+
+ setContentView(R.layout.aliasadd);
+
+ aliasInput = (EditText) findViewById(R.id.alias);
+
+ adapter = new ArrayAdapter(this, R.layout.aliasitem);
+
+ ListView list = (ListView) findViewById(R.id.aliases);
+ list.setAdapter(adapter);
+ list.setOnItemClickListener(this);
+
+ ((Button) findViewById(R.id.add)).setOnClickListener(this);
+ ((Button) findViewById(R.id.cancel)).setOnClickListener(this);
+
+ okButton = (Button) findViewById(R.id.ok);
+ okButton.setOnClickListener(this);
+ okButton.setEnabled(false);
+
+ aliases = getIntent().getExtras().getStringArrayList(Extra.ALIASES);
+
+ for (String alias : aliases) {
+ adapter.add(alias);
+ }
+ }
+
+ /**
+ * On Click
+ */
+ public void onClick(View v)
+ {
+ switch (v.getId()) {
+ case R.id.add:
+ String alias = aliasInput.getText().toString().trim();
+ aliases.add(alias);
+ adapter.add(alias);
+ aliasInput.setText("");
+ okButton.setEnabled(true);
+ break;
+ case R.id.cancel:
+ setResult(RESULT_CANCELED);
+ finish();
+ break;
+ case R.id.ok:
+ // Get list and return as result
+ Intent intent = new Intent();
+ intent.putExtra(Extra.ALIASES, aliases);
+ setResult(RESULT_OK, intent);
+ finish();
+ break;
+ }
+ }
+
+ /**
+ * On item clicked
+ */
+ public void onItemClick(AdapterView> list, View item, int position, long id)
+ {
+ final String alias = adapter.getItem(position);
+
+ String[] items = { getResources().getString(R.string.action_remove) };
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(alias);
+ builder.setItems(items, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int item) {
+ switch (item) {
+ case 0: // Remove
+ adapter.remove(alias);
+ aliases.remove(alias);
+ okButton.setEnabled(true);
+ break;
+ }
+ }
+ });
+ AlertDialog alert = builder.create();
+ alert.show();
+ }
+}
diff --git a/src/org/yaaic/activity/AddServerActivity.java b/src/org/yaaic/activity/AddServerActivity.java
index 5b641f1..0975ca0 100644
--- a/src/org/yaaic/activity/AddServerActivity.java
+++ b/src/org/yaaic/activity/AddServerActivity.java
@@ -55,8 +55,10 @@ public class AddServerActivity extends Activity implements OnClickListener
{
private static final int REQUEST_CODE_CHANNELS = 1;
private static final int REQUEST_CODE_COMMANDS = 2;
+ private static final int REQUEST_CODE_ALIASES = 3;
private Server server;
+ private ArrayList aliases;
private ArrayList channels;
private ArrayList commands;
@@ -69,11 +71,13 @@ public class AddServerActivity extends Activity implements OnClickListener
super.onCreate(savedInstanceState);
setContentView(R.layout.serveradd);
+ aliases = new ArrayList();
channels = new ArrayList();
commands = new ArrayList();
((Button) findViewById(R.id.add)).setOnClickListener(this);
((Button) findViewById(R.id.cancel)).setOnClickListener(this);
+ ((Button) findViewById(R.id.aliases)).setOnClickListener(this);
((Button) findViewById(R.id.channels)).setOnClickListener(this);
((Button) findViewById(R.id.commands)).setOnClickListener(this);
@@ -88,6 +92,7 @@ public class AddServerActivity extends Activity implements OnClickListener
// Request to edit an existing server
Database db = new Database(this);
this.server = db.getServerById(extras.getInt(Extra.SERVER));
+ aliases.addAll(server.getIdentity().getAliases());
this.channels = db.getChannelsByServerId(server.getId());
this.commands = db.getCommandsByServerId(server.getId());
db.close();
@@ -138,6 +143,10 @@ public class AddServerActivity extends Activity implements OnClickListener
}
switch (requestCode) {
+ case REQUEST_CODE_ALIASES:
+ aliases.clear();
+ aliases.addAll(data.getExtras().getStringArrayList(Extra.ALIASES));
+ break;
case REQUEST_CODE_CHANNELS:
channels = data.getExtras().getStringArrayList(Extra.CHANNELS);
break;
@@ -153,6 +162,11 @@ public class AddServerActivity extends Activity implements OnClickListener
public void onClick(View v)
{
switch (v.getId()) {
+ case R.id.aliases:
+ Intent aliasIntent = new Intent(this, AddAliasActivity.class);
+ aliasIntent.putExtra(Extra.ALIASES, aliases);
+ startActivityForResult(aliasIntent, REQUEST_CODE_ALIASES);
+ break;
case R.id.channels:
Intent channelIntent = new Intent(this, AddChannelActivity.class);
channelIntent.putExtra(Extra.CHANNELS, channels);
@@ -196,7 +210,8 @@ public class AddServerActivity extends Activity implements OnClickListener
long identityId = db.addIdentity(
identity.getNickname(),
identity.getIdent(),
- identity.getRealName()
+ identity.getRealName(),
+ identity.getAliases()
);
Server server = getServerFromView();
@@ -252,7 +267,8 @@ public class AddServerActivity extends Activity implements OnClickListener
identityId,
identity.getNickname(),
identity.getIdent(),
- identity.getNickname()
+ identity.getNickname(),
+ identity.getAliases()
);
db.setChannels(serverId, channels);
@@ -313,6 +329,8 @@ public class AddServerActivity extends Activity implements OnClickListener
identity.setIdent(ident);
identity.setRealName(realname);
+ identity.setAliases(aliases);
+
return identity;
}
diff --git a/src/org/yaaic/db/AliasConstants.java b/src/org/yaaic/db/AliasConstants.java
new file mode 100644
index 0000000..eadfeb3
--- /dev/null
+++ b/src/org/yaaic/db/AliasConstants.java
@@ -0,0 +1,19 @@
+package org.yaaic.db;
+
+import android.provider.BaseColumns;
+
+public class AliasConstants implements BaseColumns {
+
+ public static final String TABLE_NAME = "aliases";
+
+ // fields
+ public static final String ALIAS = "alias";
+ public static final String IDENTITY = "identity";
+
+ public static final String[] ALL = {
+ _ID,
+ ALIAS,
+ IDENTITY,
+ };
+
+}
diff --git a/src/org/yaaic/db/Database.java b/src/org/yaaic/db/Database.java
index 6e43d6d..03e6af4 100644
--- a/src/org/yaaic/db/Database.java
+++ b/src/org/yaaic/db/Database.java
@@ -22,6 +22,7 @@ package org.yaaic.db;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import org.yaaic.model.Identity;
import org.yaaic.model.Server;
@@ -41,7 +42,7 @@ import android.database.sqlite.SQLiteOpenHelper;
public class Database extends SQLiteOpenHelper
{
private static final String DATABASE_NAME = "servers.db";
- private static final int DATABASE_VERSION = 3;
+ private static final int DATABASE_VERSION = 4;
/**
* Create a new helper for database access
@@ -94,6 +95,13 @@ public class Database extends SQLiteOpenHelper
+ ChannelConstants.SERVER + " INTEGER"
+ ");"
);
+
+ db.execSQL("CREATE TABLE " + AliasConstants.TABLE_NAME + " ("
+ + AliasConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ + AliasConstants.ALIAS + " TEXT NOT NULL, "
+ + AliasConstants.IDENTITY + " INTEGER"
+ + ");"
+ );
}
/**
@@ -125,6 +133,17 @@ public class Database extends SQLiteOpenHelper
+ ChannelConstants.SERVER + " INTEGER"
+ ");"
);
+
+ oldVersion = 3;
+ }
+
+ if (oldVersion == 3) {
+ db.execSQL("CREATE TABLE " + AliasConstants.TABLE_NAME + " ("
+ + AliasConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ + AliasConstants.ALIAS + " TEXT NOT NULL, "
+ + AliasConstants.IDENTITY + " INTEGER"
+ + ");"
+ );
}
}
@@ -471,6 +490,7 @@ public class Database extends SQLiteOpenHelper
// until we have some kind of identity manager
int identityId = this.getIdentityIdByServerId(serverId);
if (identityId != -1) {
+ deleteAliases(identityId);
this.getWritableDatabase().execSQL(
"DELETE FROM " + IdentityConstants.TABLE_NAME + " WHERE " + IdentityConstants._ID + " = " + identityId + ";"
);
@@ -482,6 +502,48 @@ public class Database extends SQLiteOpenHelper
);
}
+ protected void setAliases(long identityId, List aliases)
+ {
+ deleteAliases(identityId);
+
+ ContentValues values = new ContentValues();
+ for (String alias : aliases) {
+ values.clear();
+ values.put(AliasConstants.ALIAS, alias);
+ values.put(AliasConstants.IDENTITY, identityId);
+ getWritableDatabase().insert(AliasConstants.TABLE_NAME, null, values);
+ }
+ }
+
+ protected void deleteAliases(long identityId)
+ {
+ getWritableDatabase().execSQL(
+ "DELETE FROM " + AliasConstants.TABLE_NAME + " WHERE " + AliasConstants.IDENTITY + " = " + identityId
+ );
+ }
+
+ protected List getAliasesByIdentityId(long identityId)
+ {
+ List aliases = new ArrayList();
+
+ Cursor cursor = this.getReadableDatabase().query(
+ AliasConstants.TABLE_NAME,
+ AliasConstants.ALL,
+ AliasConstants.IDENTITY + " = " + identityId,
+ null,
+ null,
+ null,
+ null
+ );
+
+ while (cursor.moveToNext()) {
+ aliases.add(cursor.getString(cursor.getColumnIndex(AliasConstants.ALIAS)));
+ }
+ cursor.close();
+
+ return aliases;
+ }
+
/**
* Add a new identity
*
@@ -489,8 +551,9 @@ public class Database extends SQLiteOpenHelper
* @param nickname
* @param ident
* @param realname
+ * @param aliases
*/
- public long addIdentity(String nickname, String ident, String realname)
+ public long addIdentity(String nickname, String ident, String realname, List aliases)
{
ContentValues values = new ContentValues();
@@ -498,7 +561,11 @@ public class Database extends SQLiteOpenHelper
values.put(IdentityConstants.IDENT, ident);
values.put(IdentityConstants.REALNAME, realname);
- return this.getWritableDatabase().insert(IdentityConstants.TABLE_NAME, null, values);
+ long identityId = this.getWritableDatabase().insert(IdentityConstants.TABLE_NAME, null, values);
+
+ setAliases(identityId, aliases);
+
+ return identityId;
}
/**
@@ -509,7 +576,7 @@ public class Database extends SQLiteOpenHelper
* @param ident
* @param realname
*/
- public void updateIdentity(int identityId, String nickname, String ident, String realname)
+ public void updateIdentity(int identityId, String nickname, String ident, String realname, List aliases)
{
ContentValues values = new ContentValues();
@@ -523,6 +590,8 @@ public class Database extends SQLiteOpenHelper
IdentityConstants._ID + " = " + identityId,
null
);
+
+ setAliases(identityId, aliases);
}
/**
@@ -551,6 +620,8 @@ public class Database extends SQLiteOpenHelper
identity.setNickname(cursor.getString(cursor.getColumnIndex(IdentityConstants.NICKNAME)));
identity.setIdent(cursor.getString(cursor.getColumnIndex(IdentityConstants.IDENT)));
identity.setRealName(cursor.getString(cursor.getColumnIndex(IdentityConstants.REALNAME)));
+
+ identity.setAliases(getAliasesByIdentityId(identityId));
}
cursor.close();
diff --git a/src/org/yaaic/irc/IRCConnection.java b/src/org/yaaic/irc/IRCConnection.java
index 2eeabc2..8a2429a 100644
--- a/src/org/yaaic/irc/IRCConnection.java
+++ b/src/org/yaaic/irc/IRCConnection.java
@@ -21,6 +21,7 @@ along with Yaaic. If not, see .
package org.yaaic.irc;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Vector;
diff --git a/src/org/yaaic/irc/IRCService.java b/src/org/yaaic/irc/IRCService.java
index 151c6fa..7772924 100644
--- a/src/org/yaaic/irc/IRCService.java
+++ b/src/org/yaaic/irc/IRCService.java
@@ -256,6 +256,7 @@ public class IRCService extends Service
IRCConnection connection = getConnection(server.getId());
connection.setNickname(server.getIdentity().getNickname());
+ connection.setAliases(server.getIdentity().getAliases());
connection.setIdent(server.getIdentity().getIdent());
connection.setRealName(server.getIdentity().getRealName());
connection.setUseSSL(server.useSSL());
diff --git a/src/org/yaaic/model/Extra.java b/src/org/yaaic/model/Extra.java
index 8cee141..002d6e3 100644
--- a/src/org/yaaic/model/Extra.java
+++ b/src/org/yaaic/model/Extra.java
@@ -31,6 +31,7 @@ public class Extra
public static final String CONVERSATION = "conversation";
public static final String USERS = "users";
+ public static final String ALIASES = "aliases";
public static final String CHANNELS = "channels";
public static final String COMMANDS = "commands";
public static final String MESSAGE = "message";
diff --git a/src/org/yaaic/model/Identity.java b/src/org/yaaic/model/Identity.java
index e7870eb..e7bec35 100644
--- a/src/org/yaaic/model/Identity.java
+++ b/src/org/yaaic/model/Identity.java
@@ -20,6 +20,11 @@ along with Yaaic. If not, see .
*/
package org.yaaic.model;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
/**
* An identity containing a nickname, an ident and a real name
*
@@ -28,6 +33,7 @@ package org.yaaic.model;
public class Identity
{
private String nickname;
+ private List aliases = new ArrayList();
private String ident;
private String realname;
@@ -51,6 +57,15 @@ public class Identity
return nickname;
}
+ public void setAliases(Collection aliases) {
+ this.aliases.clear();
+ this.aliases.addAll(aliases);
+ }
+
+ public List getAliases() {
+ return Collections.unmodifiableList(aliases);
+ }
+
/**
* Set the ident of this identity
*