1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-22 17:02:21 -05:00

Some more simple refactorings

This commit is contained in:
Sebastian Kaspari 2011-03-14 22:15:13 +01:00
parent 1c8076ec53
commit 95f3c4b255
17 changed files with 182 additions and 82 deletions

View File

@ -76,10 +76,12 @@ public class AddAliasActivity extends Activity implements OnClickListener, OnIte
aliasInput.setText(""); aliasInput.setText("");
okButton.setEnabled(true); okButton.setEnabled(true);
break; break;
case R.id.cancel: case R.id.cancel:
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
finish(); finish();
break; break;
case R.id.ok: case R.id.ok:
// Get list and return as result // Get list and return as result
Intent intent = new Intent(); Intent intent = new Intent();
@ -118,18 +120,30 @@ public class AddAliasActivity extends Activity implements OnClickListener, OnIte
alert.show(); alert.show();
} }
/**
* On text changed
*/
@Override @Override
public void afterTextChanged(Editable s) { public void onTextChanged(CharSequence s, int start, int before, int count)
// 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); addButton.setEnabled(aliasInput.getText().length() > 0);
} }
/**
* After text changed
*/
@Override
public void afterTextChanged(Editable s)
{
// Do nothing.
}
/**
* Before text changed
*/
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
// Do nothing.
}
} }

View File

@ -99,10 +99,12 @@ public class AddChannelActivity extends Activity implements OnClickListener, OnI
channelInput.setText("#"); channelInput.setText("#");
okButton.setEnabled(true); okButton.setEnabled(true);
break; break;
case R.id.cancel: case R.id.cancel:
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
finish(); finish();
break; break;
case R.id.ok: case R.id.ok:
// Get list and return as result // Get list and return as result
Intent intent = new Intent(); Intent intent = new Intent();

View File

@ -105,10 +105,12 @@ public class AddCommandsActivity extends Activity implements OnClickListener, On
commandInput.setText("/"); commandInput.setText("/");
okButton.setEnabled(true); okButton.setEnabled(true);
break; break;
case R.id.cancel: case R.id.cancel:
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
finish(); finish();
break; break;
case R.id.ok: case R.id.ok:
// Get list and return as result // Get list and return as result
Intent intent = new Intent(); Intent intent = new Intent();

View File

@ -145,9 +145,11 @@ public class AddServerActivity extends Activity implements OnClickListener
aliases.clear(); aliases.clear();
aliases.addAll(data.getExtras().getStringArrayList(Extra.ALIASES)); aliases.addAll(data.getExtras().getStringArrayList(Extra.ALIASES));
break; break;
case REQUEST_CODE_CHANNELS: case REQUEST_CODE_CHANNELS:
channels = data.getExtras().getStringArrayList(Extra.CHANNELS); channels = data.getExtras().getStringArrayList(Extra.CHANNELS);
break; break;
case REQUEST_CODE_COMMANDS: case REQUEST_CODE_COMMANDS:
commands = data.getExtras().getStringArrayList(Extra.COMMANDS); commands = data.getExtras().getStringArrayList(Extra.COMMANDS);
break; break;
@ -166,16 +168,19 @@ public class AddServerActivity extends Activity implements OnClickListener
aliasIntent.putExtra(Extra.ALIASES, aliases); aliasIntent.putExtra(Extra.ALIASES, aliases);
startActivityForResult(aliasIntent, REQUEST_CODE_ALIASES); startActivityForResult(aliasIntent, REQUEST_CODE_ALIASES);
break; break;
case R.id.channels: case R.id.channels:
Intent channelIntent = new Intent(this, AddChannelActivity.class); Intent channelIntent = new Intent(this, AddChannelActivity.class);
channelIntent.putExtra(Extra.CHANNELS, channels); channelIntent.putExtra(Extra.CHANNELS, channels);
startActivityForResult(channelIntent, REQUEST_CODE_CHANNELS); startActivityForResult(channelIntent, REQUEST_CODE_CHANNELS);
break; break;
case R.id.commands: case R.id.commands:
Intent commandsIntent = new Intent(this, AddCommandsActivity.class); Intent commandsIntent = new Intent(this, AddCommandsActivity.class);
commandsIntent.putExtra(Extra.COMMANDS, commands); commandsIntent.putExtra(Extra.COMMANDS, commands);
startActivityForResult(commandsIntent, REQUEST_CODE_COMMANDS); startActivityForResult(commandsIntent, REQUEST_CODE_COMMANDS);
break; break;
case R.id.add: case R.id.add:
try { try {
validateServer(); validateServer();
@ -191,6 +196,7 @@ public class AddServerActivity extends Activity implements OnClickListener
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
} }
break; break;
case R.id.cancel: case R.id.cancel:
setResult(RESULT_CANCELED); setResult(RESULT_CANCELED);
finish(); finish();

View File

