mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-26 10:52:16 -05:00
Show entered message and post to channel
This commit is contained in:
parent
d43b76c51d
commit
7a46c98e6c
@ -39,6 +39,8 @@ import android.widget.ListView;
|
|||||||
*/
|
*/
|
||||||
public class DeckAdapter extends BaseAdapter
|
public class DeckAdapter extends BaseAdapter
|
||||||
{
|
{
|
||||||
|
public static final String TAG = "Yaaic/DeckAdapter";
|
||||||
|
|
||||||
private HashMap<String, MessageListView> map = new HashMap<String, MessageListView>();
|
private HashMap<String, MessageListView> map = new HashMap<String, MessageListView>();
|
||||||
private LinkedList<Channel> channels = new LinkedList<Channel>();
|
private LinkedList<Channel> channels = new LinkedList<Channel>();
|
||||||
private MessageListView currentView;
|
private MessageListView currentView;
|
||||||
@ -57,8 +59,11 @@ public class DeckAdapter extends BaseAdapter
|
|||||||
*/
|
*/
|
||||||
public Channel getItem(int position)
|
public Channel getItem(int position)
|
||||||
{
|
{
|
||||||
|
if (position >= 0 && position < channels.size()) {
|
||||||
return channels.get(position);
|
return channels.get(position);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id of item at position
|
* Get id of item at position
|
||||||
|
@ -35,6 +35,7 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.View.OnKeyListener;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
@ -63,7 +64,7 @@ import org.yaaic.receiver.ChannelReceiver;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class ServerActivity extends Activity implements ServiceConnection, ChannelListener, OnItemClickListener
|
public class ServerActivity extends Activity implements ServiceConnection, ChannelListener, OnItemClickListener, OnKeyListener
|
||||||
{
|
{
|
||||||
public static final String TAG = "Yaaic/ServerActivity";
|
public static final String TAG = "Yaaic/ServerActivity";
|
||||||
|
|
||||||
@ -92,6 +93,7 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann
|
|||||||
|
|
||||||
((TextView) findViewById(R.id.title)).setText(server.getTitle());
|
((TextView) findViewById(R.id.title)).setText(server.getTitle());
|
||||||
((ImageView) findViewById(R.id.status)).setImageResource(server.getStatusIcon());
|
((ImageView) findViewById(R.id.status)).setImageResource(server.getStatusIcon());
|
||||||
|
((EditText) findViewById(R.id.input)).setOnKeyListener(this);
|
||||||
|
|
||||||
deck = (Gallery) findViewById(R.id.deck);
|
deck = (Gallery) findViewById(R.id.deck);
|
||||||
deckAdapter = new DeckAdapter();
|
deckAdapter = new DeckAdapter();
|
||||||
@ -299,4 +301,30 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann
|
|||||||
{
|
{
|
||||||
// XXX: Implement me :)
|
// XXX: Implement me :)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On key pressed (input line)
|
||||||
|
*/
|
||||||
|
public boolean onKey(View view, int keyCode, KeyEvent event)
|
||||||
|
{
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
|
||||||
|
EditText input = (EditText) view;
|
||||||
|
String text = input.getText().toString();
|
||||||
|
input.setText("");
|
||||||
|
|
||||||
|
Log.d(TAG, "Entered: " + text);
|
||||||
|
|
||||||
|
Channel channel = deckAdapter.getItem(deck.getSelectedItemPosition());
|
||||||
|
|
||||||
|
if (channel != null) {
|
||||||
|
String nickname = this.binder.getService().getConnection(serverId).getNick();
|
||||||
|
channel.addMessage(new Message("<" + nickname + "> " + text));
|
||||||
|
onChannelMessage(channel.getName());
|
||||||
|
this.binder.getService().getConnection(serverId).sendMessage(channel.getName(), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user