package com.tool.applockpro.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.tool.applockpro.R;


public class PinAdapter extends RecyclerView.Adapter<PinAdapter.NumberVH> {

    private String mPin = "";
    private Context mContext;

    public PinAdapter(Context context) {
        mContext = context;
    }

    @NonNull
    @Override
    public NumberVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.number_pin, null);
        return new NumberVH(view);
    }

    @Override
    public void onBindViewHolder(@NonNull NumberVH holder, @SuppressLint("RecyclerView") int position) {

        if (position < mPin.length()) {
            holder.getImageView().setSelected(true);
        } else {
            holder.getImageView().setSelected(false);
        }
    }

    @Override
    public int getItemCount() {
        return 4;
    }

    public void updateItem(String pin) {
        mPin = pin;
        notifyDataSetChanged();
    }

    public class NumberVH extends RecyclerView.ViewHolder {
        private ImageView imageView;

        public NumberVH(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.im_pin);
        }

        public ImageView getImageView() {
            return imageView;
        }
    }
}
