package com.epson.cameracopy.p006ui;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

/* renamed from: com.epson.cameracopy.ui.FolderInformation */
/* compiled from: FolderSelectActivity */
class FolderInformation {
    private static int DIRECTION_CURRENT = 0;
    private static int DIRECTION_FORWARD = 1;
    private static int DIRECTION_REVERS = -1;
    private File mCurrentFolder = null;
    private CurrentFolderName mCurrentFolderName = null;
    private File[] mFileList = null;
    private ArrayList<File> mFolderArray = null;
    private ItemDataAdapter mItemDataAdapter = null;
    private ArrayList<ItemData> mItemDataList = null;
    private int mLevel = 0;
    private MenuControl mMenuControl = null;
    private int mSelectedPosition = -1;

    FolderInformation(String str, int i, ItemDataAdapter itemDataAdapter, ArrayList<ItemData> arrayList, CurrentFolderName currentFolderName, MenuControl menuControl) {
        init(str, i, itemDataAdapter, arrayList, currentFolderName, menuControl);
    }

    private void init(String str, int i, ItemDataAdapter itemDataAdapter, ArrayList<ItemData> arrayList, CurrentFolderName currentFolderName, MenuControl menuControl) {
        mCurrentFolder = new File(str);
        mItemDataList = arrayList;
        mItemDataAdapter = itemDataAdapter;
        mLevel = i;
        mCurrentFolderName = currentFolderName;
        mMenuControl = menuControl;
    }

    public void UpdateFolder() {
        UpdateFolder(0, DIRECTION_CURRENT);
    }

    public int UpdateFolder(int i) {
        if (IsFolder(i)) {
            UpdateFolder(i, DIRECTION_FORWARD);
        } else {
            UpdateFolder(i, DIRECTION_REVERS);
        }
        mItemDataAdapter.notifyDataSetInvalidated();
        return mLevel;
    }

    public boolean IsFolder(int i) {
        return i != 0 || mLevel == 0;
    }

    public void SetSelectedPosition(int i) {
        mSelectedPosition = i;
    }

    public boolean IsFolder() {
        return mSelectedPosition != 0 || mLevel == 0;
    }

    public File GetCurrentFolder() {
        return mCurrentFolder;
    }

    private void UpdateFolder(int i, int i2) {
        if (i2 == DIRECTION_REVERS) {
            mLevel--;
            GetFolder(mFolderArray.get(i).getParentFile());
        } else if (i2 == DIRECTION_FORWARD) {
            mLevel++;
            GetFolder(mFolderArray.get(i));
        } else {
            GetFolder(mCurrentFolder);
        }
    }

    private void GetFolder(File file) {
        mItemDataList.clear();
        mCurrentFolder = file;
        mFolderArray = new ArrayList<>();
        if (mLevel != 0) {
            mItemDataList.add(new ItemData((String) null));
            mFolderArray.add(mCurrentFolder);
        }
        mFileList = mCurrentFolder.listFiles(new DirectoryFileFilter());
        Arrays.sort(mFileList, new FileNameSort());
        if (mFileList != null) {
            int i = 0;
            while (true) {
                File[] fileArr = mFileList;
                if (i >= fileArr.length) {
                    break;
                }
                mItemDataList.add(new ItemData(fileArr[i].getName()));
                mFolderArray.add(mFileList[i]);
                i++;
            }
        }
        CurrentFolderName currentFolderName = mCurrentFolderName;
        if (currentFolderName != null) {
            currentFolderName.SetFile(mCurrentFolder);
            if (mLevel != 0) {
                mCurrentFolderName.Show(true);
            } else {
                mCurrentFolderName.Show(false);
            }
        }
        MenuControl menuControl = mMenuControl;
        if (menuControl == null) {
            return;
        }
        if (mLevel != 0) {
            menuControl.ChangeMenu(1);
        } else {
            menuControl.ChangeMenu(0);
        }
    }

    /* renamed from: com.epson.cameracopy.ui.FolderInformation$DirectoryFileFilter */
    /* compiled from: FolderSelectActivity */
    private class DirectoryFileFilter implements FileFilter {
        private DirectoryFileFilter() {
        }

        public boolean accept(File file) {
            return file.isDirectory() && !file.isHidden();
        }
    }

    /* renamed from: com.epson.cameracopy.ui.FolderInformation$FileNameSort */
    /* compiled from: FolderSelectActivity */
    private class FileNameSort implements Comparator<File> {
        private FileNameSort() {
        }

        public int compare(File file, File file2) {
            return file.getName().compareToIgnoreCase(file2.getName());
        }
    }
}
