Search in sources :

Example 1 with HeroBaseData

use of cn.nicolite.palm300heroes.model.bean.HeroBaseData 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());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) List(java.util.List) HeroBaseData(cn.nicolite.palm300heroes.model.bean.HeroBaseData) HeroBaseDataDao(cn.nicolite.palm300heroes.db.dao.HeroBaseDataDao)

Aggregations

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