Search in sources :

Example 1 with SkinDao

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());
                }
            }
        }
    });
}
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)1 BmobException (cn.bmob.v3.exception.BmobException)1 SkinDao (cn.nicolite.palm300heroes.db.dao.SkinDao)1 Skin (cn.nicolite.palm300heroes.model.bean.Skin)1 List (java.util.List)1