gt:                 if (actionBar.isActionModeShowed()) {
context: /*
   * This is the source code of Telegram for Android v. 5.x.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-2018.
   */
  
  package org.telegram.ui;
  
  import android.Manifest;
  import android.animation.Animator;
  import android.animation.AnimatorListenerAdapter;
  import android.animation.AnimatorSet;
  import android.animation.ObjectAnimator;
  import android.animation.StateListAnimator;
  import android.animation.ValueAnimator;
  import android.annotation.SuppressLint;
  import android.annotation.TargetApi;
  import android.app.Activity;
  import android.app.Dialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.content.pm.PackageManager;
  import android.content.res.Configuration;
  import android.graphics.Canvas;
  import android.graphics.Outline;
  import android.graphics.Paint;
  import android.graphics.PorterDuff;
  import android.graphics.PorterDuffColorFilter;
  import android.graphics.Rect;
  import android.graphics.RectF;
  import android.graphics.drawable.Drawable;
  import android.net.Uri;
  import android.os.Build;
  import android.os.Bundle;
  import android.os.Vibrator;
  
  import androidx.annotation.NonNull;
  import androidx.recyclerview.widget.ItemTouchHelper;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.LinearSmoothScrollerCustom;
  import androidx.recyclerview.widget.RecyclerView;
  import androidx.viewpager.widget.ViewPager;
  
  import android.text.TextUtils;
  import android.util.Property;
  import android.util.StateSet;
  import android.view.Gravity;
  import android.view.HapticFeedbackConstants;
  import android.view.KeyEvent;
  import android.view.MotionEvent;
  import android.view.VelocityTracker;
  import android.view.View;
  import android.view.ViewConfiguration;
  import android.view.ViewGroup;
  import android.view.ViewOutlineProvider;
  import android.view.ViewTreeObserver;
  import android.view.WindowManager;
  import android.view.animation.AccelerateDecelerateInterpolator;
  import android.view.animation.DecelerateInterpolator;
  import android.view.animation.Interpolator;
  import android.widget.EditText;
  import android.widget.FrameLayout;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import android.widget.ScrollView;
  import android.widget.TextView;
  
  import org.telegram.messenger.AccountInstance;
  import org.telegram.messenger.AndroidUtilities;
  import org.telegram.messenger.ApplicationLoader;
  import org.telegram.messenger.BuildVars;
  import org.telegram.messenger.ChatObject;
  import org.telegram.messenger.MediaDataController;
  import org.telegram.messenger.DialogObject;
  import org.telegram.messenger.ImageLoader;
  import org.telegram.messenger.ImageLocation;
  import org.telegram.messenger.LocaleController;
  import org.telegram.messenger.MessageObject;
  import org.telegram.messenger.NotificationsController;
  import org.telegram.messenger.SharedConfig;
  import org.telegram.messenger.UserObject;
  import org.telegram.messenger.Utilities;
  import org.telegram.messenger.XiaomiUtilities;
  import org.telegram.messenger.FileLog;
  import org.telegram.tgnet.ConnectionsManager;
  import org.telegram.tgnet.TLObject;
  import org.telegram.tgnet.TLRPC;
  import org.telegram.messenger.ContactsController;
  import org.telegram.messenger.MessagesController;
  import org.telegram.messenger.NotificationCenter;
  import org.telegram.messenger.R;
  import org.telegram.messenger.UserConfig;
  import org.telegram.ui.ActionBar.ActionBarMenuSubItem;
  import org.telegram.ui.ActionBar.ActionBarPopupWindow;
  import org.telegram.ui.ActionBar.AlertDialog;
  import org.telegram.ui.ActionBar.BackDrawable;
  import org.telegram.ui.ActionBar.BottomSheet;
  import org.telegram.ui.ActionBar.ThemeDescription;
  import org.telegram.ui.Adapters.DialogsAdapter;
  import org.telegram.ui.Adapters.DialogsSearchAdapter;
  import org.telegram.ui.Cells.AccountSelectCell;
  import org.telegram.ui.Cells.ArchiveHintInnerCell;
  import org.telegram.ui.Cells.DialogsEmptyCell;
  import org.telegram.ui.Cells.DividerCell;
  import org.telegram.ui.Cells.DrawerActionCell;
  import org.telegram.ui.Cells.DrawerAddCell;
  import org.telegram.ui.Cells.DrawerProfileCell;
  import org.telegram.ui.Cells.DrawerUserCell;
  import org.telegram.ui.Cells.GraySectionCell;
  import org.telegram.ui.Cells.HashtagSearchCell;
  import org.telegram.ui.Cells.HintDialogCell;
  import org.telegram.ui.Cells.LoadingCell;
  import org.telegram.ui.Cells.ProfileSearchCell;
  import org.telegram.ui.Cells.ShadowSectionCell;
  import org.telegram.ui.Cells.TextCell;
  import org.telegram.ui.Cells.UserCell;
  import org.telegram.ui.Cells.DialogCell;
  import org.telegram.ui.ActionBar.ActionBar;
  import org.telegram.ui.ActionBar.ActionBarMenu;
  import org.telegram.ui.ActionBar.ActionBarMenuItem;
  import org.telegram.ui.ActionBar.BaseFragment;
  import org.telegram.ui.ActionBar.MenuDrawable;
  import org.telegram.ui.Components.AlertsCreator;
  import org.telegram.ui.Components.AnimatedArrowDrawable;
  import org.telegram.ui.Components.AnimationProperties;
  import org.telegram.ui.Components.FilterTabsView;
  import org.telegram.ui.Components.PullForegroundDrawable;
  import org.telegram.ui.Components.AvatarDrawable;
  import org.telegram.ui.Components.BackupImageView;
  import org.telegram.ui.Components.ChatActivityEnterView;
  import org.telegram.ui.Components.CombinedDrawable;
  import org.telegram.ui.Components.CubicBezierInterpolator;
  import org.telegram.ui.Components.DialogsItemAnimator;
  import org.telegram.ui.Components.FragmentContextView;
  import org.telegram.ui.Components.EmptyTextProgressView;
  import org.telegram.ui.Components.JoinGroupAlert;
  import org.telegram.ui.Components.LayoutHelper;
  import org.telegram.ui.Components.NumberTextView;
  import org.telegram.ui.Components.PacmanAnimation;
  import org.telegram.ui.Components.ProxyDrawable;
  import org.telegram.ui.Components.RLottieDrawable;
  import org.telegram.ui.Components.RadialProgressView;
  import org.telegram.ui.Components.RecyclerAnimationScrollHelper;
  import org.telegram.ui.Components.RecyclerListView;
  import org.telegram.ui.ActionBar.Theme;
  import org.telegram.ui.Components.SizeNotifierFrameLayout;
  import org.telegram.ui.Components.StickersAlert;
  import org.telegram.ui.Components.UndoView;
  
  import java.util.ArrayList;
  
  public class DialogsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
  
      private class ViewPage extends FrameLayout {
          private DialogsRecyclerView listView;
          private LinearLayoutManager layoutManager;
          private DialogsAdapter dialogsAdapter;
          private ItemTouchHelper itemTouchhelper;
          private SwipeController swipeController;
          private int selectedType;
          private PullForegroundDrawable pullForegroundDrawable;
          private RecyclerAnimationScrollHelper scrollHelper;
          private int dialogsType;
          private int archivePullViewState;
          private RadialProgressView progressView;
          private int lastItemsCount;
  
          public ViewPage(Context context) {
              super(context);
          }
  
          public boolean isDefaultDialogType() {
              return dialogsType == 0 || dialogsType == 7 || dialogsType == 8;
          }
      }
  
      private ViewPage[] viewPages;
      private RecyclerListView searchListView;
      private LinearLayoutManager searchlayoutManager;
      private DialogsSearchAdapter dialogsSearchAdapter;
      private EmptyTextProgressView searchEmptyView;
      private ActionBarMenuItem passcodeItem;
      private boolean passcodeItemVisible;
      private ActionBarMenuItem proxyItem;
      private boolean proxyItemVisible;
      private ActionBarMenuItem searchItem;
      private ActionBarMenuItem doneItem;
      private ProxyDrawable proxyDrawable;
      private ImageView floatingButton;
      private FrameLayout floatingButtonContainer;
      private UndoView[] undoView = new UndoView[2];
      private FilterTabsView filterTabsView;
      private boolean askingForPermissions;
  
      private Paint scrimPaint;
      private View scrimView;
      private boolean scrimViewSelected;
      private int[] scrimViewLocation = new int[2];
      private AnimatorSet scrimAnimatorSet;
      private ActionBarPopupWindow scrimPopupWindow;
      private ActionBarMenuSubItem[] scrimPopupWindowItems;
  
      private int initialDialogsType;
  
      private int messagesCount;
      private int hasPoll;
  
      private PacmanAnimation pacmanAnimation;
  
      private DialogCell slidingView;
      private DialogCell movingView;
      private boolean allowMoving;
      private boolean movingWas;
      private ArrayList<MessagesController.DialogFilter> movingDialogFilters = new ArrayList<>();
      private boolean waitingForScrollFinished;
      private boolean allowSwipeDuringCurrentTouch;
      private boolean updatePullAfterScroll;
  
      private MenuDrawable menuDrawable;
      private BackDrawable backDrawable;
  
      private NumberTextView selectedDialogsCountTextView;
      private ArrayList<View> actionModeViews = new ArrayList<>();
      private ActionBarMenuItem deleteItem;
      private ActionBarMenuItem pinItem;
      private ActionBarMenuItem muteItem;
      private ActionBarMenuItem archive2Item;
      private ActionBarMenuSubItem pin2Item;
      private ActionBarMenuSubItem archiveItem;
      private ActionBarMenuSubItem clearItem;
      private ActionBarMenuSubItem readItem;
      private ActionBarMenuSubItem blockItem;
  
      private float additionalFloatingTranslation;
      private float floatingButtonTranslation;
      private float floatingButtonHideProgress;
  
      private AnimatorSet searchAnimator;
      private Animator tabsAlphaAnimator;
      private boolean lastSearchScrolledToTop;
  
      private AnimatedArrowDrawable arrowDrawable;
      private RecyclerView sideMenu;
      private ChatActivityEnterView commentView;
      private ActionBarMenuItem switchItem;
  
      private FragmentContextView fragmentLocationContextView;
      private FragmentContextView fragmentContextView;
  
      private static ArrayList<TLRPC.Dialog> frozenDialogsList;
      private boolean dialogsListFrozen;
      private int dialogRemoveFinished;
      private int dialogInsertFinished;
      private int dialogChangeFinished;
      private DialogsItemAnimator dialogsItemAnimator;
  
      private AlertDialog permissionDialog;
      private boolean askAboutContacts = true;
  
      private boolean closeSearchFieldOnHide;
      private long searchDialogId;
      private TLObject searchObject;
  
      private int prevPosition;
      private int prevTop;
      private boolean scrollUpdated;
      private boolean floatingHidden;
      private final AccelerateDecelerateInterpolator floatingInterpolator = new AccelerateDecelerateInterpolator();
  
      private boolean checkPermission = true;
  
      private int currentConnectionState;
  
      private boolean disableActionBarScrolling;
  
      private String selectAlertString;
      private String selectAlertStringGroup;
      private String addToGroupAlertString;
      private boolean resetDelegate = true;
  
      public static boolean[] dialogsLoaded = new boolean[UserConfig.MAX_ACCOUNT_COUNT];
      private boolean searching;
      private boolean searchWas;
      private boolean onlySelect;
      private String searchString;
      private long openedDialogId;
      private boolean cantSendToChannels;
      private boolean allowSwitchAccount;
      private boolean checkCanWrite;
      private boolean afterSignup;
  
      private DialogsActivityDelegate delegate;
  
      private ArrayList<Long> selectedDialogs = new ArrayList<>();
  
      private int canReadCount;
      private int canPinCount;
      private int canMuteCount;
      private int canUnmuteCount;
      private int canClearCacheCount;
      private int canReportSpamCount;
      private int canUnarchiveCount;
  
      private int topPadding;
      
      private int folderId;
  
      private final static int pin = 100;
      private final static int read = 101;
      private final static int delete = 102;
      private final static int clear = 103;
      private final static int mute = 104;
      private final static int archive = 105;
      private final static int block = 106;
      private final static int archive2 = 107;
      private final static int pin2 = 108;
  
      private final static int ARCHIVE_ITEM_STATE_PINNED = 0;
      private final static int ARCHIVE_ITEM_STATE_SHOWED = 1;
      private final static int ARCHIVE_ITEM_STATE_HIDDEN = 2;
  
      private long startArchivePullingTime;
      private boolean scrollingManually;
      private boolean canShowHiddenArchive;
  
      private AnimatorSet tabsAnimation;
      private boolean tabsAnimationInProgress;
      private boolean animatingForward;
      private float additionalOffset;
      private boolean backAnimation;
      private int maximumVelocity;
      private boolean startedTracking;
      private boolean maybeStartTracking;
      private static final Interpolator interpolator = t -> {
          --t;
          return t * t * t * t * t + 1.0F;
      };
  
      public final Property<DialogsActivity, Float> SCROLL_Y = new AnimationProperties.FloatProperty<DialogsActivity>("animationValue") {
          @Override
          public void setValue(DialogsActivity object, float value) {
              object.setScrollY(value);
          }
  
          @Override
          public Float get(DialogsActivity object) {
              return actionBar.getTranslationY();
          }
      };
  
      private class ContentView extends SizeNotifierFrameLayout {
  
          private int inputFieldHeight;
  
          public ContentView(Context context) {
              super(context, SharedConfig.smoothKeyboard);
          }
  
          private int startedTrackingPointerId;
          private int startedTrackingX;
          private int startedTrackingY;
          private VelocityTracker velocityTracker;
          private boolean globalIgnoreLayout;
          private int[] pos = new int[2];
  
          private boolean prepareForMoving(MotionEvent ev, boolean forward) {
              int id = filterTabsView.getNextPageId(forward);
              if (id < 0) {
                  return false;
              }
              getParent().requestDisallowInterceptTouchEvent(true);
              maybeStartTracking = false;
              startedTracking = true;
              startedTrackingX = (int) (ev.getX() + additionalOffset);
              actionBar.setEnabled(false);
              filterTabsView.setEnabled(false);
              viewPages[1].selectedType = id;
              viewPages[1].setVisibility(View.VISIBLE);
              animatingForward = forward;
              showScrollbars(false);
              switchToCurrentSelectedMode(true);
              if (forward) {
                  viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth());
              } else {
                  viewPages[1].setTranslationX(-viewPages[0].getMeasuredWidth());
              }
              return true;
          }
  
          @Override
          public void setPadding(int left, int top, int right, int bottom) {
              topPadding = top;
              if (fragmentContextView != null) {
                  fragmentContextView.setTranslationY(top + (filterTabsView != null ? filterTabsView.getTranslationY() : 0));
              }
              if (fragmentLocationContextView != null) {
                  fragmentLocationContextView.setTranslationY(top + (filterTabsView != null ? filterTabsView.getTranslationY() : 0));
              }
              requestLayout();
          }
  
          public boolean checkTabsAnimationInProgress() {
              if (tabsAnimationInProgress) {
                  boolean cancel = false;
                  if (backAnimation) {
                      if (Math.abs(viewPages[0].getTranslationX()) < 1) {
                          viewPages[0].setTranslationX(0);
                          viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? 1 : -1));
                          cancel = true;
                      }
                  } else if (Math.abs(viewPages[1].getTranslationX()) < 1) {
                      viewPages[0].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? -1 : 1));
                      viewPages[1].setTranslationX(0);
                      cancel = true;
                  }
                  if (cancel) {
                      showScrollbars(true);
                      if (tabsAnimation != null) {
                          tabsAnimation.cancel();
                          tabsAnimation = null;
                      }
                      tabsAnimationInProgress = false;
                  }
                  return tabsAnimationInProgress;
              }
              return false;
          }
  
          @Override
          protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
              boolean result = super.drawChild(canvas, child, drawingTime);
              if (child == actionBar && parentLayout != null) {
                  int h = actionBar.getMeasuredHeight();
                  if (filterTabsView != null && filterTabsView.getVisibility() != GONE) {
                      h += filterTabsView.getMeasuredHeight() + filterTabsView.getTranslationY();
                  }
                  parentLayout.drawHeaderShadow(canvas, h);
              }
              return result;
          }
  
          @Override
          protected void dispatchDraw(Canvas canvas) {
              super.dispatchDraw(canvas);
              if (scrimView != null) {
                  canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), scrimPaint);
                  canvas.save();
                  getLocationInWindow(pos);
                  canvas.translate(scrimViewLocation[0] - pos[0], scrimViewLocation[1] - (Build.VERSION.SDK_INT < 21 ? AndroidUtilities.statusBarHeight : 0));
                  scrimView.draw(canvas);
                  if (scrimViewSelected) {
                      Drawable drawable = filterTabsView.getSelectorDrawable();
                      canvas.translate(-scrimViewLocation[0], -drawable.getIntrinsicHeight() - 1);
                      drawable.draw(canvas);
                  }
                  canvas.restore();
              }
          }
  
          @Override
          protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
              int widthSize = View.MeasureSpec.getSize(widthMeasureSpec);
              int heightSize = View.MeasureSpec.getSize(heightMeasureSpec);
  
              setMeasuredDimension(widthSize, heightSize);
              heightSize -= getPaddingTop();
  
              if (doneItem != null) {
                  LayoutParams layoutParams = (LayoutParams) doneItem.getLayoutParams();
                  layoutParams.topMargin = actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0;
                  layoutParams.height = ActionBar.getCurrentActionBarHeight();
              }
  
              measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
  
              int keyboardSize = SharedConfig.smoothKeyboard ? 0 : getKeyboardHeight();
              int childCount = getChildCount();
  
              if (commentView != null) {
                  measureChildWithMargins(commentView, widthMeasureSpec, 0, heightMeasureSpec, 0);
                  Object tag = commentView.getTag();
                  if (tag != null && tag.equals(2)) {
                      if (keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow) {
                          heightSize -= commentView.getEmojiPadding();
                      }
                      inputFieldHeight = commentView.getMeasuredHeight();
                  } else {
                      inputFieldHeight = 0;
                  }
  
                  if (SharedConfig.smoothKeyboard && commentView.isPopupShowing()) {
                      fragmentView.setTranslationY(getCurrentPanTranslationY());
                      for (int a = 0; a < viewPages.length; a++) {
                          if (viewPages[a] != null) {
                              viewPages[a].setTranslationY(0);
                          }
                      }
                      if (!onlySelect) {
                          actionBar.setTranslationY(0);
                      }
                      searchListView.setTranslationY(0);
                  }
              }
  
              for (int i = 0; i < childCount; i++) {
                  View child = getChildAt(i);
                  if (child == null || child.getVisibility() == GONE || child == commentView || child == actionBar) {
                      continue;
                  }
                  if (child instanceof ViewPage) {
                      int contentWidthSpec = View.MeasureSpec.makeMeasureSpec(widthSize, View.MeasureSpec.EXACTLY);
                      int h;
                      if (filterTabsView != null && filterTabsView.getVisibility() == VISIBLE) {
                          h = heightSize - inputFieldHeight + AndroidUtilities.dp(2) - AndroidUtilities.dp(44) - topPadding;
                      } else {
                          h = heightSize - inputFieldHeight + AndroidUtilities.dp(2) - (onlySelect ? 0 : actionBar.getMeasuredHeight()) - topPadding;
                      }
                      child.measure(contentWidthSpec, View.MeasureSpec.makeMeasureSpec(Math.max(AndroidUtilities.dp(10), h), View.MeasureSpec.EXACTLY));
                      child.setPivotX(child.getMeasuredWidth() / 2);
                  } else if (child == searchListView || child == searchEmptyView) {
                      int contentWidthSpec = View.MeasureSpec.makeMeasureSpec(widthSize, View.MeasureSpec.EXACTLY);
                      int contentHeightSpec = View.MeasureSpec.makeMeasureSpec(Math.max(AndroidUtilities.dp(10), heightSize - inputFieldHeight + AndroidUtilities.dp(2) - (onlySelect ? 0 : actionBar.getMeasuredHeight()) - topPadding), View.MeasureSpec.EXACTLY);
                      child.measure(contentWidthSpec, contentHeightSpec);
                      child.setPivotX(child.getMeasuredWidth() / 2);
                  } else if (commentView != null && commentView.isPopupView(child)) {
                      if (AndroidUtilities.isInMultiwindow) {
                          if (AndroidUtilities.isTablet()) {
                              child.measure(View.MeasureSpec.makeMeasureSpec(widthSize, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(320), heightSize - inputFieldHeight - AndroidUtilities.statusBarHeight + getPaddingTop()), View.MeasureSpec.EXACTLY));
                          } else {
                              child.measure(View.MeasureSpec.makeMeasureSpec(widthSize, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(heightSize - inputFieldHeight - AndroidUtilities.statusBarHeight + getPaddingTop(), View.MeasureSpec.EXACTLY));
                          }
                      } else {
                          child.measure(View.MeasureSpec.makeMeasureSpec(widthSize, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, View.MeasureSpec.EXACTLY));
                      }
                  } else {
                      measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
                  }
              }
          }
  
          @Override
          protected void onLayout(boolean changed, int l, int t, int r, int b) {
              final int count = getChildCount();
  
              int paddingBottom;
              Object tag = commentView != null ? commentView.getTag() : null;
              int keyboardSize = SharedConfig.smoothKeyboard ? 0 : getKeyboardHeight();
              if (tag != null && tag.equals(2)) {
                  paddingBottom = keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow ? commentView.getEmojiPadding() : 0;
              } else {
                  paddingBottom = 0;
              }
              setBottomClip(paddingBottom);
  
              for (int i = 0; i < count; i++) {
                  final View child = getChildAt(i);
                  if (child.getVisibility() == GONE) {
                      continue;
                  }
                  final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) child.getLayoutParams();
  
                  final int width = child.getMeasuredWidth();
                  final int height = child.getMeasuredHeight();
  
                  int childLeft;
                  int childTop;
  
                  int gravity = lp.gravity;
                  if (gravity == -1) {
                      gravity = Gravity.TOP | Gravity.LEFT;
                  }
  
                  final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                  final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
  
                  switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                      case Gravity.CENTER_HORIZONTAL:
                          childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
                          break;
                      case Gravity.RIGHT:
                          childLeft = r - width - lp.rightMargin;
                          break;
                      case Gravity.LEFT:
                      default:
                          childLeft = lp.leftMargin;
                  }
  
                  switch (verticalGravity) {
                      case Gravity.TOP:
                          childTop = lp.topMargin + getPaddingTop();
                          break;
                      case Gravity.CENTER_VERTICAL:
                          childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
                          break;
                      case Gravity.BOTTOM:
                          childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
                          break;
                      default:
                          childTop = lp.topMargin;
                  }
  
                  if (commentView != null && commentView.isPopupView(child)) {
                      if (AndroidUtilities.isInMultiwindow) {
                          childTop = commentView.getTop() - child.getMeasuredHeight() + AndroidUtilities.dp(1);
                      } else {
                          childTop = commentView.getBottom();
                      }
                  } else if (child == filterTabsView) {
                      childTop = actionBar.getMeasuredHeight();
                  } else if (child == searchListView || child == searchEmptyView) {
                      childTop = (onlySelect ? 0 : actionBar.getMeasuredHeight()) + topPadding;
                  } else if (child instanceof ViewPage) {
                      if (!onlySelect) {
                          if (filterTabsView != null && filterTabsView.getVisibility() == VISIBLE) {
                              childTop = AndroidUtilities.dp(44);
                          } else {
                              childTop = actionBar.getMeasuredHeight();
                          }
                      }
                      childTop += topPadding;
                  } else if (child instanceof FragmentContextView) {
                      childTop += actionBar.getMeasuredHeight();
                      if (filterTabsView != null && filterTabsView.getVisibility() == VISIBLE) {
                          childTop += filterTabsView.getMeasuredHeight();
                      }
                  }
                  child.layout(childLeft, childTop, childLeft + width, childTop + height);
              }
  
              notifyHeightChanged();
          }
  
          @Override
          public boolean onInterceptTouchEvent(MotionEvent ev) {
              int action = ev.getActionMasked();
              if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
                  if (actionBar.isActionModeShowed()) {
                      allowMoving = true;
                  }
              }
              return checkTabsAnimationInProgress() || filterTabsView != null && filterTabsView.isAnimatingIndicator() || onTouchEvent(ev);
          }
  
          @Override
          public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
              if (maybeStartTracking && !startedTracking) {
                  onTouchEvent(null);
              }
              super.requestDisallowInterceptTouchEvent(disallowIntercept);
          }
  
          @Override
          public boolean onTouchEvent(MotionEvent ev) {
              if (filterTabsView != null  && !filterTabsView.isEditing() && !searching &&
                      !parentLayout.checkTransitionAnimation() && !parentLayout.isInPreviewMode() && !parentLayout.isPreviewOpenAnimationInProgress() && !parentLayout.getDrawerLayoutContainer().isDrawerOpened() &&
                      (ev == null || startedTracking || ev.getY() > actionBar.getMeasuredHeight() + actionBar.getTranslationY())) {
                  if (ev != null) {
                      if (velocityTracker == null) {
                          velocityTracker = VelocityTracker.obtain();
                      }
                      velocityTracker.addMovement(ev);
                  }
                  if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && checkTabsAnimationInProgress()) {
                      startedTracking = true;
                      startedTrackingPointerId = ev.getPointerId(0);
                      startedTrackingX = (int) ev.getX();
                      parentLayout.getDrawerLayoutContainer().setAllowOpenDrawerBySwipe(false);
                      if (animatingForward) {
                          if (startedTrackingX < viewPages[0].getMeasuredWidth() + viewPages[0].getTranslationX()) {
                              additionalOffset = viewPages[0].getTranslationX();
                          } else {
                              ViewPage page = viewPages[0];
                              viewPages[0] = viewPages[1];
                              viewPages[1] = page;
                              animatingForward = false;
                              additionalOffset = viewPages[0].getTranslationX();
                              filterTabsView.selectTabWithId(viewPages[0].selectedType, 1f);
                              filterTabsView.selectTabWithId(viewPages[1].selectedType, additionalOffset / viewPages[0].getMeasuredWidth());
                              switchToCurrentSelectedMode(true);
                          }
                      } else {
                          if (startedTrackingX < viewPages[1].getMeasuredWidth() + viewPages[1].getTranslationX()) {
                              ViewPage page = viewPages[0];
                              viewPages[0] = viewPages[1];
                              viewPages[1] = page;
                              animatingForward = true;
                              additionalOffset = viewPages[0].getTranslationX();
                              filterTabsView.selectTabWithId(viewPages[0].selectedType, 1f);
                              filterTabsView.selectTabWithId(viewPages[1].selectedType, -additionalOffset / viewPages[0].getMeasuredWidth());
                              switchToCurrentSelectedMode(true);
                          } else {
                              additionalOffset = viewPages[0].getTranslationX();
                          }
                      }
                      tabsAnimation.removeAllListeners();
                      tabsAnimation.cancel();
                      tabsAnimationInProgress = false;
                  } else if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN) {
                      additionalOffset = 0;
                  }
                  if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking && filterTabsView.getVisibility() == VISIBLE) {
                      startedTrackingPointerId = ev.getPointerId(0);
                      maybeStartTracking = true;
                      startedTrackingX = (int) ev.getX();
                      startedTrackingY = (int) ev.getY();
                      velocityTracker.clear();
                  } else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
                      int dx = (int) (ev.getX() - startedTrackingX + additionalOffset);
                      int dy = Math.abs((int) ev.getY() - startedTrackingY);
                      if (startedTracking && (animatingForward && dx > 0 || !animatingForward && dx < 0)) {
                          if (!prepareForMoving(ev, dx < 0)) {
                              maybeStartTracking = true;
                              startedTracking = false;
                              viewPages[0].setTranslationX(0);
                              viewPages[1].setTranslationX(animatingForward ? viewPages[0].getMeasuredWidth() : -viewPages[0].getMeasuredWidth());
                              filterTabsView.selectTabWithId(viewPages[1].selectedType, 0);
                          }
                      }
                      if (maybeStartTracking && !startedTracking) {
                          float touchSlop = AndroidUtilities.getPixelsInCM(0.3f, true);
                          int dxLocal = (int) (ev.getX() - startedTrackingX);
                          if (Math.abs(dxLocal) >= touchSlop && Math.abs(dxLocal) > dy) {
                              prepareForMoving(ev, dx < 0);
                          }
                      } else if (startedTracking) {
                          viewPages[0].setTranslationX(dx);
                          if (animatingForward) {
                              viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() + dx);
                          } else {
                              viewPages[1].setTranslationX(dx - viewPages[0].getMeasuredWidth());
                          }
                          float scrollProgress = Math.abs(dx) / (float) viewPages[0].getMeasuredWidth();
                          filterTabsView.selectTabWithId(viewPages[1].selectedType, scrollProgress);
                      }
                  } else if (ev == null || ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
                      velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
                      float velX;
                      float velY;
                      if (ev != null && ev.getAction() != MotionEvent.ACTION_CANCEL) {
                          velX = velocityTracker.getXVelocity();
                          velY = velocityTracker.getYVelocity();
                          if (!startedTracking) {
                              if (Math.abs(velX) >= 3000 && Math.abs(velX) > Math.abs(velY)) {
                                  prepareForMoving(ev, velX < 0);
                              }
                          }
                      } else {
                          velX = 0;
                          velY = 0;
                      }
                      if (startedTracking) {
                          float x = viewPages[0].getX();
                          tabsAnimation = new AnimatorSet();
                          if (additionalOffset != 0) {
                              if (Math.abs(velX) > 1500) {
                                  backAnimation = animatingForward ? velX > 0 : velX < 0;
                              } else {
                                  if (animatingForward) {
                                      backAnimation = (viewPages[1].getX() > (viewPages[0].getMeasuredWidth() >> 1));
                                  } else {
                                      backAnimation = (viewPages[0].getX() < (viewPages[0].getMeasuredWidth() >> 1));
                                  }
                              }
                          } else {
                              backAnimation = Math.abs(x) < viewPages[0].getMeasuredWidth() / 3.0f && (Math.abs(velX) < 3500 || Math.abs(velX) < Math.abs(velY));
                          }
                          float distToMove;
                          float dx;
                          if (backAnimation) {
                              dx = Math.abs(x);
                              if (animatingForward) {
                                  tabsAnimation.playTogether(
                                          ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0),
                                          ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, viewPages[1].getMeasuredWidth())
                                  );
                              } else {
                                  tabsAnimation.playTogether(
                                          ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0),
                                          ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, -viewPages[1].getMeasuredWidth())
                                  );
                              }
                          } else {
                              dx = viewPages[0].getMeasuredWidth() - Math.abs(x);
                              if (animatingForward) {
                                  tabsAnimation.playTogether(
                                          ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, -viewPages[0].getMeasuredWidth()),
                                          ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0)
                                  );
                              } else {
                                  tabsAnimation.playTogether(
                                          ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, viewPages[0].getMeasuredWidth()),
                                          ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0)
                                  );
                              }
                          }
                          tabsAnimation.setInterpolator(interpolator);
  
                          int width = getMeasuredWidth();
                          int halfWidth = width / 2;
                          float distanceRatio = Math.min(1.0f, 1.0f * dx / (float) width);
                          float distance = (float) halfWidth + (float) halfWidth * AndroidUtilities.distanceInfluenceForSnapDuration(distanceRatio);
                          velX = Math.abs(velX);
                          int duration;
                          if (velX > 0) {
                              duration = 4 * Math.round(1000.0f * Math.abs(distance / velX));
                          } else {
                              float pageDelta = dx / getMeasuredWidth();
                              duration = (int) ((pageDelta + 1.0f) * 100.0f);
                          }
                          duration = Math.max(150, Math.min(duration, 600));
  
                          tabsAnimation.setDuration(duration);
                          tabsAnimation.addListener(new AnimatorListenerAdapter() {
                              @Override
                              public void onAnimationEnd(Animator animator) {
                                  tabsAnimation = null;
                                  if (!backAnimation) {
                                      ViewPage tempPage = viewPages[0];
                                      viewPages[0] = viewPages[1];
                                      viewPages[1] = tempPage;
                                      filterTabsView.selectTabWithId(viewPages[0].selectedType, 1.0f);
                                      updateCounters(false);
                                  }
                                  if (parentLayout != null) {
                                      parentLayout.getDrawerLayoutContainer().setAllowOpenDrawerBySwipe(viewPages[0].selectedType == filterTabsView.getFirstTabId());
                                  }
                                  viewPages[1].setVisibility(View.GONE);
                                  showScrollbars(true);
                                  tabsAnimationInProgress = false;
                                  maybeStartTracking = false;
                                  actionBar.setEnabled(true);
                                  filterTabsView.setEnabled(true);
                                  checkListLoad(viewPages[0]);
                              }
                          });
                          tabsAnimation.start();
                          tabsAnimationInProgress = true;
                          startedTracking = false;
                      } else {
                          parentLayout.getDrawerLayoutContainer().setAllowOpenDrawerBySwipe(viewPages[0].selectedType == filterTabsView.getFirstTabId());
                          maybeStartTracking = false;
                          actionBar.setEnabled(true);
                          filterTabsView.setEnabled(true);
                      }
                      if (velocityTracker != null) {
                          velocityTracker.recycle();
                          velocityTracker = null;
                      }
                  }
                  return startedTracking;
              }
              return false;
          }
  
          @Override
          public boolean hasOverlappingRendering() {
              return false;
          }
      }
  
      public static float viewOffset = 0.0f;
  
      public class DialogsRecyclerView extends RecyclerListView {
  
          private boolean firstLayout = true;
          private boolean ignoreLayout;
          private ViewPage parentPage;
          private int appliedPaddingTop;
  
          public DialogsRecyclerView(Context context, ViewPage page) {
              super(context);
              parentPage = page;
          }
  
          public void setViewsOffset(float viewOffset) {
              DialogsActivity.viewOffset = viewOffset;
              int n = getChildCount();
              for (int i = 0; i < n; i++) {
                  getChildAt(i).setTranslationY(viewOffset);
              }
  
              if (selectorPosition != NO_POSITION) {
                  View v = getLayoutManager().findViewByPosition(selectorPosition);
                  if (v != null) {
                      selectorRect.set(v.getLeft(), (int) (v.getTop() + viewOffset), v.getRight(), (int) (v.getBottom() + viewOffset));
                      selectorDrawable.setBounds(selectorRect);
                  }
              }
              invalidate();
          }
  
          public float getViewOffset() {
              return viewOffset;
          }
  
          @Override
          public void addView(View child, int index, ViewGroup.LayoutParams params) {
              super.addView(child, index, params);
              child.setTranslationY(viewOffset);
          }
  
          @Override
          public void removeView(View view) {
              super.removeView(view);
              view.setTranslationY(0);
          }
  
          @Override
          public void onDraw(Canvas canvas) {
              if (parentPage.pullForegroundDrawable != null && viewOffset != 0) {
                  int pTop = getPaddingTop();
                  if (pTop != 0) {
                      canvas.save();
                      canvas.translate(0, pTop);
                  }
                  parentPage.pullForegroundDrawable.drawOverScroll(canvas);
                  if (pTop != 0) {
                      canvas.restore();
                  }
              }
              super.onDraw(canvas);
          }
  
  
          @Override
          protected void dispatchDraw(Canvas canvas) {
              super.dispatchDraw(canvas);
              if (slidingView != null && pacmanAnimation != null) {
                  pacmanAnimation.draw(canvas, slidingView.getTop() + slidingView.getMeasuredHeight() / 2);
              }
          }
  
          @Override
          public void setAdapter(RecyclerView.Adapter adapter) {
              super.setAdapter(adapter);
              firstLayout = true;
          }
  
          private void checkIfAdapterValid() {
              RecyclerView.Adapter adapter = getAdapter();
              if (parentPage.lastItemsCount != adapter.getItemCount()) {
                  ignoreLayout = true;
                  adapter.notifyDataSetChanged();
                  ignoreLayout = false;
              }
          }
  
          @Override
          protected void onMeasure(int widthSpec, int heightSpec) {
              int t = 0;
              if (!onlySelect) {
                  ignoreLayout = true;
                  if (filterTabsView != null && filterTabsView.getVisibility() == VISIBLE) {
                      t = ActionBar.getCurrentActionBarHeight() + (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0);
                  } else {
                      t = 0;
                  }
                  setTopGlowOffset(t);
                  setPadding(0, t, 0, 0);
                  if (appliedPaddingTop != t) {
                      int pos = parentPage.layoutManager.findFirstVisibleItemPosition();
                      if (pos != RecyclerView.NO_POSITION) {
                          RecyclerView.ViewHolder holder = parentPage.listView.findViewHolderForAdapterPosition(pos);
                          if (holder != null) {
                              int top = holder.itemView.getTop();
                              parentPage.layoutManager.scrollToPositionWithOffset(pos, top - appliedPaddingTop);
                          }
                      }
                  }
                  ignoreLayout = false;
              }
  
              if (firstLayout && getMessagesController().dialogsLoaded) {
                  if (parentPage.dialogsType == 0 && hasHiddenArchive()) {
                      ignoreLayout = true;
                      LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager();
                      layoutManager.scrollToPositionWithOffset(1, (int) actionBar.getTranslationY());
                      ignoreLayout = false;
                  }
                  firstLayout = false;
              }
              checkIfAdapterValid();
              super.onMeasure(widthSpec, heightSpec);
              if (!onlySelect) {
                  if (appliedPaddingTop != t && viewPages != null && viewPages.length > 1) {
                      viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth());
                  }
              }
          }
  
          @Override
          protected void onLayout(boolean changed, int l, int t, int r, int b) {
              super.onLayout(changed, l, t, r, b);
              appliedPaddingTop = getPaddingTop();
              if ((dialogRemoveFinished != 0 || dialogInsertFinished != 0 || dialogChangeFinished != 0) && !dialogsItemAnimator.isRunning()) {
                  onDialogAnimationFinished();
              }
          }
  
          @Override
          public void requestLayout() {
              if (ignoreLayout) {
                  return;
              }
              super.requestLayout();
          }
  
          private void toggleArchiveHidden(boolean action, DialogCell dialogCell) {
              SharedConfig.toggleArchiveHidden();
              if (SharedConfig.archiveHidden) {
                  waitingForScrollFinished = true;
                  if (dialogCell != null) {
                      disableActionBarScrolling = true;
                      smoothScrollBy(0, (dialogCell.getMeasuredHeight() + (dialogCell.getTop() - getPaddingTop())), CubicBezierInterpolator.EASE_OUT);
                      if (action) {
                          updatePullAfterScroll = true;
                      } else {
                          updatePullState();
                      }
                  }
                  getUndoView().showWithAction(0, UndoView.ACTION_ARCHIVE_HIDDEN, null, null);
              } else {
                  getUndoView().showWithAction(0, UndoView.ACTION_ARCHIVE_PINNED, null, null);
                  updatePullState();
                  if (action && dialogCell != null) {
                      dialogCell.resetPinnedArchiveState();
                      dialogCell.invalidate();
                  }
              }
          }
  
          private void updatePullState() {
              parentPage.archivePullViewState = SharedConfig.archiveHidden ? ARCHIVE_ITEM_STATE_HIDDEN : ARCHIVE_ITEM_STATE_PINNED;
              if (parentPage.pullForegroundDrawable != null) {
                  parentPage.pullForegroundDrawable.setWillDraw(parentPage.archivePullViewState != ARCHIVE_ITEM_STATE_PINNED);
              }
          }
  
          @Override
          public boolean onTouchEvent(MotionEvent e) {
              if (animationRunning || waitingForScrollFinished || dialogRemoveFinished != 0 || dialogInsertFinished != 0 || dialogChangeFinished != 0) {
                  return false;
              }
              int action = e.getAction();
              if (action == MotionEvent.ACTION_DOWN) {
                  setOverScrollMode(View.OVER_SCROLL_ALWAYS);
              }
              if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
                  if (!parentPage.itemTouchhelper.isIdle() && parentPage.swipeController.swipingFolder) {
                      parentPage.swipeController.swipeFolderBack = true;
                      if (parentPage.itemTouchhelper.checkHorizontalSwipe(null, ItemTouchHelper.LEFT) != 0) {
                          toggleArchiveHidden(false, null);
                      }
                  }
              }
              boolean result = super.onTouchEvent(e);
              if (parentPage.dialogsType == 0 && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) && parentPage.archivePullViewState == ARCHIVE_ITEM_STATE_HIDDEN && hasHiddenArchive()) {
                  LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager();
                  int currentPosition = layoutManager.findFirstVisibleItemPosition();
                  if (currentPosition == 0) {
                      int pTop = getPaddingTop();
                      View view = layoutManager.findViewByPosition(currentPosition);
                      int height = (int) (AndroidUtilities.dp(SharedConfig.useThreeLinesLayout ? 78 : 72) * PullForegroundDrawable.SNAP_HEIGHT);
                      int diff = (view.getTop() - pTop) + view.getMeasuredHeight();
                      if (view != null) {
                          long pullingTime = System.currentTimeMillis() - startArchivePullingTime;
                          if (diff < height || pullingTime < PullForegroundDrawable.minPullingTime) {
                              disableActionBarScrolling = true;
                              smoothScrollBy(0, diff, CubicBezierInterpolator.EASE_OUT_QUINT);
                              parentPage.archivePullViewState = ARCHIVE_ITEM_STATE_HIDDEN;
                          } else {
                              if (parentPage.archivePullViewState != ARCHIVE_ITEM_STATE_SHOWED) {
                                  if (getViewOffset() == 0) {
                                      disableActionBarScrolling = true;
                                      smoothScrollBy(0, (view.getTop() - pTop), CubicBezierInterpolator.EASE_OUT_QUINT);
                                  }
                                  if (!canShowHiddenArchive) {
                                      canShowHiddenArchive = true;
                                      performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
                                      if (parentPage.pullForegroundDrawable != null) {
                                          parentPage.pullForegroundDrawable.colorize(true);
                                      }
                                  }
                                  ((DialogCell) view).startOutAnimation();
                                  parentPage.archivePullViewState = ARCHIVE_ITEM_STATE_SHOWED;
                              }
                          }
  
                          if (getViewOffset() != 0) {
                              ValueAnimator valueAnimator = ValueAnimator.ofFloat(getViewOffset(), 0f);
                              valueAnimator.addUpdateListener(animation -> setViewsOffset((float) animation.getAnimatedValue()));
  
                              valueAnimator.setDuration((long) (350f - 120f * (getViewOffset() / PullForegroundDrawable.getMaxOverscroll())));
                              valueAnimator.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
                              setScrollEnabled(false);
                              valueAnimator.addListener(new AnimatorListenerAdapter() {
                                  @Override
                                  public void onAnimationEnd(Animator animation) {
                                      super.onAnimationEnd(animation);
                                      setScrollEnabled(true);
                                  }
                              });
                              valueAnimator.start();
                          }
                      }
                  }
              }
              return result;
          }
  
          @Override
          public boolean onInterceptTouchEvent(MotionEvent e) {
              if (animationRunning || waitingForScrollFinished || dialogRemoveFinished != 0 || dialogInsertFinished != 0 || dialogChangeFinished != 0) {
                  return false;
              }
              if (e.getAction() == MotionEvent.ACTION_DOWN) {
                  allowSwipeDuringCurrentTouch = !actionBar.isActionModeShowed();
                  checkIfAdapterValid();
              }
              return super.onInterceptTouchEvent(e);
          }
      }
  
      private class SwipeController extends ItemTouchHelper.Callback {
  
          private RectF buttonInstance;
          private RecyclerView.ViewHolder currentItemViewHolder;
          private boolean swipingFolder;
          private boolean swipeFolderBack;
          private ViewPage parentPage;
  
          public SwipeController(ViewPage page) {
              parentPage = page;
          }
  
          @Override
          public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
              if (waitingForDialogsAnimationEnd() || parentLayout != null && parentLayout.isInPreviewMode()) {
                  return 0;
              }
              if (swipingFolder && swipeFolderBack) {
                  swipingFolder = false;
                  return 0;
              }
              if (!onlySelect && parentPage.isDefaultDialogType() && slidingView == null && viewHolder.itemView instanceof DialogCell) {
                  DialogCell dialogCell = (DialogCell) viewHolder.itemView;
                  long dialogId = dialogCell.getDialogId();
  