<commit_before>package com.ruenzuo.weatherapp.base;

import com.ruenzuo.weatherapp.R;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.support.v4.view.MenuItemCompat;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.content.Intent;
import android.widget.LinearLayout;

import com.ruenzuo.weatherapp.activities.CityActivity;
import com.ruenzuo.weatherapp.adapters.CitiesAdapter;
import com.ruenzuo.weatherapp.fragments.CitiesListFragment;
import com.ruenzuo.weatherapp.pojos.City;

public class CitiesBaseActivity extends ActionBarActivity implements CitiesListFragment.OnCitySelectedListener,
        CitiesListFragment.OnLoadCitiesListener, SearchView.OnQueryTextListener {

    private LinearLayout progressLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cities);
        CitiesListFragment fragment = (CitiesListFragment) getSupportFragmentManager()
                .findFragmentById(R.id.citiesListFragment);
        fragment.getListView().setTextFilterEnabled(true);
        progressLayout = (LinearLayout) findViewById(R.id.progressLayout);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_cities, menu);
        MenuItem searchItem = menu.findItem(R.id.action_search);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        setupSearchView(searchView);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.action_refresh) {
            CitiesListFragment fragment = (CitiesListFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.citiesListFragment);
            fragment.refreshLocation();
        }
        return super.onOptionsItemSelected(item);
    }

    private void setupSearchView(SearchView searchView) {
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint("Search cities");
        CitiesListFragment fragment = (CitiesListFragment) getSupportFragmentManager()
                .findFragmentById(R.id.citiesListFragment);
        fragment.getListView().setTextFilterEnabled(true);
    }

    public boolean onQueryTextChange(String newText) {
        CitiesListFragment fragment = (CitiesListFragment) getSupportFragmentManager()
                .findFragmentById(R.id.citiesListFragment);
        CitiesAdapter citiesAdapter = (CitiesAdapter)fragment.getListView()
                .getAdapter();
        if (TextUtils.isEmpty(newText)) {
            citiesAdapter.getFilter().filter("");
        } else {
            citiesAdapter.getFilter().filter(newText);<commit_msg>Using buildConfig to hide search feature<commit_after>package com.ruenzuo.weatherapp.base;

import com.ruenzuo.weatherapp.BuildConfig;
import com.ruenzuo.weatherapp.R;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.support.v4.view.MenuItemCompat;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.content.Intent;
import android.widget.LinearLayout;

import com.ruenzuo.weatherapp.activities.CityActivity;
import com.ruenzuo.weatherapp.adapters.CitiesAdapter;
import com.ruenzuo.weatherapp.fragments.CitiesListFragment;
import com.ruenzuo.weatherapp.pojos.City;

public class CitiesBaseActivity extends ActionBarActivity implements CitiesListFragment.OnCitySelectedListener,
        CitiesListFragment.OnLoadCitiesListener, SearchView.OnQueryTextListener {

    private LinearLayout progressLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cities);
        CitiesListFragment fragment = (CitiesListFragment) getSupportFragmentManager()
                .findFragmentById(R.id.citiesListFragment);
        fragment.getListView().setTextFilterEnabled(true);
        progressLayout = (LinearLayout) findViewById(R.id.progressLayout);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_cities, menu);
        MenuItem searchItem = menu.findItem(R.id.action_search);
        if (BuildConfig.IS_FREE) {
            searchItem.setVisible(false);
        }
        else {
            SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
            setupSearchView(searchView);
        }
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.action_refresh) {
            CitiesListFragment fragment = (CitiesListFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.citiesListFragment);
            fragment.refreshLocation();
        }
        return super.onOptionsItemSelected(item);
    }

    private void setupSearchView(SearchView searchView) {
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint("Search cities");
        CitiesListFragment fragment = (CitiesListFragment) getSupportFragmentManager()
                .findFragmentById(R.id.citiesListFragment);
        fragment.getListView().setTextFilterEnabled(true);
    }

    public boolean onQueryTextChange(String newText) {
        CitiesListFragment fragment = (CitiesListFragment) getSupportFragmentManager()
                .findFragmentById(R.id.citiesListFragment);
        CitiesAdapter citiesAdapter = (CitiesAdapter)fragment.getListView()
                .getAdapter();
        if (TextUtils.isEmpty(newText)) {
            citiesAdapter.getFilter().filter("");
        } else {
            citiesAdapter.getFilter().filter(newText);
{'fraction_non_alphanumeric': 0.08916256157635467, 'fraction_numerical': 0.0009852216748768472, 'mean_word_length': 3.7107501933488014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4047232', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1614, 'n_words': 258}