gt:         if (isGroup) {
context: /*
   * This is the source code of Telegram for Android v. 3.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-2016.
   */
  
  package org.telegram.ui;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.app.ProgressDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.SharedPreferences;
  import android.os.Bundle;
  import android.text.Spannable;
  import android.text.method.LinkMovementMethod;
  import android.util.TypedValue;
  import android.view.Gravity;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.FrameLayout;
  import android.widget.ListView;
  import android.widget.TextView;
  
  import org.telegram.messenger.AndroidUtilities;
  import org.telegram.messenger.ApplicationLoader;
  import org.telegram.messenger.ContactsController;
  import org.telegram.messenger.FileLog;
  import org.telegram.messenger.LocaleController;
  import org.telegram.messenger.MessagesController;
  import org.telegram.messenger.NotificationCenter;
  import org.telegram.messenger.R;
  import org.telegram.tgnet.ConnectionsManager;
  import org.telegram.tgnet.RequestDelegate;
  import org.telegram.tgnet.TLObject;
  import org.telegram.tgnet.TLRPC;
  import org.telegram.ui.ActionBar.ActionBar;
  import org.telegram.ui.ActionBar.ActionBarMenu;
  import org.telegram.ui.ActionBar.BaseFragment;
  import org.telegram.ui.Adapters.BaseFragmentAdapter;
  import org.telegram.ui.Cells.HeaderCell;
  import org.telegram.ui.Cells.RadioCell;
  import org.telegram.ui.Cells.TextInfoPrivacyCell;
  import org.telegram.ui.Cells.TextSettingsCell;
  import org.telegram.ui.Components.LayoutHelper;
  
  import java.util.ArrayList;
  
  public class PrivacyControlActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
  
      private ListAdapter listAdapter;
      private View doneButton;
  
      private int currentType = 0;
      private ArrayList<Integer> currentPlus;
      private ArrayList<Integer> currentMinus;
      private int lastCheckedType = -1;
  
      private boolean isGroup;
  
      private boolean enableAnimation;
  
      private int sectionRow;
      private int everybodyRow;
      private int myContactsRow;
      private int nobodyRow;
      private int detailRow;
      private int shareSectionRow;
      private int alwaysShareRow;
      private int neverShareRow;
      private int shareDetailRow;
      private int rowCount;
  
      private final static int done_button = 1;
  
      private static class LinkMovementMethodMy extends LinkMovementMethod {
          @Override
          public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
              try {
                  return super.onTouchEvent(widget, buffer, event);
              } catch (Exception e) {
                  FileLog.e("tmessages", e);
              }
              return false;
          }
      }
  
      public PrivacyControlActivity(boolean group) {
          super();
          isGroup = group;
      }
  
      @Override
      public boolean onFragmentCreate() {
          super.onFragmentCreate();
          checkPrivacy();
          updateRows();
          NotificationCenter.getInstance().addObserver(this, NotificationCenter.privacyRulesUpdated);
          return true;
      }
  
      @Override
      public void onFragmentDestroy() {
          super.onFragmentDestroy();
          NotificationCenter.getInstance().removeObserver(this, NotificationCenter.privacyRulesUpdated);
      }
  
      @Override
      public View createView(Context context) {
          actionBar.setBackButtonImage(R.drawable.ic_ab_back);
          actionBar.setAllowOverlayTitle(true);
          if (isGroup) {
              actionBar.setTitle(LocaleController.getString("GroupsAndChannels", R.string.GroupsAndChannels));
          } else {
              actionBar.setTitle(LocaleController.getString("PrivacyLastSeen", R.string.PrivacyLastSeen));
          }
          actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
              @Override
              public void onItemClick(int id) {
                  if (id == -1) {
                      finishFragment();
                  } else if (id == done_button) {
                      if (getParentActivity() == null) {
                          return;
                      }
  
                      if (currentType != 0 && !isGroup) {
                          final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                          boolean showed = preferences.getBoolean("privacyAlertShowed", false);
                          if (!showed) {
                              AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                              if (isGroup) {
                                  builder.setMessage(LocaleController.getString("WhoCanAddMeInfo", R.string.WhoCanAddMeInfo));
                              } else {
                                  builder.setMessage(LocaleController.getString("CustomHelp", R.string.CustomHelp));
                              }
                              builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                              builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialogInterface, int i) {
                                      applyCurrentPrivacySettings();
                                      preferences.edit().putBoolean("privacyAlertShowed", true).commit();
                                  }
                              });
                              builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                              showDialog(builder.create());
                              return;
                          }
                      }
                      applyCurrentPrivacySettings();
                  }
              }
          });
  
          ActionBarMenu menu = actionBar.createMenu();
          doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
          doneButton.setVisibility(View.GONE);
  
          listAdapter = new ListAdapter(context);
  
          fragmentView = new FrameLayout(context);
          FrameLayout frameLayout = (FrameLayout) fragmentView;
          frameLayout.setBackgroundColor(0xfff0f0f0);
  
          ListView listView = new ListView(context);
          listView.setDivider(null);
          listView.setDividerHeight(0);
          listView.setVerticalScrollBarEnabled(false);
          listView.setDrawSelectorOnTop(true);
          frameLayout.addView(listView);
          FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
          layoutParams.width = LayoutHelper.MATCH_PARENT;
          layoutParams.height = LayoutHelper.MATCH_PARENT;
          layoutParams.gravity = Gravity.TOP;
          listView.setLayoutParams(layoutParams);
          listView.setAdapter(listAdapter);
          listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                  if (i == nobodyRow || i == everybodyRow || i == myContactsRow) {
                      int newType = currentType;
                      if (i == nobodyRow) {
                          newType = 1;
                      } else if (i == everybodyRow) {
                          newType = 0;
                      } else if (i == myContactsRow) {
                          newType = 2;
                      }
                      if (newType == currentType) {
                          return;
                      }
                      enableAnimation = true;
                      doneButton.setVisibility(View.VISIBLE);
                      lastCheckedType = currentType;
                      currentType = newType;
                      updateRows();
                  } else if (i == neverShareRow || i == alwaysShareRow) {
                      ArrayList<Integer> createFromArray;
                      if (i == neverShareRow) {
                          createFromArray = currentMinus;
                      } else {
                          createFromArray = currentPlus;
                      }
                      if (createFromArray.isEmpty()) {
                          Bundle args = new Bundle();
                          args.putBoolean(i == neverShareRow ? "isNeverShare" : "isAlwaysShare", true);
                          args.putBoolean("isGroup", isGroup);
                          GroupCreateActivity fragment = new GroupCreateActivity(args);
                          fragment.setDelegate(new GroupCreateActivity.GroupCreateActivityDelegate() {
                              @Override
                              public void didSelectUsers(ArrayList<Integer> ids) {
                                  if (i == neverShareRow) {
                                      currentMinus = ids;
                                      for (int a = 0; a < currentMinus.size(); a++) {
                                          currentPlus.remove(currentMinus.get(a));
                                      }
                                  } else {
                                      currentPlus = ids;
                                      for (int a = 0; a < currentPlus.size(); a++) {
                                          currentMinus.remove(currentPlus.get(a));
                                      }
                                  }
                                  doneButton.setVisibility(View.VISIBLE);
                                  lastCheckedType = -1;
                                  listAdapter.notifyDataSetChanged();
                              }
                          });
                          presentFragment(fragment);
                      } else {
                          PrivacyUsersActivity fragment = new PrivacyUsersActivity(createFromArray, isGroup, i == alwaysShareRow);
                          fragment.setDelegate(new PrivacyUsersActivity.PrivacyActivityDelegate() {
                              @Override
                              public void didUpdatedUserList(ArrayList<Integer> ids, boolean added) {
                                  if (i == neverShareRow) {
                                      currentMinus = ids;
                                      if (added) {
                                          for (int a = 0; a < currentMinus.size(); a++) {
                                              currentPlus.remove(currentMinus.get(a));
                                          }
                                      }
                                  } else {
                                      currentPlus = ids;
                                      if (added) {
                                          for (int a = 0; a < currentPlus.size(); a++) {
                                              currentMinus.remove(currentPlus.get(a));
                                          }
                                      }
                                  }
                                  doneButton.setVisibility(View.VISIBLE);
                                  listAdapter.notifyDataSetChanged();
                              }
                          });
                          presentFragment(fragment);
                      }
                  }
              }
          });
  
          return fragmentView;
      }
  
      @Override
      public void didReceivedNotification(int id, Object... args) {
          if (id == NotificationCenter.privacyRulesUpdated) {
              checkPrivacy();
          }
      }
  
      private void applyCurrentPrivacySettings() {
          TLRPC.TL_account_setPrivacy req = new TLRPC.TL_account_setPrivacy();
  