JobHuntCompanyAdapter.java 4.2 KB
package com.hh.xuetubao.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hh.xuetubao.R;
import com.hh.xuetubao.bean.CompanyBean;

import java.util.List;

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

    private Context context;
    private List<CompanyBean.CompanyListBean> list;

    public JobHuntCompanyAdapter(Context context, List<CompanyBean.CompanyListBean> list) {
        this.context = context;
        this.list = list;
    }


    @NonNull
    @Override
    public JobHuntCompanyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.rv_jobhunt_company, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull JobHuntCompanyAdapter.ViewHolder holder, final int position) {

        holder.hotJobCount.setText(String.valueOf(list.get(position).getJobCount()));

        List<CompanyBean.CompanyListBean.IndustryListBean> industryListBeans = list.get(position).getIndustryList();
        ListLabelAdapter adapter = new ListLabelAdapter(industryListBeans, context);
        LinearLayoutManager manager = new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        holder.label.setLayoutManager(manager);
        holder.label.setAdapter(adapter);

        if (list.get(position).getCompanyLogo() != null)
            Glide.with(context).load(list.get(position).getCompanyLogo()).into(holder.img);
        if (list.get(position).getCompanName() != null)
            holder.companyName.setText(list.get(position).getCompanName());
        if (list.get(position).getCompanySize() != null)
            holder.count.setText(list.get(position).getCompanySize());
        if (list.get(position).getPopularJobName() != null)
            holder.hotJob.setText(list.get(position).getPopularJobName());
        if (list.get(position).getCompanyNature() != null)
            holder.nature.setText(list.get(position).getCompanyNature());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (turn != null) {
                    turn.turnTo(list.get(position).getCompanyOid());
                }
            }
        });

        holder.hotJob.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (turn != null) {
                    turn.turnToZw(list.get(position).getPopularJobOid());
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        if (list.size() > 3) {
            return 3;
        } else {
            return list.size();
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final ImageView img;
        private final TextView companyName;
        private final TextView count;
        private final TextView nature;
        private final TextView hotJob;
        private final TextView hotJobCount;
        private final RecyclerView label;

        public ViewHolder(View itemView) {
            super(itemView);
            img = (ImageView) itemView.findViewById(R.id.img);
            companyName = (TextView) itemView.findViewById(R.id.tv_name);
            count = (TextView) itemView.findViewById(R.id.tv_count);
            nature = (TextView) itemView.findViewById(R.id.tv_nature);
            hotJob = (TextView) itemView.findViewById(R.id.hot_job);
            hotJobCount = (TextView) itemView.findViewById(R.id.hot_job_count);
            label = (RecyclerView) itemView.findViewById(R.id.list_label);

        }
    }

    private Turn turn;

    public void setTurn(Turn turn) {
        this.turn = turn;
    }

    public interface Turn {
        void turnTo(String CompanyOid);

        void turnToZw(String id);
    }

}