@Override public View newView(Context context, Cursor cursor, ViewGroup parent) { LayoutInflater inflater = LayoutInflater.from(context); View view = inflater.inflate(R.layout.messaging_chat_list_item, parent, false); view.setOnClickListener(clickItemListener); ChatListItemCache cache = new ChatListItemCache(); cache.chatId = cursor.getString(1); cache.sessionId = cursor.getString(2); cache.type = cursor.getInt(3); cache.contact = cursor.getString(4); cache.data = cursor.getString(5); cache.date = cursor.getLong(6); view.setTag(cache); return view; }
public void onClick(View v) { if (!isServiceAvailable()) { Utils.showMessage(ChatList.this, getString(R.string.label_continue_chat_failed)); return; } // Get selected item ChatListItemCache cache = (ChatListItemCache) v.getTag(); if (cache.isGroupChat()) { // Group chat IChatSession session = isGroupChatActive(cache.chatId); if (session != null) { // Session already active on the device: just reload it in the UI try { Intent intent = new Intent(ChatList.this, GroupChatView.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("subject", session.getSubject()); intent.putExtra("sessionId", session.getSessionID()); startActivity(intent); } catch (Exception e) { Utils.showMessage(ChatList.this, getString(R.string.label_api_failed)); } } else { // Test if the session may be rejoined or not int status = RichMessaging.getInstance().getGroupChatStatus(cache.chatId); if (status == EventsLogApi.STATUS_TERMINATED_BY_USER) { // The session was terminated by user itself: rejoin or restart are not authorized Utils.showMessage(ChatList.this, getString(R.string.label_rejoin_unauthorized)); } else if (status == EventsLogApi.STATUS_TERMINATED_BY_REMOTE) { // The session was terminated: only a restart may be done restartChat = new RestartChat(ChatList.this, messagingApi, cache.chatId); restartChat.start(); } else { // Session terminated on the device: try to rejoin the session rejoinChat = new RejoinChat(ChatList.this, messagingApi, cache.chatId); rejoinChat.start(); } } } else { // 1-1 chat IChatSession session = isChatSessionActive(cache.sessionId); if (session != null) { // Session already active on the device: just reload it in the UI try { Intent intent = new Intent(ChatList.this, OneToOneChatView.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("contact", session.getRemoteContact()); intent.putExtra("sessionId", session.getSessionID()); startActivity(intent); } catch (Exception e) { Utils.showMessage(ChatList.this, getString(R.string.label_api_failed)); } } else { // Session terminated on the device: create a new one on the first message Intent intent = new Intent(ChatList.this, OneToOneChatView.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("contact", cache.contact); startActivity(intent); } } }