<commit_before>package com.ideasfrombrain.search_based_launcher_v3;

import android.content.ComponentName;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class AppListView implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {
    final MainActivity mainActivity;
    final ListView listView;
    private final DialogFactory dialogFactory;
    List<App> filtered = new ArrayList<>();
    List<App> recent = new ArrayList<>();

    public static final int FIRST_INDEX = 0;

    public AppListView (MainActivity mainActivity) {
        this.mainActivity = mainActivity;
        listView = (ListView) mainActivity.findViewById(R.id.listView1);
        listView.setOnItemClickListener(this);
        listView.setOnItemLongClickListener(this);
        dialogFactory = new DialogFactory(mainActivity);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        runApp(position);
    }

    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
        return showOptionsForApp(position);
    }

    public void refeshView() {
        filtered.clear();
        recent.retainAll(mainActivity.getAppListManager().getPkg());
        String filterText = mainActivity.getSearchText().getFilterText();
        for (App app: getReversedRecent()) {
            if (app.getNick().toLowerCase().matches(filterText)) {
                filtered.add(app.getAsRecent());
            }
        }
        for (App app: mainActivity.getAppListManager().getPkg()) {
            if (app.getNick().toLowerCase().matches(filterText) && !recent.contains(app)) {
                filtered.add(app);
            }
        }
        if (filtered.size() == 1 && mainActivity.getAutostartButton().isOn()) {
            runApp(FIRST_INDEX);
        } else {
            viewAppList(filtered);
        }
    }

    private List<App> getReversedRecent() {
        final ArrayList<App> reverseRecent = new ArrayList<App>(recent);
        Collections.reverse(reverseRecent);
        return reverseRecent;
    }

    private void viewAppList(List<App> appList) {<commit_msg>Extract methods from AppListView#refreshView.<commit_after>package com.ideasfrombrain.search_based_launcher_v3;

import android.content.ComponentName;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class AppListView implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {
    final MainActivity mainActivity;
    final ListView listView;
    private final DialogFactory dialogFactory;
    List<App> filtered = new ArrayList<>();
    List<App> recent = new ArrayList<>();

    public static final int FIRST_INDEX = 0;

    public AppListView (MainActivity mainActivity) {
        this.mainActivity = mainActivity;
        listView = (ListView) mainActivity.findViewById(R.id.listView1);
        listView.setOnItemClickListener(this);
        listView.setOnItemLongClickListener(this);
        dialogFactory = new DialogFactory(mainActivity);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        runApp(position);
    }

    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
        return showOptionsForApp(position);
    }

    public void refeshView() {
        String filterText = mainActivity.getSearchText().getFilterText();
        addRecent(filterText);
        addFiltered(filterText);
        if (autostartFirstApp()) {
            runApp(FIRST_INDEX);
        } else {
            viewAppList(filtered);
        }
    }

    private void addFiltered(String filterText) {
        filtered.clear();
        for (App app: mainActivity.getAppListManager().getPkg()) {
            if (app.getNick().toLowerCase().matches(filterText) && !recent.contains(app)) {
                filtered.add(app);
            }
        }
    }

    private void addRecent(String filterText) {
        recent.retainAll(mainActivity.getAppListManager().getPkg());
        for (App app: getReversedRecent()) {
            if (app.getNick().toLowerCase().matches(filterText)) {
                filtered.add(app.getAsRecent());
            }
        }
    }

    private boolean autostartFirstApp() {
        return filtered.size() == 1 && mainActivity.getAppListManager().getPkg().size() > 1 && mainActivity.getAutostartButton().isOn();
    }

    private List<App> getReversedRecent() {
        final ArrayList<App> reverseRecent = new ArrayList<App>(recent);
        Collections.reverse(reverseRecent);
        return reverseRecent;
    }

    private void viewAppList(List<App> appList) {
{'fraction_non_alphanumeric': 0.10512870898015327, 'fraction_numerical': 0.0017685203379838867, 'mean_word_length': 3.1721311475409837, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 24, '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': '6960488', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1352, 'n_words': 288}