private void getNewMessage() {
    if (NotificationsController.getInstance().popupMessages.isEmpty()) {
      onFinish();
      finish();
      return;
    }

    boolean found = false;
    if ((currentMessageNum != 0 || chatActivityEnterView.hasText() || startedMoving)
        && currentMessageObject != null) {
      for (int a = 0; a < NotificationsController.getInstance().popupMessages.size(); a++) {
        if (NotificationsController.getInstance().popupMessages.get(a).getId()
            == currentMessageObject.getId()) {
          currentMessageNum = a;
          found = true;
          break;
        }
      }
    }
    if (!found) {
      currentMessageNum = 0;
      currentMessageObject = NotificationsController.getInstance().popupMessages.get(0);
      updateInterfaceForCurrentMessage(0);
    } else if (startedMoving) {
      if (currentMessageNum == NotificationsController.getInstance().popupMessages.size() - 1) {
        prepareLayouts(3);
      } else if (currentMessageNum == 1) {
        prepareLayouts(4);
      }
    }
    countText.setText(
        String.format(
            "%d/%d",
            currentMessageNum + 1, NotificationsController.getInstance().popupMessages.size()));
  }
 private void setTypingAnimation(boolean start) {
   if (actionBar == null) {
     return;
   }
   if (start) {
     try {
       Integer type =
           MessagesController.getInstance()
               .printingStringsTypes
               .get(currentMessageObject.getDialogId());
       if (type == 0) {
         onlineTextView.setCompoundDrawablesWithIntrinsicBounds(
             typingDotsDrawable, null, null, null);
         onlineTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
         typingDotsDrawable.start();
         recordStatusDrawable.stop();
       } else if (type == 1) {
         onlineTextView.setCompoundDrawablesWithIntrinsicBounds(
             recordStatusDrawable, null, null, null);
         onlineTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
         recordStatusDrawable.start();
         typingDotsDrawable.stop();
       }
     } catch (Exception e) {
       FileLog.e("tmessages", e);
     }
   } else {
     onlineTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
     onlineTextView.setCompoundDrawablePadding(0);
     typingDotsDrawable.stop();
     recordStatusDrawable.stop();
   }
 }
  private void updateInterfaceForCurrentMessage(int move) {
    if (actionBar == null) {
      return;
    }
    currentChat = null;
    currentUser = null;
    long dialog_id = currentMessageObject.getDialogId();
    chatActivityEnterView.setDialogId(dialog_id);
    if ((int) dialog_id != 0) {
      int lower_id = (int) dialog_id;
      if (lower_id > 0) {
        currentUser = MessagesController.getInstance().getUser(lower_id);
      } else {
        currentChat = MessagesController.getInstance().getChat(-lower_id);
        currentUser =
            MessagesController.getInstance().getUser(currentMessageObject.messageOwner.from_id);
      }
    } else {
      TLRPC.EncryptedChat encryptedChat =
          MessagesController.getInstance().getEncryptedChat((int) (dialog_id >> 32));
      currentUser = MessagesController.getInstance().getUser(encryptedChat.user_id);
    }

    if (currentChat != null && currentUser != null) {
      nameTextView.setText(currentChat.title);
      onlineTextView.setText(
          ContactsController.formatName(currentUser.first_name, currentUser.last_name));
      nameTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
      nameTextView.setCompoundDrawablePadding(0);
    } else if (currentUser != null) {
      nameTextView.setText(
          ContactsController.formatName(currentUser.first_name, currentUser.last_name));
      if ((int) dialog_id == 0) {
        nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0);
        nameTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
      } else {
        nameTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        nameTextView.setCompoundDrawablePadding(0);
      }
    }

    prepareLayouts(move);
    updateSubtitle();
    checkAndUpdateAvatar();
    applyViewsLayoutParams(0);
  }
 private void openCurrentMessage() {
   if (currentMessageObject == null) {
     return;
   }
   Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
   long dialog_id = currentMessageObject.getDialogId();
   if ((int) dialog_id != 0) {
     int lower_id = (int) dialog_id;
     if (lower_id < 0) {
       intent.putExtra("chatId", -lower_id);
     } else {
       intent.putExtra("userId", lower_id);
     }
   } else {
     intent.putExtra("encId", (int) (dialog_id >> 32));
   }
   intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
   intent.setFlags(0x00008000);
   startActivity(intent);
   onFinish();
   finish();
 }
 private void updateSubtitle() {
   if (actionBar == null) {
     return;
   }
   if (currentChat != null || currentUser == null) {
     return;
   }
   if (currentUser.id / 1000 != 777
       && currentUser.id / 1000 != 333
       && ContactsController.getInstance().contactsDict.get(currentUser.id) == null
       && (ContactsController.getInstance().contactsDict.size() != 0
           || !ContactsController.getInstance().isLoadingContacts())) {
     if (currentUser.phone != null && currentUser.phone.length() != 0) {
       nameTextView.setText(PhoneFormat.getInstance().format("+" + currentUser.phone));
     } else {
       nameTextView.setText(
           ContactsController.formatName(currentUser.first_name, currentUser.last_name));
     }
   } else {
     nameTextView.setText(
         ContactsController.formatName(currentUser.first_name, currentUser.last_name));
   }
   CharSequence printString =
       MessagesController.getInstance().printingStrings.get(currentMessageObject.getDialogId());
   if (printString == null || printString.length() == 0) {
     lastPrintString = null;
     setTypingAnimation(false);
     TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
     if (user != null) {
       currentUser = user;
     }
     onlineTextView.setText(LocaleController.formatUserStatus(currentUser));
   } else {
     lastPrintString = printString;
     onlineTextView.setText(printString);
     setTypingAnimation(true);
   }
 }
 @Override
 public void didReceivedNotification(int id, Object... args) {
   if (id == NotificationCenter.appDidLogout) {
     onFinish();
     finish();
   } else if (id == NotificationCenter.pushMessagesUpdated) {
     getNewMessage();
   } else if (id == NotificationCenter.updateInterfaces) {
     if (currentMessageObject == null) {
       return;
     }
     int updateMask = (Integer) args[0];
     if ((updateMask & MessagesController.UPDATE_MASK_NAME) != 0
         || (updateMask & MessagesController.UPDATE_MASK_STATUS) != 0
         || (updateMask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0
         || (updateMask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0) {
       updateSubtitle();
     }
     if ((updateMask & MessagesController.UPDATE_MASK_AVATAR) != 0
         || (updateMask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0) {
       checkAndUpdateAvatar();
     }
     if ((updateMask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
       CharSequence printString =
           MessagesController.getInstance()
               .printingStrings
               .get(currentMessageObject.getDialogId());
       if (lastPrintString != null && printString == null
           || lastPrintString == null && printString != null
           || lastPrintString != null
               && printString != null
               && !lastPrintString.equals(printString)) {
         updateSubtitle();
       }
     }
   } else if (id == NotificationCenter.audioDidReset) {
     Integer mid = (Integer) args[0];
     if (messageContainer != null) {
       int count = messageContainer.getChildCount();
       for (int a = 0; a < count; a++) {
         View view = messageContainer.getChildAt(a);
         if ((Integer) view.getTag() == 3) {
           PopupAudioView cell = (PopupAudioView) view.findViewWithTag(300);
           if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
             cell.updateButtonState();
             break;
           }
         }
       }
     }
   } else if (id == NotificationCenter.audioProgressDidChanged) {
     Integer mid = (Integer) args[0];
     if (messageContainer != null) {
       int count = messageContainer.getChildCount();
       for (int a = 0; a < count; a++) {
         View view = messageContainer.getChildAt(a);
         if ((Integer) view.getTag() == 3) {
           PopupAudioView cell = (PopupAudioView) view.findViewWithTag(300);
           if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
             cell.updateProgress();
             break;
           }
         }
       }
     }
   } else if (id == NotificationCenter.emojiDidLoaded) {
     if (messageContainer != null) {
       int count = messageContainer.getChildCount();
       for (int a = 0; a < count; a++) {
         View view = messageContainer.getChildAt(a);
         if ((Integer) view.getTag() == 1) {
           TextView textView = (TextView) view.findViewWithTag(301);
           if (textView != null) {
             textView.invalidate();
           }
         }
       }
     }
   } else if (id == NotificationCenter.contactsDidLoaded) {
     updateSubtitle();
   }
 }