mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-26 02:42:16 -05:00
Code cleanup (Formatting)
This commit is contained in:
parent
4edaa4436d
commit
0fb2338f9c
@ -17,7 +17,7 @@ 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -36,11 +36,11 @@ import android.content.Context;
|
||||
*/
|
||||
public class Yaaic
|
||||
{
|
||||
public static Yaaic instance;
|
||||
|
||||
public static Yaaic instance;
|
||||
|
||||
private HashMap<Integer, Server> servers;
|
||||
private boolean serversLoaded = false;
|
||||
|
||||
private boolean serversLoaded = false;
|
||||
|
||||
/**
|
||||
* Private constructor, you may want to use static getInstance()
|
||||
*/
|
||||
@ -48,7 +48,7 @@ public class Yaaic
|
||||
{
|
||||
servers = new HashMap<Integer, Server>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load servers from database
|
||||
*
|
||||
@ -60,12 +60,12 @@ public class Yaaic
|
||||
Database db = new Database(context);
|
||||
servers = db.getServers();
|
||||
db.close();
|
||||
|
||||
//context.sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
|
||||
|
||||
// context.sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
|
||||
serversLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get global Yaaic instance
|
||||
*
|
||||
@ -74,12 +74,12 @@ public class Yaaic
|
||||
public static Yaaic getInstance()
|
||||
{
|
||||
if (instance == null) {
|
||||
instance = new Yaaic();
|
||||
instance = new Yaaic();
|
||||
}
|
||||
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get server by id
|
||||
*
|
||||
@ -89,7 +89,7 @@ public class Yaaic
|
||||
{
|
||||
return servers.get(serverId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove server with given unique id from list
|
||||
*
|
||||
@ -99,7 +99,7 @@ public class Yaaic
|
||||
{
|
||||
servers.remove(serverId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set servers
|
||||
*
|
||||
@ -109,7 +109,7 @@ public class Yaaic
|
||||
{
|
||||
this.servers = servers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add server to list
|
||||
*/
|
||||
@ -119,7 +119,7 @@ public class Yaaic
|
||||
servers.put(server.getId(), server);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a server in list
|
||||
*/
|
||||
@ -127,7 +127,7 @@ public class Yaaic
|
||||
{
|
||||
servers.put(server.getId(), server);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get list of servers
|
||||
*
|
||||
@ -136,12 +136,12 @@ public class Yaaic
|
||||
public ArrayList<Server> getServersAsArrayList()
|
||||
{
|
||||
ArrayList<Server> serverList = new ArrayList<Server>();
|
||||
|
||||
|
||||
Set<Integer> mKeys = servers.keySet();
|
||||
for (int key : mKeys) {
|
||||
serverList.add(servers.get(key));
|
||||
}
|
||||
|
||||
|
||||
return serverList;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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.activity;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -40,9 +40,9 @@ public class AboutActivity extends Activity
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
|
||||
setContentView(R.layout.about);
|
||||
}
|
||||
}
|
||||
|
@ -13,14 +13,14 @@ import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
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, TextWatcher
|
||||
{
|
||||
@ -35,18 +35,18 @@ public class AddAliasActivity extends Activity implements OnClickListener, OnIte
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
|
||||
setContentView(R.layout.aliasadd);
|
||||
|
||||
|
||||
aliasInput = (EditText) findViewById(R.id.alias);
|
||||
aliasInput.addTextChangedListener(this);
|
||||
|
||||
|
||||
adapter = new ArrayAdapter<String>(this, R.layout.aliasitem);
|
||||
|
||||
|
||||
ListView list = (ListView) findViewById(R.id.aliases);
|
||||
list.setAdapter(adapter);
|
||||
list.setOnItemClickListener(this);
|
||||
|
||||
|
||||
addButton = (Button) findViewById(R.id.add);
|
||||
addButton.setOnClickListener(this);
|
||||
((Button) findViewById(R.id.cancel)).setOnClickListener(this);
|
||||
@ -56,74 +56,80 @@ public class AddAliasActivity extends Activity implements OnClickListener, OnIte
|
||||
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;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
/**
|
||||
* On item clicked
|
||||
*/
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> list, View item, int position, long id)
|
||||
{
|
||||
final String alias = adapter.getItem(position);
|
||||
|
||||
public void afterTextChanged(Editable s) {
|
||||
// Do nothing.
|
||||
}
|
||||
String[] items = { getResources().getString(R.string.action_remove) };
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// Do nothing.
|
||||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(alias);
|
||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
addButton.setEnabled(aliasInput.getText().length() > 0);
|
||||
}
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
addButton.setEnabled(aliasInput.getText().length() > 0);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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.activity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -31,14 +31,14 @@ 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.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
|
||||
/**
|
||||
* Adding auto join channels to a server
|
||||
@ -51,7 +51,7 @@ public class AddChannelActivity extends Activity implements OnClickListener, OnI
|
||||
private ArrayAdapter<String> adapter;
|
||||
private ArrayList<String> channels;
|
||||
private Button okButton;
|
||||
|
||||
|
||||
/**
|
||||
* On create
|
||||
*/
|
||||
@ -60,17 +60,17 @@ public class AddChannelActivity extends Activity implements OnClickListener, OnI
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
|
||||
setContentView(R.layout.channeladd);
|
||||
|
||||
|
||||
channelInput = (EditText) findViewById(R.id.channel);
|
||||
|
||||
|
||||
adapter = new ArrayAdapter<String>(this, R.layout.channelitem);
|
||||
|
||||
|
||||
ListView list = (ListView) findViewById(R.id.channels);
|
||||
list.setAdapter(adapter);
|
||||
list.setOnItemClickListener(this);
|
||||
|
||||
|
||||
((Button) findViewById(R.id.add)).setOnClickListener(this);
|
||||
((Button) findViewById(R.id.cancel)).setOnClickListener(this);
|
||||
|
||||
@ -79,7 +79,7 @@ public class AddChannelActivity extends Activity implements OnClickListener, OnI
|
||||
okButton.setEnabled(false);
|
||||
|
||||
channels = getIntent().getExtras().getStringArrayList(Extra.CHANNELS);
|
||||
|
||||
|
||||
for (String channel : channels) {
|
||||
adapter.add(channel);
|
||||
}
|
||||
@ -88,6 +88,7 @@ public class AddChannelActivity extends Activity implements OnClickListener, OnI
|
||||
/**
|
||||
* On Click
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
switch (v.getId()) {
|
||||
@ -115,15 +116,17 @@ public class AddChannelActivity extends Activity implements OnClickListener, OnI
|
||||
/**
|
||||
* On item clicked
|
||||
*/
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> list, View item, int position, long id)
|
||||
{
|
||||
final String channel = adapter.getItem(position);
|
||||
|
||||
|
||||
String[] items = { getResources().getString(R.string.action_remove) };
|
||||
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(channel);
|
||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
switch (item) {
|
||||
case 0: // Remove
|
||||
|
@ -17,7 +17,7 @@ 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.activity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -31,14 +31,14 @@ 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.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
|
||||
/**
|
||||
* Adding commands (to execute after connect) to a server
|
||||
@ -51,7 +51,7 @@ public class AddCommandsActivity extends Activity implements OnClickListener, On
|
||||
private ArrayAdapter<String> adapter;
|
||||
private ArrayList<String> commands;
|
||||
private Button okButton;
|
||||
|
||||
|
||||
/**
|
||||
* On create
|
||||
*/
|
||||
@ -60,17 +60,17 @@ public class AddCommandsActivity extends Activity implements OnClickListener, On
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
|
||||
setContentView(R.layout.commandadd);
|
||||
|
||||
|
||||
commandInput = (EditText) findViewById(R.id.command);
|
||||
|
||||
|
||||
adapter = new ArrayAdapter<String>(this, R.layout.commanditem);
|
||||
|
||||
|
||||
ListView list = (ListView) findViewById(R.id.commands);
|
||||
list.setAdapter(adapter);
|
||||
list.setOnItemClickListener(this);
|
||||
|
||||
|
||||
((Button) findViewById(R.id.add)).setOnClickListener(this);
|
||||
((Button) findViewById(R.id.ok)).setOnClickListener(this);
|
||||
((Button) findViewById(R.id.cancel)).setOnClickListener(this);
|
||||
@ -78,9 +78,9 @@ public class AddCommandsActivity extends Activity implements OnClickListener, On
|
||||
okButton = (Button) findViewById(R.id.ok);
|
||||
okButton.setOnClickListener(this);
|
||||
okButton.setEnabled(false);
|
||||
|
||||
|
||||
commands = getIntent().getExtras().getStringArrayList(Extra.COMMANDS);
|
||||
|
||||
|
||||
for (String command : commands) {
|
||||
adapter.add(command);
|
||||
}
|
||||
@ -89,16 +89,17 @@ public class AddCommandsActivity extends Activity implements OnClickListener, On
|
||||
/**
|
||||
* On Click
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
switch (v.getId()) {
|
||||
case R.id.add:
|
||||
String command = commandInput.getText().toString().trim();
|
||||
|
||||
|
||||
if (!command.startsWith("/")) {
|
||||
command = "/" + command;
|
||||
}
|
||||
|
||||
|
||||
commands.add(command);
|
||||
adapter.add(command);
|
||||
commandInput.setText("/");
|
||||
@ -121,15 +122,17 @@ public class AddCommandsActivity extends Activity implements OnClickListener, On
|
||||
/**
|
||||
* On item clicked
|
||||
*/
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> list, View item, int position, long id)
|
||||
{
|
||||
final String command = adapter.getItem(position);
|
||||
|
||||
|
||||
String[] items = { getResources().getString(R.string.action_remove) };
|
||||
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(command);
|
||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
switch (item) {
|
||||
case 0: // Remove
|
||||
|
@ -17,7 +17,7 @@ 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.activity;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -47,13 +47,14 @@ public class JoinActivity extends Activity implements OnClickListener
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.join);
|
||||
|
||||
|
||||
((Button) findViewById(R.id.join)).setOnClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* On click
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
Intent intent = new Intent();
|
||||
|
@ -17,7 +17,7 @@ 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.activity;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -42,10 +42,10 @@ public class MessageActivity extends Activity
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.message);
|
||||
|
||||
|
||||
((TextView) findViewById(R.id.message)).setText(
|
||||
getIntent().getExtras().getString(Extra.MESSAGE)
|
||||
);
|
||||
|
@ -17,29 +17,11 @@ 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.activity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
|
||||
import org.yaaic.R;
|
||||
import org.yaaic.Yaaic;
|
||||
import org.yaaic.adapter.ServerListAdapter;
|
||||
@ -54,6 +36,24 @@ import org.yaaic.model.Server;
|
||||
import org.yaaic.model.Status;
|
||||
import org.yaaic.receiver.ServerReceiver;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* List of servers
|
||||
*
|
||||
@ -64,7 +64,7 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
private ServerReceiver receiver;
|
||||
private ServerListAdapter adapter;
|
||||
private ListView list;
|
||||
|
||||
|
||||
/**
|
||||
* On create
|
||||
*/
|
||||
@ -73,10 +73,10 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.servers);
|
||||
|
||||
|
||||
adapter = new ServerListAdapter();
|
||||
setListAdapter(adapter);
|
||||
|
||||
|
||||
list = getListView();
|
||||
list.setOnItemLongClickListener(this);
|
||||
list.setBackgroundDrawable(new NonScalingBackgroundDrawable(this, list, R.drawable.background));
|
||||
@ -89,7 +89,7 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
|
||||
// Start and connect to service
|
||||
Intent intent = new Intent(this, IRCService.class);
|
||||
intent.setAction(IRCService.ACTION_BACKGROUND);
|
||||
@ -98,10 +98,10 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
|
||||
receiver = new ServerReceiver(this);
|
||||
registerReceiver(receiver, new IntentFilter(Broadcast.SERVER_UPDATE));
|
||||
|
||||
|
||||
adapter.loadServers();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* On pause
|
||||
*/
|
||||
@ -109,18 +109,19 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
|
||||
|
||||
if (binder != null && binder.getService() != null) {
|
||||
binder.getService().checkServiceStatus();
|
||||
}
|
||||
|
||||
|
||||
unbindService(this);
|
||||
unregisterReceiver(receiver);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Service connected to Activity
|
||||
*/
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service)
|
||||
{
|
||||
binder = (IRCBinder) service;
|
||||
@ -129,6 +130,7 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
/**
|
||||
* Service disconnected from Activity
|
||||
*/
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name)
|
||||
{
|
||||
binder = null;
|
||||
@ -140,36 +142,37 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
Server server = adapter.getItem(position);
|
||||
|
||||
|
||||
if (server == null) {
|
||||
// "Add server" was selected
|
||||
startActivityForResult(new Intent(this, AddServerActivity.class), 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Intent intent = new Intent(this, ConversationActivity.class);
|
||||
|
||||
|
||||
if (server.getStatus() == Status.DISCONNECTED) {
|
||||
server.setStatus(Status.PRE_CONNECTING);
|
||||
intent.putExtra("connect", true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
intent.putExtra("serverId", server.getId());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* On long click
|
||||
*/
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> l, View v, int position, long id)
|
||||
{
|
||||
final Server server = adapter.getItem(position);
|
||||
|
||||
|
||||
if (server == null) {
|
||||
// "Add server" view selected
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
final CharSequence[] items = {
|
||||
getString(R.string.connect),
|
||||
getString(R.string.disconnect),
|
||||
@ -180,6 +183,7 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(server.getTitle());
|
||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
switch (item) {
|
||||
case 0: // Connect
|
||||
@ -208,7 +212,7 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
alert.show();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start activity to edit server with given id
|
||||
*
|
||||
@ -217,7 +221,7 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
private void editServer(int serverId)
|
||||
{
|
||||
Server server = Yaaic.getInstance().getServerById(serverId);
|
||||
|
||||
|
||||
if (server.getStatus() != Status.DISCONNECTED) {
|
||||
Toast.makeText(this, getResources().getString(R.string.disconnect_before_editing), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@ -227,18 +231,19 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
startActivityForResult(intent, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Options Menu (Menu Button pressed)
|
||||
*/
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
super.onCreateOptionsMenu(menu);
|
||||
|
||||
|
||||
// inflate from xml
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.servers, menu);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -270,7 +275,7 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
binder.getService().stopForegroundCompat(R.string.app_name);
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -285,7 +290,7 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
adapter.loadServers();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete server
|
||||
*
|
||||
@ -296,7 +301,7 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
Database db = new Database(this);
|
||||
db.removeServerById(serverId);
|
||||
db.close();
|
||||
|
||||
|
||||
Yaaic.getInstance().removeServerById(serverId);
|
||||
adapter.loadServers();
|
||||
}
|
||||
@ -304,14 +309,15 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
||||
/**
|
||||
* On server status update
|
||||
*/
|
||||
@Override
|
||||
public void onStatusUpdate()
|
||||
{
|
||||
adapter.loadServers();
|
||||
|
||||
|
||||
if (adapter.getCount() > 2) {
|
||||
// Hide background if there are servers in the list
|
||||
list.setBackgroundDrawable(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -17,7 +17,7 @@ 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.activity;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -39,7 +39,7 @@ public class SettingsActivity extends PreferenceActivity
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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.activity;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -27,9 +27,9 @@ import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
@ -42,7 +42,7 @@ import android.widget.TextView;
|
||||
public class UserActivity extends Activity implements OnClickListener
|
||||
{
|
||||
private String nickname;
|
||||
|
||||
|
||||
/**
|
||||
* On create
|
||||
*/
|
||||
@ -51,28 +51,29 @@ public class UserActivity extends Activity implements OnClickListener
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
|
||||
nickname = getIntent().getStringExtra(Extra.USER);
|
||||
setContentView(R.layout.user);
|
||||
|
||||
|
||||
// Use full width
|
||||
LayoutParams params = getWindow().getAttributes();
|
||||
params.width = WindowManager.LayoutParams.FILL_PARENT;
|
||||
getWindow().setAttributes(params);
|
||||
|
||||
|
||||
((Button) findViewById(R.id.op)).setOnClickListener(this);
|
||||
((Button) findViewById(R.id.deop)).setOnClickListener(this);
|
||||
((Button) findViewById(R.id.voice)).setOnClickListener(this);
|
||||
((Button) findViewById(R.id.devoice)).setOnClickListener(this);
|
||||
((Button) findViewById(R.id.kick)).setOnClickListener(this);
|
||||
((Button) findViewById(R.id.ban)).setOnClickListener(this);
|
||||
|
||||
|
||||
((TextView) findViewById(R.id.nickname)).setText(nickname);
|
||||
}
|
||||
|
||||
/**
|
||||
* On button click
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
Intent intent = new Intent();
|
||||
|
@ -17,7 +17,7 @@ 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.activity;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -49,9 +49,9 @@ public class UsersActivity extends ListActivity implements OnItemClickListener
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
|
||||
setContentView(R.layout.users);
|
||||
|
||||
|
||||
final String[] users = getIntent().getExtras().getStringArray(Extra.USERS);
|
||||
getListView().setOnItemClickListener(this);
|
||||
|
||||
@ -64,6 +64,7 @@ public class UsersActivity extends ListActivity implements OnItemClickListener
|
||||
/**
|
||||
* On user selected
|
||||
*/
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> list, View item, int position, long id)
|
||||
{
|
||||
Intent intent = new Intent();
|
||||
|
@ -17,7 +17,7 @@ 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.adapter;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@ -43,7 +43,7 @@ public class DeckAdapter extends BaseAdapter
|
||||
private LinkedList<Conversation> conversations;
|
||||
private MessageListView currentView;
|
||||
private String currentChannel;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new DeckAdapter instance
|
||||
*/
|
||||
@ -51,7 +51,7 @@ public class DeckAdapter extends BaseAdapter
|
||||
{
|
||||
conversations = new LinkedList<Conversation>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear conversations
|
||||
*/
|
||||
@ -59,10 +59,11 @@ public class DeckAdapter extends BaseAdapter
|
||||
{
|
||||
conversations = new LinkedList<Conversation>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get number of item
|
||||
*/
|
||||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
return conversations.size();
|
||||
@ -71,6 +72,7 @@ public class DeckAdapter extends BaseAdapter
|
||||
/**
|
||||
* Get item at position
|
||||
*/
|
||||
@Override
|
||||
public Conversation getItem(int position)
|
||||
{
|
||||
if (position >= 0 && position < conversations.size()) {
|
||||
@ -82,13 +84,14 @@ public class DeckAdapter extends BaseAdapter
|
||||
/**
|
||||
* Get id of item at position
|
||||
*/
|
||||
@Override
|
||||
public long getItemId(int position)
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an item
|
||||
* Add an item
|
||||
*
|
||||
* @param channel Name of the channel
|
||||
* @param view The view object
|
||||
@ -96,10 +99,10 @@ public class DeckAdapter extends BaseAdapter
|
||||
public void addItem(Conversation conversation)
|
||||
{
|
||||
conversations.add(conversation);
|
||||
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an item by the channel's name
|
||||
*
|
||||
@ -111,16 +114,16 @@ public class DeckAdapter extends BaseAdapter
|
||||
// Optimization - cache field lookups
|
||||
int mSize = conversations.size();
|
||||
LinkedList<Conversation> mItems = this.conversations;
|
||||
|
||||
|
||||
for (int i = 0; i < mSize; i++) {
|
||||
if (mItems.get(i).getName().equalsIgnoreCase(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an item
|
||||
*
|
||||
@ -129,13 +132,13 @@ public class DeckAdapter extends BaseAdapter
|
||||
public void removeItem(String target)
|
||||
{
|
||||
int position = getPositionByName(target);
|
||||
|
||||
|
||||
if (position != -1) {
|
||||
conversations.remove(position);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set single channel view
|
||||
*
|
||||
@ -146,7 +149,7 @@ public class DeckAdapter extends BaseAdapter
|
||||
currentChannel = channel;
|
||||
currentView = current;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get single channel view
|
||||
*
|
||||
@ -156,7 +159,7 @@ public class DeckAdapter extends BaseAdapter
|
||||
{
|
||||
return currentView;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get name of channel (single channel view)
|
||||
*
|
||||
@ -166,9 +169,9 @@ public class DeckAdapter extends BaseAdapter
|
||||
{
|
||||
return currentChannel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Has the view been switched to single channel view?
|
||||
* Has the view been switched to single channel view?
|
||||
*
|
||||
* @return view true if view is in single channel view, false otherwise
|
||||
*/
|
||||
@ -176,16 +179,17 @@ public class DeckAdapter extends BaseAdapter
|
||||
{
|
||||
return currentView != null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get view at given position
|
||||
*/
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
Conversation conversation = getItem(position);
|
||||
return renderConversation(conversation, parent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render a conversation view (MessageListView)
|
||||
*
|
||||
@ -197,21 +201,21 @@ public class DeckAdapter extends BaseAdapter
|
||||
{
|
||||
MessageListView list = new MessageListView(parent.getContext(), parent);
|
||||
list.setOnItemClickListener(MessageClickListener.getInstance());
|
||||
|
||||
|
||||
MessageListAdapter adapter = conversation.getMessageListAdapter();
|
||||
if (adapter == null) {
|
||||
adapter = new MessageListAdapter(conversation, parent.getContext());
|
||||
conversation.setMessageListAdapter(adapter);
|
||||
}
|
||||
|
||||
|
||||
list.setAdapter(adapter);
|
||||
|
||||
|
||||
list.setDivider(null);
|
||||
list.setLayoutParams(new Gallery.LayoutParams(
|
||||
parent.getWidth() / 100 * 85,
|
||||
parent.getHeight()
|
||||
));
|
||||
|
||||
|
||||
list.setBackgroundResource(R.layout.rounded);
|
||||
list.setCacheColorHint(0xee000000);
|
||||
list.setPadding(5, 5, 5, 5);
|
||||
@ -219,7 +223,7 @@ public class DeckAdapter extends BaseAdapter
|
||||
list.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_INSET);
|
||||
list.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
|
||||
list.setSelection(list.getAdapter().getCount() - 1); // scroll to bottom
|
||||
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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.adapter;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@ -38,9 +38,9 @@ import android.widget.TextView;
|
||||
*/
|
||||
public class MessageListAdapter extends BaseAdapter
|
||||
{
|
||||
private LinkedList<TextView> messages;
|
||||
private Context context;
|
||||
|
||||
private final LinkedList<TextView> messages;
|
||||
private final Context context;
|
||||
|
||||
/**
|
||||
* Create a new MessageAdapter
|
||||
*
|
||||
@ -50,26 +50,26 @@ public class MessageListAdapter extends BaseAdapter
|
||||
public MessageListAdapter(Conversation conversation, Context context)
|
||||
{
|
||||
LinkedList<TextView> messages = new LinkedList<TextView>();
|
||||
|
||||
|
||||
// Render channel name as first message in channel
|
||||
if (conversation.getType() != Conversation.TYPE_SERVER) {
|
||||
Message header = new Message(conversation.getName());
|
||||
header.setColor(Message.COLOR_RED);
|
||||
messages.add(header.renderTextView(context));
|
||||
}
|
||||
|
||||
|
||||
// Optimization - cache field lookups
|
||||
LinkedList<Message> mHistory = conversation.getHistory();
|
||||
int mSize = mHistory.size();
|
||||
|
||||
|
||||
for (int i = 0; i < mSize; i++) {
|
||||
messages.add(mHistory.get(i).renderTextView(context));
|
||||
}
|
||||
|
||||
|
||||
// XXX: We don't want to clear the buffer, we want to add only
|
||||
// buffered messages that are not already added (history)
|
||||
conversation.clearBuffer();
|
||||
|
||||
|
||||
this.messages = messages;
|
||||
this.context = context;
|
||||
}
|
||||
@ -82,14 +82,14 @@ public class MessageListAdapter extends BaseAdapter
|
||||
public void addMessage(Message message)
|
||||
{
|
||||
messages.add(message.renderTextView(context));
|
||||
|
||||
|
||||
if (messages.size() > Conversation.HISTORY_SIZE) {
|
||||
messages.remove(0);
|
||||
}
|
||||
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a list of messages to the list
|
||||
*
|
||||
@ -100,23 +100,24 @@ public class MessageListAdapter extends BaseAdapter
|
||||
LinkedList<TextView> mMessages = this.messages;
|
||||
Context mContext = this.context;
|
||||
int mSize = messages.size();
|
||||
|
||||
|
||||
for (int i = mSize - 1; i > -1; i--) {
|
||||
mMessages.add(messages.get(i).renderTextView(mContext));
|
||||
|
||||
|
||||
if (mMessages.size() > Conversation.HISTORY_SIZE) {
|
||||
mMessages.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get number of items
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
return messages.size();
|
||||
@ -128,6 +129,7 @@ public class MessageListAdapter extends BaseAdapter
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public TextView getItem(int position)
|
||||
{
|
||||
return messages.get(position);
|
||||
@ -139,6 +141,7 @@ public class MessageListAdapter extends BaseAdapter
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public long getItemId(int position)
|
||||
{
|
||||
return position;
|
||||
@ -152,6 +155,7 @@ public class MessageListAdapter extends BaseAdapter
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
return getItem(position);
|
||||
|
@ -17,7 +17,7 @@ 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.adapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -42,7 +42,7 @@ import android.widget.TextView;
|
||||
public class ServerListAdapter extends BaseAdapter
|
||||
{
|
||||
private ArrayList<Server> servers;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new adapter for server lists
|
||||
*/
|
||||
@ -50,7 +50,7 @@ public class ServerListAdapter extends BaseAdapter
|
||||
{
|
||||
loadServers();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load servers from database
|
||||
*
|
||||
@ -61,19 +61,20 @@ public class ServerListAdapter extends BaseAdapter
|
||||
servers = Yaaic.getInstance().getServersAsArrayList();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get number of items
|
||||
*/
|
||||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
int size = servers.size();
|
||||
|
||||
|
||||
// Display "Add server" item
|
||||
if (size == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
@ -82,12 +83,13 @@ public class ServerListAdapter extends BaseAdapter
|
||||
*
|
||||
* @param position
|
||||
*/
|
||||
@Override
|
||||
public Server getItem(int position)
|
||||
{
|
||||
if (servers.size() == 0) {
|
||||
return null; // No server object for the "add server" view
|
||||
}
|
||||
|
||||
|
||||
return servers.get(position);
|
||||
}
|
||||
|
||||
@ -96,12 +98,13 @@ public class ServerListAdapter extends BaseAdapter
|
||||
*
|
||||
* @param position
|
||||
*/
|
||||
@Override
|
||||
public long getItemId(int position)
|
||||
{
|
||||
if (servers.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getItem(position).getId();
|
||||
}
|
||||
|
||||
@ -112,24 +115,25 @@ public class ServerListAdapter extends BaseAdapter
|
||||
* @param convertView
|
||||
* @param parent
|
||||
*/
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
Server server = getItem(position);
|
||||
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
|
||||
if (server == null) {
|
||||
// Return "Add server" view
|
||||
return inflater.inflate(R.layout.addserveritem, null);
|
||||
}
|
||||
|
||||
|
||||
View v = inflater.inflate(R.layout.serveritem, null);
|
||||
|
||||
|
||||
((TextView) v.findViewById(R.id.title)).setText(server.getTitle());
|
||||
((TextView) v.findViewById(R.id.host)).setText(server.getIdentity().getNickname() + " @ " + server.getHost() + " : " + server.getPort());
|
||||
|
||||
|
||||
((ImageView) v.findViewById(R.id.status)).setImageResource(server.getStatusIcon());
|
||||
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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.command;
|
||||
|
||||
import org.yaaic.exception.CommandException;
|
||||
@ -44,14 +44,14 @@ public abstract class BaseHandler
|
||||
* @throws CommandException if command couldn't be executed
|
||||
*/
|
||||
public abstract void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException;
|
||||
|
||||
|
||||
/**
|
||||
* Get the usage description for this command
|
||||
*
|
||||
* @return The usage description
|
||||
*/
|
||||
public abstract String getUsage();
|
||||
|
||||
|
||||
/**
|
||||
* Get the description for this command
|
||||
*
|
||||
@ -59,7 +59,7 @@ public abstract class BaseHandler
|
||||
* @return
|
||||
*/
|
||||
public abstract String getDescription(Context context);
|
||||
|
||||
|
||||
/**
|
||||
* Merge params to a string
|
||||
*
|
||||
@ -69,7 +69,7 @@ public abstract class BaseHandler
|
||||
{
|
||||
return mergeParams(params, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Merge params to a string
|
||||
*
|
||||
@ -79,12 +79,12 @@ public abstract class BaseHandler
|
||||
public static String mergeParams(String[] params, int position)
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
|
||||
for (; position < params.length; position++) {
|
||||
buffer.append(params[position]);
|
||||
buffer.append(" ");
|
||||
}
|
||||
|
||||
|
||||
return buffer.toString().trim();
|
||||
}
|
||||
}
|
||||
|
@ -17,13 +17,11 @@ 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.command;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import org.yaaic.command.handler.AMsgHandler;
|
||||
import org.yaaic.command.handler.AwayHandler;
|
||||
import org.yaaic.command.handler.CloseHandler;
|
||||
@ -55,15 +53,17 @@ import org.yaaic.model.Conversation;
|
||||
import org.yaaic.model.Message;
|
||||
import org.yaaic.model.Server;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* Parser for commands
|
||||
*
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class CommandParser
|
||||
{
|
||||
private HashMap<String, BaseHandler> commands;
|
||||
private HashMap<String, String> aliases;
|
||||
private final HashMap<String, BaseHandler> commands;
|
||||
private final HashMap<String, String> aliases;
|
||||
private static CommandParser instance;
|
||||
|
||||
/**
|
||||
@ -72,7 +72,7 @@ public class CommandParser
|
||||
private CommandParser()
|
||||
{
|
||||
commands = new HashMap<String, BaseHandler>();
|
||||
|
||||
|
||||
// Commands
|
||||
commands.put("nick", new NickHandler());
|
||||
commands.put("join", new JoinHandler());
|
||||
@ -98,9 +98,9 @@ public class CommandParser
|
||||
commands.put("msg", new MsgHandler());
|
||||
commands.put("quote", new RawHandler());
|
||||
commands.put("amsg", new AMsgHandler());
|
||||
|
||||
|
||||
aliases = new HashMap<String, String>();
|
||||
|
||||
|
||||
// Aliases
|
||||
aliases.put("j","join");
|
||||
aliases.put("q", "query");
|
||||
@ -108,7 +108,7 @@ public class CommandParser
|
||||
aliases.put("raw", "quote");
|
||||
aliases.put("w", "whois");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the global CommandParser instance
|
||||
*
|
||||
@ -119,10 +119,10 @@ public class CommandParser
|
||||
if (instance == null) {
|
||||
instance = new CommandParser();
|
||||
}
|
||||
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the commands HashMap
|
||||
*
|
||||
@ -132,7 +132,7 @@ public class CommandParser
|
||||
{
|
||||
return commands;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the command aliases HashMap
|
||||
*
|
||||
@ -142,7 +142,7 @@ public class CommandParser
|
||||
{
|
||||
return aliases;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is the given command a valid client command?
|
||||
*
|
||||
@ -153,7 +153,7 @@ public class CommandParser
|
||||
{
|
||||
return commands.containsKey(command.toLowerCase()) || aliases.containsKey(command.toLowerCase());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle a client command
|
||||
*
|
||||
@ -180,11 +180,11 @@ public class CommandParser
|
||||
Message errorMessage = new Message(type + ": " + e.getMessage());
|
||||
errorMessage.setColor(Message.COLOR_RED);
|
||||
conversation.addMessage(errorMessage);
|
||||
|
||||
|
||||
// XXX:I18N - How to get a context here? (command_syntax)
|
||||
Message usageMessage = new Message("Syntax: " + command.getUsage());
|
||||
conversation.addMessage(usageMessage);
|
||||
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_MESSAGE,
|
||||
server.getId(),
|
||||
@ -195,7 +195,7 @@ public class CommandParser
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle a server command
|
||||
*
|
||||
@ -215,7 +215,7 @@ public class CommandParser
|
||||
service.getConnection(server.getId()).sendRawLineViaQueue(type.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse the given line
|
||||
*
|
||||
@ -226,7 +226,7 @@ public class CommandParser
|
||||
line = line.trim().substring(1); // cut the slash
|
||||
String[] params = line.split(" ");
|
||||
String type = params[0];
|
||||
|
||||
|
||||
if (isClientCommand(type)) {
|
||||
handleClientCommand(type, params, server, conversation, service);
|
||||
} else {
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -47,26 +47,26 @@ public class AMsgHandler extends BaseHandler
|
||||
* Execute /amsg
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length > 1) {
|
||||
String text = BaseHandler.mergeParams(params);
|
||||
|
||||
|
||||
|
||||
Collection<Conversation> mConversations = server.getConversations();
|
||||
for (Conversation currentConversation : mConversations) {
|
||||
if (currentConversation.getType() == Conversation.TYPE_CHANNEL) {
|
||||
Message message = new Message("<" + service.getConnection(server.getId()).getNick() + "> " + text);
|
||||
currentConversation.addMessage(message);
|
||||
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_MESSAGE,
|
||||
server.getId(),
|
||||
currentConversation.getName()
|
||||
);
|
||||
|
||||
|
||||
service.sendBroadcast(intent);
|
||||
|
||||
|
||||
service.getConnection(server.getId()).sendMessage(currentConversation.getName(), text);
|
||||
}
|
||||
}
|
||||
@ -74,7 +74,7 @@ public class AMsgHandler extends BaseHandler
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /amsg
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -44,19 +44,19 @@ public class CloseHandler extends BaseHandler
|
||||
* Execute /close
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (conversation.getType() == Conversation.TYPE_SERVER) {
|
||||
throw new CommandException(service.getString(R.string.close_server_window));
|
||||
}
|
||||
|
||||
|
||||
if (params.length == 1) {
|
||||
if (conversation.getType() == Conversation.TYPE_CHANNEL) {
|
||||
service.getConnection(server.getId()).partChannel(conversation.getName());
|
||||
}
|
||||
if (conversation.getType() == Conversation.TYPE_QUERY) {
|
||||
server.removeConversation(conversation.getName());
|
||||
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_REMOVE,
|
||||
server.getId(),
|
||||
@ -66,7 +66,7 @@ public class CloseHandler extends BaseHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /close
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import java.io.File;
|
||||
@ -46,7 +46,7 @@ public class DCCHandler extends BaseHandler
|
||||
* Execute /dcc
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length == 4) {
|
||||
if (!params[1].equalsIgnoreCase("SEND")) {
|
||||
@ -56,13 +56,13 @@ public class DCCHandler extends BaseHandler
|
||||
if (!file.exists()) {
|
||||
throw new CommandException(service.getString(R.string.dcc_file_not_found, params[3]));
|
||||
}
|
||||
|
||||
|
||||
service.getConnection(server.getId()).dccSendFile(file, params[2], 60000);
|
||||
|
||||
|
||||
Message message = new Message(service.getString(R.string.dcc_waiting_accept, params[2]));
|
||||
message.setColor(Message.COLOR_GREY);
|
||||
conversation.addMessage(message);
|
||||
|
||||
|
||||
service.sendBroadcast(
|
||||
Broadcast.createConversationIntent(Broadcast.CONVERSATION_MESSAGE, server.getId(), conversation.getName())
|
||||
);
|
||||
@ -70,7 +70,7 @@ public class DCCHandler extends BaseHandler
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /dcc
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -40,19 +40,19 @@ public class DeopHandler extends BaseHandler
|
||||
* Execute /deop
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (conversation.getType() != Conversation.TYPE_CHANNEL) {
|
||||
throw new CommandException(service.getString(R.string.only_usable_from_channel));
|
||||
}
|
||||
|
||||
|
||||
if (params.length == 2) {
|
||||
service.getConnection(server.getId()).deOp(conversation.getName(), params[1]);
|
||||
} else {
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /deop
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -40,19 +40,19 @@ public class DevoiceHandler extends BaseHandler
|
||||
* Execute /devoice
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (conversation.getType() != Conversation.TYPE_CHANNEL) {
|
||||
throw new CommandException(service.getString(R.string.only_usable_from_channel));
|
||||
}
|
||||
|
||||
|
||||
if (params.length == 2) {
|
||||
service.getConnection(server.getId()).deVoice(conversation.getName(), params[1]);
|
||||
} else {
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /devoice
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -43,12 +43,12 @@ public class EchoHandler extends BaseHandler
|
||||
* Execute /echo
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length > 1) {
|
||||
Message message = new Message(BaseHandler.mergeParams(params));
|
||||
conversation.addMessage(message);
|
||||
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_MESSAGE,
|
||||
server.getId(),
|
||||
@ -59,7 +59,7 @@ public class EchoHandler extends BaseHandler
|
||||
throw new CommandException(service.getString(R.string.text_missing));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /echo
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -37,7 +37,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* Command: /help
|
||||
* Command: /help
|
||||
*
|
||||
* @author Karol Gliniecki <karol.gliniecki@googlemail.com>
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
@ -51,14 +51,14 @@ public class HelpHandler extends BaseHandler
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length == 2) {
|
||||
showCommandDetails(service, server, conversation, params[1]);
|
||||
showCommandDetails(service, server, conversation, params[1]);
|
||||
} else if (params.length == 1) {
|
||||
showAllCommands(service, server, conversation);
|
||||
} else {
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show all available commands
|
||||
*
|
||||
@ -69,16 +69,16 @@ public class HelpHandler extends BaseHandler
|
||||
private void showAllCommands(IRCService service, Server server, Conversation conversation)
|
||||
{
|
||||
CommandParser cp = CommandParser.getInstance();
|
||||
|
||||
|
||||
StringBuffer commandList = new StringBuffer(service.getString(R.string.available_commands));
|
||||
commandList.append("\n");
|
||||
|
||||
|
||||
HashMap<String, BaseHandler> commands = cp.getCommands();
|
||||
HashMap<String, String> aliases = cp.getAliases();
|
||||
|
||||
Set<String> commandKeys = commands.keySet();
|
||||
Set<String> aliasesKeys = aliases.keySet();
|
||||
|
||||
|
||||
for (Object command : commandKeys) {
|
||||
String alias = "";
|
||||
for (Object aliasCommand : aliasesKeys) {
|
||||
@ -89,17 +89,17 @@ public class HelpHandler extends BaseHandler
|
||||
}
|
||||
commandList.append("/" + command.toString() + alias + " - "+commands.get(command).getDescription(service) + "\n");
|
||||
}
|
||||
|
||||
|
||||
Message message = new Message(commandList.toString());
|
||||
message.setColor(Message.COLOR_YELLOW);
|
||||
conversation.addMessage(message);
|
||||
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_MESSAGE,
|
||||
server.getId(),
|
||||
conversation.getName()
|
||||
);
|
||||
|
||||
|
||||
service.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
@ -116,19 +116,19 @@ public class HelpHandler extends BaseHandler
|
||||
{
|
||||
CommandParser cp = CommandParser.getInstance();
|
||||
HashMap<String, BaseHandler> commands = cp.getCommands();
|
||||
|
||||
|
||||
if (commands.containsKey(command)) {
|
||||
// XXX:I18N - String building salad :)
|
||||
Message message = new Message("Help of /" + command + "\n" + commands.get(command).getUsage() + "\n" + commands.get(command).getDescription(service) + "\n");
|
||||
message.setColor(Message.COLOR_YELLOW);
|
||||
conversation.addMessage(message);
|
||||
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_MESSAGE,
|
||||
server.getId(),
|
||||
conversation.getName()
|
||||
);
|
||||
|
||||
|
||||
service.sendBroadcast(intent);
|
||||
} else {
|
||||
throw new CommandException(service.getString(R.string.unknown_command, command));
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -50,7 +50,7 @@ public class JoinHandler extends BaseHandler
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /join
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -42,19 +42,19 @@ public class KickHandler extends BaseHandler
|
||||
* Execute /kick
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (conversation.getType() != Conversation.TYPE_CHANNEL) {
|
||||
throw new CommandException(service.getString(R.string.only_usable_from_channel));
|
||||
}
|
||||
|
||||
|
||||
if (params.length == 2) {
|
||||
service.getConnection(server.getId()).kick(conversation.getName(), params[1]);
|
||||
} else {
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /kick
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -43,33 +43,33 @@ public class MeHandler extends BaseHandler
|
||||
* Execute /me
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (conversation.getType() == Conversation.TYPE_SERVER) {
|
||||
throw new CommandException(service.getString(R.string.only_usable_from_channel_or_query));
|
||||
}
|
||||
|
||||
|
||||
if (params.length > 1) {
|
||||
String action = BaseHandler.mergeParams(params);
|
||||
String nickname = service.getConnection(server.getId()).getNick();
|
||||
|
||||
|
||||
Message message = new Message(nickname + " " + action);
|
||||
message.setIcon(R.drawable.action);
|
||||
server.getConversation(conversation.getName()).addMessage(message);
|
||||
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_MESSAGE,
|
||||
server.getId(),
|
||||
conversation.getName()
|
||||
);
|
||||
service.sendBroadcast(intent);
|
||||
|
||||
|
||||
service.getConnection(server.getId()).sendAction(conversation.getName(), action);
|
||||
} else {
|
||||
throw new CommandException(service.getString(R.string.text_missing));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /me
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -42,17 +42,17 @@ public class ModeHandler extends BaseHandler
|
||||
* Execute /mode
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length > 2) {
|
||||
String modes = BaseHandler.mergeParams(params, 2);
|
||||
|
||||
|
||||
service.getConnection(server.getId()).setMode(params[1], modes);
|
||||
} else {
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /mode
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -45,31 +45,31 @@ public class MsgHandler extends BaseHandler
|
||||
* Execute /msg
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length > 2) {
|
||||
String text = BaseHandler.mergeParams(params, 2);
|
||||
service.getConnection(server.getId()).sendMessage(params[1], text);
|
||||
|
||||
|
||||
Conversation targetConversation = server.getConversation(params[1]);
|
||||
|
||||
|
||||
if (targetConversation != null) {
|
||||
Message message = new Message("<" + service.getConnection(server.getId()).getNick() + "> " + text);
|
||||
targetConversation.addMessage(message);
|
||||
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_MESSAGE,
|
||||
server.getId(),
|
||||
targetConversation.getName()
|
||||
);
|
||||
|
||||
|
||||
service.sendBroadcast(intent);
|
||||
}
|
||||
} else {
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /msg
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.jibble.pircbot.User;
|
||||
@ -35,7 +35,7 @@ import android.content.Intent;
|
||||
|
||||
/**
|
||||
* Command: /names
|
||||
* Lists all users currently in the selected channel
|
||||
* Lists all users currently in the selected channel
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
@ -45,14 +45,14 @@ public class NamesHandler extends BaseHandler
|
||||
* Execute /names
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (conversation.getType() != Conversation.TYPE_CHANNEL) {
|
||||
throw new CommandException(service.getString(R.string.only_usable_from_channel));
|
||||
}
|
||||
|
||||
|
||||
StringBuffer userList = new StringBuffer(service.getString(R.string.message_users_on_chan, conversation.getName()));
|
||||
|
||||
|
||||
User[] mUsers = service.getConnection(server.getId()).getUsers(conversation.getName());
|
||||
int mSize = mUsers.length;
|
||||
for (int i = 0; i < mSize; i++) {
|
||||
@ -60,11 +60,11 @@ public class NamesHandler extends BaseHandler
|
||||
userList.append(mUsers[i].getPrefix());
|
||||
userList.append(mUsers[i].getNick());
|
||||
}
|
||||
|
||||
|
||||
Message message = new Message(userList.toString());
|
||||
message.setColor(Message.COLOR_YELLOW);
|
||||
conversation.addMessage(message);
|
||||
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_MESSAGE,
|
||||
server.getId(),
|
||||
@ -72,7 +72,7 @@ public class NamesHandler extends BaseHandler
|
||||
);
|
||||
service.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /names
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -40,7 +40,7 @@ public class NickHandler extends BaseHandler
|
||||
* Execute /nick
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length == 2) {
|
||||
service.getConnection(server.getId()).changeNick(params[1]);
|
||||
@ -48,7 +48,7 @@ public class NickHandler extends BaseHandler
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /nick
|
||||
*/
|
||||
@ -57,7 +57,7 @@ public class NickHandler extends BaseHandler
|
||||
{
|
||||
return "/nick <nickname>";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Description of /nick
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -45,28 +45,28 @@ public class NoticeHandler extends BaseHandler
|
||||
* Execute /notice
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length > 2) {
|
||||
String text = BaseHandler.mergeParams(params);
|
||||
|
||||
|
||||
Message message = new Message(">" + params[1] + "< " + text);
|
||||
message.setIcon(R.drawable.info);
|
||||
conversation.addMessage(message);
|
||||
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_MESSAGE,
|
||||
server.getId(),
|
||||
conversation.getName()
|
||||
);
|
||||
service.sendBroadcast(intent);
|
||||
|
||||
|
||||
service.getConnection(server.getId()).sendNotice(params[1], text);
|
||||
} else {
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /notice
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -40,19 +40,19 @@ public class OpHandler extends BaseHandler
|
||||
* Execute /deop
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (conversation.getType() != Conversation.TYPE_CHANNEL) {
|
||||
throw new CommandException(service.getString(R.string.only_usable_from_channel));
|
||||
}
|
||||
|
||||
|
||||
if (params.length == 2) {
|
||||
service.getConnection(server.getId()).op(conversation.getName(), params[1]);
|
||||
} else {
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /deop
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -42,13 +42,13 @@ public class PartHandler extends BaseHandler
|
||||
* Execute /part
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length == 1) {
|
||||
if (conversation.getType() != Conversation.TYPE_CHANNEL) {
|
||||
throw new CommandException(service.getString(R.string.only_usable_from_channel));
|
||||
}
|
||||
|
||||
|
||||
service.getConnection(server.getId()).partChannel(conversation.getName());
|
||||
} else if (params.length == 2) {
|
||||
service.getConnection(server.getId()).partChannel(params[1]);
|
||||
@ -56,7 +56,7 @@ public class PartHandler extends BaseHandler
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /part
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -45,23 +45,23 @@ public class QueryHandler extends BaseHandler
|
||||
* Execute /query
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length == 2) {
|
||||
// Simple validation
|
||||
if (params[1].startsWith("#")) {
|
||||
throw new CommandException(service.getString(R.string.query_to_channel));
|
||||
}
|
||||
|
||||
|
||||
Conversation query = server.getConversation(params[1]);
|
||||
|
||||
|
||||
if (query != null) {
|
||||
throw new CommandException(service.getString(R.string.query_exists));
|
||||
}
|
||||
|
||||
|
||||
query = new Query(params[1]);
|
||||
server.addConversationl(query);
|
||||
|
||||
|
||||
Intent intent = Broadcast.createConversationIntent(
|
||||
Broadcast.CONVERSATION_NEW,
|
||||
server.getId(),
|
||||
@ -72,7 +72,7 @@ public class QueryHandler extends BaseHandler
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /query
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -40,7 +40,7 @@ public class QuitHandler extends BaseHandler
|
||||
* Execute /quit
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length == 1) {
|
||||
service.getConnection(server.getId()).quitServer();
|
||||
@ -48,7 +48,7 @@ public class QuitHandler extends BaseHandler
|
||||
service.getConnection(server.getId()).quitServer(BaseHandler.mergeParams(params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /quit
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -42,7 +42,7 @@ public class RawHandler extends BaseHandler
|
||||
* Execute /raw
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (params.length > 1) {
|
||||
String line = BaseHandler.mergeParams(params);
|
||||
@ -51,7 +51,7 @@ public class RawHandler extends BaseHandler
|
||||
throw new CommandException(service.getString(R.string.line_missing));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /raw
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -48,9 +48,9 @@ public class TopicHandler extends BaseHandler
|
||||
if (conversation.getType() != Conversation.TYPE_CHANNEL) {
|
||||
throw new CommandException(service.getString(R.string.only_usable_from_channel));
|
||||
}
|
||||
|
||||
|
||||
Channel channel = (Channel) conversation;
|
||||
|
||||
|
||||
if (params.length == 1) {
|
||||
// Show topic
|
||||
service.getConnection(server.getId()).onTopic(channel.getName(), channel.getTopic(), "", 0, false);
|
||||
@ -59,7 +59,7 @@ public class TopicHandler extends BaseHandler
|
||||
service.getConnection(server.getId()).setTopic(channel.getName(), BaseHandler.mergeParams(params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /topic
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -40,19 +40,19 @@ public class VoiceHandler extends BaseHandler
|
||||
* Execute /voice
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException
|
||||
{
|
||||
if (conversation.getType() != Conversation.TYPE_CHANNEL) {
|
||||
throw new CommandException(service.getString(R.string.only_usable_from_channel));
|
||||
}
|
||||
|
||||
|
||||
if (params.length == 2) {
|
||||
service.getConnection(server.getId()).voice(conversation.getName(), params[1]);
|
||||
} else {
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage of /voice
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.command.handler;
|
||||
|
||||
import org.yaaic.R;
|
||||
@ -47,7 +47,7 @@ public class WhoisHandler extends BaseHandler
|
||||
if (params.length != 2) {
|
||||
throw new CommandException(service.getString(R.string.invalid_number_of_params));
|
||||
}
|
||||
|
||||
|
||||
service.getConnection(server.getId()).sendRawLineViaQueue("WHOIS " + params[1]);
|
||||
}
|
||||
|
||||
|
@ -5,15 +5,15 @@ 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,
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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.db;
|
||||
|
||||
import android.provider.BaseColumns;
|
||||
@ -30,12 +30,12 @@ import android.provider.BaseColumns;
|
||||
public interface ChannelConstants extends BaseColumns
|
||||
{
|
||||
public static final String TABLE_NAME = "channels";
|
||||
|
||||
|
||||
// fields
|
||||
public static final String NAME = "name";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String SERVER = "server";
|
||||
|
||||
|
||||
/**
|
||||
* All fields of the table
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.db;
|
||||
|
||||
import android.provider.BaseColumns;
|
||||
@ -30,11 +30,11 @@ import android.provider.BaseColumns;
|
||||
public interface CommandConstants extends BaseColumns
|
||||
{
|
||||
public static final String TABLE_NAME = "commands";
|
||||
|
||||
|
||||
// fields
|
||||
public static final String COMMAND = "command";
|
||||
public static final String SERVER = "server";
|
||||
|
||||
|
||||
/**
|
||||
* All fields of the table
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.db;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -35,7 +35,7 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
/**
|
||||
* Database Helper for the servers and channels tables
|
||||
* Database Helper for the servers and channels tables
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
@ -43,7 +43,7 @@ public class Database extends SQLiteOpenHelper
|
||||
{
|
||||
private static final String DATABASE_NAME = "servers.db";
|
||||
private static final int DATABASE_VERSION = 4;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new helper for database access
|
||||
*
|
||||
@ -53,7 +53,7 @@ public class Database extends SQLiteOpenHelper
|
||||
{
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create all needed tables on first start
|
||||
*/
|
||||
@ -61,41 +61,41 @@ public class Database extends SQLiteOpenHelper
|
||||
public void onCreate(SQLiteDatabase db)
|
||||
{
|
||||
db.execSQL("CREATE TABLE " + ServerConstants.TABLE_NAME + " ( "
|
||||
+ ServerConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ ServerConstants.TITLE + " TEXT NOT NULL, "
|
||||
+ ServerConstants.HOST + " TEXT NOT NULL, "
|
||||
+ ServerConstants.PORT + " INTEGER, "
|
||||
+ ServerConstants.PASSWORD + " TEXT, "
|
||||
+ ServerConstants.AUTOCONNECT + " BOOLEAN, " // XXX: Does SQLLite support boolean?
|
||||
+ ServerConstants.USE_SSL + " BOOLEAN, "
|
||||
+ ServerConstants.CHARSET + " TEXT, "
|
||||
+ ServerConstants.IDENTITY + " INTEGER"
|
||||
+ ");"
|
||||
+ ServerConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ ServerConstants.TITLE + " TEXT NOT NULL, "
|
||||
+ ServerConstants.HOST + " TEXT NOT NULL, "
|
||||
+ ServerConstants.PORT + " INTEGER, "
|
||||
+ ServerConstants.PASSWORD + " TEXT, "
|
||||
+ ServerConstants.AUTOCONNECT + " BOOLEAN, " // XXX: Does SQLLite support boolean?
|
||||
+ ServerConstants.USE_SSL + " BOOLEAN, "
|
||||
+ ServerConstants.CHARSET + " TEXT, "
|
||||
+ ServerConstants.IDENTITY + " INTEGER"
|
||||
+ ");"
|
||||
);
|
||||
|
||||
|
||||
db.execSQL("CREATE TABLE " + ChannelConstants.TABLE_NAME + " ("
|
||||
+ ChannelConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ ChannelConstants.NAME + " TEXT NOT NULL, "
|
||||
+ ChannelConstants.PASSWORD + " TEXT, "
|
||||
+ ChannelConstants.SERVER + " INTEGER"
|
||||
+ ");"
|
||||
+ ChannelConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ ChannelConstants.NAME + " TEXT NOT NULL, "
|
||||
+ ChannelConstants.PASSWORD + " TEXT, "
|
||||
+ ChannelConstants.SERVER + " INTEGER"
|
||||
+ ");"
|
||||
);
|
||||
|
||||
|
||||
db.execSQL("CREATE TABLE " + IdentityConstants.TABLE_NAME +" ("
|
||||
+ IdentityConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ IdentityConstants.NICKNAME + " TEXT NOT NULL,"
|
||||
+ IdentityConstants.IDENT + " TEXT NOT NULL,"
|
||||
+ IdentityConstants.REALNAME + " TEXT NOT NULL"
|
||||
+ ");"
|
||||
+ IdentityConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ IdentityConstants.NICKNAME + " TEXT NOT NULL,"
|
||||
+ IdentityConstants.IDENT + " TEXT NOT NULL,"
|
||||
+ IdentityConstants.REALNAME + " TEXT NOT NULL"
|
||||
+ ");"
|
||||
);
|
||||
|
||||
|
||||
db.execSQL("CREATE TABLE " + CommandConstants.TABLE_NAME + " ("
|
||||
+ CommandConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ CommandConstants.COMMAND + " TEXT NOT NULL, "
|
||||
+ ChannelConstants.SERVER + " INTEGER"
|
||||
+ ");"
|
||||
);
|
||||
|
||||
|
||||
db.execSQL("CREATE TABLE " + AliasConstants.TABLE_NAME + " ("
|
||||
+ AliasConstants._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ AliasConstants.ALIAS + " TEXT NOT NULL, "
|
||||
@ -103,7 +103,7 @@ public class Database extends SQLiteOpenHelper
|
||||
+ ");"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Migrate existing databases to
|
||||
*/
|
||||
@ -111,20 +111,20 @@ public class Database extends SQLiteOpenHelper
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
|
||||
{
|
||||
// XXX: Do not delete databases (release version)
|
||||
|
||||
|
||||
// db.execSQL("DROP TABLE IF EXISTS " + ServerConstants.TABLE_NAME + ";");
|
||||
// db.execSQL("DROP TABLE IF EXISTS " + ChannelConstants.TABLE_NAME + ";");
|
||||
// db.execSQL("DROP TABLE IF EXISTS " + IdentityConstants.TABLE_NAME + ";");
|
||||
|
||||
|
||||
// onCreate(db);
|
||||
|
||||
|
||||
if (oldVersion == 1) {
|
||||
// Add charset field to server table
|
||||
db.execSQL("ALTER TABLE " + ServerConstants.TABLE_NAME + " ADD " + ServerConstants.CHARSET + " TEXT AFTER " + ServerConstants.USE_SSL + ";");
|
||||
|
||||
|
||||
oldVersion = 2; // now do the updates for version 2
|
||||
}
|
||||
|
||||
|
||||
if (oldVersion == 2) {
|
||||
// Add new commands table (copy&paste from onCreate())
|
||||
db.execSQL("CREATE TABLE " + CommandConstants.TABLE_NAME + " ("
|
||||
@ -133,10 +133,10 @@ 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, "
|
||||
@ -146,9 +146,9 @@ public class Database extends SQLiteOpenHelper
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new server to the database
|
||||
* Add a new server to the database
|
||||
*
|
||||
* @param title Unique title of the server
|
||||
* @param host Hostname of the server
|
||||
@ -161,7 +161,7 @@ public class Database extends SQLiteOpenHelper
|
||||
public long addServer(String title, String host, int port, String password, boolean autoConnect, boolean useSSL, long identityId, String charset)
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
|
||||
values.put(ServerConstants.TITLE, title);
|
||||
values.put(ServerConstants.HOST, host);
|
||||
values.put(ServerConstants.PORT, port);
|
||||
@ -170,10 +170,10 @@ public class Database extends SQLiteOpenHelper
|
||||
values.put(ServerConstants.USE_SSL, useSSL);
|
||||
values.put(ServerConstants.IDENTITY, identityId);
|
||||
values.put(ServerConstants.CHARSET, charset);
|
||||
|
||||
|
||||
return this.getWritableDatabase().insert(ServerConstants.TABLE_NAME, null, values);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the server record in the database
|
||||
*
|
||||
@ -189,7 +189,7 @@ public class Database extends SQLiteOpenHelper
|
||||
public void updateServer(int serverId, String title, String host, int port, String password, boolean autoConnect, boolean useSSL, long identityId, String charset)
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
|
||||
values.put(ServerConstants.TITLE, title);
|
||||
values.put(ServerConstants.HOST, host);
|
||||
values.put(ServerConstants.PORT, port);
|
||||
@ -198,7 +198,7 @@ public class Database extends SQLiteOpenHelper
|
||||
values.put(ServerConstants.USE_SSL, useSSL);
|
||||
values.put(ServerConstants.IDENTITY, identityId);
|
||||
values.put(ServerConstants.CHARSET, charset);
|
||||
|
||||
|
||||
this.getWritableDatabase().update(
|
||||
ServerConstants.TABLE_NAME,
|
||||
values,
|
||||
@ -206,7 +206,7 @@ public class Database extends SQLiteOpenHelper
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a channel to the database
|
||||
*
|
||||
@ -217,14 +217,14 @@ public class Database extends SQLiteOpenHelper
|
||||
public void addChannel(int serverId, String name, String password)
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
|
||||
values.put(ChannelConstants.NAME, name);
|
||||
values.put(ChannelConstants.PASSWORD, password);
|
||||
values.put(ChannelConstants.SERVER, serverId);
|
||||
|
||||
|
||||
this.getWritableDatabase().insert(ChannelConstants.TABLE_NAME, null, values);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace list of channels for the given server
|
||||
*
|
||||
@ -239,13 +239,13 @@ public class Database extends SQLiteOpenHelper
|
||||
ChannelConstants.SERVER + " = " + serverId,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
// Add new channels
|
||||
for (String channel : channels) {
|
||||
addChannel(serverId, channel, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all commands to execute on connect
|
||||
*
|
||||
@ -255,7 +255,7 @@ public class Database extends SQLiteOpenHelper
|
||||
public ArrayList<String> getCommandsByServerId(int serverId)
|
||||
{
|
||||
ArrayList<String> commands = new ArrayList<String>();
|
||||
|
||||
|
||||
Cursor cursor = this.getReadableDatabase().query(
|
||||
CommandConstants.TABLE_NAME,
|
||||
CommandConstants.ALL,
|
||||
@ -265,17 +265,17 @@ public class Database extends SQLiteOpenHelper
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
String command = cursor.getString(cursor.getColumnIndex(CommandConstants.COMMAND));
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
|
||||
cursor.close();
|
||||
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a command to a server
|
||||
*
|
||||
@ -285,13 +285,13 @@ public class Database extends SQLiteOpenHelper
|
||||
public void addCommand(int serverId, String command)
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
|
||||
values.put(CommandConstants.COMMAND, command);
|
||||
values.put(CommandConstants.SERVER, serverId);
|
||||
|
||||
|
||||
this.getWritableDatabase().insert(CommandConstants.TABLE_NAME, null, values);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace list of commands for the given server
|
||||
*
|
||||
@ -306,13 +306,13 @@ public class Database extends SQLiteOpenHelper
|
||||
CommandConstants.SERVER + " = " + serverId,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
// Add new commands
|
||||
for (String command : commands) {
|
||||
addCommand(serverId, command);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all servers from database
|
||||
*
|
||||
@ -321,7 +321,7 @@ public class Database extends SQLiteOpenHelper
|
||||
public HashMap<Integer, Server> getServers()
|
||||
{
|
||||
HashMap<Integer, Server> servers = new HashMap<Integer, Server>();
|
||||
|
||||
|
||||
Cursor cursor = this.getReadableDatabase().query(
|
||||
ServerConstants.TABLE_NAME,
|
||||
ServerConstants.ALL,
|
||||
@ -331,20 +331,20 @@ public class Database extends SQLiteOpenHelper
|
||||
null,
|
||||
ServerConstants.TITLE + " ASC"
|
||||
);
|
||||
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
Server server = populateServer(cursor);
|
||||
servers.put(server.getId(), server);
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
|
||||
return servers;
|
||||
}
|
||||
|
||||
|
||||
public Server getServerById(int serverId)
|
||||
{
|
||||
Server server = null;
|
||||
|
||||
|
||||
Cursor cursor = this.getReadableDatabase().query(
|
||||
ServerConstants.TABLE_NAME,
|
||||
ServerConstants.ALL,
|
||||
@ -354,16 +354,16 @@ public class Database extends SQLiteOpenHelper
|
||||
null,
|
||||
ServerConstants.TITLE + " ASC"
|
||||
);
|
||||
|
||||
|
||||
if (cursor.moveToNext()) {
|
||||
server = populateServer(cursor);
|
||||
}
|
||||
|
||||
|
||||
cursor.close();
|
||||
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the given server title is currently used
|
||||
*
|
||||
@ -373,7 +373,7 @@ public class Database extends SQLiteOpenHelper
|
||||
public boolean isTitleUsed(String title)
|
||||
{
|
||||
boolean isTitleUsed = false;
|
||||
|
||||
|
||||
Cursor cursor = this.getReadableDatabase().query(
|
||||
ServerConstants.TABLE_NAME,
|
||||
ServerConstants.ALL,
|
||||
@ -383,16 +383,16 @@ public class Database extends SQLiteOpenHelper
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
if (cursor.moveToNext()) {
|
||||
isTitleUsed = true;
|
||||
}
|
||||
|
||||
|
||||
cursor.close();
|
||||
|
||||
|
||||
return isTitleUsed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Populate a server object from the given database cursor
|
||||
* @param cursor
|
||||
@ -401,36 +401,36 @@ public class Database extends SQLiteOpenHelper
|
||||
private Server populateServer(Cursor cursor)
|
||||
{
|
||||
Server server = new Server();
|
||||
|
||||
|
||||
server.setTitle(cursor.getString(cursor.getColumnIndex((ServerConstants.TITLE))));
|
||||
server.setHost(cursor.getString(cursor.getColumnIndex((ServerConstants.HOST))));
|
||||
server.setPort(cursor.getInt(cursor.getColumnIndex((ServerConstants.PORT))));
|
||||
server.setPassword(cursor.getString(cursor.getColumnIndex(ServerConstants.PASSWORD)));
|
||||
server.setId(cursor.getInt(cursor.getColumnIndex((ServerConstants._ID))));
|
||||
server.setCharset(cursor.getString(cursor.getColumnIndex(ServerConstants.CHARSET)));
|
||||
|
||||
|
||||
String useSSLvalue = cursor.getString(cursor.getColumnIndex(ServerConstants.USE_SSL));
|
||||
if (useSSLvalue != null && useSSLvalue.equals("1")) {
|
||||
server.setUseSSL(true);
|
||||
}
|
||||
|
||||
|
||||
server.setStatus(Status.DISCONNECTED);
|
||||
|
||||
|
||||
// Load identity for server
|
||||
Identity identity = this.getIdentityById(cursor.getInt(cursor.getColumnIndex(ServerConstants.IDENTITY)));
|
||||
server.setIdentity(identity);
|
||||
|
||||
|
||||
// Load auto join channels
|
||||
ArrayList<String> channels = this.getChannelsByServerId(server.getId());
|
||||
server.setAutoJoinChannels(channels);
|
||||
|
||||
|
||||
// Load commands to execute after connect
|
||||
ArrayList<String> commands = this.getCommandsByServerId(server.getId());
|
||||
server.setConnectCommands(commands);
|
||||
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all servers with autoconnect enabled
|
||||
*
|
||||
@ -448,7 +448,7 @@ public class Database extends SQLiteOpenHelper
|
||||
ServerConstants.TITLE + " ASC"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all channels of server
|
||||
*
|
||||
@ -458,7 +458,7 @@ public class Database extends SQLiteOpenHelper
|
||||
public ArrayList<String> getChannelsByServerId(int serverId)
|
||||
{
|
||||
ArrayList<String> channels = new ArrayList<String>();
|
||||
|
||||
|
||||
Cursor cursor = this.getReadableDatabase().query(
|
||||
ChannelConstants.TABLE_NAME,
|
||||
ChannelConstants.ALL,
|
||||
@ -468,17 +468,17 @@ public class Database extends SQLiteOpenHelper
|
||||
null,
|
||||
ChannelConstants.NAME + " ASC"
|
||||
);
|
||||
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
String channel = cursor.getString(cursor.getColumnIndex(ChannelConstants.NAME));
|
||||
channels.add(channel);
|
||||
}
|
||||
|
||||
|
||||
cursor.close();
|
||||
|
||||
|
||||
return channels;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove server from database by unique id
|
||||
*
|
||||
@ -493,19 +493,19 @@ public class Database extends SQLiteOpenHelper
|
||||
deleteAliases(identityId);
|
||||
this.getWritableDatabase().execSQL(
|
||||
"DELETE FROM " + IdentityConstants.TABLE_NAME + " WHERE " + IdentityConstants._ID + " = " + identityId + ";"
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Now delete the server entry
|
||||
this.getWritableDatabase().execSQL(
|
||||
"DELETE FROM " + ServerConstants.TABLE_NAME + " WHERE " + ServerConstants._ID + " = " + serverId + ";"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
protected void setAliases(long identityId, List<String> aliases)
|
||||
{
|
||||
deleteAliases(identityId);
|
||||
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
for (String alias : aliases) {
|
||||
values.clear();
|
||||
@ -514,18 +514,18 @@ public class Database extends SQLiteOpenHelper
|
||||
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,
|
||||
@ -535,15 +535,15 @@ public class Database extends SQLiteOpenHelper
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
aliases.add(cursor.getString(cursor.getColumnIndex(AliasConstants.ALIAS)));
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
|
||||
return aliases;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new identity
|
||||
*
|
||||
@ -556,18 +556,18 @@ public class Database extends SQLiteOpenHelper
|
||||
public long addIdentity(String nickname, String ident, String realname, List<String> aliases)
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
|
||||
values.put(IdentityConstants.NICKNAME, nickname);
|
||||
values.put(IdentityConstants.IDENT, ident);
|
||||
values.put(IdentityConstants.REALNAME, realname);
|
||||
|
||||
|
||||
long identityId = this.getWritableDatabase().insert(IdentityConstants.TABLE_NAME, null, values);
|
||||
|
||||
|
||||
setAliases(identityId, aliases);
|
||||
|
||||
|
||||
return identityId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the identity with the given id
|
||||
*
|
||||
@ -579,21 +579,21 @@ public class Database extends SQLiteOpenHelper
|
||||
public void updateIdentity(int identityId, String nickname, String ident, String realname, List<String> aliases)
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
|
||||
values.put(IdentityConstants.NICKNAME, nickname);
|
||||
values.put(IdentityConstants.IDENT, ident);
|
||||
values.put(IdentityConstants.REALNAME, realname);
|
||||
|
||||
|
||||
this.getWritableDatabase().update(
|
||||
IdentityConstants.TABLE_NAME,
|
||||
values,
|
||||
IdentityConstants._ID + " = " + identityId,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
setAliases(identityId, aliases);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an identity by its id
|
||||
*
|
||||
@ -603,7 +603,7 @@ public class Database extends SQLiteOpenHelper
|
||||
public Identity getIdentityById(int identityId)
|
||||
{
|
||||
Identity identity = null;
|
||||
|
||||
|
||||
Cursor cursor = this.getReadableDatabase().query(
|
||||
IdentityConstants.TABLE_NAME,
|
||||
IdentityConstants.ALL,
|
||||
@ -613,22 +613,22 @@ public class Database extends SQLiteOpenHelper
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
if (cursor.moveToNext()) {
|
||||
identity = new Identity();
|
||||
|
||||
|
||||
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();
|
||||
|
||||
|
||||
return identity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a server by its id
|
||||
*
|
||||
@ -638,7 +638,7 @@ public class Database extends SQLiteOpenHelper
|
||||
public int getIdentityIdByServerId(int serverId)
|
||||
{
|
||||
int identityId = -1;
|
||||
|
||||
|
||||
Cursor cursor = this.getReadableDatabase().query(
|
||||
ServerConstants.TABLE_NAME,
|
||||
ServerConstants.ALL,
|
||||
@ -648,13 +648,13 @@ public class Database extends SQLiteOpenHelper
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
if (cursor.moveToNext()) {
|
||||
identityId = cursor.getInt(cursor.getColumnIndex(ServerConstants.IDENTITY));
|
||||
}
|
||||
|
||||
|
||||
cursor.close();
|
||||
|
||||
|
||||
return identityId;
|
||||
}
|
||||
}
|
||||
|
@ -17,25 +17,25 @@ 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.db;
|
||||
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
/**
|
||||
* Constants for the identity table
|
||||
*
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class IdentityConstants implements BaseColumns
|
||||
{
|
||||
public static final String TABLE_NAME = "identities";
|
||||
|
||||
|
||||
// fields
|
||||
public static final String NICKNAME = "nickname";
|
||||
public static final String IDENT = "ident";
|
||||
public static final String REALNAME = "realname";
|
||||
|
||||
|
||||
/**
|
||||
* All fields of the table
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.db;
|
||||
|
||||
import android.provider.BaseColumns;
|
||||
@ -30,7 +30,7 @@ import android.provider.BaseColumns;
|
||||
public interface ServerConstants extends BaseColumns
|
||||
{
|
||||
public static final String TABLE_NAME = "servers";
|
||||
|
||||
|
||||
// fields
|
||||
public static final String TITLE = "title";
|
||||
public static final String HOST = "host";
|
||||
@ -40,7 +40,7 @@ public interface ServerConstants extends BaseColumns
|
||||
public static final String USE_SSL = "useSSL";
|
||||
public static final String CHARSET = "charset";
|
||||
public static final String IDENTITY = "identity";
|
||||
|
||||
|
||||
/**
|
||||
* All fields of the table
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.exception;
|
||||
|
||||
/**
|
||||
@ -29,7 +29,7 @@ package org.yaaic.exception;
|
||||
public class CommandException extends Throwable
|
||||
{
|
||||
private static final long serialVersionUID = -8317993941455253288L;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new CommandException object
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ 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.exception;
|
||||
|
||||
/**
|
||||
@ -28,7 +28,7 @@ package org.yaaic.exception;
|
||||
public class ValidationException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 6951535205062761539L;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new ValidationException with the given message
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ 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.irc;
|
||||
|
||||
import org.yaaic.model.Server;
|
||||
@ -26,25 +26,25 @@ import android.os.Binder;
|
||||
|
||||
/**
|
||||
* Binder for service communication
|
||||
*
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class IRCBinder extends Binder
|
||||
{
|
||||
private IRCService service;
|
||||
|
||||
private final IRCService service;
|
||||
|
||||
/**
|
||||
* Create a new binder for given service
|
||||
* Create a new binder for given service
|
||||
*
|
||||
* @param service
|
||||
*/
|
||||
public IRCBinder(IRCService service)
|
||||
{
|
||||
super();
|
||||
|
||||
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Connect to given server
|
||||
*
|
||||
@ -54,7 +54,7 @@ public class IRCBinder extends Binder
|
||||
{
|
||||
service.connect(server);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get service associated with this service
|
||||
* @return
|
||||
|
@ -17,7 +17,7 @@ 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.layout;
|
||||
|
||||
import android.content.Context;
|
||||
@ -31,10 +31,11 @@ import android.view.View;
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class NonScalingBackgroundDrawable extends Drawable {
|
||||
private View view;
|
||||
private Drawable drawable;
|
||||
|
||||
public class NonScalingBackgroundDrawable extends Drawable
|
||||
{
|
||||
private final View view;
|
||||
private final Drawable drawable;
|
||||
|
||||
/**
|
||||
* Create a new non scaling background drawable
|
||||
*
|
||||
@ -44,13 +45,14 @@ public class NonScalingBackgroundDrawable extends Drawable {
|
||||
*/
|
||||
public NonScalingBackgroundDrawable(Context context, View view, int resource)
|
||||
{
|
||||
this.view = view;
|
||||
this.drawable = context.getResources().getDrawable(resource);
|
||||
this.view = view;
|
||||
this.drawable = context.getResources().getDrawable(resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the background drawable
|
||||
*/
|
||||
@Override
|
||||
public void draw(Canvas canvas)
|
||||
{
|
||||
int left = (view.getWidth() / 2) - (drawable.getIntrinsicWidth() / 2);
|
||||
@ -59,21 +61,23 @@ public class NonScalingBackgroundDrawable extends Drawable {
|
||||
int bottom = top + drawable.getIntrinsicHeight();
|
||||
|
||||
drawable.setBounds(left, top, right, bottom);
|
||||
|
||||
|
||||
drawable.draw(canvas);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the opacity
|
||||
*/
|
||||
@Override
|
||||
public int getOpacity()
|
||||
{
|
||||
return drawable.getOpacity();
|
||||
return drawable.getOpacity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the alpha
|
||||
*/
|
||||
@Override
|
||||
public void setAlpha(int alpha)
|
||||
{
|
||||
drawable.setAlpha(alpha);
|
||||
@ -82,6 +86,7 @@ public class NonScalingBackgroundDrawable extends Drawable {
|
||||
/**
|
||||
* Set the color filter
|
||||
*/
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter cf)
|
||||
{
|
||||
drawable.setColorFilter(cf);
|
||||
|
@ -17,20 +17,20 @@ 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.listener;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ViewSwitcher;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.TableLayout.LayoutParams;
|
||||
|
||||
import org.yaaic.adapter.DeckAdapter;
|
||||
import org.yaaic.model.Conversation;
|
||||
import org.yaaic.view.MessageListView;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TableLayout.LayoutParams;
|
||||
import android.widget.ViewSwitcher;
|
||||
|
||||
/**
|
||||
* Listener for clicks on conversations
|
||||
*
|
||||
@ -38,9 +38,9 @@ import org.yaaic.view.MessageListView;
|
||||
*/
|
||||
public class ConversationClickListener implements OnItemClickListener
|
||||
{
|
||||
private DeckAdapter adapter;
|
||||
private ViewSwitcher switcher;
|
||||
|
||||
private final DeckAdapter adapter;
|
||||
private final ViewSwitcher switcher;
|
||||
|
||||
/**
|
||||
* Create a new ConversationClickListener
|
||||
*
|
||||
@ -52,19 +52,20 @@ public class ConversationClickListener implements OnItemClickListener
|
||||
this.adapter = adapter;
|
||||
this.switcher = switcher;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* On conversation item clicked
|
||||
*/
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
|
||||
{
|
||||
Conversation conversation = adapter.getItem(position);
|
||||
|
||||
|
||||
MessageListView canvas = adapter.renderConversation(conversation, switcher);
|
||||
canvas.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
|
||||
canvas.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
|
||||
canvas.setDelegateTouchEvents(false); // Do not delegate
|
||||
|
||||
|
||||
adapter.setSwitched(conversation.getName(), canvas);
|
||||
switcher.addView(canvas);
|
||||
switcher.showNext();
|
||||
|
@ -17,9 +17,14 @@ 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.listener;
|
||||
|
||||
/**
|
||||
* Listener for conversations
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public interface ConversationListener
|
||||
{
|
||||
public void onConversationMessage(String target);
|
||||
|
@ -17,18 +17,18 @@ 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.listener;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
|
||||
import org.yaaic.model.Conversation;
|
||||
import org.yaaic.model.Server;
|
||||
import org.yaaic.view.ConversationSwitcher;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Listener for conversation selections
|
||||
*
|
||||
@ -36,10 +36,10 @@ import org.yaaic.view.ConversationSwitcher;
|
||||
*/
|
||||
public class ConversationSelectedListener implements OnItemSelectedListener
|
||||
{
|
||||
private Server server;
|
||||
private TextView titleView;
|
||||
private ConversationSwitcher switcher;
|
||||
|
||||
private final Server server;
|
||||
private final TextView titleView;
|
||||
private final ConversationSwitcher switcher;
|
||||
|
||||
/**
|
||||
* Create a new ConversationSelectedListener
|
||||
*
|
||||
@ -52,38 +52,40 @@ public class ConversationSelectedListener implements OnItemSelectedListener
|
||||
this.titleView = titleView;
|
||||
this.switcher = switcher;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* On conversation selected/focused
|
||||
*/
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> deck, View view, int position, long id)
|
||||
{
|
||||
Conversation conversation = (Conversation) deck.getItemAtPosition(position);
|
||||
|
||||
|
||||
if (conversation != null && conversation.getType() != Conversation.TYPE_SERVER) {
|
||||
titleView.setText(server.getTitle() + " - " + conversation.getName());
|
||||
} else {
|
||||
onNothingSelected(deck);
|
||||
}
|
||||
|
||||
|
||||
// Remember selection
|
||||
if (conversation != null) {
|
||||
Conversation previousConversation = server.getConversation(server.getSelectedConversation());
|
||||
|
||||
|
||||
if (previousConversation != null) {
|
||||
previousConversation.setStatus(Conversation.STATUS_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
conversation.setStatus(Conversation.STATUS_SELECTED);
|
||||
server.setSelectedConversation(conversation.getName());
|
||||
}
|
||||
|
||||
switcher.invalidate();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* On no conversation selected/focused
|
||||
*/
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> deck)
|
||||
{
|
||||
titleView.setText(server.getTitle());
|
||||
|
@ -17,7 +17,7 @@ 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.listener;
|
||||
|
||||
import org.yaaic.activity.MessageActivity;
|
||||
@ -37,16 +37,16 @@ import android.widget.AdapterView.OnItemClickListener;
|
||||
public class MessageClickListener implements OnItemClickListener
|
||||
{
|
||||
private static MessageClickListener instance;
|
||||
|
||||
|
||||
/**
|
||||
* Private constructor
|
||||
*/
|
||||
private MessageClickListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get global instance of message click listener
|
||||
* Get global instance of message click listener
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ -55,17 +55,18 @@ public class MessageClickListener implements OnItemClickListener
|
||||
if (instance == null) {
|
||||
instance = new MessageClickListener();
|
||||
}
|
||||
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* On message item clicked
|
||||
*/
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> group, View view, int position, long id)
|
||||
{
|
||||
MessageListAdapter adapter = (MessageListAdapter) group.getAdapter();
|
||||
|
||||
|
||||
Intent intent = new Intent(group.getContext(), MessageActivity.class);
|
||||
intent.putExtra(Extra.MESSAGE, adapter.getItem(position).getText().toString());
|
||||
group.getContext().startActivity(intent);
|
||||
|
@ -17,7 +17,7 @@ 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.listener;
|
||||
|
||||
public interface ServerListener
|
||||
|
@ -17,7 +17,7 @@ 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.listener;
|
||||
|
||||
import org.yaaic.activity.ConversationActivity;
|
||||
@ -35,8 +35,8 @@ import android.view.View.OnClickListener;
|
||||
*/
|
||||
public class SpeechClickListener implements OnClickListener
|
||||
{
|
||||
private Activity activity;
|
||||
|
||||
private final Activity activity;
|
||||
|
||||
/**
|
||||
* Create a new listener for speech button
|
||||
*
|
||||
@ -47,17 +47,18 @@ public class SpeechClickListener implements OnClickListener
|
||||
{
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* On Click on speech button
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
|
||||
|
||||
|
||||
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
|
||||
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "");
|
||||
|
||||
|
||||
activity.startActivityForResult(intent, ConversationActivity.REQUEST_CODE_SPEECH);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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;
|
||||
|
||||
import android.content.Intent;
|
||||
@ -30,11 +30,11 @@ import android.content.Intent;
|
||||
public abstract class Broadcast
|
||||
{
|
||||
public static final String SERVER_UPDATE = "org.yaaic.server.status";
|
||||
|
||||
|
||||
public static final String CONVERSATION_MESSAGE = "org.yaaic.conversation.message";
|
||||
public static final String CONVERSATION_NEW = "org.yaaic.conversation.new";
|
||||
public static final String CONVERSATION_REMOVE = "org.yaaic.conversation.remove";
|
||||
|
||||
|
||||
/**
|
||||
* Create an Intent for conversation broadcasting
|
||||
*
|
||||
@ -46,13 +46,13 @@ public abstract class Broadcast
|
||||
public static Intent createConversationIntent(String broadcastType, int serverId, String conversationName)
|
||||
{
|
||||
Intent intent = new Intent(broadcastType);
|
||||
|
||||
|
||||
intent.putExtra(Extra.SERVER, serverId);
|
||||
intent.putExtra(Extra.CONVERSATION, conversationName);
|
||||
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an Intent for server broadcasting
|
||||
*
|
||||
@ -63,9 +63,9 @@ public abstract class Broadcast
|
||||
public static Intent createServerIntent(String broadcastType, int serverId)
|
||||
{
|
||||
Intent intent = new Intent(broadcastType);
|
||||
|
||||
|
||||
intent.putExtra(Extra.SERVER, serverId);
|
||||
|
||||
|
||||
return intent;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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;
|
||||
|
||||
/**
|
||||
@ -39,7 +39,7 @@ public class Channel extends Conversation
|
||||
super(name);
|
||||
this.topic = "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of this conversation
|
||||
*/
|
||||
@ -48,7 +48,7 @@ public class Channel extends Conversation
|
||||
{
|
||||
return Conversation.TYPE_CHANNEL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the channel's topic
|
||||
*
|
||||
@ -58,7 +58,7 @@ public class Channel extends Conversation
|
||||
{
|
||||
this.topic = topic;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the topic of the channel
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ 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;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@ -36,27 +36,27 @@ public abstract class Conversation
|
||||
public static final int TYPE_CHANNEL = 1;
|
||||
public static final int TYPE_QUERY = 2;
|
||||
public static final int TYPE_SERVER = 3;
|
||||
|
||||
|
||||
public static final int STATUS_DEFAULT = 1;
|
||||
public static final int STATUS_SELECTED = 2;
|
||||
public static final int STATUS_MESSAGE = 3;
|
||||
public static final int STATUS_HIGHLIGHT = 4;
|
||||
|
||||
|
||||
public static final int HISTORY_SIZE = 30;
|
||||
|
||||
private LinkedList<Message> buffer;
|
||||
private LinkedList<Message> history;
|
||||
private String name;
|
||||
|
||||
private final LinkedList<Message> buffer;
|
||||
private final LinkedList<Message> history;
|
||||
private final String name;
|
||||
private MessageListAdapter adapter;
|
||||
private int status = 1;
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of conversation (channel, query, ..)
|
||||
*
|
||||
* @return See the constants: Conversation.TYPE_*
|
||||
*/
|
||||
public abstract int getType();
|
||||
|
||||
|
||||
/**
|
||||
* Create a new conversation with the given name
|
||||
*
|
||||
@ -68,7 +68,7 @@ public abstract class Conversation
|
||||
this.history = new LinkedList<Message>();
|
||||
this.name = name.toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get name of the conversation (channel, user)
|
||||
*/
|
||||
@ -76,7 +76,7 @@ public abstract class Conversation
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a message to the channel
|
||||
*/
|
||||
@ -84,12 +84,12 @@ public abstract class Conversation
|
||||
{
|
||||
buffer.add(0, message);
|
||||
history.add(message);
|
||||
|
||||
|
||||
if (history.size() > HISTORY_SIZE) {
|
||||
history.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the history
|
||||
*/
|
||||
@ -97,7 +97,7 @@ public abstract class Conversation
|
||||
{
|
||||
return history;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get message of the history at the given position
|
||||
*
|
||||
@ -108,7 +108,7 @@ public abstract class Conversation
|
||||
{
|
||||
return history.get(position);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get last buffered message
|
||||
*
|
||||
@ -120,7 +120,7 @@ public abstract class Conversation
|
||||
buffer.remove(buffer.size() - 1);
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the buffer
|
||||
*
|
||||
@ -130,7 +130,7 @@ public abstract class Conversation
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Does the channel have buffered messages?
|
||||
*/
|
||||
@ -138,7 +138,7 @@ public abstract class Conversation
|
||||
{
|
||||
return buffer.size() > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the message buffer
|
||||
*/
|
||||
@ -146,7 +146,7 @@ public abstract class Conversation
|
||||
{
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store the adapter of this conversation
|
||||
*/
|
||||
@ -154,7 +154,7 @@ public abstract class Conversation
|
||||
{
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the MessageList Adapter of this conversation if known
|
||||
*/
|
||||
@ -162,7 +162,7 @@ public abstract class Conversation
|
||||
{
|
||||
return adapter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set status of conversation
|
||||
*
|
||||
@ -174,15 +174,15 @@ public abstract class Conversation
|
||||
if (this.status == STATUS_SELECTED && status != STATUS_DEFAULT) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Highlight status can only be changed by selecting
|
||||
if (this.status == STATUS_HIGHLIGHT && status != STATUS_SELECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get status of conversation
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ 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;
|
||||
|
||||
/**
|
||||
@ -27,12 +27,12 @@ package org.yaaic.model;
|
||||
*/
|
||||
public class Extra
|
||||
{
|
||||
public static final String SERVER = "server";
|
||||
public static final String SERVER = "server";
|
||||
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 CHANNELS = "channels";
|
||||
public static final String COMMANDS = "commands";
|
||||
public static final String MESSAGE = "message";
|
||||
public static final String USER = "user";
|
||||
|
@ -17,7 +17,7 @@ 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -33,10 +33,10 @@ import java.util.List;
|
||||
public class Identity
|
||||
{
|
||||
private String nickname;
|
||||
private List<String> aliases = new ArrayList<String>();
|
||||
private final List<String> aliases = new ArrayList<String>();
|
||||
private String ident;
|
||||
private String realname;
|
||||
|
||||
|
||||
/**
|
||||
* Set the nickname of this identity
|
||||
*
|
||||
@ -46,7 +46,7 @@ public class Identity
|
||||
{
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the nickname of this identity
|
||||
*
|
||||
@ -56,16 +56,16 @@ 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
|
||||
*
|
||||
@ -75,7 +75,7 @@ public class Identity
|
||||
{
|
||||
this.ident = ident;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the ident of this identity
|
||||
*
|
||||
@ -85,7 +85,7 @@ public class Identity
|
||||
{
|
||||
return ident;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the real name of this identity
|
||||
*
|
||||
@ -95,7 +95,7 @@ public class Identity
|
||||
{
|
||||
this.realname = realname;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the real name of this identity
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ 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;
|
||||
|
||||
import java.util.Date;
|
||||
@ -37,39 +37,39 @@ import android.widget.TextView;
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class Message {
|
||||
public static final int COLOR_GREEN = 0xFF458509;
|
||||
public static final int COLOR_RED = 0xFFcc0000;
|
||||
public static final int COLOR_BLUE = 0xFF729fcf;
|
||||
public static final int COLOR_YELLOW = 0xFFbe9b01;
|
||||
public static final int COLOR_GREY = 0xFFaaaaaa;
|
||||
public static final int COLOR_DEFAULT = 0xFFeeeeee;
|
||||
|
||||
public static final int COLOR_GREEN = 0xFF458509;
|
||||
public static final int COLOR_RED = 0xFFcc0000;
|
||||
public static final int COLOR_BLUE = 0xFF729fcf;
|
||||
public static final int COLOR_YELLOW = 0xFFbe9b01;
|
||||
public static final int COLOR_GREY = 0xFFaaaaaa;
|
||||
public static final int COLOR_DEFAULT = 0xFFeeeeee;
|
||||
|
||||
public static final int[] colors = {
|
||||
0xFFffffff, //White
|
||||
0xFFffff00, //Yellow
|
||||
0xFFff00ff, //Fuchsia
|
||||
0xFFff0000, //Red
|
||||
0xFFc0c0c0, //Silver
|
||||
0xFF808080, //Gray
|
||||
0xFF808000, //Olive
|
||||
0xFF800080, //Purple
|
||||
0xFF800000, //Maroon
|
||||
0xFF00ffff, //Agua
|
||||
0xFF00ff00, //Lime
|
||||
0xFF008080, //Teal
|
||||
0xFF008000, //Green
|
||||
0xFF0000FF, //Blue
|
||||
0xFF000080, //Navy
|
||||
0xFF000000, //Black
|
||||
0xFFffffff, // White
|
||||
0xFFffff00, // Yellow
|
||||
0xFFff00ff, // Fuchsia
|
||||
0xFFff0000, // Red
|
||||
0xFFc0c0c0, // Silver
|
||||
0xFF808080, // Gray
|
||||
0xFF808000, // Olive
|
||||
0xFF800080, // Purple
|
||||
0xFF800000, // Maroon
|
||||
0xFF00ffff, // Agua
|
||||
0xFF00ff00, // Lime
|
||||
0xFF008080, // Teal
|
||||
0xFF008000, // Green
|
||||
0xFF0000FF, // Blue
|
||||
0xFF000080, // Navy
|
||||
0xFF000000, // Black
|
||||
};
|
||||
|
||||
private int icon = -1;
|
||||
private String text;
|
||||
private String sender;
|
||||
private final String text;
|
||||
private final String sender;
|
||||
private SpannableString canvas;
|
||||
private int color = -1;
|
||||
private long timestamp;
|
||||
|
||||
private final long timestamp;
|
||||
|
||||
/**
|
||||
* Create a new message without an icon
|
||||
*
|
||||
@ -91,7 +91,7 @@ public class Message {
|
||||
this.sender = sender;
|
||||
this.timestamp = new Date().getTime();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the message's icon
|
||||
*/
|
||||
@ -99,7 +99,7 @@ public class Message {
|
||||
{
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the message's icon
|
||||
*
|
||||
@ -109,7 +109,7 @@ public class Message {
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the text of this message
|
||||
*
|
||||
@ -119,7 +119,7 @@ public class Message {
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the color of this message
|
||||
*/
|
||||
@ -135,7 +135,9 @@ public class Message {
|
||||
private int getSenderColor()
|
||||
{
|
||||
/* It might be worth to use some hash table here */
|
||||
if (sender == null) return COLOR_DEFAULT;
|
||||
if (sender == null) {
|
||||
return COLOR_DEFAULT;
|
||||
}
|
||||
int color = 0;
|
||||
for(int i = 0; i < sender.length(); i++){
|
||||
color += sender.charAt(i);
|
||||
@ -152,14 +154,14 @@ public class Message {
|
||||
public SpannableString render(Context context)
|
||||
{
|
||||
Settings settings = new Settings(context);
|
||||
|
||||
|
||||
if (canvas == null) {
|
||||
String prefix = icon != -1 && settings.showIcons() ? " " : "";
|
||||
String nick = sender != null ? "<" + sender + "> " : "";
|
||||
String timestamp = settings.showTimestamp() ? Message.generateTimestamp(this.timestamp, settings.use24hFormat()) : "";
|
||||
|
||||
|
||||
canvas = new SpannableString(prefix + timestamp + nick + text);
|
||||
|
||||
|
||||
if (sender != null) {
|
||||
int start = (prefix + timestamp).length() + 1;
|
||||
int end = start + sender.length();
|
||||
@ -177,10 +179,10 @@ public class Message {
|
||||
canvas.setSpan(new ForegroundColorSpan(color), 0, canvas.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return canvas;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render message as text view
|
||||
*
|
||||
@ -191,17 +193,17 @@ public class Message {
|
||||
{
|
||||
// XXX: We should not read settings here ALWAYS for EVERY textview
|
||||
Settings settings = new Settings(context);
|
||||
|
||||
|
||||
TextView canvas = new TextView(context);
|
||||
|
||||
|
||||
canvas.setText(this.render(context));
|
||||
canvas.setTextSize(settings.getFontSize());
|
||||
canvas.setTypeface(Typeface.MONOSPACE);
|
||||
canvas.setTextColor(COLOR_DEFAULT);
|
||||
|
||||
|
||||
return canvas;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a timestamp
|
||||
*
|
||||
@ -211,7 +213,7 @@ public class Message {
|
||||
public static String generateTimestamp(long timestamp, boolean use24hFormat)
|
||||
{
|
||||
Date date = new Date(timestamp);
|
||||
|
||||
|
||||
int hours = date.getHours();
|
||||
int minutes = date.getMinutes();
|
||||
|
||||
@ -221,7 +223,7 @@ public class Message {
|
||||
hours = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return "[" + (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + "] ";
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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;
|
||||
|
||||
/**
|
||||
@ -36,10 +36,11 @@ public class Query extends Conversation
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of this conversation
|
||||
*/
|
||||
@Override
|
||||
public int getType()
|
||||
{
|
||||
return Conversation.TYPE_QUERY;
|
||||
|
@ -17,7 +17,7 @@ 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;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@ -30,10 +30,10 @@ import java.util.LinkedList;
|
||||
public class Scrollback
|
||||
{
|
||||
public static final int MAX_HISTORY = 10;
|
||||
|
||||
private LinkedList<String> messages;
|
||||
|
||||
private final LinkedList<String> messages;
|
||||
private int pointer;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new scrollback object
|
||||
*/
|
||||
@ -41,21 +41,21 @@ public class Scrollback
|
||||
{
|
||||
messages = new LinkedList<String>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a message to the history
|
||||
*/
|
||||
public void addMessage(String message)
|
||||
{
|
||||
messages.addLast(message);
|
||||
|
||||
|
||||
if (messages.size() > MAX_HISTORY) {
|
||||
messages.removeFirst();
|
||||
}
|
||||
|
||||
|
||||
pointer = messages.size();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Go back in history
|
||||
*
|
||||
@ -66,14 +66,14 @@ public class Scrollback
|
||||
if (pointer > 0) {
|
||||
pointer--;
|
||||
}
|
||||
|
||||
|
||||
if (messages.size() > 0) {
|
||||
return messages.get(pointer);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Go forward in history
|
||||
*
|
||||
@ -86,11 +86,11 @@ public class Scrollback
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
if (messages.size() > 0) {
|
||||
return messages.get(pointer);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -41,14 +41,14 @@ public class Server
|
||||
private String charset;
|
||||
private boolean useSSL = false;
|
||||
private Identity identity;
|
||||
|
||||
private LinkedHashMap<String, Conversation> conversations = new LinkedHashMap<String, Conversation>();
|
||||
|
||||
private final LinkedHashMap<String, Conversation> conversations = new LinkedHashMap<String, Conversation>();
|
||||
private ArrayList<String> autoJoinChannels;
|
||||
private ArrayList<String> connectCommands;
|
||||
|
||||
|
||||
private int status = Status.DISCONNECTED;
|
||||
private String selected = "";
|
||||
|
||||
|
||||
/**
|
||||
* Create a new server object
|
||||
*/
|
||||
@ -57,7 +57,7 @@ public class Server
|
||||
conversations.put(ServerInfo.DEFAULT_NAME, new ServerInfo());
|
||||
this.selected = ServerInfo.DEFAULT_NAME;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the identity for this server
|
||||
*
|
||||
@ -67,7 +67,7 @@ public class Server
|
||||
{
|
||||
this.identity = identity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the identity for this server
|
||||
*
|
||||
@ -77,7 +77,7 @@ public class Server
|
||||
{
|
||||
return identity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get unique id of server
|
||||
*
|
||||
@ -87,7 +87,7 @@ public class Server
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set unique id of server
|
||||
*
|
||||
@ -97,7 +97,7 @@ public class Server
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set password of the server
|
||||
*
|
||||
@ -107,7 +107,7 @@ public class Server
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the password of the server
|
||||
*
|
||||
@ -117,7 +117,7 @@ public class Server
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get title of server
|
||||
*
|
||||
@ -127,7 +127,7 @@ public class Server
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set title of server
|
||||
*
|
||||
@ -137,7 +137,7 @@ public class Server
|
||||
{
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get hostname of server
|
||||
*
|
||||
@ -147,7 +147,7 @@ public class Server
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set hostname of server
|
||||
*
|
||||
@ -157,7 +157,7 @@ public class Server
|
||||
{
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get port of server
|
||||
*
|
||||
@ -167,7 +167,7 @@ public class Server
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set port of server
|
||||
*
|
||||
@ -177,7 +177,7 @@ public class Server
|
||||
{
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the charset to be used for all messages sent to the server
|
||||
*
|
||||
@ -187,7 +187,7 @@ public class Server
|
||||
{
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the charset to be used with this server
|
||||
*
|
||||
@ -197,7 +197,7 @@ public class Server
|
||||
{
|
||||
return charset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set if this connections needs to use ssl
|
||||
*/
|
||||
@ -205,7 +205,7 @@ public class Server
|
||||
{
|
||||
this.useSSL = useSSL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Does this connection use SSL?
|
||||
*
|
||||
@ -215,7 +215,7 @@ public class Server
|
||||
{
|
||||
return useSSL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set connection status of server
|
||||
*
|
||||
@ -225,7 +225,7 @@ public class Server
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get connection status of server
|
||||
*
|
||||
@ -235,7 +235,7 @@ public class Server
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set list of channels to auto join after connect
|
||||
*
|
||||
@ -245,7 +245,7 @@ public class Server
|
||||
{
|
||||
this.autoJoinChannels = autoJoinChannels;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get list of channels to auto join after connect
|
||||
*
|
||||
@ -255,7 +255,7 @@ public class Server
|
||||
{
|
||||
return autoJoinChannels;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set commands to execute after connect
|
||||
*
|
||||
@ -265,7 +265,7 @@ public class Server
|
||||
{
|
||||
this.connectCommands = connectCommands;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get commands to execute after connect
|
||||
*
|
||||
@ -275,17 +275,17 @@ public class Server
|
||||
{
|
||||
return connectCommands;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is disconnected?
|
||||
*
|
||||
* @return true if the user is disconnected, false if the user is connected or currently connecting
|
||||
* @return true if the user is disconnected, false if the user is connected or currently connecting
|
||||
*/
|
||||
public boolean isDisconnected()
|
||||
{
|
||||
return status == Status.DISCONNECTED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is connected?
|
||||
*
|
||||
@ -295,7 +295,7 @@ public class Server
|
||||
{
|
||||
return status == Status.CONNECTED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all conversations
|
||||
*
|
||||
@ -305,7 +305,7 @@ public class Server
|
||||
{
|
||||
return conversations.values();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get conversation by name
|
||||
*/
|
||||
@ -313,7 +313,7 @@ public class Server
|
||||
{
|
||||
return conversations.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new conversation
|
||||
*
|
||||
@ -323,7 +323,7 @@ public class Server
|
||||
{
|
||||
conversations.put(conversation.getName().toLowerCase(), conversation);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes a conversation by name
|
||||
*
|
||||
@ -333,19 +333,19 @@ public class Server
|
||||
{
|
||||
conversations.remove(name.toLowerCase());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove all conversations
|
||||
*/
|
||||
public void clearConversations()
|
||||
{
|
||||
conversations.clear();
|
||||
|
||||
|
||||
// reset defaults
|
||||
conversations.put(ServerInfo.DEFAULT_NAME, new ServerInfo());
|
||||
this.selected = ServerInfo.DEFAULT_NAME;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set name of currently selected conversation
|
||||
*
|
||||
@ -355,9 +355,9 @@ public class Server
|
||||
{
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get name of currently selected conversation
|
||||
* Get name of currently selected conversation
|
||||
*
|
||||
* @return The name of the selected conversation
|
||||
*/
|
||||
@ -365,7 +365,7 @@ public class Server
|
||||
{
|
||||
return selected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get names of the currently joined channels
|
||||
*
|
||||
@ -375,16 +375,16 @@ public class Server
|
||||
{
|
||||
ArrayList<String> channels = new ArrayList<String>();
|
||||
Collection<Conversation> mConversations = conversations.values();
|
||||
|
||||
|
||||
for (Conversation conversation : mConversations) {
|
||||
if (conversation.getType() == Conversation.TYPE_CHANNEL) {
|
||||
channels.add(conversation.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return channels;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get icon for current server status
|
||||
*
|
||||
@ -401,7 +401,7 @@ public class Server
|
||||
case Status.CONNECTING:
|
||||
return R.drawable.connecting;
|
||||
}
|
||||
|
||||
|
||||
return R.drawable.connecting;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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;
|
||||
|
||||
/**
|
||||
@ -28,7 +28,7 @@ package org.yaaic.model;
|
||||
public class ServerInfo extends Conversation
|
||||
{
|
||||
public static final String DEFAULT_NAME = "";
|
||||
|
||||
|
||||
/**
|
||||
* Create a new ServerInfo object
|
||||
*
|
||||
|
@ -17,15 +17,16 @@ 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 server status constants
|
||||
* Helper class for server status constants
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class Status {
|
||||
public class Status
|
||||
{
|
||||
public static final int DISCONNECTED = 0;
|
||||
public static final int CONNECTING = 1;
|
||||
public static final int CONNECTED = 2;
|
||||
|
@ -17,17 +17,17 @@ 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.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.yaaic.listener.ConversationListener;
|
||||
import org.yaaic.model.Broadcast;
|
||||
import org.yaaic.model.Extra;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* A channel receiver for receiving channel updates
|
||||
*
|
||||
@ -35,14 +35,14 @@ import org.yaaic.model.Extra;
|
||||
*/
|
||||
public class ConversationReceiver extends BroadcastReceiver
|
||||
{
|
||||
private ConversationListener listener;
|
||||
private int serverId;
|
||||
|
||||
private final ConversationListener listener;
|
||||
private final int serverId;
|
||||
|
||||
/**
|
||||
* Create a new channel receiver
|
||||
*
|
||||
*
|
||||
* @param serverId Only listen on channels of this server
|
||||
* @param listener
|
||||
* @param listener
|
||||
*/
|
||||
public ConversationReceiver(int serverId, ConversationListener listener)
|
||||
{
|
||||
@ -63,7 +63,7 @@ public class ConversationReceiver extends BroadcastReceiver
|
||||
if (serverId != this.serverId) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String action = intent.getAction();
|
||||
|
||||
if (action.equals(Broadcast.CONVERSATION_MESSAGE)) {
|
||||
@ -73,6 +73,6 @@ public class ConversationReceiver extends BroadcastReceiver
|
||||
} else if (action.equals(Broadcast.CONVERSATION_REMOVE)) {
|
||||
listener.onRemoveConversation(intent.getExtras().getString(Extra.CONVERSATION));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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.receiver;
|
||||
|
||||
import org.yaaic.listener.ServerListener;
|
||||
@ -33,8 +33,8 @@ import android.content.Intent;
|
||||
*/
|
||||
public class ServerReceiver extends BroadcastReceiver
|
||||
{
|
||||
private ServerListener listener;
|
||||
|
||||
private final ServerListener listener;
|
||||
|
||||
/**
|
||||
* Create a new server receiver
|
||||
*
|
||||
@ -51,6 +51,6 @@ public class ServerReceiver extends BroadcastReceiver
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
listener.onStatusUpdate();
|
||||
listener.onStatusUpdate();
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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.ssl;
|
||||
|
||||
import java.security.cert.CertificateException;
|
||||
@ -37,6 +37,7 @@ public class NaiveTrustManager implements X509TrustManager
|
||||
*
|
||||
* @throws CertificateException if not trusted
|
||||
*/
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException
|
||||
{
|
||||
// No Exception == Trust
|
||||
@ -47,6 +48,7 @@ public class NaiveTrustManager implements X509TrustManager
|
||||
*
|
||||
* @throws CertificateException if not trusted
|
||||
*/
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException
|
||||
{
|
||||
// No Exception == Trust
|
||||
@ -55,6 +57,7 @@ public class NaiveTrustManager implements X509TrustManager
|
||||
/**
|
||||
* Get accepted issuers
|
||||
*/
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers()
|
||||
{
|
||||
return new X509Certificate[0];
|
||||
|
@ -17,7 +17,7 @@ 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.view;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -39,8 +39,8 @@ import android.view.View;
|
||||
public class ConversationSwitcher extends View
|
||||
{
|
||||
private Server server;
|
||||
private Paint paint;
|
||||
|
||||
private final Paint paint;
|
||||
|
||||
/**
|
||||
* Create a new ConversationSwitcher
|
||||
*
|
||||
@ -49,11 +49,11 @@ public class ConversationSwitcher extends View
|
||||
public ConversationSwitcher(Context context, AttributeSet attributes)
|
||||
{
|
||||
super(context, attributes);
|
||||
|
||||
|
||||
paint = new Paint();
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the server whos conversations should be displayed
|
||||
*
|
||||
@ -63,37 +63,39 @@ public class ConversationSwitcher extends View
|
||||
{
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Measure the size of the view
|
||||
*
|
||||
* @param widthMeasureSpec
|
||||
* @param heightMeasureSpec
|
||||
*/
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
||||
{
|
||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), 16);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* On draw
|
||||
*/
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas)
|
||||
{
|
||||
super.onDraw(canvas);
|
||||
|
||||
|
||||
if (server == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<Conversation> conversations = server.getConversations();
|
||||
|
||||
|
||||
int i = 0;
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
int circles = conversations.size();
|
||||
int startX = (width / 2) - (((circles + 1) / 2) * 12);
|
||||
|
||||
|
||||
for (Conversation conversation : conversations) {
|
||||
switch (conversation.getStatus()) {
|
||||
case Conversation.STATUS_DEFAULT:
|
||||
@ -109,10 +111,10 @@ public class ConversationSwitcher extends View
|
||||
paint.setColor(0xFFFFFFFF);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
canvas.drawCircle(startX + 12 * i, height / 2, 4, paint);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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.view;
|
||||
|
||||
import org.yaaic.adapter.MessageListAdapter;
|
||||
@ -31,17 +31,17 @@ import android.widget.Gallery;
|
||||
import android.widget.ListView;
|
||||
|
||||
/**
|
||||
* A customized ListView for Messages
|
||||
* A customized ListView for Messages
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class MessageListView extends ListView
|
||||
{
|
||||
private boolean delegate = true;
|
||||
private View parent;
|
||||
private final View parent;
|
||||
private int parentWidth;
|
||||
private int parentHeight;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new MessageListView
|
||||
*
|
||||
@ -50,14 +50,14 @@ public class MessageListView extends ListView
|
||||
public MessageListView(Context context, View parent)
|
||||
{
|
||||
super(context);
|
||||
|
||||
|
||||
this.parent = parent;
|
||||
this.setOnItemClickListener(MessageClickListener.getInstance());
|
||||
|
||||
|
||||
parentWidth = parent.getWidth();
|
||||
parentHeight = parent.getHeight();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Should all touch events delegated?
|
||||
*
|
||||
@ -67,7 +67,7 @@ public class MessageListView extends ListView
|
||||
{
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle touch screen motion events
|
||||
*/
|
||||
@ -75,7 +75,7 @@ public class MessageListView extends ListView
|
||||
public boolean onTouchEvent(MotionEvent event)
|
||||
{
|
||||
if (delegate) {
|
||||
// We delegate the touch events to the underlying view
|
||||
// We delegate the touch events to the underlying view
|
||||
return false;
|
||||
} else {
|
||||
return super.onTouchEvent(event);
|
||||
@ -90,25 +90,26 @@ public class MessageListView extends ListView
|
||||
{
|
||||
if (delegate && (parent.getWidth() != parentWidth || parent.getHeight() != parentHeight)) {
|
||||
// parent size changed, resizing this child too
|
||||
|
||||
|
||||
parentWidth = parent.getWidth();
|
||||
parentHeight = parent.getHeight();
|
||||
|
||||
|
||||
this.setLayoutParams(new Gallery.LayoutParams(
|
||||
parent.getWidth() / 100 * 85,
|
||||
parent.getHeight()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the adapter of this MessageListView
|
||||
* (Helper to avoid casting)
|
||||
*
|
||||
* @return The MessageListAdapter
|
||||
*/
|
||||
@Override
|
||||
public MessageListAdapter getAdapter()
|
||||
{
|
||||
return (MessageListAdapter) super.getAdapter();
|
||||
|
Loading…
Reference in New Issue
Block a user