| skipped 3 lines |
4 | 4 | | |
5 | 5 | | import org.tigase.mobile.MessengerApplication; |
6 | 6 | | import org.tigase.mobile.MultiJaxmpp; |
| 7 | + | import org.tigase.mobile.MultiJaxmpp.ChatWrapper; |
7 | 8 | | import org.tigase.mobile.R; |
8 | 9 | | import org.tigase.mobile.RosterDisplayTools; |
9 | 10 | | import org.tigase.mobile.db.RosterTableMetaData; |
| skipped 1 lines |
11 | 12 | | import org.tigase.mobile.roster.CPresence; |
12 | 13 | | |
13 | 14 | | import tigase.jaxmpp.core.client.xmpp.modules.chat.Chat; |
| 15 | + | import tigase.jaxmpp.core.client.xmpp.modules.muc.Room; |
14 | 16 | | import tigase.jaxmpp.core.client.xmpp.modules.roster.RosterItem; |
15 | 17 | | import tigase.jaxmpp.core.client.xmpp.modules.roster.RosterStore; |
16 | 18 | | import android.app.Activity; |
| skipped 19 lines |
36 | 38 | | |
37 | 39 | | private class ImageAdapter extends BaseAdapter { |
38 | 40 | | |
39 | | - | private final ArrayList<Chat> chats = new ArrayList<Chat>(); |
| 41 | + | private final ArrayList<ChatWrapper> chats = new ArrayList<ChatWrapper>(); |
40 | 42 | | |
41 | 43 | | private Context mContext; |
42 | 44 | | |
| skipped 23 lines |
66 | 68 | | |
67 | 69 | | @Override |
68 | 70 | | public long getItemId(int position) { |
69 | | - | return this.chats.get(position).getId(); |
| 71 | + | // XXX |
| 72 | + | return this.chats.get(position).hashCode(); |
70 | 73 | | } |
71 | 74 | | |
72 | 75 | | @Override |
| skipped 12 lines |
85 | 88 | | imageView = convertView; |
86 | 89 | | } |
87 | 90 | | |
88 | | - | Chat chat = this.chats.get(position); |
| 91 | + | final TextView tv = (TextView) imageView.findViewById(R.id.chat_list_item_name); |
| 92 | + | final ImageView avatar = (ImageView) imageView.findViewById(R.id.imageView1); |
| 93 | + | final ImageView itemPresence = (ImageView) imageView.findViewById(R.id.imageView2); |
89 | 94 | | |
90 | | - | final Cursor cursor = getContentResolver().query( |
91 | | - | Uri.parse(RosterProvider.CONTENT_URI + "/" + chat.getJid().getBareJid()), null, null, null, null); |
92 | | - | byte[] avatarData = null; |
93 | | - | try { |
94 | | - | cursor.moveToNext(); |
95 | | - | avatarData = cursor.getBlob(cursor.getColumnIndex(RosterTableMetaData.FIELD_AVATAR)); |
96 | | - | } catch (Exception ex) { |
97 | | - | Log.v("ChatListActivity", "no avatar for " + chat.getJid().getBareJid().toString()); |
98 | | - | } finally { |
99 | | - | cursor.close(); |
100 | | - | } |
| 95 | + | ChatWrapper wrapper = this.chats.get(position); |
| 96 | + | if (wrapper.isChat()) { |
| 97 | + | Chat chat = wrapper.getChat(); |
101 | 98 | | |
102 | | - | String x; |
103 | | - | RosterStore roster = multi.get(chat.getSessionObject()).getRoster(); |
104 | | - | RosterItem ri = roster.get(chat.getJid().getBareJid()); |
105 | | - | if (ri == null) |
106 | | - | x = chat.getJid().toString(); |
107 | | - | else |
108 | | - | x = rdt.getDisplayName(ri); |
| 99 | + | final Cursor cursor = getContentResolver().query( |
| 100 | + | Uri.parse(RosterProvider.CONTENT_URI + "/" + chat.getJid().getBareJid()), null, null, null, null); |
| 101 | + | byte[] avatarData = null; |
| 102 | + | try { |
| 103 | + | cursor.moveToNext(); |
| 104 | + | avatarData = cursor.getBlob(cursor.getColumnIndex(RosterTableMetaData.FIELD_AVATAR)); |
| 105 | + | } catch (Exception ex) { |
| 106 | + | Log.v("ChatListActivity", "no avatar for " + chat.getJid().getBareJid().toString()); |
| 107 | + | } finally { |
| 108 | + | cursor.close(); |
| 109 | + | } |
109 | 110 | | |
110 | | - | final CPresence cp = rdt.getShowOf(chat.getSessionObject(), chat.getJid()); |
| 111 | + | String x; |
| 112 | + | RosterStore roster = multi.get(chat.getSessionObject()).getRoster(); |
| 113 | + | RosterItem ri = roster.get(chat.getJid().getBareJid()); |
| 114 | + | if (ri == null) |
| 115 | + | x = chat.getJid().toString(); |
| 116 | + | else |
| 117 | + | x = rdt.getDisplayName(ri); |
111 | 118 | | |
112 | | - | ImageView itemPresence = (ImageView) imageView.findViewById(R.id.imageView2); |
113 | | - | if (cp == null) |
114 | | - | itemPresence.setImageResource(R.drawable.user_offline); |
115 | | - | else |
116 | | - | switch (cp) { |
117 | | - | case chat: |
118 | | - | case online: |
119 | | - | itemPresence.setImageResource(R.drawable.user_available); |
120 | | - | break; |
121 | | - | case away: |
122 | | - | itemPresence.setImageResource(R.drawable.user_away); |
123 | | - | break; |
124 | | - | case xa: |
125 | | - | itemPresence.setImageResource(R.drawable.user_extended_away); |
126 | | - | break; |
127 | | - | case dnd: |
128 | | - | itemPresence.setImageResource(R.drawable.user_busy); |
129 | | - | break; |
130 | | - | default: |
| 119 | + | final CPresence cp = rdt.getShowOf(chat.getSessionObject(), chat.getJid()); |
| 120 | + | |
| 121 | + | if (cp == null) |
131 | 122 | | itemPresence.setImageResource(R.drawable.user_offline); |
132 | | - | break; |
133 | | - | } |
| 123 | + | else |
| 124 | + | switch (cp) { |
| 125 | + | case chat: |
| 126 | + | case online: |
| 127 | + | itemPresence.setImageResource(R.drawable.user_available); |
| 128 | + | break; |
| 129 | + | case away: |
| 130 | + | itemPresence.setImageResource(R.drawable.user_away); |
| 131 | + | break; |
| 132 | + | case xa: |
| 133 | + | itemPresence.setImageResource(R.drawable.user_extended_away); |
| 134 | + | break; |
| 135 | + | case dnd: |
| 136 | + | itemPresence.setImageResource(R.drawable.user_busy); |
| 137 | + | break; |
| 138 | + | default: |
| 139 | + | itemPresence.setImageResource(R.drawable.user_offline); |
| 140 | + | break; |
| 141 | + | } |
134 | 142 | | |
135 | | - | TextView tv = (TextView) imageView.findViewById(R.id.chat_list_item_name); |
136 | | - | tv.setText(x); |
| 143 | + | tv.setText(x); |
137 | 144 | | |
138 | | - | ImageView avatar = (ImageView) imageView.findViewById(R.id.imageView1); |
139 | | - | |
140 | | - | if (avatarData != null) { |
141 | | - | Bitmap bmp = BitmapFactory.decodeByteArray(avatarData, 0, avatarData.length); |
142 | | - | avatar.setImageBitmap(bmp); |
| 145 | + | if (avatarData != null) { |
| 146 | + | Bitmap bmp = BitmapFactory.decodeByteArray(avatarData, 0, avatarData.length); |
| 147 | + | avatar.setImageBitmap(bmp); |
| 148 | + | } else { |
| 149 | + | avatar.setImageResource(R.drawable.user_avatar); |
| 150 | + | } |
143 | 151 | | } else { |
144 | | - | avatar.setImageResource(R.drawable.user_avatar); |
| 152 | + | Room room = wrapper.getRoom(); |
| 153 | + | tv.setText(room.getRoomJid().toString()); |
145 | 154 | | } |
146 | 155 | | |
147 | 156 | | return imageView; |
| skipped 13 lines |
161 | 170 | | |
162 | 171 | | @Override |
163 | 172 | | public void onItemClick(AdapterView<?> parent, View v, int position, long id) { |
164 | | - | Chat chat = (Chat) parent.getItemAtPosition(position); |
| 173 | + | ChatWrapper wrapper = (ChatWrapper) parent.getItemAtPosition(position); |
165 | 174 | | Intent result = new Intent(); |
166 | | - | result.putExtra("jid", chat.getJid().toString()); |
167 | | - | result.putExtra("chatId", chat.getId()); |
| 175 | + | if (wrapper.isChat()) { |
| 176 | + | result.putExtra("jid", wrapper.getChat().getJid().toString()); |
| 177 | + | result.putExtra("chatId", wrapper.getChat().getId()); |
| 178 | + | } else { |
| 179 | + | result.putExtra("room", wrapper.getRoom().getRoomJid().toString()); |
| 180 | + | result.putExtra("roomId", wrapper.getRoom().getId()); |
| 181 | + | } |
168 | 182 | | setResult(Activity.RESULT_OK, result); |
169 | 183 | | finish(); |
170 | 184 | | } |
| skipped 7 lines |