1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-12-26 01:18:57 -05:00

Get channel view from channel list and not from a (broken) cache

This commit is contained in:
Sebastian Kaspari 2010-03-09 01:57:22 +01:00
parent 6b8b1d25b9
commit 691f3b3982
2 changed files with 19 additions and 21 deletions

View File

@ -20,7 +20,6 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.adapter;
import java.util.HashMap;
import java.util.LinkedList;
import org.yaaic.model.Channel;
@ -41,7 +40,6 @@ public class DeckAdapter extends BaseAdapter
{
public static final String TAG = "Yaaic/DeckAdapter";
private HashMap<String, MessageListView> map = new HashMap<String, MessageListView>();
private LinkedList<Channel> channels = new LinkedList<Channel>();
private MessageListView currentView;
private String currentChannel;
@ -92,13 +90,15 @@ public class DeckAdapter extends BaseAdapter
* @param channel
* @return The item
*/
public MessageListView getItemByName(String channel)
public int getPositionByName(String name)
{
if (map.containsKey(channel)) {
return map.get(channel);
for (int i = 0; i < channels.size(); i++) {
if (channels.get(i).getName().equals(name)) {
return i;
}
}
return null;
return -1;
}
/**
@ -153,22 +153,14 @@ public class DeckAdapter extends BaseAdapter
{
return currentView != null;
}
/**
* Get view at given position
*/
public View getView(int position, View convertView, ViewGroup parent)
{
Channel channel = getItem(position);
convertView = map.get(channel.getName());
if (convertView == null) {
MessageListView view = renderChannel(channel, parent);
map.put(channel.getName(), view);
return view;
} else {
return convertView;
}
return renderChannel(channel, parent);
}
/**
@ -190,8 +182,8 @@ public class DeckAdapter extends BaseAdapter
));
list.setBackgroundColor(0xff222222);
list.setPadding(5, 5, 5, 5);
list.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
list.setScrollContainer(false);
list.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
list.setSelection(list.getAdapter().getCount() - 1); // scroll to bottom
return list;

View File

@ -221,11 +221,17 @@ public class ServerActivity extends Activity implements ServiceConnection, Chann
while(channel.hasBufferedMessages()) {
Message message = channel.pollBufferedMessage();
MessageListView view = (MessageListView) deckAdapter.getItemByName(target);
if (view != null) {
MessageListAdapter adapter = view.getAdapter();
adapter.addMessage(message);
int position = deckAdapter.getPositionByName(target);
if (position != -1) {
MessageListView view = (MessageListView) deck.getChildAt(position);
if (view != null) {
MessageListAdapter adapter = view.getAdapter();
adapter.addMessage(message);
} else {
Log.d(TAG, "MessageListView Adapter is null");
}
}
if (deckAdapter.isSwitched()) {