Search in sources :

Example 1 with HeroDao

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());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) Hero(cn.nicolite.palm300heroes.model.bean.Hero) HeroDao(cn.nicolite.palm300heroes.db.dao.HeroDao)

Aggregations

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