<commit_before>package bg.nijel.xswiftkey;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

class DialogChooseDirectory implements OnClickListener, OnItemClickListener {
    private final Context m_context;
    private File m_currentDir;
    private final List<File> m_entries = new ArrayList<>();
    private final ListView m_list;
    private Result mResult = null;
    private static String mBrowsingFolder;
    private static int[] mSavedScroll;
    private final Button mPositiveBtn;
    private String mResultJson;
    private AlertDialog m_alertDialog;

    public class DirAdapter extends ArrayAdapter<File> {
        public DirAdapter(int resid) {
            super(DialogChooseDirectory.this.m_context, resid, DialogChooseDirectory.this.m_entries);
        }

        @SuppressWarnings("deprecation")
        public View getView(final int position, View convertView, final ViewGroup parent) {
            TextView textview = (TextView) super.getView(position, convertView, parent);
            File file = DialogChooseDirectory.this.m_entries.get(position);
            if (file != null) {
                textview.setText(file.getName());
                if (!file.getName().equals("..")) {
                    if (file.isDirectory()) {
                        textview.setCompoundDrawablesWithIntrinsicBounds(DialogChooseDirectory.this.m_context.getResources().getDrawable(R.drawable.folder), null, null, null);
                    } else {
                        textview.setCompoundDrawablesWithIntrinsicBounds(DialogChooseDirectory.this.m_context.getResources().getDrawable(R.drawable.file), null, null, null);
                    }
                } else {
                    textview.setCompoundDrawablesWithIntrinsicBounds(DialogChooseDirectory.this.m_context.getResources().getDrawable(R.drawable.folder_up), null, null, null);
                }
                if (mSavedScroll != null && mSavedScroll[0] > 0) {
                    m_list.setSelectionFromTop(mSavedScroll[0], mSavedScroll[1]);
                }
            }
            return textview;
        }
    }

    public interface Result {
        void onChooseDirectory(String str);
    }

