mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-22 08:52:18 -05:00
Some more simple refactorings
This commit is contained in:
parent
1c8076ec53
commit
95f3c4b255
@ -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.
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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<ResolveInfo> 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;
|
||||
|
@ -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<Server> 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());
|
||||
|
@ -124,7 +124,6 @@ public class UserActionListAdapter extends BaseAdapter
|
||||
textView.setText(labels[position]);
|
||||
iconView.setImageResource(icons[position]);
|
||||
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ public class AMsgHandler extends BaseHandler
|
||||
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);
|
||||
|
@ -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;
|
||||
|
||||
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";
|
||||
|
||||
// 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,
|
||||
|
@ -21,7 +21,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
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
|
||||
*/
|
||||
|
@ -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()
|
||||
|
@ -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<String> channels = getChannelsByNickname(newNick);
|
||||
|
||||
for (String target : channels) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -20,7 +20,15 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<String> aliases) {
|
||||
/**
|
||||
* Set a collection of aliases for this identity
|
||||
*
|
||||
* @param aliases
|
||||
*/
|
||||
public void setAliases(Collection<String> aliases)
|
||||
{
|
||||
this.aliases.clear();
|
||||
this.aliases.addAll(aliases);
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
/**
|
||||
* Get all aliases for this identity
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<String> getAliases()
|
||||
{
|
||||
return Collections.unmodifiableList(aliases);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user