@ -72,8 +72,8 @@ import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.View.OnKeyListener; import android.view.View.OnKeyListener;
import android.view.Window;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
@ -197,6 +197,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
PackageManager pm = getPackageManager(); PackageManager pm = getPackageManager();
Button speechButton = (Button) findViewById(R.id.speech); Button speechButton = (Button) findViewById(R.id.speech);
List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() != 0) { if (activities.size() != 0) {
((Button) findViewById(R.id.speech)).setOnClickListener(new SpeechClickListener(this)); ((Button) findViewById(R.id.speech)).setOnClickListener(new SpeechClickListener(this));
speechButton.setVisibility(View.VISIBLE); speechButton.setVisibility(View.VISIBLE);
@ -326,6 +327,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
setResult(RESULT_OK); setResult(RESULT_OK);
finish(); finish();
break; break;
case R.id.close: case R.id.close:
Conversation conversationToClose = deckAdapter.getItem(deck.getSelectedItemPosition()); Conversation conversationToClose = deckAdapter.getItem(deck.getSelectedItemPosition());
// Make sure we part a channel when closing the channel conversation // Make sure we part a channel when closing the channel conversation
@ -339,9 +341,11 @@ public class ConversationActivity extends Activity implements ServiceConnection,
Toast.makeText(this, getResources().getString(R.string.close_server_window), Toast.LENGTH_SHORT).show(); Toast.makeText(this, getResources().getString(R.string.close_server_window), Toast.LENGTH_SHORT).show();
} }
break; break;
case R.id.join: case R.id.join:
startActivityForResult(new Intent(this, JoinActivity.class), REQUEST_CODE_JOIN); startActivityForResult(new Intent(this, JoinActivity.class), REQUEST_CODE_JOIN);
break; break;
case R.id.users: case R.id.users:
Conversation conversationForUserList = deckAdapter.getItem(deck.getSelectedItemPosition()); Conversation conversationForUserList = deckAdapter.getItem(deck.getSelectedItemPosition());
if (conversationForUserList.getType() == Conversation.TYPE_CHANNEL) { if (conversationForUserList.getType() == Conversation.TYPE_CHANNEL) {
@ -394,11 +398,13 @@ public class ConversationActivity extends Activity implements ServiceConnection,
if (adapter != null) { if (adapter != null) {
adapter.addMessage(message); adapter.addMessage(message);
int status; int status;
switch (message.getType()) switch (message.getType())
{ {
case Message.TYPE_MISC: case Message.TYPE_MISC:
status = Conversation.STATUS_MISC; status = Conversation.STATUS_MISC;
break; break;
default: default:
status = Conversation.STATUS_MESSAGE; status = Conversation.STATUS_MESSAGE;
break; break;

View File

@ -41,6 +41,9 @@ import android.widget.TextView;
*/ */
public class ServerListAdapter extends BaseAdapter public class ServerListAdapter extends BaseAdapter
{ {
private static final int COLOR_CONNECTED = 0xFFbcbcbc;
private static final int COLOR_DISCONNECTED = 0xFF585858;
private ArrayList<Server> servers; private ArrayList<Server> servers;
/** /**
@ -136,11 +139,11 @@ public class ServerListAdapter extends BaseAdapter
hostView.setText(server.getIdentity().getNickname() + " @ " + server.getHost() + " : " + server.getPort()); hostView.setText(server.getIdentity().getNickname() + " @ " + server.getHost() + " : " + server.getPort());
if (server.isConnected()) { if (server.isConnected()) {
titleView.setTextColor(0xFFbcbcbc); titleView.setTextColor(COLOR_CONNECTED);
hostView.setTextColor(0xFFbcbcbc); hostView.setTextColor(COLOR_CONNECTED);
} else { } else {
titleView.setTextColor(0xFF585858); titleView.setTextColor(COLOR_DISCONNECTED);
hostView.setTextColor(0xFF585858); hostView.setTextColor(COLOR_DISCONNECTED);
} }
((ImageView) v.findViewById(R.id.status)).setImageResource(server.getStatusIcon()); ((ImageView) v.findViewById(R.id.status)).setImageResource(server.getStatusIcon());

View File

@ -124,7 +124,6 @@ public class UserActionListAdapter extends BaseAdapter
textView.setText(labels[position]); textView.setText(labels[position]);
iconView.setImageResource(icons[position]); iconView.setImageResource(icons[position]);
return convertView; return convertView;
} }
} }

View File

@ -52,8 +52,8 @@ public class AMsgHandler extends BaseHandler
if (params.length > 1) { if (params.length > 1) {
String text = BaseHandler.mergeParams(params); String text = BaseHandler.mergeParams(params);
Collection<Conversation> mConversations = server.getConversations(); Collection<Conversation> mConversations = server.getConversations();
for (Conversation currentConversation : mConversations) { for (Conversation currentConversation : mConversations) {
if (currentConversation.getType() == Conversation.TYPE_CHANNEL) { if (currentConversation.getType() == Conversation.TYPE_CHANNEL) {
Message message = new Message("<" + service.getConnection(server.getId()).getNick() + "> " + text); Message message = new Message("<" + service.getConnection(server.getId()).getNick() + "> " + text);

View File

@ -1,15 +1,43 @@
/*
Yaaic - Yet Another Android IRC Client
Copyright 2009-2011 Sebastian Kaspari
This file is part of Yaaic.
Yaaic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Yaaic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.db; package org.yaaic.db;
import android.provider.BaseColumns; import android.provider.BaseColumns;
public class AliasConstants implements BaseColumns { /**
* Constants for the aliases table
*
* @author Sebastian Kaspari <s.kaspari@googlemail.com>
*/
public class AliasConstants implements BaseColumns
{
public static final String TABLE_NAME = "aliases"; public static final String TABLE_NAME = "aliases";
// fields // fields
public static final String ALIAS = "alias"; public static final String ALIAS = "alias";
public static final String IDENTITY = "identity"; public static final String IDENTITY = "identity";
/**
* All fields of the table
*/
public static final String[] ALL = { public static final String[] ALL = {
_ID, _ID,
ALIAS, ALIAS,

View File

@ -21,7 +21,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
package org.yaaic.exception; package org.yaaic.exception;
/** /**
* A valiadtion exception is thrown if any user input is invalid * A ValidationException is thrown if any user input is invalid
* *
* @author Sebastian Kaspari * @author Sebastian Kaspari
*/ */

View File

@ -56,7 +56,8 @@ public class IRCBinder extends Binder
} }
/** /**
* Get service associated with this service * Get service associated with this binder
*
* @return * @return
*/ */
public IRCService getService() public IRCService getService()

View File

@ -434,7 +434,9 @@ public class IRCConnection extends PircBot
@Override @Override
protected void onMode(String target, String sourceNick, String sourceLogin, String sourceHostname, String mode) protected void onMode(String target, String sourceNick, String sourceLogin, String sourceHostname, String mode)
{ {
/*//Disabled as it doubles events (e.g. onOp and onMode will be called) // Disabled as it doubles events (e.g. onOp and onMode will be called)
/*
Message message = new Message(sourceNick + " sets mode " + mode); Message message = new Message(sourceNick + " sets mode " + mode);
server.getChannel(target).addMessage(message); server.getChannel(target).addMessage(message);
@ -454,6 +456,7 @@ public class IRCConnection extends PircBot
if (getNick().equalsIgnoreCase(newNick)) { if (getNick().equalsIgnoreCase(newNick)) {
this.updateNickMatchPattern(); this.updateNickMatchPattern();
} }
Vector<String> channels = getChannelsByNickname(newNick); Vector<String> channels = getChannelsByNickname(newNick);
for (String target : channels) { for (String target : channels) {

View File

@ -27,7 +27,24 @@ package org.yaaic.listener;
*/ */
public interface ConversationListener public interface ConversationListener
{ {
/**
* On new conversation message for given target
*
* @param target
*/
public void onConversationMessage(String target); public void onConversationMessage(String target);
/**
* On new conversation created (for given target)
*
* @param target
*/
public void onNewConversation(String target); public void onNewConversation(String target);
/**
* On conversation removed (for given target)
*
* @param target
*/
public void onRemoveConversation(String target); public void onRemoveConversation(String target);
} }

View File

@ -20,7 +20,15 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.listener; package org.yaaic.listener;
/**
* Listener for changes regarding a server
*
* @author Sebastian Kaspari
*/
public interface ServerListener public interface ServerListener
{ {
/**
* On server status update (disconnected, connecting, connected)
*/
public void onStatusUpdate(); public void onStatusUpdate();
} }

View File

@ -41,8 +41,7 @@ public abstract class Conversation
public static final int STATUS_SELECTED = 2; public static final int STATUS_SELECTED = 2;
public static final int STATUS_MESSAGE = 3; public static final int STATUS_MESSAGE = 3;
public static final int STATUS_HIGHLIGHT = 4; public static final int STATUS_HIGHLIGHT = 4;
/* join/part/quit */ public static final int STATUS_MISC = 5; // join/part/quit
public static final int STATUS_MISC = 5;
public static final int HISTORY_SIZE = 30; public static final int HISTORY_SIZE = 30;

View File

@ -57,12 +57,24 @@ public class Identity
return nickname; return nickname;
} }
public void setAliases(Collection<String> aliases) { /**
* Set a collection of aliases for this identity
*
* @param aliases
*/
public void setAliases(Collection<String> aliases)
{
this.aliases.clear(); this.aliases.clear();
this.aliases.addAll(aliases); this.aliases.addAll(aliases);
} }
public List<String> getAliases() { /**
* Get all aliases for this identity
*
* @return
*/
public List<String> getAliases()
{
return Collections.unmodifiableList(aliases); return Collections.unmodifiableList(aliases);
} }