gt:         saveButton = new BottomSheet.BottomSheetCell(context, 1);
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.Components;
  
  import android.annotation.SuppressLint;
  import android.content.Context;
  import android.graphics.Canvas;
  import android.graphics.PorterDuff;
  import android.graphics.PorterDuffColorFilter;
  import android.graphics.drawable.Drawable;
  import android.os.Build;
  import android.util.SparseArray;
  import android.view.Gravity;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.FrameLayout;
  
  import org.telegram.messenger.AndroidUtilities;
  import org.telegram.messenger.LocaleController;
  import org.telegram.messenger.MessageObject;
  import org.telegram.messenger.MessagesController;
  import org.telegram.messenger.R;
  import org.telegram.tgnet.TLRPC;
  import org.telegram.ui.ActionBar.BottomSheet;
  import org.telegram.ui.ActionBar.Theme;
  import org.telegram.ui.Cells.CheckBoxCell;
  import org.telegram.ui.Cells.CheckBoxUserCell;
  import org.telegram.ui.Cells.ShadowSectionCell;
  import org.telegram.ui.ContentPreviewViewer;
  
  import java.util.ArrayList;
  import java.util.regex.Pattern;
  
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  public class AdminLogFilterAlert extends BottomSheet {
  
      public interface AdminLogFilterAlertDelegate {
          void didSelectRights(TLRPC.TL_channelAdminLogEventsFilter filter, SparseArray<TLRPC.User> admins);
      }
  
      private Pattern urlPattern;
      private RecyclerListView listView;
      private ListAdapter adapter;
      private FrameLayout pickerBottomLayout;
      private Drawable shadowDrawable;
      private BottomSheet.BottomSheetCell saveButton;
  
      private AdminLogFilterAlertDelegate delegate;
  
      private int scrollOffsetY;
      private int reqId;
      private boolean ignoreLayout;
  
      private TLRPC.TL_channelAdminLogEventsFilter currentFilter;
      private ArrayList<TLRPC.ChannelParticipant> currentAdmins;
      private SparseArray<TLRPC.User> selectedAdmins;
      private boolean isMegagroup;
  
      private int restrictionsRow;
      private int adminsRow;
      private int membersRow;
      private int invitesRow;
      private int infoRow;
      private int deleteRow;
      private int editRow;
      private int pinnedRow;
      private int leavingRow;
      private int callsRow;
      private int allAdminsRow;
  
      public AdminLogFilterAlert(Context context, TLRPC.TL_channelAdminLogEventsFilter filter, SparseArray<TLRPC.User> admins, boolean megagroup) {
          super(context, false);
          if (filter != null) {
              currentFilter = new TLRPC.TL_channelAdminLogEventsFilter();
              currentFilter.join = filter.join;
              currentFilter.leave = filter.leave;
              currentFilter.invite = filter.invite;
              currentFilter.ban = filter.ban;
              currentFilter.unban = filter.unban;
              currentFilter.kick = filter.kick;
              currentFilter.unkick = filter.unkick;
              currentFilter.promote = filter.promote;
              currentFilter.demote = filter.demote;
              currentFilter.info = filter.info;
              currentFilter.settings = filter.settings;
              currentFilter.pinned = filter.pinned;
              currentFilter.edit = filter.edit;
              currentFilter.delete = filter.delete;
              currentFilter.group_call = filter.group_call;
              currentFilter.invites = filter.invites;
          }
          if (admins != null) {
              selectedAdmins = admins.clone();
          }
          isMegagroup = megagroup;
  
          int rowCount = 1;
          if (isMegagroup) {
              restrictionsRow = rowCount++;
          } else {
              restrictionsRow = -1;
          }
          adminsRow = rowCount++;
          membersRow = rowCount++;
          invitesRow = rowCount++;
          infoRow = rowCount++;
          deleteRow = rowCount++;
          editRow = rowCount++;
          if (isMegagroup) {
              pinnedRow = rowCount++;
          } else {
              pinnedRow = -1;
          }
          leavingRow = rowCount++;
          callsRow = rowCount++;
          rowCount += 1;
          allAdminsRow = rowCount;
  
          shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow_round).mutate();
          shadowDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogBackground), PorterDuff.Mode.MULTIPLY));
  
          containerView = new FrameLayout(context) {
  
              @Override
              public boolean onInterceptTouchEvent(MotionEvent ev) {
                  if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) {
                      dismiss();
                      return true;
                  }
                  return super.onInterceptTouchEvent(ev);
              }
  
              @Override
              public boolean onTouchEvent(MotionEvent e) {
                  return !isDismissed() && super.onTouchEvent(e);
              }
  
              @Override
              protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                  int height = MeasureSpec.getSize(heightMeasureSpec);
                  if (Build.VERSION.SDK_INT >= 21) {
                      height -= AndroidUtilities.statusBarHeight;
                  }
                  int measuredWidth = getMeasuredWidth();
                  int contentSize = AndroidUtilities.dp(48) + (isMegagroup ? 11 : 8) * AndroidUtilities.dp(48) + backgroundPaddingTop + AndroidUtilities.dp(17);
                  if (currentAdmins != null) {
                      contentSize += (currentAdmins.size() + 1) * AndroidUtilities.dp(48) + AndroidUtilities.dp(20);
                  }
  
                  int padding = contentSize < (height / 5 * 3.2f) ? 0 : (height / 5 * 2);
                  if (padding != 0 && contentSize < height) {
                      padding -= (height - contentSize);
                  }
                  if (padding == 0) {
                      padding = backgroundPaddingTop;
                  }
                  if (listView.getPaddingTop() != padding) {
                      ignoreLayout = true;
                      listView.setPadding(0, padding, 0, 0);
                      ignoreLayout = false;
                  }
                  super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY));
              }
  
              @Override
              protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
                  super.onLayout(changed, left, top, right, bottom);
                  updateLayout();
              }
  
              @Override
              public void requestLayout() {
                  if (ignoreLayout) {
                      return;
                  }
                  super.requestLayout();
              }
  
              @Override
              protected void onDraw(Canvas canvas) {
                  shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(), getMeasuredHeight());
                  shadowDrawable.draw(canvas);
              }
          };
          containerView.setWillNotDraw(false);
          containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0);
  
          listView = new RecyclerListView(context) {
              @Override
              public boolean onInterceptTouchEvent(MotionEvent event) {
                  boolean result = ContentPreviewViewer.getInstance().onInterceptTouchEvent(event, listView, 0, null);
                  return super.onInterceptTouchEvent(event) || result;
              }
  
              @Override
              public void requestLayout() {
                  if (ignoreLayout) {
                      return;
                  }
                  super.requestLayout();
              }
          };
          listView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
          listView.setAdapter(adapter = new ListAdapter(context));
          listView.setVerticalScrollBarEnabled(false);
          listView.setClipToPadding(false);
          listView.setEnabled(true);
          listView.setGlowColor(Theme.getColor(Theme.key_dialogScrollGlow));
          listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
              @Override
              public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                  updateLayout();
              }
          });
          listView.setOnItemClickListener((view, position) -> {
              if (view instanceof CheckBoxCell) {
                  CheckBoxCell cell = (CheckBoxCell) view;
                  boolean isChecked = cell.isChecked();
                  cell.setChecked(!isChecked, true);
                  if (position == 0) {
                      if (isChecked) {
                          currentFilter = new TLRPC.TL_channelAdminLogEventsFilter();
                          currentFilter.join = currentFilter.leave = currentFilter.invite = currentFilter.ban =
                          currentFilter.unban = currentFilter.kick = currentFilter.unkick = currentFilter.promote =
                          currentFilter.demote = currentFilter.info = currentFilter.settings = currentFilter.pinned =
                          currentFilter.edit = currentFilter.delete = currentFilter.group_call = currentFilter.invites = false;
                      } else {
                          currentFilter = null;
                      }
                      int count = listView.getChildCount();
                      for (int a = 0; a < count; a++) {
                          View child = listView.getChildAt(a);
                          RecyclerView.ViewHolder holder = listView.findContainingViewHolder(child);
                          int pos = holder.getAdapterPosition();
                          if (holder.getItemViewType() == 0 && pos > 0 && pos < allAdminsRow - 1) {
                              ((CheckBoxCell) child).setChecked(!isChecked, true);
                          }
                      }
                  } else if (position == allAdminsRow) {
                      if (isChecked) {
                          selectedAdmins = new SparseArray<>();
                      } else {
                          selectedAdmins = null;
                      }
                      int count = listView.getChildCount();
                      for (int a = 0; a < count; a++) {
                          View child = listView.getChildAt(a);
                          RecyclerView.ViewHolder holder = listView.findContainingViewHolder(child);
                          int pos = holder.getAdapterPosition();
                          if (holder.getItemViewType() == 2) {
                              CheckBoxUserCell userCell = (CheckBoxUserCell) child;
                              userCell.setChecked(!isChecked, true);
                          }
                      }
                  } else {
                      if (currentFilter == null) {
                          currentFilter = new TLRPC.TL_channelAdminLogEventsFilter();
                          currentFilter.join = currentFilter.leave = currentFilter.invite = currentFilter.ban =
                          currentFilter.unban = currentFilter.kick = currentFilter.unkick = currentFilter.promote =
                          currentFilter.demote = currentFilter.info = currentFilter.settings = currentFilter.pinned =
                          currentFilter.edit = currentFilter.delete = currentFilter.group_call = currentFilter.invites = true;
                          RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(0);
                          if (holder != null) {
                              ((CheckBoxCell) holder.itemView).setChecked(false, true);
                          }
                      }
                      if (position == restrictionsRow) {
                          currentFilter.kick = currentFilter.ban = currentFilter.unkick = currentFilter.unban = !currentFilter.kick;
                      } else if (position == adminsRow) {
                          currentFilter.promote = currentFilter.demote = !currentFilter.demote;
                      } else if (position == membersRow) {
                          currentFilter.invite = currentFilter.join = !currentFilter.join;
                      } else if (position == infoRow) {
                          currentFilter.info = currentFilter.settings = !currentFilter.info;
                      } else if (position == deleteRow) {
                          currentFilter.delete = !currentFilter.delete;
                      } else if (position == editRow) {
                          currentFilter.edit = !currentFilter.edit;
                      } else if (position == pinnedRow) {
                          currentFilter.pinned = !currentFilter.pinned;
                      } else if (position == leavingRow) {
                          currentFilter.leave = !currentFilter.leave;
                      } else if (position == callsRow) {
                          currentFilter.group_call = !currentFilter.group_call;
                      } else if (position == invitesRow) {
                          currentFilter.invites = !currentFilter.invites;
                      }
                  }
                  if (currentFilter != null &&
                          !currentFilter.join && !currentFilter.leave && !currentFilter.invite && !currentFilter.ban &&
                          !currentFilter.invites && !currentFilter.unban && !currentFilter.kick && !currentFilter.unkick &&
                          !currentFilter.promote && !currentFilter.demote && !currentFilter.info && !currentFilter.settings &&
                          !currentFilter.pinned && !currentFilter.edit && !currentFilter.delete && !currentFilter.group_call) {
                      saveButton.setEnabled(false);
                      saveButton.setAlpha(0.5f);
                  } else {
                      saveButton.setEnabled(true);
                      saveButton.setAlpha(1.0f);
                  }
              } else if (view instanceof CheckBoxUserCell) {
                  CheckBoxUserCell checkBoxUserCell = (CheckBoxUserCell) view;
                  if (selectedAdmins == null) {
                      selectedAdmins = new SparseArray<>();
                      RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(allAdminsRow);
                      if (holder != null) {
                          ((CheckBoxCell) holder.itemView).setChecked(false, true);
                      }
                      for (int a = 0; a < currentAdmins.size(); a++) {
                          TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(MessageObject.getPeerId(currentAdmins.get(a).peer));
                          selectedAdmins.put(user.id, user);
                      }
                  }
                  boolean isChecked = checkBoxUserCell.isChecked();
                  TLRPC.User user = checkBoxUserCell.getCurrentUser();
                  if (isChecked) {
                      selectedAdmins.remove(user.id);
                  } else {
                      selectedAdmins.put(user.id, user);
                  }
                  checkBoxUserCell.setChecked(!isChecked, true);
              }
          });
          containerView.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 48));
  
          View shadow = new View(context);
          shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
          containerView.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
  
  