    private void listJsonFiles() {
        this.m_entries.clear();
        if (this.m_currentDir.canRead()) {
            FileFilter themelist = new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    return pathname.getName().equals("themelist.json") && pathname.isFile();
                }
            };
            File[] files = this.m_currentDir.listFiles();
            if (this.m_currentDir.getParent() != null) {
                this.m_entries.add(new File(".."));
            }
            if (files != null) {
                for (File file : files) {
                    if (file.isDirectory()) {
                        this.m_entries.add(file);
                    }
                }
                Collections.addAll(this.m_entries, this.m_currentDir.listFiles(themelist));
            }
        } else {
            Toast.makeText(this.m_context, this.m_currentDir.getAbsolutePath() + ": " + this.m_context.getString(R.string.label_unable_access), Toast.LENGTH_SHORT).show();
        }
        Collections.sort(this.m_entries, new Comparator<File>() {
            public int compare(File f1, File f2) {
                return f1.getName().toLowerCase().compareTo(f2.getName().toLowerCase());
            }
        });
    }

    @SuppressWarnings("deprecation")
    public DialogChooseDirectory(Context context, Result res, String startDir) {
        this.m_context = context;
        this.mResult = res;
        mBrowsingFolder = startDir;
        if (startDir != null) {
            this.m_currentDir = new File(startDir).getParentFile();
        } else {
            this.m_currentDir = Environment.getExternalStorageDirectory();
        }
        listJsonFiles();
        DirAdapter adapter = new DirAdapter(R.layout.listitem_row_textview);
        final Builder builder = new Builder(this.m_context);
        builder.setAdapter(adapter, this);
        builder.setPositiveButton("SELECT", new OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                if (DialogChooseDirectory.this.mResult != null) {
                    DialogChooseDirectory.this.mResult.onChooseDirectory(DialogChooseDirectory.this.mResultJson);
                }
                dialog.dismiss();
                mBrowsingFolder = null;
            }
        });
        builder.setNegativeButton("CANCEL", new OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();<commit_msg>thmelist.json is at the topof the list so no unnecessary scrolling<commit_after>package bg.nijel.xswiftkey;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

class DialogChooseDirectory implements OnClickListener, OnItemClickListener {
    private final Context m_context;
    private File m_currentDir;
    private final List<File> m_entries = new ArrayList<>();
    private final ListView m_list;
    private Result mResult = null;
    private static String mBrowsingFolder;
    private static int[] mSavedScroll;
    private final Button mPositiveBtn;
    private String mResultJson;
    private AlertDialog m_alertDialog;

    public class DirAdapter extends ArrayAdapter<File> {
        public DirAdapter(int resid) {
            super(DialogChooseDirectory.this.m_context, resid, DialogChooseDirectory.this.m_entries);
        }

        @SuppressWarnings("deprecation")
        public View getView(final int position, View convertView, final ViewGroup parent) {
            TextView textview = (TextView) super.getView(position, convertView, parent);
            File file = DialogChooseDirectory.this.m_entries.get(position);
            if (file != null) {
                textview.setText(file.getName());
                if (!file.getName().equals("..")) {
                    if (file.isDirectory()) {
                        textview.setCompoundDrawablesWithIntrinsicBounds(DialogChooseDirectory.this.m_context.getResources().getDrawable(R.drawable.folder), null, null, null);
                    } else {
                        textview.setCompoundDrawablesWithIntrinsicBounds(DialogChooseDirectory.this.m_context.getResources().getDrawable(R.drawable.file), null, null, null);
                    }
                } else {
                    textview.setCompoundDrawablesWithIntrinsicBounds(DialogChooseDirectory.this.m_context.getResources().getDrawable(R.drawable.folder_up), null, null, null);
                }
                if (mSavedScroll != null && mSavedScroll[0] > 0) {
                    m_list.setSelectionFromTop(mSavedScroll[0], mSavedScroll[1]);
                }
            }
            return textview;
        }
    }

    public interface Result {
        void onChooseDirectory(String str);
    }

    private void listJsonFiles() {
        this.m_entries.clear();
        if (this.m_currentDir.canRead()) {
            FileFilter themelist = new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    return pathname.getName().equals("themelist.json") && pathname.isFile();
                }
            };
            File[] files = this.m_currentDir.listFiles();
            if (this.m_currentDir.getParent() != null) {
                this.m_entries.add(new File(".."));
            }
            if (files != null) {
                for (File file : files) {
                    if (file.isDirectory()) {
                        this.m_entries.add(file);
                    }
                }
            }
            Collections.addAll(this.m_entries, this.m_currentDir.listFiles(themelist));
        } else {
            Toast.makeText(this.m_context, this.m_currentDir.getAbsolutePath() + ": " + this.m_context.getString(R.string.label_unable_access), Toast.LENGTH_SHORT).show();
        }
        Collections.sort(this.m_entries, new Comparator<File>() {
            public int compare(File f1, File f2) {
                if (f1.isDirectory() && f2.isDirectory()) {
                    return f1.getName().toLowerCase().compareTo(f2.getName().toLowerCase());
                } else if (f1.isDirectory()) {
                    return 1;
                }else if(f2.getName().equals("..")){
                    return 1;
                } else {
                    return -1;
                }
            }
        });
    }

    @SuppressWarnings("deprecation")
    public DialogChooseDirectory(Context context, Result res, String startDir) {
        this.m_context = context;
        this.mResult = res;
        mBrowsingFolder = startDir;
        if (startDir != null) {
            this.m_currentDir = new File(startDir).getParentFile();
        } else {
            this.m_currentDir = Environment.getExternalStorageDirectory();
        }
        listJsonFiles();
        DirAdapter adapter = new DirAdapter(R.layout.listitem_row_textview);
        final Builder builder = new Builder(this.m_context);
        builder.setAdapter(adapter, this);
        builder.setPositiveButton("SELECT", new OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                if (DialogChooseDirectory.this.mResult != null) {
                    DialogChooseDirectory.this.mResult.onChooseDirectory(DialogChooseDirectory.this.mResultJson);
                }
                dialog.dismiss();
                mBrowsingFolder = null;
            }
        });
        builder.setNegativeButton("CANCEL", new OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
{'fraction_non_alphanumeric': 0.09970778358275037, 'fraction_numerical': 0.002036659877800407, 'mean_word_length': 2.339444115907747, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 13, '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': '6888274', 'n_tokens_mistral': 3015, 'n_tokens_neox': 2884, 'n_words': 578}