Search in sources :

Example 1 with SoundDao

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());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) Sound(cn.nicolite.palm300heroes.model.bean.Sound) List(java.util.List) SoundDao(cn.nicolite.palm300heroes.db.dao.SoundDao)

Aggregations

BmobQuery (cn.bmob.v3.BmobQuery)1 BmobException (cn.bmob.v3.exception.BmobException)1 SoundDao (cn.nicolite.palm300heroes.db.dao.SoundDao)1 Sound (cn.nicolite.palm300heroes.model.bean.Sound)1 List (java.util.List)1