<commit_before>/*
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hippo.widget;

import android.content.Context;
import android.os.Environment;
import android.support.v7.widget.LinearLayoutManager;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hippo.easyrecyclerview.EasyRecyclerView;
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
import com.hippo.ehviewer.R;
import com.hippo.rippleold.RippleSalon;
import com.hippo.yorozuya.LayoutUtils;
import com.hippo.yorozuya.ResourcesUtils;

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

public class DirExplorer extends EasyRecyclerView implements EasyRecyclerView.OnItemClickListener {

    private static final DirFilter DIR_FILTER = new DirFilter();
    private static final FileSort FILE_SORT = new FileSort();

    private static final File PARENT_DIR = null;
    private static final String PARENT_DIR_NAME = "..";

    private File mCurrentFile;
    private final List<File> mFiles = new ArrayList<>();

    private DirAdapter mAdapter;

    private OnChangeDirListener mOnChangeDirListener;

    public DirExplorer(Context context) {
        super(context);
        init(context);
    }

    public DirExplorer(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public DirExplorer(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        mAdapter = new DirAdapter();
        setAdapter(mAdapter);
        setLayoutManager(new LinearLayoutManager(context));
        LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
                LinearDividerItemDecoration.VERTICAL, getResources().getColor(R.color.divider),
                LayoutUtils.dp2pix(context, 1));
        decoration.setShowLastDivider(true);
        addItemDecoration(decoration);
        setSelector(RippleSalon.generateRippleDrawable(ResourcesUtils.getAttrBoolean(context, R.attr.dark)));
        setOnItemClickListener(this);

        mCurrentFile = Environment.getExternalStorageDirectory();
        if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
                || mCurrentFile == null) {
            mCurrentFile = new File("/");
        }
        updateFileList();
    }

    public void setOnChangeDirListener(OnChangeDirListener listener) {
        mOnChangeDirListener = listener;
    }

    public void updateFileList() {
        File[] files = mCurrentFile.listFiles(DIR_FILTER);

        mFiles.clear();
        if (mCurrentFile.getParent() != null) {
            mFiles.add(PARENT_DIR);
        }
        if (files != null) {
            Collections.addAll(mFiles, files);
        }
        // sort
        Collections.sort(mFiles, FILE_SORT);
    }

    public File getCurrentFile() {
        return mCurrentFile;
    }<commit_msg>Remove invalid attr<commit_after>/*
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hippo.widget;

import android.content.Context;
import android.os.Environment;
import android.support.v7.widget.LinearLayoutManager;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hippo.easyrecyclerview.EasyRecyclerView;
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
import com.hippo.ehviewer.R;
import com.hippo.rippleold.RippleSalon;
import com.hippo.yorozuya.LayoutUtils;

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

public class DirExplorer extends EasyRecyclerView implements EasyRecyclerView.OnItemClickListener {

    private static final DirFilter DIR_FILTER = new DirFilter();
    private static final FileSort FILE_SORT = new FileSort();

    private static final File PARENT_DIR = null;
    private static final String PARENT_DIR_NAME = "..";

    private File mCurrentFile;
    private final List<File> mFiles = new ArrayList<>();

    private DirAdapter mAdapter;

    private OnChangeDirListener mOnChangeDirListener;

    public DirExplorer(Context context) {
        super(context);
        init(context);
    }

    public DirExplorer(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public DirExplorer(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        mAdapter = new DirAdapter();
        setAdapter(mAdapter);
        setLayoutManager(new LinearLayoutManager(context));
        LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
                LinearDividerItemDecoration.VERTICAL, getResources().getColor(R.color.divider),
                LayoutUtils.dp2pix(context, 1));
        decoration.setShowLastDivider(true);
        addItemDecoration(decoration);
        setSelector(RippleSalon.generateRippleDrawable(false));
        setOnItemClickListener(this);

        mCurrentFile = Environment.getExternalStorageDirectory();
        if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
                || mCurrentFile == null) {
            mCurrentFile = new File("/");
        }
        updateFileList();
    }

    public void setOnChangeDirListener(OnChangeDirListener listener) {
        mOnChangeDirListener = listener;
    }

    public void updateFileList() {
        File[] files = mCurrentFile.listFiles(DIR_FILTER);

        mFiles.clear();
        if (mCurrentFile.getParent() != null) {
            mFiles.add(PARENT_DIR);
        }
        if (files != null) {
            Collections.addAll(mFiles, files);
        }
        // sort
        Collections.sort(mFiles, FILE_SORT);
    }

    public File getCurrentFile() {
        return mCurrentFile;
    }
{'fraction_non_alphanumeric': 0.08801754867013985, 'fraction_numerical': 0.003016177680285166, 'mean_word_length': 3.399879372738239, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7144728', 'n_tokens_mistral': 2046, 'n_tokens_neox': 1964, 'n_words': 515}