Search in sources :

Example 1 with EquipmentDao

use of cn.nicolite.palm300heroes.db.dao.EquipmentDao 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

BmobQuery (cn.bmob.v3.BmobQuery)1 BmobException (cn.bmob.v3.exception.BmobException)1 EquipmentDao (cn.nicolite.palm300heroes.db.dao.EquipmentDao)1 Equipment (cn.nicolite.palm300heroes.model.bean.Equipment)1 List (java.util.List)1