package epson.print.storage.gdrivev3;

import android.content.Context;

import android.support.annotation.UiThread;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;



public class FileListAdapter extends BaseAdapter {
    private ArrayList<OnlineFile> mDriveFiles;
    private final LayoutInflater mLayoutInflater;

    public Object getItem(int i) {
        return null;
    }

    public long getItemId(int i) {
        return 0;
    }

    public FileListAdapter(@NonNull Context context) {
        mLayoutInflater = LayoutInflater.from(context);
    }

    @UiThread
    public void setDriveFile(ArrayList<OnlineFile> arrayList) {
        mDriveFiles = arrayList;
        notifyDataSetChanged();
    }

    public int getCount() {
        ArrayList<OnlineFile> arrayList = mDriveFiles;
        if (arrayList == null) {
            return 0;
        }
        return arrayList.size();
    }

    public OnlineFile getDriveItem(int i) {
        return mDriveFiles.get(i);
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        int i2;
        if (view == null) {
            view = mLayoutInflater.inflate(R.layout.file_list_item, viewGroup, false);
        }
        OnlineFile onlineFile = mDriveFiles.get(i);
        String name = onlineFile.getName();
        int i3 = R.C2136drawable.file;
        if (onlineFile.isFolder()) {
            i3 = onlineFile instanceof ParentFolder ? R.C2136drawable.parent_folder : R.C2136drawable.folder;
            i2 = R.C2136drawable.more;
        } else {
            i2 = 0;
        }
        ((TextView) view.findViewById(R.id.file_folder_name)).setText(name);
        ImageView imageView = (ImageView) view.findViewById(R.id.file_folder_icon);
        imageView.setImageResource(i3);
        imageView.setVisibility(0);
        ImageView imageView2 = (ImageView) view.findViewById(R.id.browse_folder);
        if (i2 != 0) {
            imageView2.setVisibility(0);
            imageView2.setImageResource(i2);
        } else {
            imageView2.setVisibility(8);
        }
        return view;
    }

    public void clearItems() {
        ArrayList<OnlineFile> arrayList = mDriveFiles;
        if (arrayList != null) {
            arrayList.clear();
        }
        notifyDataSetChanged();
    }
}
