package com.lc.myapplication.security.locks.adapter;

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

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

import com.lc.myapplication.security.locks.databinding.TopCodeViewBinding;

import java.util.logging.Handler;

public class TopInputadapter extends RecyclerView.Adapter<TopInputadapter.TopViewHolder>{

    private String topcode = "";

    @NonNull
    @Override
    public TopViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        TopCodeViewBinding topCodeViewBinding = TopCodeViewBinding.inflate(LayoutInflater.from(parent.getContext()),parent,false);
        return new TopViewHolder(topCodeViewBinding);
    }

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

    @Override
    public int getItemCount() {
        return 4;
    }
    public void upDatakey(String code){
        topcode = code;
        notifyDataSetChanged();
    }


    public class TopViewHolder extends RecyclerView.ViewHolder {
        private TopCodeViewBinding topCodeViewBinding;
        public TopViewHolder(@NonNull TopCodeViewBinding topViewBinding) {
            super(topViewBinding.getRoot());
            topCodeViewBinding = topViewBinding;
        }
    }
}
