private void initChat() { if (dialog.getType() == QBDialogType.GROUP) { chat = new GroupChatImpl(this); progressBar.setVisibility(View.VISIBLE); joinGroupChat(); } else if (dialog.getType() == QBDialogType.PRIVATE) { Integer opponentID = ChatService.getInstance().getOpponentIDForPrivateDialog(dialog); chat = new PrivateChatImpl(this, opponentID); loadChatHistory(); } }
public void tryJoinRoomChats(List<QBDialog> chatDialogsList) { if (!chatDialogsList.isEmpty()) { DatabaseManager.saveDialogs(context, chatDialogsList); initGroupDialogsList(); for (QBDialog dialog : chatDialogsList) { if (!QBDialogType.PRIVATE.equals(dialog.getType())) { groupDialogsList.add(dialog); tryJoinRoomChat(dialog); } } } }
private void createDialogByNotification(QBChatMessage chatMessage) { long time; String roomJidId; time = DateUtilsCore.getCurrentTime(); QBDialog dialog = ChatUtils.parseDialogFromMessage(context, chatMessage, chatMessage.getBody(), time); roomJidId = dialog.getRoomJid(); if (roomJidId != null && !QBDialogType.PRIVATE.equals(dialog.getType())) { tryJoinRoomChat(dialog); new FindUnknownFriendsTask(context).execute(null, dialog); saveDialogToCache(context, dialog); } }
@Override public void reconnectionSuccessful() { Log.i(TAG, "reconnectionSuccessful"); // Join active room // if (dialog.getType() == QBDialogType.GROUP) { ChatActivity.this.runOnUiThread( new Runnable() { @Override public void run() { joinGroupChat(); } }); } }
@Override public void connectionClosedOnError(final Exception e) { Log.i(TAG, "connectionClosedOnError: " + e.getLocalizedMessage()); // leave active room // if (dialog.getType() == QBDialogType.GROUP) { ChatActivity.this.runOnUiThread( new Runnable() { @Override public void run() { ((GroupChatImpl) chat).leave(); } }); } }
private void sendChatMessage(String messageText) { QBChatMessage chatMessage = new QBChatMessage(); chatMessage.setBody(messageText); chatMessage.setProperty(PROPERTY_SAVE_TO_HISTORY, "1"); chatMessage.setDateSent(new Date().getTime() / 1000); try { chat.sendMessage(chatMessage); } catch (XMPPException | SmackException.NotConnectedException e) { Log.e(TAG, "failed to send a message", e); } messageEditText.setText(""); if (dialog.getType() == QBDialogType.PRIVATE) { showMessage(chatMessage); } }
public void sendOccupantStatusGroup(String sendStr) { long time = DateUtilsCore.getCurrentTime(); QBChatMessage chatMessage = new QBChatMessage(); chatMessage.setBody(sendStr); chatMessage.setProperty( ChatUtils.PROPERTY_NOTIFICATION_TYPE, ChatUtils.PROPERTY_NOTIFICATION_TYPE_CREATE_CHAT); chatMessage.setProperty(ChatUtils.PROPERTY_DIALOG_ID, currentDialog.getDialogId()); chatMessage.setProperty(ChatUtils.PROPERTY_ROOM_JID, currentDialog.getRoomJid()); chatMessage.setProperty( ChatUtils.PROPERTY_OCCUPANTS_IDS, TextUtils.join(ChatUtils.OCCUPANT_IDS_DIVIDER, currentDialog.getOccupants())); chatMessage.setProperty(ChatUtils.PROPERTY_ROOM_NAME, currentDialog.getName()); chatMessage.setProperty( ChatUtils.PROPERTY_DIALOG_TYPE_CODE, String.valueOf(currentDialog.getType().getCode())); chatMessage.setProperty(ChatUtils.PROPERTY_DATE_SENT, time + ConstsCore.EMPTY_STRING); chatMessage.setProperty(ChatUtils.PROPERTY_SAVE_TO_HISTORY, ChatUtils.VALUE_SAVE_TO_HISTORY); try { sendRoomMessage(chatMessage, currentDialog.getRoomJid(), currentDialog.getDialogId()); } catch (QBResponseException e) { ErrorUtils.showError(context, e); } }
protected GroupDialogOccupantsAdapter getFriendsAdapter() { if (dialogCurrent.getType() == QBDialogType.PUBLIC_GROUP) return new GroupDialogOccupantsAdapter(this, ChatUtils.getJoinUsers()); else return new GroupDialogOccupantsAdapter(this, groupDialog.getOccupantList()); }
private void startLoadGroupDialog() { if (dialogCurrent.getType() == QBDialogType.PUBLIC_GROUP) initListView(); else QBLoadGroupDialogCommand.start(this, dialogCurrent, groupDialog.getRoomJid()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); Intent intent = getIntent(); dialog = (QBDialog) intent.getSerializableExtra(EXTRA_DIALOG); messagesContainer = (ListView) findViewById(R.id.messagesContainer); messageEditText = (EditText) findViewById(R.id.messageEdit); progressBar = (ProgressBar) findViewById(R.id.progressBar); companionLabel = (TextView) findViewById(R.id.companionLabel); container = (RelativeLayout) findViewById(R.id.container); if (dialog.getType() == QBDialogType.GROUP) { TextView meLabel = (TextView) findViewById(R.id.meLabel); container.removeView(meLabel); container.removeView(companionLabel); } else if (dialog.getType() == QBDialogType.PRIVATE) { Integer opponentID = ChatService.getInstance().getOpponentIDForPrivateDialog(dialog); companionLabel.setText( ChatService.getInstance().getDialogsUsers().get(opponentID).getLogin()); } sendButton = (Button) findViewById(R.id.chatSendButton); sendButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String messageText = messageEditText.getText().toString(); if (!TextUtils.isEmpty(messageText)) { sendChatMessage(messageText); } } }); keyboardHandleLayout = (KeyboardHandleRelativeLayout) findViewById(R.id.sizeNotifierLayout); keyboardHandleLayout.listener = this; stickersFrame = findViewById(R.id.frame); stickerButton = (ImageView) findViewById(R.id.stickers_button); stickerButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (isStickersFrameVisible) { showKeyboard(); stickerButton.setImageResource(R.drawable.ic_action_insert_emoticon); } else { if (keyboardHandleLayout.isKeyboardVisible()) { keyboardHandleLayout.hideKeyboard( ChatActivity.this, new KeyboardHandleRelativeLayout.OnKeyboardHideCallback() { @Override public void onKeyboardHide() { stickerButton.setImageResource(R.drawable.ic_action_keyboard); setStickersFrameVisible(true); } }); } else { stickerButton.setImageResource(R.drawable.ic_action_keyboard); setStickersFrameVisible(true); } } } }); updateStickersFrameParams(); stickersFragment = (StickersFragment) getSupportFragmentManager().findFragmentById(R.id.frame); if (stickersFragment == null) { stickersFragment = new StickersFragment.Builder() .setStickerPlaceholderColorFilterRes(android.R.color.darker_gray) .build(); getSupportFragmentManager().beginTransaction().replace(R.id.frame, stickersFragment).commit(); } stickersFragment.setOnStickerSelectedListener(stickerSelectedListener); stickersFragment.setOnEmojiBackspaceClickListener( new OnEmojiBackspaceClickListener() { @Override public void onEmojiBackspaceClicked() { KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL); messageEditText.dispatchKeyEvent(event); } }); setStickersFrameVisible(isStickersFrameVisible); if (isSessionActive()) { initChat(); } ChatService.getInstance().addConnectionListener(chatConnectionListener); }