use of cn.nicolite.palm300heroes.db.dao.SoundDao in project Palm300Heroes by nicolite.
the class HeroSoundPresenter method showSound.
public void showSound(final String UNCode, boolean isForce) {
final SoundDao soundDao = getDaoSession().getSoundDao();
if (!isForce && getView() != null) {
List<Sound> list = soundDao.queryBuilder().where(SoundDao.Properties.UNCode.eq(UNCode)).list();
if (!ListUtils.isEmpty(list)) {
getView().showSound(list);
return;
}
}
BmobQuery<Sound> query = new BmobQuery<>(Constants.BMOB_Sound);
query.addWhereEqualTo("UNCode", UNCode).findObjects(new FindListener<Sound>() {
@Override
public void done(final List<Sound> list, BmobException e) {
if (getView() != null) {
if (e == null) {
getView().showSound(list);
if (!isSaving) {
isSaving = true;
new Thread(new Runnable() {
@Override
public void run() {
List<Sound> oldList = soundDao.queryBuilder().where(SoundDao.Properties.UNCode.eq(UNCode)).list();
for (Sound sound : oldList) {
soundDao.delete(sound);
}
for (Sound sound : list) {
soundDao.insert(sound);
}
isSaving = false;
}
}).start();
}
} else {
getView().loadFailure();
BmobUtils.showErrorMessage(e.toString());
}
}
}
});
}
Aggregations