Search in sources :

Example 1 with FightSkillDao

use of cn.nicolite.palm300heroes.db.dao.FightSkillDao in project Palm300Heroes by nicolite.

the class FightSkillPresenter method showFightSkill.

public void showFightSkill(boolean isForce) {
    final FightSkillDao fightSkillDao = getDaoSession().getFightSkillDao();
    if (!isForce && fightSkillDao.count() > 0) {
        if (getView() != null) {
            List<FightSkill> list = fightSkillDao.queryBuilder().orderAsc(FightSkillDao.Properties.Position).list();
            getView().showFightSkill(list);
        }
        return;
    }
    if (getView() != null) {
        getView().showLoading();
    }
    BmobQuery<FightSkill> query = new BmobQuery<>(Constants.BMOB_FIGHT_SKILL);
    query.setLimit(20).order("position").findObjects(new FindListener<FightSkill>() {

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

                            @Override
                            public void run() {
                                fightSkillDao.deleteAll();
                                for (FightSkill fightSkill : list) {
                                    fightSkillDao.insert(fightSkill);
                                }
                                saveFlag = false;
                            }
                        }).start();
                    }
                } else {
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) FightSkillDao(cn.nicolite.palm300heroes.db.dao.FightSkillDao) FightSkill(cn.nicolite.palm300heroes.model.bean.FightSkill)

Aggregations

BmobQuery (cn.bmob.v3.BmobQuery)1 BmobException (cn.bmob.v3.exception.BmobException)1 FightSkillDao (cn.nicolite.palm300heroes.db.dao.FightSkillDao)1 FightSkill (cn.nicolite.palm300heroes.model.bean.FightSkill)1