示例#1
1
  @Override
  public void setMessageObject(MessageObject messageObject) {
    boolean dataChanged = currentMessageObject == messageObject && isUserDataChanged();
    if (currentMessageObject != messageObject || dataChanged) {
      if (AndroidUtilities.isTablet()) {
        backgroundWidth =
            Math.min(
                AndroidUtilities.getMinTabletSide()
                    - AndroidUtilities.dp(
                        isChat && messageObject.messageOwner.from_id > 0 ? 102 : 50),
                AndroidUtilities.dp(300));
      } else {
        backgroundWidth =
            Math.min(
                AndroidUtilities.displaySize.x
                    - AndroidUtilities.dp(
                        isChat && messageObject.messageOwner.from_id > 0 ? 102 : 50),
                AndroidUtilities.dp(300));
      }

      if (messageObject.isOutOwner()) {
        seekBar.type = 0;
        radialProgress.setProgressColor(theme.ChatMusicCell_radialProgress_color);
      } else {
        seekBar.type = 1;
        radialProgress.setProgressColor(theme.ChatMusicCell_radialProgress_color_2);
      }

      int maxWidth = backgroundWidth - AndroidUtilities.dp(86);

      CharSequence stringFinal =
          TextUtils.ellipsize(
              messageObject.getMusicTitle().replace("\n", " "),
              titlePaint,
              maxWidth,
              TextUtils.TruncateAt.END);
      titleLayout =
          new StaticLayout(
              stringFinal, titlePaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
      if (titleLayout.getLineCount() > 0) {
        titleX = (int) Math.ceil(titleLayout.getLineLeft(0));
      }

      stringFinal =
          TextUtils.ellipsize(
              messageObject.getMusicAuthor().replace("\n", " "),
              authorPaint,
              maxWidth,
              TextUtils.TruncateAt.END);
      authorLayout =
          new StaticLayout(
              stringFinal, authorPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
      if (authorLayout.getLineCount() > 0) {
        authorX = (int) Math.ceil(authorLayout.getLineLeft(0));
      }

      super.setMessageObject(messageObject);
    }
    updateButtonState(dataChanged);
  }
示例#2
0
  public void draw(Canvas canvas) {
    if (waveformBytes == null || width == 0) {
      return;
    }
    float totalBarsCount = width / AndroidUtilities.dp(3);
    if (totalBarsCount <= 0.1f) {
      return;
    }
    byte value;
    int samplesCount = (waveformBytes.length * 8 / 5);
    float samplesPerBar = samplesCount / totalBarsCount;
    float barCounter = 0;
    int nextBarNum = 0;

    paintInner.setColor(
        messageObject != null
                && !messageObject.isOutOwner()
                && messageObject.isContentUnread()
                && messageObject.messageOwner.to_id.channel_id == 0
            ? outerColor
            : (selected ? selectedColor : innerColor));
    paintOuter.setColor(outerColor);

    int y = (height - AndroidUtilities.dp(14)) / 2;
    int barNum = 0;
    int lastBarNum;
    int drawBarCount;

    for (int a = 0; a < samplesCount; a++) {
      if (a != nextBarNum) {
        continue;
      }
      drawBarCount = 0;
      lastBarNum = nextBarNum;
      while (lastBarNum == nextBarNum) {
        barCounter += samplesPerBar;
        nextBarNum = (int) barCounter;
        drawBarCount++;
      }

      int bitPointer = a * 5;
      int byteNum = bitPointer / 8;
      int byteBitOffset = bitPointer - byteNum * 8;
      int currentByteCount = 8 - byteBitOffset;
      int nextByteRest = 5 - currentByteCount;
      value =
          (byte)
              ((waveformBytes[byteNum] >> byteBitOffset)
                  & ((2 << (Math.min(5, currentByteCount) - 1)) - 1));
      if (nextByteRest > 0) {
        value <<= nextByteRest;
        value |= waveformBytes[byteNum + 1] & ((2 << (nextByteRest - 1)) - 1);
      }

      for (int b = 0; b < drawBarCount; b++) {
        int x = barNum * AndroidUtilities.dp(3);
        if (x < thumbX && x + AndroidUtilities.dp(2) < thumbX) {
          canvas.drawRect(
              x,
              y + AndroidUtilities.dp(14 - Math.max(1, 14.0f * value / 31.0f)),
              x + AndroidUtilities.dp(2),
              y + AndroidUtilities.dp(14),
              paintOuter);
        } else {
          canvas.drawRect(
              x,
              y + AndroidUtilities.dp(14 - Math.max(1, 14.0f * value / 31.0f)),
              x + AndroidUtilities.dp(2),
              y + AndroidUtilities.dp(14),
              paintInner);
          if (x < thumbX) {
            canvas.drawRect(
                x,
                y + AndroidUtilities.dp(14 - Math.max(1, 14.0f * value / 31.0f)),
                thumbX,
                y + AndroidUtilities.dp(14),
                paintOuter);
          }
        }
        barNum++;
      }
    }
  }
  public static void loadReplyMessagesForMessages(
      final ArrayList<MessageObject> messages, final long dialog_id) {
    final ArrayList<Integer> replyMessages = new ArrayList<>();
    final HashMap<Integer, ArrayList<MessageObject>> replyMessageOwners = new HashMap<>();
    final StringBuilder stringBuilder = new StringBuilder();
    int channelId = 0;
    for (MessageObject messageObject : messages) {
      if (messageObject.getId() > 0
          && messageObject.isReply()
          && messageObject.replyMessageObject == null) {
        Integer id = messageObject.messageOwner.reply_to_msg_id;
        long messageId = id;
        if (messageObject.messageOwner.to_id.channel_id != 0) {
          messageId |= ((long) messageObject.messageOwner.to_id.channel_id) << 32;
          channelId = messageObject.messageOwner.to_id.channel_id;
        }
        if (stringBuilder.length() > 0) {
          stringBuilder.append(',');
        }
        stringBuilder.append(messageId);
        ArrayList<MessageObject> messageObjects = replyMessageOwners.get(id);
        if (messageObjects == null) {
          messageObjects = new ArrayList<>();
          replyMessageOwners.put(id, messageObjects);
        }
        messageObjects.add(messageObject);
        if (!replyMessages.contains(id)) {
          replyMessages.add(id);
        }
      }
    }
    if (replyMessages.isEmpty()) {
      return;
    }

    final int channelIdFinal = channelId;
    MessagesStorage.getInstance()
        .getStorageQueue()
        .postRunnable(
            new Runnable() {
              @Override
              public void run() {
                try {
                  final ArrayList<TLRPC.Message> result = new ArrayList<>();
                  final ArrayList<TLRPC.User> users = new ArrayList<>();
                  final ArrayList<TLRPC.Chat> chats = new ArrayList<>();
                  ArrayList<Integer> usersToLoad = new ArrayList<>();
                  ArrayList<Integer> chatsToLoad = new ArrayList<>();

                  SQLiteCursor cursor =
                      MessagesStorage.getInstance()
                          .getDatabase()
                          .queryFinalized(
                              String.format(
                                  Locale.US,
                                  "SELECT data, mid, date FROM messages WHERE mid IN(%s)",
                                  stringBuilder.toString()));
                  while (cursor.next()) {
                    NativeByteBuffer data = new NativeByteBuffer(cursor.byteArrayLength(0));
                    if (data != null && cursor.byteBufferValue(0, data) != 0) {
                      TLRPC.Message message =
                          TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
                      message.id = cursor.intValue(1);
                      message.date = cursor.intValue(2);
                      message.dialog_id = dialog_id;
                      if (message.from_id > 0) {
                        if (!usersToLoad.contains(message.from_id)) {
                          usersToLoad.add(message.from_id);
                        }
                      } else {
                        if (!chatsToLoad.contains(-message.from_id)) {
                          chatsToLoad.add(-message.from_id);
                        }
                      }
                      if (message.action != null && message.action.user_id != 0) {
                        if (!usersToLoad.contains(message.action.user_id)) {
                          usersToLoad.add(message.action.user_id);
                        }
                      }
                      if (message.media != null && message.media.user_id != 0) {
                        if (!usersToLoad.contains(message.media.user_id)) {
                          usersToLoad.add(message.media.user_id);
                        }
                      }
                      if (message.media != null
                          && message.media.audio != null
                          && message.media.audio.user_id != 0) {
                        if (!usersToLoad.contains(message.media.audio.user_id)) {
                          usersToLoad.add(message.media.audio.user_id);
                        }
                      }
                      if (message.fwd_from_id instanceof TLRPC.TL_peerUser) {
                        if (!usersToLoad.contains(message.fwd_from_id.user_id)) {
                          usersToLoad.add(message.fwd_from_id.user_id);
                        }
                      } else if (message.fwd_from_id instanceof TLRPC.TL_peerChannel) {
                        if (!chatsToLoad.contains(message.fwd_from_id.channel_id)) {
                          chatsToLoad.add(message.fwd_from_id.channel_id);
                        }
                      }
                      result.add(message);
                      replyMessages.remove((Integer) message.id);
                    }
                    data.reuse();
                  }
                  cursor.dispose();

                  if (!usersToLoad.isEmpty()) {
                    MessagesStorage.getInstance()
                        .getUsersInternal(TextUtils.join(",", usersToLoad), users);
                  }
                  if (!chatsToLoad.isEmpty()) {
                    MessagesStorage.getInstance()
                        .getChatsInternal(TextUtils.join(",", chatsToLoad), chats);
                  }
                  broadcastReplyMessages(result, replyMessageOwners, users, chats, dialog_id, true);

                  if (!replyMessages.isEmpty()) {
                    if (channelIdFinal != 0) {
                      final TLRPC.TL_channels_getMessages req = new TLRPC.TL_channels_getMessages();
                      req.channel = MessagesController.getInputChannel(channelIdFinal);
                      req.id = replyMessages;
                      ConnectionsManager.getInstance()
                          .sendRequest(
                              req,
                              new RequestDelegate() {
                                @Override
                                public void run(TLObject response, TLRPC.TL_error error) {
                                  if (error == null) {
                                    TLRPC.messages_Messages messagesRes =
                                        (TLRPC.messages_Messages) response;
                                    ImageLoader.saveMessagesThumbs(messagesRes.messages);
                                    broadcastReplyMessages(
                                        messagesRes.messages,
                                        replyMessageOwners,
                                        messagesRes.users,
                                        messagesRes.chats,
                                        dialog_id,
                                        false);
                                    MessagesStorage.getInstance()
                                        .putUsersAndChats(
                                            messagesRes.users, messagesRes.chats, true, true);
                                    saveReplyMessages(replyMessageOwners, messagesRes.messages);
                                  }
                                }
                              });
                    } else {
                      TLRPC.TL_messages_getMessages req = new TLRPC.TL_messages_getMessages();
                      req.id = replyMessages;
                      ConnectionsManager.getInstance()
                          .sendRequest(
                              req,
                              new RequestDelegate() {
                                @Override
                                public void run(TLObject response, TLRPC.TL_error error) {
                                  if (error == null) {
                                    TLRPC.messages_Messages messagesRes =
                                        (TLRPC.messages_Messages) response;
                                    ImageLoader.saveMessagesThumbs(messagesRes.messages);
                                    broadcastReplyMessages(
                                        messagesRes.messages,
                                        replyMessageOwners,
                                        messagesRes.users,
                                        messagesRes.chats,
                                        dialog_id,
                                        false);
                                    MessagesStorage.getInstance()
                                        .putUsersAndChats(
                                            messagesRes.users, messagesRes.chats, true, true);
                                    saveReplyMessages(replyMessageOwners, messagesRes.messages);
                                  }
                                }
                              });
                    }
                  }
                } catch (Exception e) {
                  FileLog.e("tmessages", e);
                }
              }
            });
  }