diff --git a/src/org/yaaic/listener/ConversationClickListener.java b/src/org/yaaic/listener/ConversationClickListener.java new file mode 100644 index 0000000..527e811 --- /dev/null +++ b/src/org/yaaic/listener/ConversationClickListener.java @@ -0,0 +1,72 @@ +/* +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.ListView; +import android.widget.ViewSwitcher; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.TableLayout.LayoutParams; + +import org.yaaic.adapter.DeckAdapter; +import org.yaaic.model.Conversation; +import org.yaaic.view.MessageListView; + +/** + * Listener for clicks on conversations + * + * @author Sebastian Kaspari + */ +public class ConversationClickListener implements OnItemClickListener +{ + private DeckAdapter adapter; + private ViewSwitcher switcher; + + /** + * Create a new ConversationClickListener + * + * @param adapter + * @param switcher + */ + public ConversationClickListener(DeckAdapter adapter, ViewSwitcher switcher) + { + this.adapter = adapter; + this.switcher = switcher; + } + + /** + * On conversation item clicked + */ + public void onItemClick(AdapterView adapterView, View view, int position, long id) + { + Conversation conversation = adapter.getItem(position); + + MessageListView canvas = adapter.renderConversation(conversation, switcher); + canvas.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL); + canvas.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); + canvas.setDelegateTouchEvents(false); // Do not delegate + + adapter.setSwitched(conversation.getName(), canvas); + switcher.addView(canvas); + switcher.showNext(); + } +}