mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-26 02:42:16 -05:00
Aliases are now configurable.
This commit is contained in:
parent
b9c1363a2d
commit
288a1a9093
@ -68,6 +68,10 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
android:label="@string/users"
|
||||
android:theme="@android:style/Theme.Dialog">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.AddAliasActivity"
|
||||
android:theme="@android:style/Theme.Dialog">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.AddChannelActivity"
|
||||
android:theme="@android:style/Theme.Dialog">
|
||||
@ -85,7 +89,8 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
android:theme="@android:style/Theme.Dialog">
|
||||
</activity>
|
||||
<service android:name=".irc.IRCService"></service>
|
||||
</application>
|
||||
|
||||
</application>
|
||||
|
||||
<uses-sdk android:minSdkVersion="3" />
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
|
48
res/layout/aliasadd.xml
Normal file
48
res/layout/aliasadd.xml
Normal file
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/alias_add_description"
|
||||
android:padding="5px" />
|
||||
<ListView
|
||||
android:id="@+id/aliases"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<EditText
|
||||
android:id="@+id/alias"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:text=""
|
||||
android:layout_weight="1" />
|
||||
<Button
|
||||
android:id="@+id/add"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Add" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/ok"
|
||||
android:text="Ok" />
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/cancel"
|
||||
android:text="Cancel" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
8
res/layout/aliasitem.xml
Normal file
8
res/layout/aliasitem.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/host"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="7px"
|
||||
android:text=""
|
||||
android:textSize="12px" />
|
@ -108,6 +108,11 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true" />
|
||||
<Button
|
||||
android:id="@+id/aliases"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/aliases" />
|
||||
<TextView
|
||||
android:text="@string/ident"
|
||||
android:layout_width="fill_parent"
|
||||
|
@ -22,6 +22,7 @@
|
||||
<string name="add_server">Add server</string>
|
||||
<string name="select_charset">Select a charset</string>
|
||||
<string name="nickname">Nickname</string>
|
||||
<string name="aliases">Aliases</string>
|
||||
<string name="ident">Ident</string>
|
||||
<string name="realname">Real Name</string>
|
||||
|
||||
@ -48,6 +49,7 @@
|
||||
<string name="action_cancel">Cancel</string>
|
||||
<string name="negative_button">No</string>
|
||||
|
||||
<string name="alias_add_description">These aliases will be used if the main nickname is unavailable.</string>
|
||||
<string name="channel_add_description">These channels will be automatically joined after connect.</string>
|
||||
<string name="command_add_description">These commands will be executed after connect.</string>
|
||||
|
||||
|
@ -2333,7 +2333,7 @@ public abstract class PircBot implements ReplyConstants {
|
||||
_name = name;
|
||||
}
|
||||
|
||||
protected final void setAliases(Collection<String> aliases) {
|
||||
public final void setAliases(Collection<String> aliases) {
|
||||
_aliases.clear();
|
||||
_aliases.addAll(aliases);
|
||||
}
|
||||
|
112
src/org/yaaic/activity/AddAliasActivity.java
Normal file
112
src/org/yaaic/activity/AddAliasActivity.java
Normal file
@ -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<String> adapter;
|
||||
private ArrayList<String> 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<String>(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();
|
||||
}
|
||||
}
|
@ -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<String> aliases;
|
||||
private ArrayList<String> channels;
|
||||
private ArrayList<String> commands;
|
||||
|
||||
@ -69,11 +71,13 @@ public class AddServerActivity extends Activity implements OnClickListener
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.serveradd);
|
||||
aliases = new ArrayList<String>();
|
||||
channels = new ArrayList<String>();
|
||||
commands = new ArrayList<String>();
|
||||
|
||||
((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;
|
||||
}
|
||||
|
||||
|
19
src/org/yaaic/db/AliasConstants.java
Normal file
19
src/org/yaaic/db/AliasConstants.java
Normal file
@ -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,
|
||||
};
|
||||
|
||||
}
|
@ -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<String> 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<String> getAliasesByIdentityId(long identityId)
|
||||
{
|
||||
List<String> aliases = new ArrayList<String>();
|
||||
|
||||
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<String> 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<String> 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();
|
||||
|
@ -21,6 +21,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
package org.yaaic.irc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Vector;
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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";
|
||||
|
@ -20,6 +20,11 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<String> aliases = new ArrayList<String>();
|
||||
private String ident;
|
||||
private String realname;
|
||||
|
||||
@ -51,6 +57,15 @@ public class Identity
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setAliases(Collection<String> aliases) {
|
||||
this.aliases.clear();
|
||||
this.aliases.addAll(aliases);
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
return Collections.unmodifiableList(aliases);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ident of this identity
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user