gt:             if (alert) {
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.felegram.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.text.Editable;
  import android.text.InputType;
  import android.text.TextWatcher;
  import android.util.TypedValue;
  import android.view.Gravity;
  import android.view.KeyEvent;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.inputmethod.EditorInfo;
  import android.widget.EditText;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  import org.telegram.messenger.AndroidUtilities;
  import org.telegram.messenger.ApplicationLoader;
  import org.telegram.messenger.FileLog;
  import org.telegram.messenger.LocaleController;
  import org.telegram.messenger.MessagesController;
  import org.telegram.messenger.MessagesStorage;
  import org.telegram.messenger.NotificationCenter;
  import org.telegram.messenger.R;
  import org.telegram.messenger.UserConfig;
  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.Components.LayoutHelper;
  
  import java.util.ArrayList;
  
  public class IdFinderActivity extends BaseFragment {
  
      private EditText userNameField;
      private View doneButton;
      private TextView checkTextView;
      private int checkReqId = 0;
      private String lastCheckName = null;
      private Runnable checkRunnable = null;
      private boolean lastNameAvailable = false;
  
      private final static int done_button = 1;
  
      @Override
      public View createView(Context context) {
          actionBar.setBackButtonImage(R.drawable.ic_ab_back);
          actionBar.setAllowOverlayTitle(true);
          actionBar.setTitle(LocaleController.getString("IdFinder", R.string.IdFinder));
          actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
              @Override
              public void onItemClick(int id) {
                  if (id == -1) {
                      finishFragment();
                  } else if (id == done_button) {
                      showProfile();
                  }
              }
          });
  
          ActionBarMenu menu = actionBar.createMenu();
          doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
          doneButton.setVisibility(View.GONE);
  
          TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
          if (user == null) {
              user = UserConfig.getCurrentUser();
          }
  
          fragmentView = new LinearLayout(context);
          ((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
          fragmentView.setOnTouchListener(new View.OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                  return true;
              }
          });
  
          userNameField = new EditText(context);
          userNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
          userNameField.setHintTextColor(0xff979797);
          userNameField.setTextColor(0xff212121);
          userNameField.setMaxLines(1);
          userNameField.setLines(1);
          userNameField.setPadding(0, 0, 0, 0);
          userNameField.setSingleLine(true);
          userNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
          userNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
          userNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
          userNameField.setHint(LocaleController.getString("IdFinderPlaceholder", R.string.IdFinderPlaceholder));
          AndroidUtilities.clearCursorDrawable(userNameField);
          userNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
              @Override
              public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                  if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
                      doneButton.performClick();
                      return true;
                  }
                  return false;
              }
          });
  
          ((LinearLayout) fragmentView).addView(userNameField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));
  
          checkTextView = new TextView(context);
          checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
          checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
          ((LinearLayout) fragmentView).addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 12, 24, 0));
  
          TextView helpTextView = new TextView(context);
          helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
          helpTextView.setTextColor(0xff6d6d72);
          helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
          helpTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("UsernameHelp", R.string.UsernameHelp)));
          ((LinearLayout) fragmentView).addView(helpTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 0));
  
          userNameField.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
  
              }
  
              @Override
              public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                  checkUserName(userNameField.getText().toString(), false);
              }
  
              @Override
              public void afterTextChanged(Editable editable) {
  
              }
          });
  
          checkTextView.setVisibility(View.GONE);
  
          return fragmentView;
      }
  
      @Override
      public void onResume() {
          super.onResume();
          SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
          boolean animations = preferences.getBoolean("view_animations", true);
          if (!animations) {
              userNameField.requestFocus();
              AndroidUtilities.showKeyboard(userNameField);
          }
      }
  
      private void showErrorAlert(String error) {
          if (getParentActivity() == null) {
              return;
          }
          AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
          builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
          switch (error) {
              case "USERNAME_INVALID":
                  builder.setMessage(LocaleController.getString("UsernameInvalid", R.string.UsernameInvalid));
                  break;
              case "USERNAME_OCCUPIED":
                  builder.setMessage(LocaleController.getString("UsernameInUse", R.string.UsernameInUse));
                  break;
              case "USERNAMES_UNAVAILABLE":
                  builder.setMessage(LocaleController.getString("FeatureUnavailable", R.string.FeatureUnavailable));
                  break;
              default:
                  builder.setMessage(LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred));
                  break;
          }
          builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
          showDialog(builder.create());
      }
  
      private boolean checkUserName(final String name, boolean alert) {
          doneButton.setVisibility(View.GONE);
          if (name != null && name.length() > 0) {
              checkTextView.setVisibility(View.VISIBLE);
          } else {
              checkTextView.setVisibility(View.GONE);
          }
          if (alert && name.length() == 0) {
              return true;
          }
          if (checkRunnable != null) {
              AndroidUtilities.cancelRunOnUIThread(checkRunnable);
              checkRunnable = null;
              lastCheckName = null;
              if (checkReqId != 0) {
                  ConnectionsManager.getInstance().cancelRequest(checkReqId, true);
              }
          }
          lastNameAvailable = false;
          if (name != null) {
              if (name.startsWith("_") || name.endsWith("_")) {
                  checkTextView.setText(LocaleController.getString("UsernameInvalid", R.string.UsernameInvalid));
                  checkTextView.setTextColor(0xffcf3030);
                  return false;
              }
              for (int a = 0; a < name.length(); a++) {
                  char ch = name.charAt(a);
                  if (a == 0 && ch >= '0' && ch <= '9') {
                      if (alert) {
                          showErrorAlert(LocaleController.getString("UsernameInvalidStartNumber", R.string.UsernameInvalidStartNumber));
                      } else {
                          checkTextView.setText(LocaleController.getString("UsernameInvalidStartNumber", R.string.UsernameInvalidStartNumber));
                          checkTextView.setTextColor(0xffcf3030);
                      }
                      return false;
                  }
                  if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) {
                      if (alert) {
                          showErrorAlert(LocaleController.getString("UsernameInvalid", R.string.UsernameInvalid));
                      } else {
                          checkTextView.setText(LocaleController.getString("UsernameInvalid", R.string.UsernameInvalid));
                          checkTextView.setTextColor(0xffcf3030);
                      }
                      return false;
                  }
              }
          }
          if (name == null || name.length() < 5) {
  