2009-12-17 15:27:57 -05:00
|
|
|
/*
|
2010-03-12 14:35:25 -05:00
|
|
|
Yaaic - Yet Another Android IRC Client
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-13 10:52:20 -05:00
|
|
|
Copyright 2009-2010 Sebastian Kaspari
|
2009-12-17 15:27:57 -05:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
2010-03-24 13:48:38 -04:00
|
|
|
package org.yaaic.activity;
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-21 11:37:56 -04:00
|
|
|
import java.util.Collection;
|
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Intent;
|
2010-03-02 14:18:44 -05:00
|
|
|
import android.content.IntentFilter;
|
2009-12-17 15:27:57 -05:00
|
|
|
import android.content.ServiceConnection;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.IBinder;
|
2010-03-05 13:34:05 -05:00
|
|
|
import android.view.KeyEvent;
|
2009-12-17 15:27:57 -05:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
2010-04-06 16:48:00 -04:00
|
|
|
import android.view.Window;
|
2010-03-08 18:30:17 -05:00
|
|
|
import android.view.View.OnKeyListener;
|
2010-03-05 13:34:05 -05:00
|
|
|
import android.widget.AdapterView;
|
2009-12-17 15:27:57 -05:00
|
|
|
import android.widget.EditText;
|
2010-03-05 09:56:57 -05:00
|
|
|
import android.widget.Gallery;
|
2009-12-17 15:27:57 -05:00
|
|
|
import android.widget.ImageView;
|
2010-03-18 15:26:04 -04:00
|
|
|
import android.widget.ListView;
|
2009-12-17 15:27:57 -05:00
|
|
|
import android.widget.TextView;
|
2010-03-30 17:17:23 -04:00
|
|
|
import android.widget.Toast;
|
2010-03-05 09:56:57 -05:00
|
|
|
import android.widget.ViewSwitcher;
|
2010-03-05 13:34:05 -05:00
|
|
|
import android.widget.AdapterView.OnItemClickListener;
|
2010-03-08 20:11:34 -05:00
|
|
|
import android.widget.AdapterView.OnItemSelectedListener;
|
2010-03-05 13:34:05 -05:00
|
|
|
import android.widget.TableLayout.LayoutParams;
|
2010-03-05 09:56:57 -05:00
|
|
|
|
|
|
|
import org.yaaic.R;
|
|
|
|
import org.yaaic.Yaaic;
|
|
|
|
import org.yaaic.adapter.DeckAdapter;
|
2010-03-13 18:03:38 -05:00
|
|
|
import org.yaaic.adapter.MessageListAdapter;
|
2010-03-09 13:46:02 -05:00
|
|
|
import org.yaaic.command.CommandParser;
|
2010-03-05 09:56:57 -05:00
|
|
|
import org.yaaic.irc.IRCBinder;
|
|
|
|
import org.yaaic.irc.IRCService;
|
2010-03-17 16:52:51 -04:00
|
|
|
import org.yaaic.layout.NonScalingBackgroundDrawable;
|
2010-03-14 17:13:23 -04:00
|
|
|
import org.yaaic.listener.ConversationListener;
|
2010-03-10 17:28:49 -05:00
|
|
|
import org.yaaic.listener.ServerListener;
|
2010-03-05 09:56:57 -05:00
|
|
|
import org.yaaic.model.Broadcast;
|
2010-03-10 14:56:14 -05:00
|
|
|
import org.yaaic.model.Conversation;
|
2010-04-06 16:45:32 -04:00
|
|
|
import org.yaaic.model.Extra;
|
2010-03-06 11:52:22 -05:00
|
|
|
import org.yaaic.model.Message;
|
2010-04-12 14:41:31 -04:00
|
|
|
import org.yaaic.model.Scrollback;
|
2010-03-05 09:56:57 -05:00
|
|
|
import org.yaaic.model.Server;
|
2010-03-21 10:26:11 -04:00
|
|
|
import org.yaaic.model.Status;
|
2010-03-14 17:13:23 -04:00
|
|
|
import org.yaaic.receiver.ConversationReceiver;
|
2010-03-10 17:28:49 -05:00
|
|
|
import org.yaaic.receiver.ServerReceiver;
|
2010-03-24 13:48:38 -04:00
|
|
|
import org.yaaic.view.MessageListView;
|
2009-12-17 15:27:57 -05:00
|
|
|
|
|
|
|
/**
|
2010-03-08 15:38:29 -05:00
|
|
|
* The server view with a scrollable list of all channels
|
2009-12-17 15:27:57 -05:00
|
|
|
*
|
|
|
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
|
|
|
*/
|
2010-03-14 17:13:23 -04:00
|
|
|
public class ConversationActivity extends Activity implements ServiceConnection, ServerListener, ConversationListener, OnItemClickListener, OnKeyListener, OnItemSelectedListener
|
2009-12-17 15:27:57 -05:00
|
|
|
{
|
2010-03-05 09:56:57 -05:00
|
|
|
private int serverId;
|
2010-03-02 14:18:44 -05:00
|
|
|
private Server server;
|
2009-12-17 15:27:57 -05:00
|
|
|
private IRCBinder binder;
|
2010-03-14 17:13:23 -04:00
|
|
|
private ConversationReceiver channelReceiver;
|
2010-03-10 17:28:49 -05:00
|
|
|
private ServerReceiver serverReceiver;
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-05 09:56:57 -05:00
|
|
|
private ViewSwitcher switcher;
|
|
|
|
private Gallery deck;
|
|
|
|
private DeckAdapter deckAdapter;
|
2010-04-12 14:41:31 -04:00
|
|
|
private Scrollback scrollback;
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-08 15:38:29 -05:00
|
|
|
/**
|
|
|
|
* On create
|
|
|
|
*/
|
2009-12-17 15:27:57 -05:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
super.onCreate(savedInstanceState);
|
2010-04-06 16:48:00 -04:00
|
|
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-05 09:56:57 -05:00
|
|
|
serverId = getIntent().getExtras().getInt("serverId");
|
2010-03-02 14:18:44 -05:00
|
|
|
server = (Server) Yaaic.getInstance().getServerById(serverId);
|
2010-03-05 09:56:57 -05:00
|
|
|
setTitle("Yaaic - " + server.getTitle());
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-11 18:10:18 -05:00
|
|
|
setContentView(R.layout.conversations);
|
2009-12-17 15:27:57 -05:00
|
|
|
|
|
|
|
((TextView) findViewById(R.id.title)).setText(server.getTitle());
|
2010-03-10 17:28:49 -05:00
|
|
|
((EditText) findViewById(R.id.input)).setOnKeyListener(this);
|
2010-03-21 14:57:30 -04:00
|
|
|
|
2010-03-17 16:52:51 -04:00
|
|
|
deckAdapter = new DeckAdapter();
|
2010-03-05 09:56:57 -05:00
|
|
|
deck = (Gallery) findViewById(R.id.deck);
|
2010-03-08 20:11:34 -05:00
|
|
|
deck.setOnItemSelectedListener(this);
|
2010-03-05 09:56:57 -05:00
|
|
|
deck.setAdapter(deckAdapter);
|
2010-03-05 13:34:05 -05:00
|
|
|
deck.setOnItemClickListener(this);
|
2010-03-31 14:48:22 -04:00
|
|
|
deck.setBackgroundDrawable(new NonScalingBackgroundDrawable(this, deck, R.drawable.background));
|
2010-03-05 13:34:05 -05:00
|
|
|
|
2010-03-05 09:56:57 -05:00
|
|
|
switcher = (ViewSwitcher) findViewById(R.id.switcher);
|
2010-03-05 13:34:05 -05:00
|
|
|
|
2010-03-21 11:37:56 -04:00
|
|
|
// Optimization : cache field lookups
|
|
|
|
Collection<Conversation> mConversations = server.getConversations();
|
|
|
|
|
|
|
|
for (Conversation conversation : mConversations) {
|
2010-03-10 14:56:14 -05:00
|
|
|
onNewConversation(conversation.getName());
|
2010-03-05 13:34:05 -05:00
|
|
|
}
|
2010-04-12 14:41:31 -04:00
|
|
|
|
|
|
|
// Create a new scrollback history
|
|
|
|
scrollback = new Scrollback();
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|
|
|
|
|
2010-03-08 15:38:29 -05:00
|
|
|
/**
|
|
|
|
* On resume
|
|
|
|
*/
|
2009-12-17 15:27:57 -05:00
|
|
|
@Override
|
|
|
|
public void onResume()
|
|
|
|
{
|
2010-04-12 14:01:42 -04:00
|
|
|
// register the receivers as early as possible, otherwise we may loose a broadcast message
|
|
|
|
channelReceiver = new ConversationReceiver(server.getId(), this);
|
|
|
|
registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_MESSAGE));
|
|
|
|
registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_NEW));
|
|
|
|
registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_REMOVE));
|
|
|
|
|
|
|
|
serverReceiver = new ServerReceiver(this);
|
|
|
|
registerReceiver(serverReceiver, new IntentFilter(Broadcast.SERVER_UPDATE));
|
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
super.onResume();
|
|
|
|
|
2010-03-20 18:15:29 -04:00
|
|
|
((ImageView) findViewById(R.id.status)).setImageResource(server.getStatusIcon());
|
|
|
|
|
2010-03-21 14:57:30 -04:00
|
|
|
// Start service
|
2009-12-17 15:27:57 -05:00
|
|
|
Intent intent = new Intent(this, IRCService.class);
|
2010-03-29 15:48:23 -04:00
|
|
|
intent.setAction(IRCService.ACTION_FOREGROUND);
|
2010-03-21 14:57:30 -04:00
|
|
|
startService(intent);
|
2009-12-17 15:27:57 -05:00
|
|
|
bindService(intent, this, 0);
|
2010-03-05 09:56:57 -05:00
|
|
|
|
2010-03-10 17:28:49 -05:00
|
|
|
if (!server.isConnected()) {
|
|
|
|
((EditText) findViewById(R.id.input)).setEnabled(false);
|
2010-03-20 18:15:29 -04:00
|
|
|
} else {
|
|
|
|
((EditText) findViewById(R.id.input)).setEnabled(true);
|
2010-03-10 17:28:49 -05:00
|
|
|
}
|
2010-03-21 11:37:56 -04:00
|
|
|
|
|
|
|
// Optimization - cache field lookup
|
|
|
|
Collection<Conversation> mConversations = server.getConversations();
|
|
|
|
MessageListAdapter mAdapter;
|
2010-03-18 17:37:37 -04:00
|
|
|
|
|
|
|
// Fill view with messages that have been buffered while paused
|
2010-03-21 11:37:56 -04:00
|
|
|
for (Conversation conversation : mConversations) {
|
|
|
|
mAdapter = conversation.getMessageListAdapter();
|
|
|
|
|
|
|
|
if (mAdapter != null) {
|
|
|
|
mAdapter.addBulkMessages(conversation.getBuffer());
|
2010-03-18 17:37:37 -04:00
|
|
|
}
|
2010-03-20 18:15:52 -04:00
|
|
|
}
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|
|
|
|
|
2010-03-08 15:38:29 -05:00
|
|
|
/**
|
|
|
|
* On Pause
|
|
|
|
*/
|
2009-12-17 15:27:57 -05:00
|
|
|
@Override
|
|
|
|
public void onPause()
|
|
|
|
{
|
|
|
|
super.onPause();
|
|
|
|
|
2010-04-06 14:31:44 -04:00
|
|
|
if (binder != null && binder.getService() != null) {
|
|
|
|
binder.getService().checkServiceStatus();
|
|
|
|
}
|
2010-03-21 14:57:30 -04:00
|
|
|
|
|
|
|
/*if (!binder.getService().hasConnections()) {
|
|
|
|
Log.d("Yaaic", "Stopping service");
|
|
|
|
//binder.getService().stopSelf();
|
|
|
|
} else {
|
|
|
|
Log.d("Yaaic", "Unbinding service");
|
|
|
|
}*/
|
|
|
|
|
2009-12-17 15:27:57 -05:00
|
|
|
unbindService(this);
|
2010-03-10 17:28:49 -05:00
|
|
|
unregisterReceiver(channelReceiver);
|
|
|
|
unregisterReceiver(serverReceiver);
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|
|
|
|
|
2010-03-08 15:38:29 -05:00
|
|
|
/**
|
|
|
|
* On service connected
|
|
|
|
*/
|
2009-12-17 15:27:57 -05:00
|
|
|
public void onServiceConnected(ComponentName name, IBinder service)
|
|
|
|
{
|
|
|
|
this.binder = (IRCBinder) service;
|
2010-03-20 15:21:51 -04:00
|
|
|
|
|
|
|
// connect to irc server if connect has been requested
|
2010-03-21 10:26:11 -04:00
|
|
|
if (server.getStatus() == Status.PRE_CONNECTING && getIntent().hasExtra("connect")) {
|
|
|
|
server.setStatus(Status.CONNECTING);
|
2010-03-20 15:21:51 -04:00
|
|
|
binder.connect(server);
|
|
|
|
}
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|
|
|
|
|
2010-03-08 15:38:29 -05:00
|
|
|
/**
|
|
|
|
* On service disconnected
|
|
|
|
*/
|
2009-12-17 15:27:57 -05:00
|
|
|
public void onServiceDisconnected(ComponentName name)
|
|
|
|
{
|
|
|
|
this.binder = null;
|
|
|
|
}
|
|
|
|
|
2010-03-08 15:38:29 -05:00
|
|
|
/**
|
|
|
|
* On options menu requested
|
|
|
|
*/
|
2009-12-17 15:27:57 -05:00
|
|
|
@Override
|
2010-03-08 15:38:29 -05:00
|
|
|
public boolean onCreateOptionsMenu(Menu menu)
|
|
|
|
{
|
2009-12-17 15:27:57 -05:00
|
|
|
super.onCreateOptionsMenu(menu);
|
|
|
|
|
|
|
|
// inflate from xml
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
2010-03-13 12:04:59 -05:00
|
|
|
inflater.inflate(R.menu.conversations, menu);
|
2009-12-17 15:27:57 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-04-11 18:55:34 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On prepare options menu
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu)
|
|
|
|
{
|
|
|
|
menu.getItem(0).setEnabled(server.isConnected()); // join
|
|
|
|
menu.getItem(1).setEnabled(server.isConnected()); // users
|
|
|
|
menu.getItem(2).setEnabled(server.isConnected()); // close
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-12-17 15:27:57 -05:00
|
|
|
|
2010-03-08 15:38:29 -05:00
|
|
|
/**
|
|
|
|
* On menu item selected
|
|
|
|
*/
|
2009-12-17 15:27:57 -05:00
|
|
|
@Override
|
|
|
|
public boolean onMenuItemSelected(int featureId, MenuItem item)
|
|
|
|
{
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.disconnect:
|
|
|
|
binder.getService().getConnection(serverId).quitServer();
|
2010-03-21 14:57:30 -04:00
|
|
|
server.setStatus(Status.DISCONNECTED);
|
2010-03-10 14:56:14 -05:00
|
|
|
server.clearConversations();
|
2009-12-17 15:27:57 -05:00
|
|
|
setResult(RESULT_OK);
|
|
|
|
finish();
|
|
|
|
break;
|
2010-03-30 17:17:23 -04:00
|
|
|
case R.id.close:
|
2010-04-06 14:32:10 -04:00
|
|
|
Conversation conversationToClose = deckAdapter.getItem(deck.getSelectedItemPosition());
|
2010-04-11 15:04:34 -04:00
|
|
|
// Make sure we part a channel when closing the channel conversation
|
2010-04-11 16:11:47 -04:00
|
|
|
if (conversationToClose.getType() == Conversation.TYPE_CHANNEL) {
|
2010-04-11 15:04:34 -04:00
|
|
|
binder.getService().getConnection(serverId).partChannel(conversationToClose.getName());
|
|
|
|
}
|
2010-04-11 16:11:47 -04:00
|
|
|
else if (conversationToClose.getType() == Conversation.TYPE_QUERY) {
|
|
|
|
onRemoveConversation(conversationToClose.getName());
|
2010-03-30 17:17:23 -04:00
|
|
|
} else {
|
|
|
|
Toast.makeText(this, "You can not close the server info window", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
break;
|
2009-12-17 15:27:57 -05:00
|
|
|
case R.id.join:
|
2010-03-17 17:43:56 -04:00
|
|
|
startActivityForResult(new Intent(this, JoinActivity.class), 0);
|
2009-12-17 15:27:57 -05:00
|
|
|
break;
|
2010-04-06 14:00:57 -04:00
|
|
|
case R.id.users:
|
2010-04-06 14:32:10 -04:00
|
|
|
Conversation conversationForUserList = deckAdapter.getItem(deck.getSelectedItemPosition());
|
|
|
|
if (conversationForUserList.getType() == Conversation.TYPE_CHANNEL) {
|
2010-04-06 16:45:32 -04:00
|
|
|
Intent intent = new Intent(this, UsersActivity.class);
|
|
|
|
intent.putExtra(
|
|
|
|
Extra.USERS,
|
|
|
|
binder.getService().getConnection(server.getId()).getUsersAsStringArray(
|
|
|
|
conversationForUserList.getName()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
startActivity(intent);
|
2010-04-06 14:32:10 -04:00
|
|
|
} else {
|
|
|
|
Toast.makeText(this, "Only usable from within a channel", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2010-04-06 14:00:57 -04:00
|
|
|
break;
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-05 13:54:04 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get server object assigned to this activity
|
|
|
|
*
|
|
|
|
* @return the server object
|
|
|
|
*/
|
|
|
|
public Server getServer()
|
|
|
|
{
|
|
|
|
return server;
|
|
|
|
}
|
2010-03-02 14:18:44 -05:00
|
|
|
|
|
|
|
/**
|
2010-03-10 19:10:21 -05:00
|
|
|
* On conversation message
|
2010-03-02 14:18:44 -05:00
|
|
|
*/
|
2010-03-10 14:56:14 -05:00
|
|
|
public void onConversationMessage(String target)
|
2010-03-02 14:18:44 -05:00
|
|
|
{
|
2010-03-10 14:56:14 -05:00
|
|
|
Conversation conversation = server.getConversation(target);
|
2010-03-17 14:32:27 -04:00
|
|
|
MessageListAdapter adapter = conversation.getMessageListAdapter();
|
2010-03-02 14:28:32 -05:00
|
|
|
|
2010-03-10 14:56:14 -05:00
|
|
|
while(conversation.hasBufferedMessages()) {
|
|
|
|
Message message = conversation.pollBufferedMessage();
|
2010-03-08 15:59:38 -05:00
|
|
|
|
2010-03-17 14:32:27 -04:00
|
|
|
if (adapter != null) {
|
|
|
|
adapter.addMessage(message);
|
|
|
|
} else {
|
2010-03-21 10:51:08 -04:00
|
|
|
//"MessageListAdapter is null (conversation " + conversation.getName() + " has no adapter assigned)"
|
2010-03-08 15:59:38 -05:00
|
|
|
}
|
2010-03-08 15:44:42 -05:00
|
|
|
}
|
2010-03-02 14:18:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-03-10 19:10:21 -05:00
|
|
|
* On new conversation
|
2010-03-02 14:18:44 -05:00
|
|
|
*/
|
2010-03-10 14:56:14 -05:00
|
|
|
public void onNewConversation(String target)
|
2010-03-02 14:18:44 -05:00
|
|
|
{
|
2010-03-10 14:56:14 -05:00
|
|
|
deckAdapter.addItem(server.getConversation(target));
|
2010-03-10 16:10:40 -05:00
|
|
|
|
|
|
|
if (!deckAdapter.isSwitched()) {
|
|
|
|
// Scroll to new conversation
|
|
|
|
deck.setSelection(deckAdapter.getCount() - 1);
|
|
|
|
}
|
2010-03-05 13:34:05 -05:00
|
|
|
}
|
2010-03-10 17:28:49 -05:00
|
|
|
|
|
|
|
/**
|
2010-03-10 19:10:21 -05:00
|
|
|
* On conversation remove
|
2010-03-10 17:28:49 -05:00
|
|
|
*/
|
|
|
|
public void onRemoveConversation(String target)
|
|
|
|
{
|
2010-03-10 19:10:21 -05:00
|
|
|
deckAdapter.removeItem(target);
|
|
|
|
|
|
|
|
if (deckAdapter.isSwitched()) {
|
2010-03-24 13:44:17 -04:00
|
|
|
switcher.showNext();
|
|
|
|
switcher.removeView(deckAdapter.getSwitchedView());
|
|
|
|
deckAdapter.setSwitched(null, null);
|
2010-03-10 19:10:21 -05:00
|
|
|
}
|
2010-03-10 17:28:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On server status update
|
|
|
|
*/
|
|
|
|
public void onStatusUpdate()
|
|
|
|
{
|
|
|
|
((ImageView) findViewById(R.id.status)).setImageResource(server.getStatusIcon());
|
|
|
|
|
|
|
|
EditText input = (EditText) findViewById(R.id.input);
|
|
|
|
if (server.isConnected()) {
|
|
|
|
input.setEnabled(true);
|
|
|
|
} else {
|
|
|
|
input.setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
2010-03-05 13:34:05 -05:00
|
|
|
|
|
|
|
/**
|
2010-03-10 19:10:21 -05:00
|
|
|
* On conversation item clicked
|
2010-03-05 13:34:05 -05:00
|
|
|
*/
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
|
|
|
|
{
|
2010-03-10 14:56:14 -05:00
|
|
|
Conversation conversation = deckAdapter.getItem(position);
|
2010-03-10 19:10:21 -05:00
|
|
|
|
2010-03-10 14:56:14 -05:00
|
|
|
MessageListView canvas = deckAdapter.renderConversation(conversation, switcher);
|
2010-03-18 15:26:04 -04:00
|
|
|
canvas.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
|
2010-03-08 15:36:36 -05:00
|
|
|
canvas.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
|
|
|
|
canvas.setDelegateTouchEvents(false); // Do not delegate
|
2010-03-10 19:10:21 -05:00
|
|
|
|
2010-03-10 14:56:14 -05:00
|
|
|
deckAdapter.setSwitched(conversation.getName(), canvas);
|
2010-03-08 15:36:36 -05:00
|
|
|
switcher.addView(canvas);
|
2010-03-05 13:34:05 -05:00
|
|
|
switcher.showNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On key down
|
2010-03-24 13:44:17 -04:00
|
|
|
*
|
|
|
|
* XXX: As we only track the back key: Android >= 2.0 will call a method called onBackPressed()
|
2010-03-05 13:34:05 -05:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event)
|
|
|
|
{
|
2010-03-24 13:44:17 -04:00
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
|
|
|
|
if (deckAdapter.isSwitched()) {
|
|
|
|
switcher.showNext();
|
|
|
|
switcher.removeView(deckAdapter.getSwitchedView());
|
|
|
|
deckAdapter.setSwitched(null, null);
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-05 13:34:05 -05:00
|
|
|
}
|
2010-03-24 13:44:17 -04:00
|
|
|
return super.onKeyDown(keyCode, event);
|
2010-03-02 14:18:44 -05:00
|
|
|
}
|
|
|
|
|
2010-03-08 18:30:17 -05:00
|
|
|
/**
|
|
|
|
* On key pressed (input line)
|
|
|
|
*/
|
|
|
|
public boolean onKey(View view, int keyCode, KeyEvent event)
|
|
|
|
{
|
2010-04-12 14:41:31 -04:00
|
|
|
EditText input = (EditText) view;
|
|
|
|
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_DPAD_UP && event.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
|
String message = scrollback.goBack();
|
|
|
|
if (message != null) {
|
|
|
|
input.setText(message);
|
|
|
|
}
|
2010-04-05 19:00:23 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-12 14:41:31 -04:00
|
|
|
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && event.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
|
String message = scrollback.goForward();
|
|
|
|
if (message != null) {
|
|
|
|
input.setText(message);
|
|
|
|
}
|
2010-04-05 19:00:23 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-08 18:30:17 -05:00
|
|
|
if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
|
2010-03-10 17:53:39 -05:00
|
|
|
if (!server.isConnected()) {
|
|
|
|
Message message = new Message("Not connected");
|
|
|
|
message.setColor(Message.COLOR_RED);
|
|
|
|
message.setIcon(R.drawable.error);
|
|
|
|
server.getConversation(server.getSelectedConversation()).addMessage(message);
|
|
|
|
onConversationMessage(server.getSelectedConversation());
|
|
|
|
}
|
|
|
|
|
2010-03-08 18:30:17 -05:00
|
|
|
String text = input.getText().toString();
|
|
|
|
input.setText("");
|
|
|
|
|
2010-03-10 16:17:53 -05:00
|
|
|
if (text == "") {
|
|
|
|
// ignore empty messages
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-12 14:41:31 -04:00
|
|
|
scrollback.addMessage(text);
|
|
|
|
|
2010-03-10 14:56:14 -05:00
|
|
|
Conversation conversation = deckAdapter.getItem(deck.getSelectedItemPosition());
|
2010-03-08 18:30:17 -05:00
|
|
|
|
2010-03-10 14:56:14 -05:00
|
|
|
if (conversation != null) {
|
2010-03-09 13:46:02 -05:00
|
|
|
if (!text.trim().startsWith("/")) {
|
2010-03-10 18:05:04 -05:00
|
|
|
if (conversation.getType() != Conversation.TYPE_SERVER) {
|
2010-03-20 17:39:42 -04:00
|
|
|
String nickname = binder.getService().getConnection(serverId).getNick();
|
2010-03-10 18:05:04 -05:00
|
|
|
conversation.addMessage(new Message("<" + nickname + "> " + text));
|
2010-03-20 17:39:42 -04:00
|
|
|
binder.getService().getConnection(serverId).sendMessage(conversation.getName(), text);
|
2010-03-10 18:05:04 -05:00
|
|
|
} else {
|
|
|
|
Message message = new Message("You can only chat from within a channel or a query");
|
|
|
|
message.setColor(Message.COLOR_YELLOW);
|
|
|
|
message.setIcon(R.drawable.warning);
|
|
|
|
conversation.addMessage(message);
|
|
|
|
}
|
2010-03-10 14:56:14 -05:00
|
|
|
onConversationMessage(conversation.getName());
|
2010-03-09 13:46:02 -05:00
|
|
|
} else {
|
2010-03-10 14:56:14 -05:00
|
|
|
CommandParser.getInstance().parse(text, server, conversation, binder.getService());
|
2010-03-09 13:46:02 -05:00
|
|
|
}
|
2010-03-08 18:30:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-03-17 17:43:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On activity result
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
|
|
|
{
|
2010-03-20 17:39:42 -04:00
|
|
|
// currently there's only the "join channel" activity
|
2010-03-17 17:43:56 -04:00
|
|
|
if (resultCode == RESULT_OK) {
|
2010-03-20 17:39:42 -04:00
|
|
|
final String channel = data.getExtras().getString("channel");
|
|
|
|
|
|
|
|
// run on own thread
|
|
|
|
new Thread() {
|
|
|
|
public void run() {
|
|
|
|
binder.getService().getConnection(serverId).joinChannel(channel);
|
|
|
|
}
|
|
|
|
}.start();
|
2010-03-17 17:43:56 -04:00
|
|
|
}
|
|
|
|
}
|
2010-03-08 20:11:34 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On channel selected/focused
|
|
|
|
*/
|
|
|
|
public void onItemSelected(AdapterView<?> deck, View view, int position, long id)
|
|
|
|
{
|
2010-03-10 15:34:20 -05:00
|
|
|
Conversation conversation = (Conversation) deck.getItemAtPosition(position);
|
2010-03-10 16:52:48 -05:00
|
|
|
|
|
|
|
if (conversation != null && conversation.getType() != Conversation.TYPE_SERVER) {
|
2010-03-10 15:34:20 -05:00
|
|
|
((TextView) findViewById(R.id.title)).setText(server.getTitle() + " - " + conversation.getName());
|
2010-03-10 16:52:48 -05:00
|
|
|
} else {
|
|
|
|
onNothingSelected(deck);
|
2010-03-08 20:11:34 -05:00
|
|
|
}
|
2010-03-10 16:56:44 -05:00
|
|
|
|
|
|
|
// Remember selection
|
|
|
|
if (conversation != null) {
|
|
|
|
server.setSelectedConversation(conversation.getName());
|
|
|
|
}
|
2010-03-08 20:11:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On no channel selected/focused
|
|
|
|
*/
|
2010-03-10 16:52:48 -05:00
|
|
|
public void onNothingSelected(AdapterView<?> deck)
|
2010-03-08 20:11:34 -05:00
|
|
|
{
|
|
|
|
((TextView) findViewById(R.id.title)).setText(server.getTitle());
|
|
|
|
}
|
2009-12-17 15:27:57 -05:00
|
|
|
}
|