package info.knacki.pass.ui.passwordList;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import info.knacki.pass.R;
import info.knacki.pass.io.FileUtils;

public class PasswordView extends LinearLayout {
    public final static int ICON_SIZE = 128;
    protected final ImageView vIcon;
    protected final TextView vName;
    protected final int fType;
    protected final String fFullName;

    public static final int TYPE_DIR = 1;
    public static final int TYPE_PARENT = 2;
    public static final int TYPE_PASSWORD = 4;

    public PasswordView(Context ctx, int type, String name) {
        super(ctx);
        LinearLayout content = (LinearLayout) LayoutInflater.from(ctx).inflate(R.layout.password_line, this, true);
        fFullName = name;
        vIcon = content.findViewById(R.id.password_icon);
        fType = type;
        if ((type & TYPE_PARENT) != 0)
            vIcon.setImageResource(android.R.drawable.ic_media_previous);
        else if ((type & TYPE_DIR) != 0)
            vIcon.setImageResource(R.drawable.ic_doc_folder);
        else
            vIcon.setImageResource(R.drawable.ic_doc_text);

        vName = content.findViewById(R.id.password_name);
        vName.setText(FileUtils.TrimExtension(name));
        setClickable(true);
    }

    public boolean IsDir() {
        return (fType & TYPE_DIR) != 0;
    }
}
