<commit_before>package org.wikipedia.language;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.apache.commons.lang3.StringUtils;
import org.wikipedia.R;
import org.wikipedia.WikipediaApp;
import org.wikipedia.activity.BaseActivity;
import org.wikipedia.history.SearchActionModeCallback;
import org.wikipedia.util.ResourceUtil;
import org.wikipedia.views.ViewUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import retrofit2.Call;

import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.wikipedia.util.DeviceUtil.hideSoftKeyboard;

public class LanguagesListActivity extends BaseActivity {

    private WikipediaApp app;

    private View progressBar;
    private RecyclerView recyclerView;

    private LanguagesListAdapter adapter;
    private String currentSearchQuery;
    private ActionMode actionMode;
    private SearchActionModeCallback searchActionModeCallback;

    private final LanguagesListActivity.SiteMatrixCallback siteMatrixCallback = new LanguagesListActivity.SiteMatrixCallback();
    @Nullable private List<SiteMatrixClient.SiteInfo> siteInfoList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusBarColor(ResourceUtil.getThemedAttributeId(this, R.attr.page_status_bar_color));

        setContentView(R.layout.activity_languages_list);

        app = WikipediaApp.getInstance();

        adapter = new LanguagesListAdapter(app.language().getAppMruLanguageCodes(), app.language().getRemainingAvailableLanguageCodes());

        setUpViews();

        // TODO: add funnel?
    }

    private void setUpViews() {
        recyclerView = findViewById(R.id.languages_list_recycler);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        progressBar = findViewById(R.id.languages_list_load_progress);
        progressBar.setVisibility(View.VISIBLE);

        searchActionModeCallback = new LanguagesListActivity.LanguageSearchCallback();
        new SiteMatrixClient().request(app.getWikiSite(), siteMatrixCallback);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_languages_list, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_search_language:
                if (actionMode == null) {
                    actionMode = startSupportActionMode(searchActionModeCallback);
                }
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public void onBackPressed() {
        hideSoftKeyboard(this);
        super.onBackPressed();
    }

    private class LanguageSearchCallback extends SearchActionModeCallback {
        private LanguagesListAdapter languageAdapter = (LanguagesListAdapter) recyclerView.getAdapter();
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            actionMode = mode;
            ViewUtil.finishActionModeWhenTappingOnView(recyclerView, actionMode);
            return super.onCreateActionMode(mode, menu);
        }

        @Override
        protected void onQueryChange(String s) {
            currentSearchQuery = s.trim();
            languageAdapter.setFilterText(currentSearchQuery);
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            super.onDestroyActionMode(mode);
            if (!TextUtils.isEmpty(currentSearchQuery)) {
                currentSearchQuery = "";
            }
            languageAdapter.reset();
            actionMode = null;
        }

        @Override<commit_msg>Tweak: Show message if no match results in search languages mode<commit_after>package org.wikipedia.language;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.apache.commons.lang3.StringUtils;
import org.wikipedia.R;
import org.wikipedia.WikipediaApp;
import org.wikipedia.activity.BaseActivity;
import org.wikipedia.history.SearchActionModeCallback;
import org.wikipedia.util.ResourceUtil;
import org.wikipedia.views.ViewUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import retrofit2.Call;

import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.wikipedia.util.DeviceUtil.hideSoftKeyboard;

public class LanguagesListActivity extends BaseActivity {

    private WikipediaApp app;

    private View progressBar;
    private View queryNoMatchView;
    private RecyclerView recyclerView;

    private LanguagesListAdapter adapter;
    private String currentSearchQuery;
    private ActionMode actionMode;
    private SearchActionModeCallback searchActionModeCallback;

    private final LanguagesListActivity.SiteMatrixCallback siteMatrixCallback = new LanguagesListActivity.SiteMatrixCallback();
    @Nullable private List<SiteMatrixClient.SiteInfo> siteInfoList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusBarColor(ResourceUtil.getThemedAttributeId(this, R.attr.page_status_bar_color));

        setContentView(R.layout.activity_languages_list);

        app = WikipediaApp.getInstance();

        adapter = new LanguagesListAdapter(app.language().getAppMruLanguageCodes(), app.language().getRemainingAvailableLanguageCodes());

        setUpViews();

        // TODO: add funnel?
    }

    private void setUpViews() {
        recyclerView = findViewById(R.id.languages_list_recycler);
        queryNoMatchView = findViewById(R.id.languages_list_no_match);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        progressBar = findViewById(R.id.languages_list_load_progress);
        progressBar.setVisibility(View.VISIBLE);

        searchActionModeCallback = new LanguagesListActivity.LanguageSearchCallback();
        new SiteMatrixClient().request(app.getWikiSite(), siteMatrixCallback);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_languages_list, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_search_language:
                if (actionMode == null) {
                    actionMode = startSupportActionMode(searchActionModeCallback);
                }
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public void onBackPressed() {
        hideSoftKeyboard(this);
        super.onBackPressed();
    }

    private class LanguageSearchCallback extends SearchActionModeCallback {
        private LanguagesListAdapter languageAdapter = (LanguagesListAdapter) recyclerView.getAdapter();
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            actionMode = mode;
            ViewUtil.finishActionModeWhenTappingOnView(recyclerView, actionMode);
            return super.onCreateActionMode(mode, menu);
        }

        @Override
        protected void onQueryChange(String s) {
            currentSearchQuery = s.trim();
            languageAdapter.setFilterText(currentSearchQuery);

            if (recyclerView.getAdapter().getItemCount() == 0) {
                queryNoMatchView.setVisibility(View.VISIBLE);
            } else {
                queryNoMatchView.setVisibility(View.GONE);
            }
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            super.onDestroyActionMode(mode);
            if (!TextUtils.isEmpty(currentSearchQuery)) {
                currentSearchQuery = "";
            }
            queryNoMatchView.setVisibility(View.GONE);
            languageAdapter.reset();
            actionMode = null;
        }

        @Override
{'fraction_non_alphanumeric': 0.08142353459673865, 'fraction_numerical': 0.0014323490524460114, 'mean_word_length': 3.3472222222222223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6202917', 'n_tokens_mistral': 2368, 'n_tokens_neox': 2294, 'n_words': 439}