gt:         if (listAdapter != null) {
context: /*
   * This is the source code of ZiosGram for Android v. 1.3.x.
   * It is licensed under GNU GPL v. 2 or later.
   * You should have received a copy of the license in this archive (see LICENSE).
   *
   * Copyright Nikolai Kudashov, 2013-2017.
   */
  
  package org.blaez.ui;
  
  import android.content.Context;
  import android.content.DialogInterface;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.EditText;
  import android.widget.FrameLayout;
  
  import org.blaez.ziosgram.AndroidUtilities;
  import org.blaez.ziosgram.FileLog;
  import org.blaez.ziosgram.LocaleController;
  import org.blaez.ziosgram.R;
  import org.blaez.ziosgram.Utilities;
  import org.blaez.ziosgram.support.widget.LinearLayoutManager;
  import org.blaez.ziosgram.support.widget.RecyclerView;
  import org.blaez.ui.ActionBar.AlertDialog;
  import org.blaez.ui.ActionBar.Theme;
  import org.blaez.ui.ActionBar.ThemeDescription;
  import org.blaez.ui.Cells.TextSettingsCell;
  import org.blaez.ui.ActionBar.ActionBar;
  import org.blaez.ui.ActionBar.ActionBarMenu;
  import org.blaez.ui.ActionBar.ActionBarMenuItem;
  import org.blaez.ui.ActionBar.BaseFragment;
  import org.blaez.ui.Components.EmptyTextProgressView;
  import org.blaez.ui.Components.LayoutHelper;
  import org.blaez.ui.Components.RecyclerListView;
  
  import java.util.ArrayList;
  import java.util.Timer;
  import java.util.TimerTask;
  
  public class LanguageSelectActivity extends BaseFragment {
  
      private ListAdapter listAdapter;
      private RecyclerListView listView;
      private ListAdapter searchListViewAdapter;
      private EmptyTextProgressView emptyView;
  
      private boolean searchWas;
      private boolean searching;
  
      private Timer searchTimer;
      public ArrayList<LocaleController.LocaleInfo> searchResult;
  
      @Override
      public View createView(Context context) {
          searching = false;
          searchWas = false;
  
          actionBar.setBackButtonImage(R.drawable.ic_ab_back);
          actionBar.setAllowOverlayTitle(true);
          actionBar.setTitle(LocaleController.getString("Language", R.string.Language));
  
          actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
              @Override
              public void onItemClick(int id) {
                  if (id == -1) {
                      finishFragment();
                  }
              }
          });
  
          ActionBarMenu menu = actionBar.createMenu();
          ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
              @Override
              public void onSearchExpand() {
                  searching = true;
              }
  
              @Override
              public void onSearchCollapse() {
                  search(null);
                  searching = false;
                  searchWas = false;
                  if (listView != null) {
                      emptyView.setVisibility(View.GONE);
                      listView.setAdapter(listAdapter);
                  }
              }
  
              @Override
              public void onTextChanged(EditText editText) {
                  String text = editText.getText().toString();
                  search(text);
                  if (text.length() != 0) {
                      searchWas = true;
                      if (listView != null) {
                          listView.setAdapter(searchListViewAdapter);
                      }
                  }
              }
          });
          item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
  
          listAdapter = new ListAdapter(context, false);
          searchListViewAdapter = new ListAdapter(context, true);
  
          fragmentView = new FrameLayout(context);
          FrameLayout frameLayout = (FrameLayout) fragmentView;
  
          emptyView = new EmptyTextProgressView(context);
          emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
          emptyView.showTextView();
          emptyView.setShowAtCenter(true);
          frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
  
          listView = new RecyclerListView(context);
          listView.setEmptyView(emptyView);
          listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
          listView.setVerticalScrollBarEnabled(false);
          listView.setAdapter(listAdapter);
          frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
  
          listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
              @Override
              public void onItemClick(View view, int position) {
                  LocaleController.LocaleInfo localeInfo = null;
                  if (searching && searchWas) {
                      if (position >= 0 && position < searchResult.size()) {
                          localeInfo = searchResult.get(position);
                      }
                  } else {
                      if (position >= 0 && position < LocaleController.getInstance().sortedLanguages.size()) {
                          localeInfo = LocaleController.getInstance().sortedLanguages.get(position);
                      }
                  }
                  if (localeInfo != null) {
                      LocaleController.getInstance().applyLanguage(localeInfo, true);
                      parentLayout.rebuildAllFragmentViews(false);
                  }
                  finishFragment();
              }
          });
  
          listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
              @Override
              public boolean onItemClick(View view, int position) {
                  LocaleController.LocaleInfo localeInfo = null;
                  if (searching && searchWas) {
                      if (position >= 0 && position < searchResult.size()) {
                          localeInfo = searchResult.get(position);
                      }
                  } else {
                      if (position >= 0 && position < LocaleController.getInstance().sortedLanguages.size()) {
                          localeInfo = LocaleController.getInstance().sortedLanguages.get(position);
                      }
                  }
                  if (localeInfo == null || localeInfo.pathToFile == null || getParentActivity() == null) {
                      return false;
                  }
                  final LocaleController.LocaleInfo finalLocaleInfo = localeInfo;
                  AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                  builder.setMessage(LocaleController.getString("DeleteLocalization", R.string.DeleteLocalization));
                  builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                  builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialogInterface, int i) {
                          if (LocaleController.getInstance().deleteLanguage(finalLocaleInfo)) {
                              if (searchResult != null) {
                                  searchResult.remove(finalLocaleInfo);
                              }
                              if (listAdapter != null) {
                                  listAdapter.notifyDataSetChanged();
                              }
                              if (searchListViewAdapter != null) {
                                  searchListViewAdapter.notifyDataSetChanged();
                              }
                          }
                      }
                  });
                  builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                  showDialog(builder.create());
                  return true;
              }
          });
  
          listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
              @Override
              public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                  if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) {
                      AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
                  }
              }
          });
  
          return fragmentView;
      }
  
      @Override
      public void onResume() {
          super.onResume();
  