Search in sources :

Example 6 with FindListener

use of cn.bmob.v3.listener.FindListener in project SmartCampus by Vegen.

the class HomePresenter method getBanner.

@Override
public void getBanner() {
    BmobQuery<Banner> query = new BmobQuery<Banner>();
    // 先从缓存获取数据,如果没有,再从网络获取。
    query.setCachePolicy(BmobQuery.CachePolicy.CACHE_THEN_NETWORK);
    // 按照时间降序
    query.order("-createdAt");
    Subscription subscription = query.findObjects(new FindListener<Banner>() {

        @Override
        public void done(List<Banner> list, BmobException e) {
            if (mView != null) {
                if (e == null) {
                    // 请求成功
                    mView.showBanner(list);
                    mView.hideLoading(false);
                } else {
                    mView.showMessage(HttpError.getErrorMessage(e));
                    mView.hideLoading(true);
                }
            }
        }
    });
    mHttpLinkers.add(new SubscriptionHolder(subscription));
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) Banner(com.itculturalfestival.smartcampus.entity.db.Banner) SubscriptionHolder(com.itculturalfestival.smartcampus.network.SubscriptionHolder) Subscription(rx.Subscription)

Example 7 with FindListener

use of cn.bmob.v3.listener.FindListener in project Palm300Heroes by nicolite.

the class UpdateDataModel method updateTalent.

public static void updateTalent() {
    BmobQuery<Talent> query = new BmobQuery<>(Constants.BMOB_TALENT);
    query.setLimit(45).order("position").findObjects(new FindListener<Talent>() {

        @Override
        public void done(final List<Talent> list, BmobException e) {
            if (e == null) {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        TalentDao talentDao = daoSession.getTalentDao();
                        talentDao.deleteAll();
                        for (Talent talent : list) {
                            talentDao.insert(talent);
                        }
                        progress.incrementAndGet();
                    }
                });
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) TalentDao(cn.nicolite.palm300heroes.db.dao.TalentDao) BmobQuery(cn.bmob.v3.BmobQuery) Talent(cn.nicolite.palm300heroes.model.bean.Talent)

Example 8 with FindListener

use of cn.bmob.v3.listener.FindListener in project Palm300Heroes by nicolite.

the class FightSkillPresenter method showFightSkill.

public void showFightSkill(boolean isForce) {
    final FightSkillDao fightSkillDao = getDaoSession().getFightSkillDao();
    if (!isForce && fightSkillDao.count() > 0) {
        if (getView() != null) {
            List<FightSkill> list = fightSkillDao.queryBuilder().orderAsc(FightSkillDao.Properties.Position).list();
            getView().showFightSkill(list);
        }
        return;
    }
    if (getView() != null) {
        getView().showLoading();
    }
    BmobQuery<FightSkill> query = new BmobQuery<>(Constants.BMOB_FIGHT_SKILL);
    query.setLimit(20).order("position").findObjects(new FindListener<FightSkill>() {

        @Override
        public void done(final List<FightSkill> list, BmobException e) {
            if (getView() != null) {
                getView().closeLoading();
                if (e == null) {
                    getView().showFightSkill(list);
                    if (!saveFlag) {
                        saveFlag = true;
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                fightSkillDao.deleteAll();
                                for (FightSkill fightSkill : list) {
                                    fightSkillDao.insert(fightSkill);
                                }
                                saveFlag = false;
                            }
                        }).start();
                    }
                } else {
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) FightSkillDao(cn.nicolite.palm300heroes.db.dao.FightSkillDao) FightSkill(cn.nicolite.palm300heroes.model.bean.FightSkill)

Example 9 with FindListener

use of cn.bmob.v3.listener.FindListener 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)

Example 10 with FindListener

use of cn.bmob.v3.listener.FindListener in project Palm300Heroes by nicolite.

the class HeroSkinPresenter method showSkin.

public void showSkin(final String UNCode, boolean isForce) {
    final SkinDao skinDao = getDaoSession().getSkinDao();
    if (!isForce && getView() != null) {
        List<Skin> list = skinDao.queryBuilder().where(SkinDao.Properties.UNCode.eq(UNCode)).list();
        if (!ListUtils.isEmpty(list)) {
            getView().showSkin(list);
            return;
        }
    }
    BmobQuery<Skin> query = new BmobQuery<>(Constants.BMOB_SKin);
    query.addWhereEqualTo("UNCode", UNCode).findObjects(new FindListener<Skin>() {

        @Override
        public void done(final List<Skin> list, BmobException e) {
            if (getView() != null) {
                if (e == null) {
                    getView().showSkin(list);
                    if (!isSaving) {
                        isSaving = true;
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                List<Skin> oldList = skinDao.queryBuilder().where(SkinDao.Properties.UNCode.eq(UNCode)).list();
                                for (Skin skin : oldList) {
                                    skinDao.delete(skin);
                                }
                                for (Skin skin : list) {
                                    skinDao.insert(skin);
                                }
                                isSaving = false;
                            }
                        }).start();
                    }
                } else {
                    getView().loadFailure();
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) SkinDao(cn.nicolite.palm300heroes.db.dao.SkinDao) BmobQuery(cn.bmob.v3.BmobQuery) Skin(cn.nicolite.palm300heroes.model.bean.Skin) List(java.util.List)

Aggregations

BmobQuery (cn.bmob.v3.BmobQuery)23 BmobException (cn.bmob.v3.exception.BmobException)16 BmobUser (cn.bmob.v3.BmobUser)12 User (com.nightonke.saver.model.User)8 File (java.io.File)8 Logo (com.nightonke.saver.model.Logo)7 Bitmap (android.graphics.Bitmap)6 FutureCallback (com.koushikdutta.async.future.FutureCallback)6 FileInputStream (java.io.FileInputStream)6 FileNotFoundException (java.io.FileNotFoundException)6 List (java.util.List)6 BmobFile (cn.bmob.v3.datatype.BmobFile)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 UpdateListener (cn.bmob.v3.listener.UpdateListener)3 UserDqInfomation (com.yuxuan.admin.expression.entity.UserDqInfomation)3 SaveListener (cn.bmob.v3.listener.SaveListener)2 TalentDao (cn.nicolite.palm300heroes.db.dao.TalentDao)2 Talent (cn.nicolite.palm300heroes.model.bean.Talent)2 BmobProFile (com.bmob.BmobProFile)2