Search in sources :

Example 16 with FindListener

use of cn.bmob.v3.listener.FindListener in project CoCoin by Nightonke.

the class AccountBookSettingActivity method downloadLogoFromServer.

// download logo to local///////////////////////////////////////////////////////////////////////////
private void downloadLogoFromServer() {
    User user = getCurrentUser();
    if (user.getLogoObjectId() == null) {
        // the user has no logo
        return;
    }
    BmobQuery<Logo> bmobQuery = new BmobQuery();
    bmobQuery.addWhereEqualTo("objectId", user.getLogoObjectId());
    bmobQuery.findObjects(CoCoinApplication.getAppContext(), new FindListener<Logo>() {

        @Override
        public void onSuccess(List<Logo> object) {
            // there has been an old logo in the server/////////////////////////////////////////////////////////
            Log.d("Saver", "There is an old logo");
            String url = object.get(0).getFile().getUrl();
            Ion.with(CoCoinApplication.getAppContext()).load(url).write(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)).setCallback(new FutureCallback<File>() {

                @Override
                public void onCompleted(Exception e, File file) {
                    Bitmap bitmap = BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
                    if (bitmap == null) {
                        Log.d("Saver", "Logo misses");
                    } else {
                        logo.setImageBitmap(bitmap);
                    }
                    SettingManager.getInstance().setHasLogo(true);
                }
            });
            SettingManager.getInstance().setTodayViewLogoShouldChange(true);
        }

        @Override
        public void onError(int code, String msg) {
            // the picture is lost
            Log.d("Saver", "Can't find the old logo in server.");
        }
    });
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) BmobFile(cn.bmob.v3.datatype.BmobFile) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Example 17 with FindListener

use of cn.bmob.v3.listener.FindListener in project Palm300Heroes by nicolite.

the class TalentPresenter method showTalent.

public void showTalent(boolean isForce) {
    final TalentDao talentDao = getDaoSession().getTalentDao();
    if (!isForce && talentDao.count() > 0) {
        if (getView() != null) {
            List<Talent> list = talentDao.queryBuilder().orderAsc(TalentDao.Properties.Position).list();
            getView().showTalentList(list);
        }
        return;
    }
    if (getView() != null) {
        getView().showLoading();
    }
    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 (getView() != null) {
                getView().closeLoading();
                if (e == null) {
                    getView().showTalentList(list);
                    if (!saveFlag) {
                        saveFlag = true;
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                for (Talent talent : list) {
                                    talentDao.insert(talent);
                                }
                                saveFlag = false;
                            }
                        });
                    }
                } else {
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : TalentDao(cn.nicolite.palm300heroes.db.dao.TalentDao) BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) Talent(cn.nicolite.palm300heroes.model.bean.Talent)

Example 18 with FindListener

use of cn.bmob.v3.listener.FindListener in project Palm300Heroes by nicolite.

the class EquJJCPresenter method showEquJJCList.

public void showEquJJCList(boolean isForce) {
    final EquipmentDao equipmentDao = getDaoSession().getEquipmentDao();
    if (!isForce && equipmentDao.count() > 0) {
        if (getView() != null) {
            List<Equipment> equipmentList = equipmentDao.queryBuilder().where(EquipmentDao.Properties.Type.eq("JJC")).orderAsc(EquipmentDao.Properties.Id).list();
            getView().showEquJJCList(equipmentList);
        }
        return;
    }
    if (getView() != null) {
        getView().showLoading();
    }
    BmobQuery<Equipment> query = new BmobQuery<>(Constants.BMOB_EQUIPMENT);
    query.addWhereEqualTo("type", "JJC").order("id").setLimit(300).findObjects(new FindListener<Equipment>() {

        @Override
        public void done(final List<Equipment> list, BmobException e) {
            if (getView() != null) {
                getView().closeLoading();
                if (e == null) {
                    getView().showEquJJCList(list);
                    if (!saveFlag) {
                        saveFlag = true;
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                List<Equipment> jjcList = equipmentDao.queryBuilder().where(EquipmentDao.Properties.Type.eq("JJC")).list();
                                for (Equipment equipment : jjcList) {
                                    equipmentDao.delete(equipment);
                                }
                                for (Equipment equipment : list) {
                                    equipmentDao.insert(equipment);
                                }
                                saveFlag = false;
                            }
                        }).start();
                    }
                } else {
                    getView().loadFailure();
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : BmobException(cn.bmob.v3.exception.BmobException) Equipment(cn.nicolite.palm300heroes.model.bean.Equipment) BmobQuery(cn.bmob.v3.BmobQuery) EquipmentDao(cn.nicolite.palm300heroes.db.dao.EquipmentDao) List(java.util.List)

Example 19 with FindListener

use of cn.bmob.v3.listener.FindListener in project Palm300Heroes by nicolite.

the class HeroSkillPresenter method showSkill.

public void showSkill(final String UNCode, boolean isForce) {
    final SkillDao skillDao = getDaoSession().getSkillDao();
    if (!isForce && getView() != null) {
        List<Skill> list = skillDao.queryBuilder().where(SkillDao.Properties.UNCode.eq(UNCode)).list();
        if (!ListUtils.isEmpty(list)) {
            getView().showSkill(list);
            return;
        }
    }
    BmobQuery<Skill> query = new BmobQuery<>(Constants.BMOB_SKILL);
    query.addWhereEqualTo("UNCode", UNCode).findObjects(new FindListener<Skill>() {

        @Override
        public void done(final List<Skill> list, BmobException e) {
            if (getView() != null) {
                if (e == null) {
                    if (!ListUtils.isEmpty(list)) {
                        getView().showSkill(list);
                        if (!isSaving) {
                            isSaving = true;
                            new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    List<Skill> oldList = skillDao.queryBuilder().where(SkillDao.Properties.UNCode.eq(UNCode)).list();
                                    for (Skill skill : oldList) {
                                        skillDao.delete(skill);
                                    }
                                    for (Skill skill : list) {
                                        skillDao.save(skill);
                                    }
                                    isSaving = false;
                                }
                            }).start();
                        }
                    }
                } else {
                    getView().loadFailure();
                    BmobUtils.showErrorMessage(e.toString());
                }
            }
        }
    });
}
Also used : Skill(cn.nicolite.palm300heroes.model.bean.Skill) BmobException(cn.bmob.v3.exception.BmobException) BmobQuery(cn.bmob.v3.BmobQuery) List(java.util.List) SkillDao(cn.nicolite.palm300heroes.db.dao.SkillDao)

Example 20 with FindListener

use of cn.bmob.v3.listener.FindListener 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)23 BmobException (cn.bmob.v3.exception.BmobException)16 BmobUser (cn.bmob.v3.BmobUser)12 User (com.nightonke.saver.model.User)8 File (java.io.File)8 Logo (com.nightonke.saver.model.Logo)7 Bitmap (android.graphics.Bitmap)6 FutureCallback (com.koushikdutta.async.future.FutureCallback)6 FileInputStream (java.io.FileInputStream)6 FileNotFoundException (java.io.FileNotFoundException)6 List (java.util.List)6 BmobFile (cn.bmob.v3.datatype.BmobFile)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 UpdateListener (cn.bmob.v3.listener.UpdateListener)3 UserDqInfomation (com.yuxuan.admin.expression.entity.UserDqInfomation)3 SaveListener (cn.bmob.v3.listener.SaveListener)2 TalentDao (cn.nicolite.palm300heroes.db.dao.TalentDao)2 Talent (cn.nicolite.palm300heroes.model.bean.Talent)2 BmobProFile (com.bmob.BmobProFile)2