Search in sources :

Example 1 with Equipment

use of cn.nicolite.palm300heroes.model.bean.Equipment in project Palm300Heroes by nicolite.

the class EquJJCFragment method doBusiness.

@Override
protected void doBusiness() {
    // 根据屏幕宽度计算一行能放多少个
    int spanCount = (int) (ScreenUtils.getScreenWidth(context) / ScreenUtils.dp2px(context, 80));
    // 防止每行个数为0
    if (spanCount == 0) {
        spanCount = 4;
    }
    equJJCPresenter = new EquJJCPresenter(this, this);
    lRecyclerView.setLayoutManager(new GridLayoutManager(context, spanCount, OrientationHelper.VERTICAL, false));
    lRecyclerViewAdapter = new LRecyclerViewAdapter(new EquipmentJJCAdapter(context, dataList));
    lRecyclerView.setAdapter(lRecyclerViewAdapter);
    lRecyclerView.setLoadMoreEnabled(false);
    lRecyclerView.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh() {
            equJJCPresenter.showEquJJCList(true);
        }
    });
    lRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {

        @Override
        public void onLoadMore() {
        }
    });
    lRecyclerView.setOnNetWorkErrorListener(new OnNetWorkErrorListener() {

        @Override
        public void reload() {
        }
    });
    lRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            Equipment equipment = dataList.get(position);
            String purchasePrice = equipment.getPurchasePrice() == null ? "" : String.valueOf(equipment.getPurchasePrice());
            String compoundPrice = equipment.getCompoundPrice() == null ? "无法合成" : String.valueOf(equipment.getCompoundPrice());
            String attribute = TextUtils.isEmpty(equipment.getAttribute()) ? "无" : equipment.getAttribute();
            String skill = TextUtils.isEmpty(equipment.getSkill()) ? "无" : equipment.getSkill();
            Bundle bundle = new Bundle();
            bundle.putString("picture", equipment.getPicture());
            bundle.putString("name", equipment.getName());
            bundle.putString("pp", purchasePrice);
            bundle.putString("cp", compoundPrice);
            bundle.putString("attribute", attribute);
            bundle.putString("skill", skill);
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
                startActivity(EquJJCDetailActivity.class, bundle);
            } else {
                Bundle options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, "equJJCTransition").toBundle();
                startActivity(EquJJCDetailActivity.class, bundle, options);
            }
        }
    });
}
Also used : OnLoadMoreListener(com.github.jdsjlzx.interfaces.OnLoadMoreListener) OnNetWorkErrorListener(com.github.jdsjlzx.interfaces.OnNetWorkErrorListener) OnItemClickListener(com.github.jdsjlzx.interfaces.OnItemClickListener) Bundle(android.os.Bundle) EquipmentJJCAdapter(cn.nicolite.palm300heroes.view.oldAdapter.EquipmentJJCAdapter) BindView(butterknife.BindView) LRecyclerView(com.github.jdsjlzx.recyclerview.LRecyclerView) View(android.view.View) IEquJJCView(cn.nicolite.palm300heroes.view.iview.IEquJJCView) EquJJCDetailActivity(cn.nicolite.palm300heroes.view.activity.EquJJCDetailActivity) LRecyclerViewAdapter(com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter) GridLayoutManager(android.support.v7.widget.GridLayoutManager) Equipment(cn.nicolite.palm300heroes.model.bean.Equipment) EquJJCPresenter(cn.nicolite.palm300heroes.presenter.EquJJCPresenter) OnRefreshListener(com.github.jdsjlzx.interfaces.OnRefreshListener)

Example 2 with Equipment

use of cn.nicolite.palm300heroes.model.bean.Equipment in project Palm300Heroes by nicolite.

the class EquJJCPresenter method showEquJJCList.

public void showEquJJCList(boolean isForce) {
    final EquipmentDao equipmentDao = getDaoSession().getEquipmentDao();
    if (!isForce && equipmentDao.count() > 0) {
        if (getView() != null) {
            List<Equipment> equipmentList = equipmentDao.queryBuilder().where(EquipmentDao.Properties.Type.eq("JJC")).orderAsc(EquipmentDao.Properties.Id).list();
            getView().showEquJJCList(equipmentList);
        }
        return;
    }
    if (getView() != null) {
        getView().showLoading();
    }
    BmobQuery<Equipment> query = new BmobQuery<>(Constants.BMOB_EQUIPMENT);
    query.addWhereEqualTo("type", "JJC").order("id").setLimit(300).findObjects(new FindListener<Equipment>() {

        @Override
        public void done(final List<Equipment> list, BmobException e) {
            if (getView() != null) {
                getView().closeLoading();
                if (e == null) {
                    getView().showEquJJCList(list);
                    if (!saveFlag) {
                        saveFlag = true;
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                List<Equipment> jjcList = equipmentDao.queryBuilder().where(EquipmentDao.Properties.Type.eq("JJC")).list();
                                for (Equipment equipment : jjcList) {
                                    equipmentDao.delete(equipment);
                                }
                                for (Equipment equipment : list) {
                                    equipmentDao.insert(equipment);
                                }
                                saveFlag = false;
                            }
                        }).start();
                    }
                } else {
                    getView().loadFailure();
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) Equipment(cn.nicolite.palm300heroes.model.bean.Equipment) BmobQuery(cn.bmob.v3.BmobQuery) EquipmentDao(cn.nicolite.palm300heroes.db.dao.EquipmentDao) List(java.util.List)

Aggregations

Equipment (cn.nicolite.palm300heroes.model.bean.Equipment)2 Bundle (android.os.Bundle)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 View (android.view.View)1 BindView (butterknife.BindView)1 BmobQuery (cn.bmob.v3.BmobQuery)1 BmobException (cn.bmob.v3.exception.BmobException)1 EquipmentDao (cn.nicolite.palm300heroes.db.dao.EquipmentDao)1 EquJJCPresenter (cn.nicolite.palm300heroes.presenter.EquJJCPresenter)1 EquJJCDetailActivity (cn.nicolite.palm300heroes.view.activity.EquJJCDetailActivity)1 IEquJJCView (cn.nicolite.palm300heroes.view.iview.IEquJJCView)1 EquipmentJJCAdapter (cn.nicolite.palm300heroes.view.oldAdapter.EquipmentJJCAdapter)1 OnItemClickListener (com.github.jdsjlzx.interfaces.OnItemClickListener)1 OnLoadMoreListener (com.github.jdsjlzx.interfaces.OnLoadMoreListener)1 OnNetWorkErrorListener (com.github.jdsjlzx.interfaces.OnNetWorkErrorListener)1 OnRefreshListener (com.github.jdsjlzx.interfaces.OnRefreshListener)1 LRecyclerView (com.github.jdsjlzx.recyclerview.LRecyclerView)1 LRecyclerViewAdapter (com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter)1 List (java.util.List)1