@Override
  public void onItemLongClick(final Conversation conversation, View view) {
    if (mAdapter.isInMultiSelectMode()) {
      mAdapter.toggleSelection(conversation.getThreadId());
      return;
    }

    final long threadId = conversation.getThreadId();
    final String name = conversation.getRecipients().formatNames(", ");

    final ConversationPrefsHelper conversationPrefs =
        new ConversationPrefsHelper(mContext, threadId);
    final boolean muted = !conversationPrefs.getNotificationsEnabled();

    final QKDialog dialog = new QKDialog().setContext(mContext).setTitle(name);

    if (!mAdapter.isInMultiSelectMode()) {
      dialog.addMenuItem(R.string.menu_multi_select, MENU_MULTI_SELECT);
    }

    if (muted) {
      dialog.addMenuItem(R.string.menu_unmute_conversation, MENU_UNMUTE_CONVERSATION);
    } else {
      dialog.addMenuItem(R.string.menu_mute_conversation, MENU_MUTE_CONVERSATION);
    }

    if (conversation.hasUnreadMessages()) {
      dialog.addMenuItem(R.string.menu_mark_read, MENU_MARK_READ);
    } else {
      dialog.addMenuItem(R.string.menu_mark_unread, MENU_MARK_UNREAD);
    }

    dialog.addMenuItem(R.string.menu_notification_settings, MENU_NOTIFICATION_SETTINGS);
    dialog.addMenuItem(R.string.menu_view_details, MENU_VIEW_DETAILS);

    if (conversation.hasError()) {
      dialog.addMenuItem(R.string.delete_all_failed, MENU_DELETE_FAILED);
    }

    dialog.addMenuItem(R.string.menu_delete_conversation, MENU_DELETE_CONVERSATION);

    dialog
        .buildMenu(
            new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch ((int) id) {
                  case MENU_MUTE_CONVERSATION:
                    conversationPrefs.putBoolean(SettingsFragment.NOTIFICATIONS, false);
                    mAdapter.notifyDataSetChanged();
                    break;

                  case MENU_UNMUTE_CONVERSATION:
                    conversationPrefs.putBoolean(SettingsFragment.NOTIFICATIONS, true);
                    mAdapter.notifyDataSetChanged();
                    break;

                  case MENU_NOTIFICATION_SETTINGS:
                    ConversationNotificationSettingsDialog.newInstance(threadId, name)
                        .setContext(mContext)
                        .show(((MainActivity) mContext).getFragmentManager(), "notification prefs");
                    break;

                  case MENU_VIEW_DETAILS:
                    mConversationDetailsDialog.showDetails(conversation);
                    break;

                  case MENU_MARK_READ:
                    new ConversationLegacy(mContext, threadId).markRead();
                    break;

                  case MENU_MARK_UNREAD:
                    new ConversationLegacy(mContext, threadId).markUnread();
                    break;

                  case MENU_MULTI_SELECT:
                    mAdapter.setSelected(threadId);
                    break;

                  case MENU_DELETE_CONVERSATION:
                    DialogHelper.showDeleteConversationDialog((MainActivity) mContext, threadId);
                    break;
                  case MENU_DELETE_FAILED:
                    // Deletes all failed messages from all conversations
                    DialogHelper.showDeleteFailedMessagesDialog((MainActivity) mContext, threadId);
                    break;
                }
              }
            })
        .show(mContext.getFragmentManager(), "conversation options");
  }
Exemplo n.º 2
0
  public void sendSms() {
    String body = mReplyText.getText().toString();

    final Drawable attachment;
    if (mAttachment.hasAttachment()) {
      attachment = mAttachment.getDrawable();
    } else {
      attachment = null;
    }
    clearAttachment();

    String[] recipients = null;
    if (mConversation != null) {
      recipients = mConversation.getRecipients().getNumbers();
      for (int i = 0; i < recipients.length; i++) {
        recipients[i] = PhoneNumberUtils.stripSeparators(recipients[i]);
      }
    } else if (mRecipientProvider != null) {
      recipients = mRecipientProvider.getRecipientAddresses();
    }

    // If we have some recipients, send the message!
    if (recipients != null && recipients.length > 0) {
      mReplyText.setText("");

      AnalyticsManager.getInstance()
          .sendEvent(
              AnalyticsManager.CATEGORY_MESSAGES, AnalyticsManager.ACTION_SEND_MESSAGE, mLabel);

      Transaction sendTransaction = new Transaction(mContext, SmsHelper.getSendSettings(mContext));

      com.moez.QKSMS.mmssms.Message message = new com.moez.QKSMS.mmssms.Message(body, recipients);
      message.setType(com.moez.QKSMS.mmssms.Message.TYPE_SMSMMS);
      if (attachment != null) {
        message.setImage(ImageUtils.drawableToBitmap(attachment));
      }

      // Notify the listener about the new text message
      if (mOnSendListener != null) {
        mOnSendListener.onSend(recipients, message.getSubject());
      }

      long threadId = mConversation != null ? mConversation.getThreadId() : 0;
      if (!message.toString().equals("")) {
        sendTransaction.sendNewMessage(message, threadId);
      }
      NotificationManager.update(mContext);

      if (mConversationLegacy != null) {
        mConversationLegacy.markRead();
      }

      // Reset the image button state
      updateButtonState();

      // Otherwise, show a toast to the user to prompt them to add recipients.
    } else {
      Toast.makeText(mContext, mRes.getString(R.string.error_no_recipients), Toast.LENGTH_SHORT)
          .show();
    }
  }