From 8924f4cf884a12de8c3ecf05cc2334c8aeb8cd4f Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Wed, 12 May 2010 11:43:33 +0200 Subject: [PATCH] Created ConversationSelectedListener --- .../ConversationSelectedListener.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/org/yaaic/listener/ConversationSelectedListener.java diff --git a/src/org/yaaic/listener/ConversationSelectedListener.java b/src/org/yaaic/listener/ConversationSelectedListener.java new file mode 100644 index 0000000..3188826 --- /dev/null +++ b/src/org/yaaic/listener/ConversationSelectedListener.java @@ -0,0 +1,86 @@ +/* +Yaaic - Yet Another Android IRC Client + +Copyright 2009-2010 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.listener; + +import android.view.View; +import android.widget.AdapterView; +import android.widget.TextView; +import android.widget.AdapterView.OnItemSelectedListener; + +import org.yaaic.model.Conversation; +import org.yaaic.model.Server; + +/** + * Listener for conversation selections + * + * @author Sebastian Kaspari + */ +public class ConversationSelectedListener implements OnItemSelectedListener +{ + private Server server; + private TextView titleView; + + /** + * Create a new ConversationSelectedListener + * + * @param server + * @param titleView + */ + public ConversationSelectedListener(Server server, TextView titleView) + { + this.server = server; + this.titleView = titleView; + } + + /** + * On conversation selected/focused + */ + public void onItemSelected(AdapterView deck, View view, int position, long id) + { + Conversation conversation = (Conversation) deck.getItemAtPosition(position); + + if (conversation != null && conversation.getType() != Conversation.TYPE_SERVER) { + titleView.setText(server.getTitle() + " - " + conversation.getName()); + } else { + onNothingSelected(deck); + } + + // Remember selection + if (conversation != null) { + Conversation previousConversation = server.getConversation(server.getSelectedConversation()); + + if (previousConversation != null) { + previousConversation.setStatus(Conversation.STATUS_DEFAULT); + } + + conversation.setStatus(Conversation.STATUS_SELECTED); + server.setSelectedConversation(conversation.getName()); + } + } + + /** + * On no conversation selected/focused + */ + public void onNothingSelected(AdapterView deck) + { + titleView.setText(server.getTitle()); + } +}