PraticeWrongFragment.java 4.1 KB
package com.hh.xuetubao.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.hh.xuetubao.R;
import com.hh.xuetubao.Utils.SharedPrefrenceUtils;
import com.hh.xuetubao.activity.pratice.c;
import com.hh.xuetubao.adapter.PractiveWrongAdapter;
import com.hh.xuetubao.bean.AnswerBean;
import com.hh.xuetubao.model.ExerciseModel;
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.List;

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

/**
 * 我的错题
 */
public class PraticeWrongFragment extends BaseMvpFragment<CommonPresenter, ExerciseModel> implements ICommonView {

    @BindView(R.id.listview)
    ListView listview;
    Unbinder unbinder;
    @BindView(R.id.tv_num)
    TextView tvNum;
    private PractiveWrongAdapter practiveWrongAdapter;
    private List<AnswerBean.CatalogLstBean> catalogLst = new ArrayList<>();
    private PraticeWrongFragment fragment;
    private String accountOid;
    private int count;

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

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {
        accountOid = SharedPrefrenceUtils.getString(getActivity(), "AccountOid");

        practiveWrongAdapter = new PractiveWrongAdapter(catalogLst, getActivity());
        listview.setAdapter(practiveWrongAdapter);
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                Intent intent = new Intent(getActivity(), AnswerWrongActivity.class);
                Intent intent = new Intent(getActivity(), c.class);
                intent.putExtra("catalogOid", catalogLst.get(position).getCatalogOid());
                startActivity(intent);
            }
        });

    }

    @Override
    public void onResume() {
        super.onResume();
        mPresenter.getPresenter(6, 1, accountOid);
    }

    @Override
    public void initData() {
        mPresenter.getPresenter(6, 1, accountOid);
    }

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

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


    @Override
    public void getData(Object o, int api, int intent) {
        if (api == 6 && intent == 1) {
            count=0;
            catalogLst.clear();
            AnswerBean bean = (AnswerBean) o;
            List<AnswerBean.CatalogLstBean> catalogLstBeans = bean.getCatalogLst();

            for (int i = 0; i < catalogLstBeans.size(); i++) {
                count += catalogLstBeans.get(i).getWrongNum();
                Log.e("xuetubao", String.valueOf(count));
            }
            tvNum.setText(String.valueOf(count));

            catalogLst.addAll(catalogLstBeans);
            practiveWrongAdapter.notifyDataSetChanged();
        }

    }

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

    public static void onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == event.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {

            Log.e("zhangtao", "你点击了回退建");
        }

    }
}