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));
}
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();
}
});
}
}
});
}
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());
}
}
}
});
}
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());
}
}
}
});
}
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());
}
}
}
});
}
Aggregations