use of cn.nicolite.palm300heroes.db.dao.SkinDao 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