package com.android.launcher3.debug.adapter;

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

import com.android.launcher3.R;
import com.android.launcher3.manager.ColumnDef;
import com.android.launcher3.manager.ManagementInfo;

import java.util.List;

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

public class TimeAdapter extends RecyclerView.Adapter<TimeAdapter.ViewHolder> {

    private LayoutInflater mInflater;

    private List<ManagementInfo> managementInfos;


    public void setManagementInfos(List<ManagementInfo> managementInfos) {
        this.managementInfos = managementInfos;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (mInflater == null) {
            mInflater = LayoutInflater.from(parent.getContext());
        }
        return new ViewHolder(mInflater.inflate(R.layout.adapter_app_manager_info, null));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.bindData(managementInfos.get(position));
    }

    @Override
    public int getItemCount() {
        return managementInfos == null ? 0 : managementInfos.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {


        private TextView tv_package_info;


        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_package_info = itemView.findViewById(R.id.tv_package_info);
        }


        public void bindData(ManagementInfo managementInfo) {

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.append(managementInfo.getPackageName()).append("\t");


            switch (managementInfo.getUseType()) {
                case ColumnDef.AppUseType.GAME_LOCK_TYPE:
                    stringBuilder.append("游戏类");
                    break;
                case ColumnDef.AppUseType.LEARN_TYPE:
                    stringBuilder.append("学习类");
                    break;
                case ColumnDef.AppUseType.SAFE_TYPE:
                    stringBuilder.append("无需管控类");
                    break;
                case ColumnDef.AppUseType.UNCLASS_TYPE:
                    stringBuilder.append("未分类");
                    break;
            }
            stringBuilder.append("\t");

            stringBuilder.append("应用可使用时长" + managementInfo.getUseEndTimeStamp() + "秒\n");
            stringBuilder.append(managementInfo.getLock() == ColumnDef.LockApp.LOCKED ? "应用已锁定" : "未锁定");

            tv_package_info.setText(stringBuilder.toString());
        }
    }
}
