IntroduceFragment.java 3.6 KB
package com.hh.xuetubao.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.TextView;

import com.hh.xuetubao.R;
import com.hh.xuetubao.adapter.IntroduceGridAdapter;
import com.hh.xuetubao.bean.CourseDetailInfoBean;
import com.hh.xuetubao.bean.Event;
import com.hh.xuetubao.model.LearnModel;
import com.hh.xuetubao.mvp.BaseMvpFragment;
import com.hh.xuetubao.mvp.CommonPresenter;
import com.hh.xuetubao.mvp.ICommonView;

import org.greenrobot.eventbus.EventBus;

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

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

/**
 * 介绍Fragment
 */
public class IntroduceFragment extends BaseMvpFragment<CommonPresenter, LearnModel> implements ICommonView {

    Unbinder unbinder;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_count_people)
    TextView tvCount;
    @BindView(R.id.tv_sort)
    TextView tvSort;
    @BindView(R.id.tv_jianjie_show)
    TextView tvJianjieShow;
    @BindView(R.id.gridview)
    GridView gridview;
    private String lessonOid;
    private LearnModel model;
    private List<String> list = new ArrayList<>();
    private IntroduceGridAdapter gridAdapter;

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

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

        lessonOid = getTag();

        tvTitle.setFocusable(true);
        tvTitle.setFocusableInTouchMode(true);
        tvTitle.requestFocus();

        gridAdapter = new IntroduceGridAdapter(list, getActivity());
        gridview.setAdapter(gridAdapter);
    }

    @Override
    public void initData() {

        model = new LearnModel();
        model.getModel(this, 2, 1, lessonOid);
    }

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

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

    @Override
    public void getData(Object o, int api, int intent) {
        if (api == 2 && intent == 1) {
            CourseDetailInfoBean bean = (CourseDetailInfoBean) o;
            Log.e("zhangtao", bean.toString());
            tvCount.setText(bean.getLearningPeopleCount());
            if (bean.getLessonName() != null)
                tvTitle.setText(bean.getLessonName());
            if (bean.getDifficult() != null)
                tvSort.setText(bean.getDifficult());
            if (bean.getLessonDesc() != null)
                tvJianjieShow.setText(bean.getLessonDesc());
            if (bean.getSkillLst() != null)
                list.addAll(bean.getSkillLst());
            gridAdapter.notifyDataSetChanged();
            if (bean.getLessonCoverUrl() != null) {
                Event event = new Event(2, null, null, null, null, bean.getLessonCoverUrl());
                EventBus.getDefault().postSticky(event);
            }
        }
    }

    @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();
    }
}