gt:             if (a == layout.getLineCount() - 1 || a == maxLines - 1) {
context: /*
   * This is the source code of Telegram for Android v. 1.3.x.
   * It is licensed under GNU GPL v. 2 or later.
   * You should have received a copy of the license in this archive (see LICENSE).
   *
   * Copyright Nikolai Kudashov, 2013.
   */
  
  package org.telegram.ui.Cells;
  
  import android.content.Context;
  import android.graphics.Canvas;
  import android.graphics.Paint;
  import android.graphics.Path;
  import android.graphics.drawable.Drawable;
  import android.net.Uri;
  import android.text.Layout;
  import android.text.Spannable;
  import android.text.SpannableStringBuilder;
  import android.text.StaticLayout;
  import android.text.TextPaint;
  import android.text.TextUtils;
  import android.text.style.ClickableSpan;
  import android.text.style.URLSpan;
  import android.view.MotionEvent;
  
  import org.telegram.android.AndroidUtilities;
  import org.telegram.android.ImageReceiver;
  import org.telegram.android.MediaController;
  import org.telegram.android.MessageObject;
  import org.telegram.messenger.BuildVars;
  import org.telegram.messenger.FileLoader;
  import org.telegram.messenger.FileLog;
  import org.telegram.messenger.R;
  import org.telegram.messenger.TLRPC;
  import org.telegram.ui.Components.StaticLayoutEx;
  import org.telegram.ui.Components.URLSpanNoUnderline;
  
  import java.util.Locale;
  
  public class ChatMessageCell extends ChatBaseCell {
  
  
      public interface ChatMessageCellDelegate {
          void pressedUrl(String url);
      }
  
      private int textX, textY;
      private int totalHeight = 0;
      private ClickableSpan pressedLink;
      private int linkBlockNum;
      private MyPath urlPath = new MyPath();
      private boolean linkPreviewPressed;
      private static Paint urlPaint;
  
      private int lastVisibleBlockNum = 0;
      private int firstVisibleBlockNum = 0;
      private int totalVisibleBlocksCount = 0;
  
      private ImageReceiver linkImageView;
      private boolean isSmallImage;
      private boolean drawLinkImageView;
      private boolean hasLinkPreview;
      private int linkPreviewHeight;
      private boolean isInstagram;
      private int smallImageX;
      private int descriptionY;
      private int durationWidth;
      private StaticLayout siteNameLayout;
      private StaticLayout titleLayout;
      private StaticLayout descriptionLayout;
      private StaticLayout durationLayout;
      private StaticLayout authorLayout;
      private static TextPaint durationPaint;
      private TLRPC.PhotoSize currentPhotoObject;
      private TLRPC.PhotoSize currentPhotoObjectThumb;
      private boolean imageCleared;
      protected ChatMessageCellDelegate mDelegate;
  
      private static Drawable igvideoDrawable;
  
      private class MyPath extends Path {
  
          private StaticLayout currentLayout;
          private int currentLine;
          private float lastTop = -1;
  
          public void setCurrentLayout(StaticLayout layout, int start) {
              currentLayout = layout;
              currentLine = layout.getLineForOffset(start);
              lastTop = -1;
          }
  
          @Override
          public void addRect(float left, float top, float right, float bottom, Direction dir) {
              if (lastTop == -1) {
                  lastTop = top;
              } else if (lastTop != top) {
                  lastTop = top;
                  currentLine++;
              }
              float lineRight = currentLayout.getLineRight(currentLine);
              float lineLeft = currentLayout.getLineLeft(currentLine);
              if (left >= lineRight) {
                  return;
              }
              if (right > lineRight) {
                  right = lineRight;
              }
              if (left < lineLeft) {
                  left = lineLeft;
              }
              super.addRect(left, top, right, bottom, dir);
          }
      }
  
      public ChatMessageCell(Context context) {
          super(context);
          drawForwardedName = true;
          linkImageView = new ImageReceiver(this);
          if (urlPaint == null) {
              urlPaint = new Paint();
              urlPaint.setColor(0x33316f9f);
          }
      }
  
      public void setDelegate(ChatMessageCellDelegate delegate) {
          this.mDelegate = delegate;
      }
  
      private void resetPressedLink() {
          if (pressedLink != null) {
              pressedLink = null;
          }
          linkPreviewPressed = false;
          invalidate();
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
          boolean result = false;
          if (currentMessageObject != null && currentMessageObject.textLayoutBlocks != null && !currentMessageObject.textLayoutBlocks.isEmpty() && currentMessageObject.messageText instanceof Spannable && !isPressed) {
              if (event.getAction() == MotionEvent.ACTION_DOWN || (linkPreviewPressed || pressedLink != null) && event.getAction() == MotionEvent.ACTION_UP) {
                  int x = (int)event.getX();
                  int y = (int)event.getY();
                  if (x >= textX && y >= textY && x <= textX + currentMessageObject.textWidth && y <= textY + currentMessageObject.textHeight) {
                      y -= textY;
                      int blockNum = Math.max(0, y / currentMessageObject.blockHeight);
                      if (blockNum < currentMessageObject.textLayoutBlocks.size()) {
                          try {
                              MessageObject.TextLayoutBlock block = currentMessageObject.textLayoutBlocks.get(blockNum);
                              x -= textX - (int)Math.ceil(block.textXOffset);
                              y -= block.textYOffset;
                              final int line = block.textLayout.getLineForVertical(y);
                              final int off = block.textLayout.getOffsetForHorizontal(line, x) + block.charactersOffset;
  
                              final float left = block.textLayout.getLineLeft(line);
                              if (left <= x && left + block.textLayout.getLineWidth(line) >= x) {
                                  Spannable buffer = (Spannable)currentMessageObject.messageText;
                                  ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
                                  if (link.length != 0) {
                                      if (event.getAction() == MotionEvent.ACTION_DOWN) {
                                          resetPressedLink();
                                          pressedLink = link[0];
                                          linkBlockNum = blockNum;
                                          try {
                                              int start = buffer.getSpanStart(pressedLink) - block.charactersOffset;
                                              urlPath.setCurrentLayout(block.textLayout, start);
                                              block.textLayout.getSelectionPath(start, buffer.getSpanEnd(pressedLink) - block.charactersOffset, urlPath);
                                          } catch (Exception e) {
                                              FileLog.e("tmessages", e);
                                          }
                                          result = true;
                                      } else {
                                          if (link[0] == pressedLink) {
                                              try {
                                                  if (pressedLink instanceof URLSpanNoUnderline) {
                                                      String url = ((URLSpanNoUnderline) pressedLink).getURL();
                                                      if (url.startsWith("@") || url.startsWith("#")) {
                                                          if (delegate != null) {
                                                              delegate.didPressUrl(url);
                                                          }
                                                      }
                                                  } else {
                                                      FileLog.d(BuildVars.TAG, "pressedLink onclick 1");
  //                                                    pressedLink.onClick(this);
                                                      if (mDelegate != null)
                                                          mDelegate.pressedUrl(((URLSpan)pressedLink).getURL());
                                                  }
                                              } catch (Exception e) {
                                                  FileLog.e("tmessages", e);
                                              }
                                              resetPressedLink();
                                              result = true;
                                          }
                                      }
                                  } else {
                                      resetPressedLink();
                                  }
                              } else {
                                  resetPressedLink();
                              }
                          } catch (Exception e) {
                              resetPressedLink();
                              FileLog.e("tmessages", e);
                          }
                      } else {
                          resetPressedLink();
                      }
                  } else if (hasLinkPreview && x >= textX && x <= textX + backgroundWidth && y >= textY + currentMessageObject.textHeight && y <= textY + currentMessageObject.textHeight + linkPreviewHeight + AndroidUtilities.dp(8)) {
                      if (event.getAction() == MotionEvent.ACTION_DOWN) {
                          resetPressedLink();
                          if (drawLinkImageView && linkImageView.isInsideImage(x, y)) {
                              linkPreviewPressed = true;
                              result = true;
                          } else {
                              if (descriptionLayout != null && y >= descriptionY) {
                                  try {
                                      x -= textX + AndroidUtilities.dp(10);
                                      y -= descriptionY;
                                      final int line = descriptionLayout.getLineForVertical(y);
                                      final int off = descriptionLayout.getOffsetForHorizontal(line, x);
  
                                      final float left = descriptionLayout.getLineLeft(line);
                                      if (left <= x && left + descriptionLayout.getLineWidth(line) >= x) {
                                          Spannable buffer = (Spannable) currentMessageObject.linkDescription;
                                          ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
                                          if (link.length != 0) {
                                              resetPressedLink();
                                              pressedLink = link[0];
                                              linkPreviewPressed = true;
                                              linkBlockNum = -10;
                                              result = true;
                                              try {
                                                  int start = buffer.getSpanStart(pressedLink);
                                                  urlPath.setCurrentLayout(descriptionLayout, start);
                                                  descriptionLayout.getSelectionPath(start, buffer.getSpanEnd(pressedLink), urlPath);
                                              } catch (Exception e) {
                                                  FileLog.e("tmessages", e);
                                              }
                                          } else {
                                              resetPressedLink();
                                          }
                                      } else {
                                          resetPressedLink();
                                      }
                                  } catch (Exception e) {
                                      resetPressedLink();
                                      FileLog.e("tmessages", e);
                                  }
                              }
                          }
                      } else if (linkPreviewPressed) {
                          try {
                              if (pressedLink != null) {
                                  FileLog.d(BuildVars.TAG, "pressedLink onclick 2");
  //                                pressedLink.onClick(this);
                                  if (mDelegate != null)
                                      mDelegate.pressedUrl(((URLSpan)pressedLink).getURL());
                              } else {
                                  Uri uri = Uri.parse(currentMessageObject.messageOwner.media.webpage.url);
                                  if (mDelegate != null)
                                      mDelegate.pressedUrl(uri.toString());
  //                                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
  //                                intent.putExtra(Browser.EXTRA_APPLICATION_ID, getContext().getPackageName());
                                  FileLog.d(BuildVars.TAG, "linkPreviewPressed onclick 1 uri : "+uri);
  //                                getContext().startActivity(intent);
                              }
                          } catch (Exception e) {
                              FileLog.e("tmessages", e);
                          }
                          resetPressedLink();
                          result = true;
                      }
                  } else {
                      resetPressedLink();
                  }
              } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
                  resetPressedLink();
              }
          } else {
              resetPressedLink();
          }
          if (result && event.getAction() == MotionEvent.ACTION_DOWN) {
              startCheckLongPress();
          }
          if (event.getAction() != MotionEvent.ACTION_DOWN && event.getAction() != MotionEvent.ACTION_MOVE) {
              cancelCheckLongPress();
          }
          return result || super.onTouchEvent(event);
      }
  
      public void setVisiblePart(int position, int height) {
          if (currentMessageObject == null || currentMessageObject.textLayoutBlocks == null) {
              return;
          }
          int newFirst = -1, newLast = -1, newCount = 0;
  
          for (int a = Math.max(0, (position - textY) / currentMessageObject.blockHeight); a < currentMessageObject.textLayoutBlocks.size(); a++) {
              MessageObject.TextLayoutBlock block = currentMessageObject.textLayoutBlocks.get(a);
              float y = textY + block.textYOffset;
              if (intersect(y, y + currentMessageObject.blockHeight, position, position + height)) {
                  if (newFirst == -1) {
                      newFirst = a;
                  }
                  newLast = a;
                  newCount++;
              } else if (y > position) {
                  break;
              }
          }
  
          if (lastVisibleBlockNum != newLast || firstVisibleBlockNum != newFirst || totalVisibleBlocksCount != newCount) {
              lastVisibleBlockNum = newLast;
              firstVisibleBlockNum = newFirst;
              totalVisibleBlocksCount = newCount;
              invalidate();
          }
      }
  
      private boolean intersect(float left1, float right1, float left2, float right2) {
          if (left1 <= left2) {
              return right1 >= left2;
          }
          return left1 <= right2;
      }
  
      private StaticLayout generateStaticLayout(CharSequence text, TextPaint paint, int maxWidth, int smallWidth, int linesCount, int maxLines) {
          SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
          int addedChars = 0;
          StaticLayout layout = new StaticLayout(text, paint, smallWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
          for (int a = 0; a < linesCount; a++) {
              int pos = layout.getLineEnd(a);
              if (pos == text.length()) {
                  break;
              }
              pos--;
              if (stringBuilder.charAt(pos + addedChars) == ' ') {
                  stringBuilder.replace(pos + addedChars, pos + addedChars + 1, "\n");
              } else {
                  stringBuilder.insert(pos + addedChars, "\n");
                  addedChars++;
              }
  