From 95f3c4b25572a5885581d6ca7678448f464c734f Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Mon, 14 Mar 2011 22:15:13 +0100 Subject: [PATCH] Some more simple refactorings --- .../org/yaaic/activity/AddAliasActivity.java | 136 ++++++++++-------- .../yaaic/activity/AddChannelActivity.java | 2 + .../yaaic/activity/AddCommandsActivity.java | 2 + .../org/yaaic/activity/AddServerActivity.java | 6 + .../yaaic/activity/ConversationActivity.java | 8 +- .../org/yaaic/adapter/ServerListAdapter.java | 11 +- .../yaaic/adapter/UserActionListAdapter.java | 1 - .../yaaic/command/handler/AMsgHandler.java | 2 +- .../src/org/yaaic/db/AliasConstants.java | 32 ++++- .../yaaic/exception/ValidationException.java | 2 +- application/src/org/yaaic/irc/IRCBinder.java | 5 +- .../src/org/yaaic/irc/IRCConnection.java | 5 +- .../yaaic/listener/ConversationListener.java | 17 +++ .../org/yaaic/listener/ServerListener.java | 8 ++ .../src/org/yaaic/model/Conversation.java | 3 +- application/src/org/yaaic/model/Identity.java | 18 ++- application/src/org/yaaic/model/Status.java | 6 +- 17 files changed, 182 insertions(+), 82 deletions(-) diff --git a/application/src/org/yaaic/activity/AddAliasActivity.java b/application/src/org/yaaic/activity/AddAliasActivity.java index 3edbc46..53bc5f7 100644 --- a/application/src/org/yaaic/activity/AddAliasActivity.java +++ b/application/src/org/yaaic/activity/AddAliasActivity.java @@ -65,71 +65,85 @@ public class AddAliasActivity extends Activity implements OnClickListener, OnIte /** * On Click */ - @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; - } - } + @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; - /** - * On item clicked - */ - @Override - public void onItemClick(AdapterView list, View item, int position, long id) - { - final String alias = adapter.getItem(position); + case R.id.cancel: + setResult(RESULT_CANCELED); + finish(); + break; - String[] items = { getResources().getString(R.string.action_remove) }; + 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; + } + } - 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(); - } + /** + * On item clicked + */ + @Override + public void onItemClick(AdapterView list, View item, int position, long id) + { + final String alias = adapter.getItem(position); - @Override - public void afterTextChanged(Editable s) { - // Do nothing. - } + String[] items = { getResources().getString(R.string.action_remove) }; - @Override - 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(); + } - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - addButton.setEnabled(aliasInput.getText().length() > 0); - } + /** + * On text changed + */ + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) + { + 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. + } } diff --git a/application/src/org/yaaic/activity/AddChannelActivity.java b/application/src/org/yaaic/activity/AddChannelActivity.java index dd8c767..fd60f62 100644 --- a/application/src/org/yaaic/activity/AddChannelActivity.java +++ b/application/src/org/yaaic/activity/AddChannelActivity.java @@ -99,10 +99,12 @@ public class AddChannelActivity extends Activity implements OnClickListener, OnI channelInput.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(); diff --git a/application/src/org/yaaic/activity/AddCommandsActivity.java b/application/src/org/yaaic/activity/AddCommandsActivity.java index cf995bc..09b9db1 100644 --- a/application/src/org/yaaic/activity/AddCommandsActivity.java +++ b/application/src/org/yaaic/activity/AddCommandsActivity.java @@ -105,10 +105,12 @@ public class AddCommandsActivity extends Activity implements OnClickListener, On commandInput.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(); diff --git a/application/src/org/yaaic/activity/AddServerActivity.java b/application/src/org/yaaic/activity/AddServerActivity.java index 55b6e21..3a8dfb6 100644 --- a/application/src/org/yaaic/activity/AddServerActivity.java +++ b/application/src/org/yaaic/activity/AddServerActivity.java @@ -145,9 +145,11 @@ public class AddServerActivity extends Activity implements OnClickListener aliases.clear(); aliases.addAll(data.getExtras().getStringArrayList(Extra.ALIASES)); break; + case REQUEST_CODE_CHANNELS: channels = data.getExtras().getStringArrayList(Extra.CHANNELS); break; + case REQUEST_CODE_COMMANDS: commands = data.getExtras().getStringArrayList(Extra.COMMANDS); break; @@ -166,16 +168,19 @@ public class AddServerActivity extends Activity implements OnClickListener aliasIntent.putExtra(Extra.ALIASES, aliases); startActivityForResult(aliasIntent, REQUEST_CODE_ALIASES); break; + case R.id.channels: Intent channelIntent = new Intent(this, AddChannelActivity.class); channelIntent.putExtra(Extra.CHANNELS, channels); startActivityForResult(channelIntent, REQUEST_CODE_CHANNELS); break; + case R.id.commands: Intent commandsIntent = new Intent(this, AddCommandsActivity.class); commandsIntent.putExtra(Extra.COMMANDS, commands); startActivityForResult(commandsIntent, REQUEST_CODE_COMMANDS); break; + case R.id.add: try { validateServer(); @@ -191,6 +196,7 @@ public class AddServerActivity extends Activity implements OnClickListener Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); } break; + case R.id.cancel: setResult(RESULT_CANCELED); finish(); diff --git a/application/src/org/yaaic/activity/ConversationActivity.java b/application/src/org/yaaic/activity/ConversationActivity.java index 65aafbc..3c6ac29 100644 --- a/application/src/org/yaaic/activity/ConversationActivity.java +++ b/application/src/org/yaaic/activity/ConversationActivity.java @@ -72,8 +72,8 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.Window; import android.view.View.OnKeyListener; +import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; @@ -197,6 +197,7 @@ public class ConversationActivity extends Activity implements ServiceConnection, PackageManager pm = getPackageManager(); Button speechButton = (Button) findViewById(R.id.speech); List activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); + if (activities.size() != 0) { ((Button) findViewById(R.id.speech)).setOnClickListener(new SpeechClickListener(this)); speechButton.setVisibility(View.VISIBLE); @@ -326,6 +327,7 @@ public class ConversationActivity extends Activity implements ServiceConnection, setResult(RESULT_OK); finish(); break; + case R.id.close: Conversation conversationToClose = deckAdapter.getItem(deck.getSelectedItemPosition()); // 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(); } break; + case R.id.join: startActivityForResult(new Intent(this, JoinActivity.class), REQUEST_CODE_JOIN); break; + case R.id.users: Conversation conversationForUserList = deckAdapter.getItem(deck.getSelectedItemPosition()); if (conversationForUserList.getType() == Conversation.TYPE_CHANNEL) { @@ -394,11 +398,13 @@ public class ConversationActivity extends Activity implements ServiceConnection, if (adapter != null) { adapter.addMessage(message); int status; + switch (message.getType()) { case Message.TYPE_MISC: status = Conversation.STATUS_MISC; break; + default: status = Conversation.STATUS_MESSAGE; break; diff --git a/application/src/org/yaaic/adapter/ServerListAdapter.java b/application/src/org/yaaic/adapter/ServerListAdapter.java index 62471e3..1b024f8 100644 --- a/application/src/org/yaaic/adapter/ServerListAdapter.java +++ b/application/src/org/yaaic/adapter/ServerListAdapter.java @@ -41,6 +41,9 @@ import android.widget.TextView; */ public class ServerListAdapter extends BaseAdapter { + private static final int COLOR_CONNECTED = 0xFFbcbcbc; + private static final int COLOR_DISCONNECTED = 0xFF585858; + private ArrayList servers; /** @@ -136,11 +139,11 @@ public class ServerListAdapter extends BaseAdapter hostView.setText(server.getIdentity().getNickname() + " @ " + server.getHost() + " : " + server.getPort()); if (server.isConnected()) { - titleView.setTextColor(0xFFbcbcbc); - hostView.setTextColor(0xFFbcbcbc); + titleView.setTextColor(COLOR_CONNECTED); + hostView.setTextColor(COLOR_CONNECTED); } else { - titleView.setTextColor(0xFF585858); - hostView.setTextColor(0xFF585858); + titleView.setTextColor(COLOR_DISCONNECTED); + hostView.setTextColor(COLOR_DISCONNECTED); } ((ImageView) v.findViewById(R.id.status)).setImageResource(server.getStatusIcon()); diff --git a/application/src/org/yaaic/adapter/UserActionListAdapter.java b/application/src/org/yaaic/adapter/UserActionListAdapter.java index 7329292..8a8f945 100644 --- a/application/src/org/yaaic/adapter/UserActionListAdapter.java +++ b/application/src/org/yaaic/adapter/UserActionListAdapter.java @@ -124,7 +124,6 @@ public class UserActionListAdapter extends BaseAdapter textView.setText(labels[position]); iconView.setImageResource(icons[position]); - return convertView; } } diff --git a/application/src/org/yaaic/command/handler/AMsgHandler.java b/application/src/org/yaaic/command/handler/AMsgHandler.java index 10c22d8..9d11f69 100644 --- a/application/src/org/yaaic/command/handler/AMsgHandler.java +++ b/application/src/org/yaaic/command/handler/AMsgHandler.java @@ -52,8 +52,8 @@ public class AMsgHandler extends BaseHandler if (params.length > 1) { String text = BaseHandler.mergeParams(params); - Collection mConversations = server.getConversations(); + for (Conversation currentConversation : mConversations) { if (currentConversation.getType() == Conversation.TYPE_CHANNEL) { Message message = new Message("<" + service.getConnection(server.getId()).getNick() + "> " + text); diff --git a/application/src/org/yaaic/db/AliasConstants.java b/application/src/org/yaaic/db/AliasConstants.java index 89a01b9..a2d04be 100644 --- a/application/src/org/yaaic/db/AliasConstants.java +++ b/application/src/org/yaaic/db/AliasConstants.java @@ -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 . + */ package org.yaaic.db; import android.provider.BaseColumns; -public class AliasConstants implements BaseColumns { - +/** + * Constants for the aliases table + * + * @author Sebastian Kaspari + */ +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"; + /** + * All fields of the table + */ public static final String[] ALL = { _ID, ALIAS, diff --git a/application/src/org/yaaic/exception/ValidationException.java b/application/src/org/yaaic/exception/ValidationException.java index e30aff9..82e3b0d 100644 --- a/application/src/org/yaaic/exception/ValidationException.java +++ b/application/src/org/yaaic/exception/ValidationException.java @@ -21,7 +21,7 @@ along with Yaaic. If not, see . 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 */ diff --git a/application/src/org/yaaic/irc/IRCBinder.java b/application/src/org/yaaic/irc/IRCBinder.java index 53b0b1b..7690021 100644 --- a/application/src/org/yaaic/irc/IRCBinder.java +++ b/application/src/org/yaaic/irc/IRCBinder.java @@ -35,7 +35,7 @@ public class IRCBinder extends Binder /** * Create a new binder for given service - * + * * @param service */ public IRCBinder(IRCService service) @@ -56,7 +56,8 @@ public class IRCBinder extends Binder } /** - * Get service associated with this service + * Get service associated with this binder + * * @return */ public IRCService getService() diff --git a/application/src/org/yaaic/irc/IRCConnection.java b/application/src/org/yaaic/irc/IRCConnection.java index 63fbe98..ffe1b8e 100644 --- a/application/src/org/yaaic/irc/IRCConnection.java +++ b/application/src/org/yaaic/irc/IRCConnection.java @@ -434,7 +434,9 @@ public class IRCConnection extends PircBot @Override 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); server.getChannel(target).addMessage(message); @@ -454,6 +456,7 @@ public class IRCConnection extends PircBot if (getNick().equalsIgnoreCase(newNick)) { this.updateNickMatchPattern(); } + Vector channels = getChannelsByNickname(newNick); for (String target : channels) { diff --git a/application/src/org/yaaic/listener/ConversationListener.java b/application/src/org/yaaic/listener/ConversationListener.java index 3f531e4..ec760dd 100644 --- a/application/src/org/yaaic/listener/ConversationListener.java +++ b/application/src/org/yaaic/listener/ConversationListener.java @@ -27,7 +27,24 @@ package org.yaaic.listener; */ public interface ConversationListener { + /** + * On new conversation message for given target + * + * @param target + */ public void onConversationMessage(String target); + + /** + * On new conversation created (for given target) + * + * @param target + */ public void onNewConversation(String target); + + /** + * On conversation removed (for given target) + * + * @param target + */ public void onRemoveConversation(String target); } diff --git a/application/src/org/yaaic/listener/ServerListener.java b/application/src/org/yaaic/listener/ServerListener.java index 10c745b..9ba33bb 100644 --- a/application/src/org/yaaic/listener/ServerListener.java +++ b/application/src/org/yaaic/listener/ServerListener.java @@ -20,7 +20,15 @@ along with Yaaic. If not, see . */ package org.yaaic.listener; +/** + * Listener for changes regarding a server + * + * @author Sebastian Kaspari + */ public interface ServerListener { + /** + * On server status update (disconnected, connecting, connected) + */ public void onStatusUpdate(); } diff --git a/application/src/org/yaaic/model/Conversation.java b/application/src/org/yaaic/model/Conversation.java index 868dd56..0d32bc4 100644 --- a/application/src/org/yaaic/model/Conversation.java +++ b/application/src/org/yaaic/model/Conversation.java @@ -41,8 +41,7 @@ public abstract class Conversation public static final int STATUS_SELECTED = 2; public static final int STATUS_MESSAGE = 3; public static final int STATUS_HIGHLIGHT = 4; - /* join/part/quit */ - public static final int STATUS_MISC = 5; + public static final int STATUS_MISC = 5; // join/part/quit public static final int HISTORY_SIZE = 30; diff --git a/application/src/org/yaaic/model/Identity.java b/application/src/org/yaaic/model/Identity.java index 8f16087..5c7e815 100644 --- a/application/src/org/yaaic/model/Identity.java +++ b/application/src/org/yaaic/model/Identity.java @@ -49,7 +49,7 @@ public class Identity /** * Get the nickname of this identity - * + * * @return The nickname */ public String getNickname() @@ -57,12 +57,24 @@ public class Identity return nickname; } - public void setAliases(Collection aliases) { + /** + * Set a collection of aliases for this identity + * + * @param aliases + */ + public void setAliases(Collection aliases) + { this.aliases.clear(); this.aliases.addAll(aliases); } - public List getAliases() { + /** + * Get all aliases for this identity + * + * @return + */ + public List getAliases() + { return Collections.unmodifiableList(aliases); } diff --git a/application/src/org/yaaic/model/Status.java b/application/src/org/yaaic/model/Status.java index 2eb3f4d..9039b79 100644 --- a/application/src/org/yaaic/model/Status.java +++ b/application/src/org/yaaic/model/Status.java @@ -27,8 +27,8 @@ package org.yaaic.model; */ public class Status { - public static final int DISCONNECTED = 0; - public static final int CONNECTING = 1; - public static final int CONNECTED = 2; + public static final int DISCONNECTED = 0; + public static final int CONNECTING = 1; + public static final int CONNECTED = 2; public static final int PRE_CONNECTING = 3; }