Search in sources :

Example 1 with SkillDao

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

the class HeroSkillPresenter method showSkill.

public void showSkill(final String UNCode, boolean isForce) {
    final SkillDao skillDao = getDaoSession().getSkillDao();
    if (!isForce && getView() != null) {
        List<Skill> list = skillDao.queryBuilder().where(SkillDao.Properties.UNCode.eq(UNCode)).list();
        if (!ListUtils.isEmpty(list)) {
            getView().showSkill(list);
            return;
        }
    }
    BmobQuery<Skill> query = new BmobQuery<>(Constants.BMOB_SKILL);
    query.addWhereEqualTo("UNCode", UNCode).findObjects(new FindListener<Skill>() {

        @Override
        public void done(final List<Skill> list, BmobException e) {
            if (getView() != null) {
                if (e == null) {
                    if (!ListUtils.isEmpty(list)) {
                        getView().showSkill(list);
                        if (!isSaving) {
                            isSaving = true;
                            new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    List<Skill> oldList = skillDao.queryBuilder().where(SkillDao.Properties.UNCode.eq(UNCode)).list();
                                    for (Skill skill : oldList) {
                                        skillDao.delete(skill);
                                    }
                                    for (Skill skill : list) {
                                        skillDao.save(skill);
                                    }
                                    isSaving = false;
                                }
                            }).start();
                        }
                    }
                } else {
                    getView().loadFailure();
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : Skill(cn.nicolite.palm300heroes.model.bean.Skill) BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) List(java.util.List) SkillDao(cn.nicolite.palm300heroes.db.dao.SkillDao)

Aggregations

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