use of cn.nicolite.palm300heroes.db.dao.HeroDao in project Palm300Heroes by nicolite.
the class HeroListPresenter method showHeroList.
public void showHeroList(boolean isForce) {
final HeroDao heroDao = getDaoSession().getHeroDao();
if (!isForce && heroDao.count() > 0) {
if (getView() != null) {
List<Hero> heroList = heroDao.queryBuilder().orderDesc(HeroDao.Properties.Position).list();
getView().showHeroList(heroList);
}
return;
}
if (getView() != null) {
getView().showLoading();
}
BmobQuery<Hero> query = new BmobQuery<>(Constants.BMOB_HERO);
query.setLimit(300).order("-position").findObjects(new FindListener<Hero>() {
@Override
public void done(final List<Hero> list, BmobException e) {
if (getView() != null) {
getView().closeLoading();
if (e == null) {
getView().showHeroList(list);
if (!saveFlag) {
saveFlag = true;
new Thread(new Runnable() {
@Override
public void run() {
heroDao.deleteAll();
for (Hero hero : list) {
heroDao.insert(hero);
}
saveFlag = false;
}
}).start();
}
} else {
getView().loadFailure();
BmobUtils.showErrorMessage(e.toString());
}
}
}
});
}
Aggregations