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