JobHuntFragment.java 7.2 KB
package com.hh.xuetubao.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
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.LinearLayout;

import com.hh.xuetubao.R;
import com.hh.xuetubao.Utils.RecyclerViewSpacesItemDecoration;
import com.hh.xuetubao.activity.personal.DeliveryActivity;
import com.hh.xuetubao.activity.work.CompanyActivity;
import com.hh.xuetubao.activity.work.CompanyDetailActivity;
import com.hh.xuetubao.activity.work.JobHuntActivity;
import com.hh.xuetubao.activity.work.OfficeDetailActivity;
import com.hh.xuetubao.adapter.JobHuntCompanyAdapter;
import com.hh.xuetubao.adapter.JobHuntWorkAdapter;
import com.hh.xuetubao.bean.CompanyBean;
import com.hh.xuetubao.bean.HotJobBean;
import com.hh.xuetubao.model.ZhaopinModel;
import com.hh.xuetubao.mvp.BaseMvpFragment;
import com.hh.xuetubao.mvp.CommonPresenter;
import com.hh.xuetubao.mvp.ICommonView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 求职圈
 */
public class JobHuntFragment extends BaseMvpFragment<CommonPresenter, ZhaopinModel> implements ICommonView, View.OnClickListener, JobHuntCompanyAdapter.Turn, JobHuntWorkAdapter.JumpToDetail {


    Unbinder unbinder;
    @BindView(R.id.rv_company)
    RecyclerView rvCompany;
    @BindView(R.id.rv_work)
    RecyclerView rvWork;
    @BindView(R.id.lin_more_company)
    LinearLayout linMoreCompany;
    @BindView(R.id.zhiwei_more)
    LinearLayout zhiweiMore;
    @BindView(R.id.img_zhiwei)
    ImageView imgZhiwei;
    @BindView(R.id.img_company)
    ImageView imgCompany;
    @BindView(R.id.image_tdjl)
    ImageView imageTdjl;
    private JobHuntCompanyAdapter adapter;
    private JobHuntWorkAdapter workAdapter;
    private List<CompanyBean.CompanyListBean> companyList = new ArrayList<>();
    private List<HotJobBean.JobListBean> jobList = new ArrayList<>();
    //    private OfficeFragment officeFragment;
//    private FragmentTransaction transaction;
    private Intent intent;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_job_hunt;
    }

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {

        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvCompany.setLayoutManager(manager);

        HashMap<String, Integer> stringIntegerHashMap = new HashMap<>();
        stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.RIGHT_DECORATION, 20);//右间距
        rvCompany.addItemDecoration(new RecyclerViewSpacesItemDecoration(stringIntegerHashMap));

        adapter = new JobHuntCompanyAdapter(getActivity(), companyList);
        rvCompany.setAdapter(adapter);
        adapter.setTurn(this);

        LinearLayoutManager manager1 = new LinearLayoutManager(getActivity());
        rvWork.setLayoutManager(manager1);
        workAdapter = new JobHuntWorkAdapter(getActivity(), jobList);
        rvWork.setAdapter(workAdapter);
        workAdapter.setJumpToDetail(this);
        rvWork.setNestedScrollingEnabled(false);

        linMoreCompany.setOnClickListener(this);
        zhiweiMore.setOnClickListener(this);
        imgZhiwei.setOnClickListener(this);
        imgCompany.setOnClickListener(this);
        imageTdjl.setOnClickListener(this);

    }

    @Override
    public void initData() {
        ZhaopinModel model = new ZhaopinModel();
        model.getModel(this, 3, 1, String.valueOf(10));
        model.getModel(this, 3, 2, String.valueOf(10));

    }

    @Override
    public CommonPresenter getPresenter() {
        return new CommonPresenter();
    }

    @Override
    public ZhaopinModel getModel() {
        return new ZhaopinModel();
    }

    @Override
    public void getData(Object o, int api, int intent) {
        if (api == 3 && intent == 1) {
            CompanyBean bean = (CompanyBean) o;
            List<CompanyBean.CompanyListBean> companyListBeans = bean.getCompanyList();

            companyList.addAll(companyListBeans);
            adapter.notifyDataSetChanged();

            if (companyList.size() > 3) {
                linMoreCompany.setVisibility(View.VISIBLE);
            } else {
                linMoreCompany.setVisibility(View.GONE);
            }
        }
        if (api == 3 && intent == 2) {
            HotJobBean bean = (HotJobBean) o;
            List<HotJobBean.JobListBean> beanJobList = bean.getJobList();

            jobList.addAll(beanJobList);
            workAdapter.notifyDataSetChanged();

            if (jobList.size() > 3) {
                zhiweiMore.setVisibility(View.VISIBLE);
            } else {
                zhiweiMore.setVisibility(View.GONE);
            }
        }
    }

    @Override
    public void onComplete(int api) {

    }

    @Override
    public void onError(Throwable e, int api) {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.img_company:   // 顶部公司
            case R.id.lin_more_company:
                startActivity(new Intent(getActivity(), CompanyActivity.class));
                break;

            case R.id.zhiwei_more:
            case R.id.img_zhiwei:

                Intent intent1 = new Intent(getActivity(), JobHuntActivity.class);
                intent1.putExtra("jobTag", "1");
                startActivity(intent1);

                getActivity().finish();
//                transaction = getActivity().getSupportFragmentManager().beginTransaction();
//                officeFragment = new OfficeFragment();
//                transaction.replace(R.id.frame, officeFragment);
//                transaction.commit();
                break;
            case R.id.image_tdjl: // 投递记录
                Intent intent = new Intent(getActivity(), DeliveryActivity.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void turnTo(String CompanyOid) {
        intent = new Intent(getActivity(), CompanyDetailActivity.class);
        intent.putExtra("CompanyOid", CompanyOid);
        startActivity(intent);
    }

    // 职位id
    @Override
    public void turnToZw(String id) {
        intent = new Intent(getActivity(), OfficeDetailActivity.class);
        intent.putExtra("JobOid", id);
        startActivity(intent);
    }

    @Override
    public void turnToDetail(String JobOid) {
        intent = new Intent(getActivity(), OfficeDetailActivity.class);
        intent.putExtra("JobOid", JobOid);
        startActivity(intent);
    }

}