package com.example.applock.lockadapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

import com.example.applock.databinding.TopKeyViewBinding;

public class TopAdapter extends RecyclerView.Adapter<TopAdapter.TopViewHolder> {
    private String mytopkey = "";
    @NonNull
    @Override
    public TopViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        TopKeyViewBinding topKeyViewBinding = TopKeyViewBinding.inflate(LayoutInflater.from(parent.getContext()),parent,false);
        return new TopViewHolder(topKeyViewBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull TopViewHolder holder, int position) {
        if(position ==0){
            holder.topKeyViewBinding.topView.setVisibility(View.GONE);
            holder.topKeyViewBinding.topImageKey.setVisibility(View.VISIBLE);
        }else {
            holder.topKeyViewBinding.topView.setVisibility(View.VISIBLE);
            holder.topKeyViewBinding.topImageKey.setVisibility(View.VISIBLE);
        }
        if(position > mytopkey.length()-1){
            holder.topKeyViewBinding.topImageKey.setSelected(true);
        }else {
            holder.topKeyViewBinding.topImageKey.setSelected(false);
        }

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

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

    public class TopViewHolder extends RecyclerView.ViewHolder{
        private TopKeyViewBinding topKeyViewBinding;
        public TopViewHolder(@NonNull TopKeyViewBinding topKeyBinding){
            super(topKeyBinding.getRoot());
            topKeyViewBinding = topKeyBinding;

        }

    }
}
