use of cn.nicolite.palm300heroes.db.dao.HeroBaseDataDao in project Palm300Heroes by nicolite.
the class HeroDataPresenter method showHeroData.
public void showHeroData(final String UNCode, boolean isForce) {
final HeroBaseDataDao heroBaseDataDao = getDaoSession().getHeroBaseDataDao();
if (!isForce && getView() != null) {
List<HeroBaseData> list = heroBaseDataDao.queryBuilder().where(HeroBaseDataDao.Properties.UNCode.eq(UNCode)).list();
if (!ListUtils.isEmpty(list)) {
getView().showHeroData(list.get(0));
return;
}
}
BmobQuery<HeroBaseData> query = new BmobQuery<>(Constants.BMOB_HERO_DETAIL);
query.addWhereEqualTo("UNCode", UNCode).findObjects(new FindListener<HeroBaseData>() {
@Override
public void done(final List<HeroBaseData> list, BmobException e) {
if (getView() != null) {
if (e == null) {
if (!ListUtils.isEmpty(list)) {
getView().showHeroData(list.get(0));
if (!isSaving) {
isSaving = true;
new Thread(new Runnable() {
@Override
public void run() {
List<HeroBaseData> oldList = heroBaseDataDao.queryBuilder().where(HeroBaseDataDao.Properties.UNCode.eq(UNCode)).list();
for (HeroBaseData heroBaseData : oldList) {
heroBaseDataDao.delete(heroBaseData);
}
for (HeroBaseData heroBaseData : list) {
heroBaseDataDao.insert(heroBaseData);
}
isSaving = false;
}
}).start();
}
} else {
getView().showMessage("暂时没有相关数据");
getView().loadFailure();
}
} else {
getView().loadFailure();
BmobUtils.showErrorMessage(e.toString());
}
}
}
});
}
Aggregations